88from .directives import InversionDirective
99from simpeg .maps import IdentityMap
1010
11+ from geoh5py .data import NumericData
1112from geoh5py .groups .property_group import GroupTypeEnum
12- from geoh5py .groups import PropertyGroup , UIJsonGroup
13+ from geoh5py .groups import UIJsonGroup
1314from geoh5py .objects import ObjectBase
1415from geoh5py .ui_json .utils import fetch_active_workspace
1516
@@ -419,7 +420,7 @@ def save_log(self):
419420
420421class SavePropertyGroup (BaseSaveGeoH5 ):
421422 """
422- Save the model as a property group in the geoh5 file
423+ Assign the data to a property group in the geoh5 file
423424 """
424425
425426 def __init__ (
@@ -446,21 +447,61 @@ def write(self, iteration: int, **_):
446447 channel_name , base_name = self .get_names (
447448 component , channel , iteration
448449 )
449- child = [
450+ children = [
450451 child
451452 for child in h5_object .children
452- if channel_name in child .name
453- ][0 ]
453+ if (
454+ channel_name in child .name
455+ and isinstance (child , NumericData )
456+ )
457+ ]
454458
455- if child is not None :
456- properties . append ( child )
459+ if children [ 0 ] is not None :
460+ properties += children
457461
458462 if len (properties ) == 0 :
459463 return
460464
461- PropertyGroup (
462- parent = h5_object ,
463- name = base_name ,
464- properties = properties ,
465- property_group_type = self .group_type ,
466- )
465+ prop_group = h5_object .get_property_group (base_name )[0 ]
466+
467+ if prop_group is None :
468+ prop_group = h5_object .create_property_group (
469+ name = base_name ,
470+ properties = properties ,
471+ property_group_type = self .group_type ,
472+ )
473+ else :
474+ prop_group .add_properties (properties )
475+
476+
477+ class SaveLPModelGroup (SavePropertyGroup ):
478+ """
479+ Save the model as a property group in the geoh5 file
480+ """
481+
482+ def __init__ (
483+ self ,
484+ h5_object ,
485+ irls_directive ,
486+ group_type : GroupTypeEnum = GroupTypeEnum .MULTI ,
487+ ** kwargs ,
488+ ):
489+ self .group_type = group_type
490+ self .irls_directive = irls_directive
491+
492+ super ().__init__ (h5_object , ** kwargs )
493+
494+ def get_names (
495+ self , component : str , channel : str , iteration : int
496+ ) -> tuple [str , str ]:
497+ """
498+ Format the data and property_group name.
499+ """
500+ channel_name , base_name = super ().get_names (component , channel , iteration )
501+
502+ if self .irls_directive .metrics .irls_iteration_count == 0 :
503+ base_name = "L2 models"
504+ else :
505+ base_name = "LP models"
506+
507+ return channel_name , base_name
0 commit comments