@@ -43,15 +43,15 @@ def __init__(self, name=None, section=None, kw=None, custom_loader=None, postpro
4343 self ._binary_section = binary_section
4444 self ._binary_process = binary_process
4545
46- def _load_value (self , data , path_to_results , basename , logger ):
47- __import__ ('ipdb' ).set_trace ()
46+ def _load_value (self , data , binary_data , logger ):
4847 if self ._binary_file is not None :
49- val = self ._load_ecl_binary_value (path_to_results , basename , logger )
48+ val = self ._load_ecl_binary_value (binary_data , logger )
5049 else :
5150 val = None
5251 if val is not None :
5352 self ._value = val
5453 return self
54+ __import__ ('pdb' ).set_trace ()
5555 if self ._custom_loader is not None :
5656 self ._value = self ._custom_loader (data )
5757 return self
@@ -62,21 +62,30 @@ def _load_value(self, data, path_to_results, basename, logger):
6262 self ._value = self ._not_present
6363 return self
6464
65- def _load_ecl_binary_value (self , path_to_results , basename , logger ):
66- path = get_single_path (path_to_results , basename + self ._binary_file , logger )
67- if path is None :
65+ def _load_ecl_binary_value (self , binary_data , logger ):
66+ if binary_data is None :
6867 return None
69- attrs = [self ._binary_section ]
70- sections = read_ecl_bin (path , attrs , logger = logger )
71- if self ._binary_section in sections :
72- val = sections [self ._binary_section ]
73- if self ._binary_process is not None :
74- return self ._binary_process (val )
75- else :
68+ if self ._binary_file not in binary_data :
7669 return None
70+ file_data = binary_data [self ._binary_file ]
71+ val = file_data .find_unique (self ._binary_section )
72+ if val is None :
73+ return None
74+ if self ._binary_process is not None :
75+ return self ._binary_process (file_data [val ].value )
76+ return file_data [val ].value
7777
78- def load (self , data , path_to_results , basename , logger ):
79- self ._load_value (data , path_to_results , basename , logger )
78+ def load (self , data , binary_data , logger ):
79+ self ._load_value (data , binary_data , logger )
80+
81+ @property
82+ def value (self ):
83+ """The value property."""
84+ return self ._value
85+
86+ @value .setter
87+ def value (self , value ):
88+ self ._value = value
8089
8190MAX_STRLEN = 40
8291
@@ -100,18 +109,20 @@ class BaseComponent:
100109 """Base class for components of geological model."""
101110
102111 _attributes_to_load = []
103- def __init__ (self , * args , ** kwargs ):
104- _ = args
112+ def __init__ (self , dump = None , field = None ):
113+ self ._field = None
114+ if dump is not None :
115+ self ._attributes = dump ['attributes' ]
116+ self .field = dump ['field' ]
117+ self ._state = dump ['state' ]
118+ return None
119+ self ._attributes = []
105120 self ._state = State ()
106- self ._class_name = kwargs .pop ('class_name' , self .__class__ .__name__ )
107- self ._data = {}
108- if 'field' in kwargs :
109- self .field = kwargs ['field' ]
110- else :
111- self .field = None
112- for k , v in kwargs .items ():
113- if k != 'field' :
114- setattr (self , k , v )
121+ # self._class_name = kwargs.pop('class_name', self.__class__.__name__)
122+ self .field = field
123+ # for k, v in kwargs.items():
124+ # if k != 'field':
125+ # setattr(self, k, v)
115126
116127 @property
117128 def field (self ):
@@ -130,7 +141,7 @@ def field(self, field):
130141 @property
131142 def attributes (self ):
132143 """Array of attributes."""
133- return tuple (self ._data . keys ( ))
144+ return tuple (( attr . name for attr in self ._attributes ))
134145
135146 @property
136147 def empty (self ):
@@ -147,7 +158,7 @@ def values(self):
147158
148159 def items (self ):
149160 """Returns pairs of attribute's names and data."""
150- return self . _data . items ( )
161+ return (( attr . name , attr . value ) for attr in self . _attributes )
151162
152163 @property
153164 def state (self ):
@@ -157,11 +168,11 @@ def state(self):
157168 @property
158169 def class_name (self ):
159170 """Name of the component."""
160- return self ._class_name
171+ return self .__class__ . __name__
161172
162- @class_name .setter
163- def class_name (self , v ):
164- self ._class_name = v
173+ # @class_name.setter
174+ # def class_name(self, v):
175+ # self._class_name = v
165176
166177 def empty_like (self ):
167178 """Get an empty component with the same state and the structure of embedded BaseComponents (if any)."""
@@ -187,18 +198,28 @@ def del_state(self, *args):
187198 return self
188199
189200 def __getattr__ (self , key ):
190- if key .upper () in self ._data :
191- return self ._data [key .upper ()]
201+ for attr in self ._attributes :
202+ if key .upper () == attr .name :
203+ return attr .value
192204 raise AttributeError ("{} has no attribute {}" .format (self .class_name , key ))
205+ def dump_dict (self ):
206+ return {
207+ 'attributes' : deepcopy (self ._attributes ),
208+ 'field' : self .field ,
209+ 'state' : self .state
210+ }
193211
194212 def __getitem__ (self , key ):
195213 return getattr (self , key )
196214
197215 def __setattr__ (self , key , value ):
198216 if (key [0 ] == '_' ) or (key in dir (self )):
199217 return super ().__setattr__ (key , value )
200- self ._data [key .upper ()] = value
201- return self
218+ for att in self ._attributes :
219+ if key == att .name :
220+ att .value = value
221+ return None
222+ raise AttributeError (f'{ self .class_name } has no attribute { key } .' )
202223
203224 def __setitem__ (self , key , value ):
204225 return setattr (self , key , value )
@@ -335,11 +356,11 @@ def load(self, path_or_buffer, **kwargs):
335356 return self ._get_fmt_loader (fmt )(path_or_buffer , ** kwargs )
336357 return self ._read_buffer (path_or_buffer , ** kwargs )
337358
338- def load (self , data , path_to_results , basename , logger ):
359+ def load (self , data , binary_data , logger ):
339360 """Load data."""
340361 self ._attributes = deepcopy (self ._attributes_to_load )
341362 for attr in self ._attributes :
342- attr .load (data , path_to_results , basename , logger )
363+ attr .load (data , binary_data , logger )
343364
344365
345366 def _load_ecl_binary (self , path_to_results , ** kwargs ):
0 commit comments