@@ -52,20 +52,20 @@ def __init__(
5252 )
5353
5454 def initialize (self ):
55- if self .open_geoh5 :
56- self ._geoh5 .open (mode = "r+" )
55+ if self .open_geoh5 and not getattr ( self . _workspace , "_geoh5" , None ) :
56+ self ._workspace .open (mode = "r+" )
5757
5858 self .write (0 )
5959
6060 if self .close_geoh5 :
61- self ._geoh5 .close ()
61+ self ._workspace .close ()
6262
6363 def endIter (self ):
64- if self .open_geoh5 :
65- self ._geoh5 .open (mode = "r+" )
64+ if self .open_geoh5 and not getattr ( self . _workspace , "_geoh5" , None ) :
65+ self ._workspace .open (mode = "r+" )
6666 self .write (self .opt .iter )
6767 if self .close_geoh5 :
68- self ._geoh5 .close ()
68+ self ._workspace .close ()
6969
7070 def get_names (
7171 self , component : str , channel : str , iteration : int
@@ -127,7 +127,7 @@ def h5_object(self, entity: ObjectBase):
127127 )
128128
129129 self ._h5_object = entity .uid
130- self ._geoh5 = entity .workspace
130+ self ._workspace = entity .workspace
131131
132132 if getattr (entity , "n_cells" , None ) is not None :
133133 self .association = "CELL"
@@ -263,7 +263,7 @@ def write(self, iteration: int, values: list[np.ndarray] = None): # flake8: noq
263263 prop = self .apply_transformations (prop )
264264
265265 # Save results
266- with fetch_active_workspace (self ._geoh5 , mode = "r+" ) as w_s :
266+ with fetch_active_workspace (self ._workspace , mode = "r+" ) as w_s :
267267 h5_object = w_s .get_entity (self .h5_object )[0 ]
268268 for cc , component in enumerate (self .components ):
269269 if component not in self .data_type :
@@ -386,7 +386,7 @@ def joint_index(self, value: list[int] | None):
386386class SaveLogFilesGeoH5 (BaseSaveGeoH5 ):
387387
388388 def write (self , iteration : int , ** _ ):
389- dirpath = Path (self ._geoh5 .h5file ).parent
389+ dirpath = Path (self ._workspace .h5file ).parent
390390 filepath = dirpath / "SimPEG.out"
391391
392392 if iteration == 0 :
@@ -412,9 +412,9 @@ def save_log(self):
412412 """
413413 Save iteration metrics to comments.
414414 """
415- dirpath = Path (self ._geoh5 .h5file ).parent
415+ dirpath = Path (self ._workspace .h5file ).parent
416416
417- with fetch_active_workspace (self ._geoh5 , mode = "r+" ) as w_s :
417+ with fetch_active_workspace (self ._workspace , mode = "r+" ) as w_s :
418418 h5_object = w_s .get_entity (self .h5_object )[0 ]
419419
420420 for file in ["SimPEG.out" , "SimPEG.log" , "ChiFactors.log" ]:
@@ -452,7 +452,7 @@ def write(self, iteration: int, **_):
452452 """
453453 Save the model to the geoh5 file
454454 """
455- with fetch_active_workspace (self ._geoh5 , mode = "r+" ) as w_s :
455+ with fetch_active_workspace (self ._workspace , mode = "r+" ) as w_s :
456456 h5_object = w_s .get_entity (self .h5_object )[0 ]
457457
458458 for component in self .components :
@@ -560,7 +560,7 @@ def write(self, iteration: int, values: list[np.ndarray] | None = None):
560560 petro_model = self .get_values (values )
561561 petro_model = self .apply_transformations (petro_model ).flatten ()
562562 channel_name , _ = self .get_names ("petrophysics" , "" , iteration )
563- with fetch_active_workspace (self ._geoh5 , mode = "r+" ) as w_s :
563+ with fetch_active_workspace (self ._workspace , mode = "r+" ) as w_s :
564564 h5_object = w_s .get_entity (self .h5_object )[0 ]
565565 data = h5_object .add_data (
566566 {
0 commit comments