@@ -863,6 +863,14 @@ class FieldXmf:
863863 def root (self ) -> Element :
864864 return xmlET .parse (str (self .path )).getroot ()
865865
866+ def get_snap (self , isnap : int ) -> Element :
867+ # Domain, Temporal Collection, Snapshot
868+ # should check that this is indeed the required snapshot
869+ elt_snap = self .root [0 ][0 ][isnap ]
870+ if elt_snap is None :
871+ raise ParsingError (self .path , f"Snapshot { isnap } not present" )
872+ return elt_snap
873+
866874
867875def read_geom_h5 (xdmf : FieldXmf , snapshot : int ) -> dict [str , Any ]:
868876 """Extract geometry information from hdf5 files.
@@ -874,13 +882,8 @@ def read_geom_h5(xdmf: FieldXmf, snapshot: int) -> dict[str, Any]:
874882 geometry information.
875883 """
876884 header : Dict [str , Any ] = {}
877- xdmf_root = xdmf .root
878885
879- # Domain, Temporal Collection, Snapshot
880- # should check that this is indeed the required snapshot
881- elt_snap = xdmf_root [0 ][0 ][snapshot ]
882- if elt_snap is None :
883- raise ParsingError (xdmf .path , f"Snapshot { snapshot } not present" )
886+ elt_snap = xdmf .get_snap (snapshot )
884887 header ["ti_ad" ] = _maybe_get (elt_snap , "Time" , "Value" , float )
885888 header ["mo_lambda" ] = _maybe_get (elt_snap , "mo_lambda" , "Value" , float )
886889 header ["mo_thick_sol" ] = _maybe_get (elt_snap , "mo_thick_sol" , "Value" , float )
@@ -977,13 +980,12 @@ def read_field_h5(
977980 """
978981 if header is None :
979982 header = read_geom_h5 (xdmf , snapshot )
980- xdmf_root = xdmf .root
981983
982984 npc = header ["nts" ] // header ["ncs" ] # number of grid point per node
983985 flds = np .zeros (_flds_shape (fieldname , header ))
984986 data_found = False
985987
986- for elt_subdomain in xdmf_root [ 0 ][ 0 ][ snapshot ] .findall ("Grid" ):
988+ for elt_subdomain in xdmf . get_snap ( snapshot ) .findall ("Grid" ):
987989 elt_name = _try_get (xdmf .path , elt_subdomain , "Name" )
988990 ibk = int (elt_name .startswith ("meshYang" ))
989991 for data_attr in elt_subdomain .findall ("Attribute" ):
0 commit comments