@@ -78,11 +78,10 @@ class Refstate:
7878 @cached_property
7979 def _data (self ) -> tuple [list [list [DataFrame ]], list [DataFrame ]]:
8080 """Read reference state profile."""
81- reffile = self .sdat .filename ("refstat.dat" )
82- if self .sdat .hdf5 and not reffile .is_file ():
83- # check legacy folder as well
84- reffile = self .sdat .filename ("refstat.dat" , force_legacy = True )
85- data = parsers .txt .refstate (reffile )
81+ reffile = self .sdat ._find_file ("refstat.dat" )
82+ data = None
83+ if reffile is not None :
84+ data = parsers .txt .refstate (reffile )
8685 if data is None :
8786 raise error .NoRefstateError (self .sdat )
8887 return data
@@ -147,15 +146,14 @@ def _cached_extra(self) -> dict[str, dt.Tseries]:
147146
148147 @cached_property
149148 def _data (self ) -> DataFrame | None :
150- timefile = self .sdat .filename ("TimeSeries.h5" )
149+ timefile : Path | None
150+ timefile = self .sdat .par .h5_output ("TimeSeries.h5" )
151151 data = parsers .h5 .tseries .tseries (timefile )
152152 if data is not None :
153153 return data
154- timefile = self .sdat .filename ("time.dat" )
155- if self .sdat .hdf5 and not timefile .is_file ():
156- # check legacy folder as well
157- timefile = self .sdat .filename ("time.dat" , force_legacy = True )
158- data = parsers .txt .tseries (timefile )
154+ timefile = self .sdat ._find_file ("time.dat" )
155+ if timefile is not None :
156+ data = parsers .txt .tseries (timefile )
159157 return data
160158
161159 @property
@@ -671,12 +669,6 @@ def parpath(self) -> Path:
671669 return parpath
672670 return parpath / "par"
673671
674- @cached_property
675- def hdf5 (self ) -> Path | None :
676- """Path of output hdf5 folder if relevant, None otherwise."""
677- h5xmf = self .par .h5_output ("Data.xmf" )
678- return h5xmf .parent if h5xmf .is_file () else None
679-
680672 @cached_property
681673 def steps (self ) -> Steps :
682674 """Collection of time steps."""
@@ -698,32 +690,32 @@ def refstate(self) -> Refstate:
698690 return Refstate (self )
699691
700692 @cached_property
701- def _dataxmf (self ) -> FieldXmf :
702- assert self .hdf5 is not None
703- return FieldXmf (
704- path = self . hdf5 / "Data.xmf" ,
705- )
693+ def _dataxmf (self ) -> FieldXmf | None :
694+ path = self .par . h5_output ( "Data.xmf" )
695+ if path . is_file ():
696+ return FieldXmf ( path = path )
697+ return None
706698
707699 @cached_property
708- def _topxmf (self ) -> FieldXmf :
709- assert self .hdf5 is not None
710- return FieldXmf (
711- path = self . hdf5 / "DataSurface.xmf" ,
712- )
700+ def _topxmf (self ) -> FieldXmf | None :
701+ path = self .par . h5_output ( "DataSurface.xmf" )
702+ if path . is_file ():
703+ return FieldXmf ( path = path )
704+ return None
713705
714706 @cached_property
715- def _botxmf (self ) -> FieldXmf :
716- assert self .hdf5 is not None
717- return FieldXmf (
718- path = self . hdf5 / "DataBottom.xmf" ,
719- )
707+ def _botxmf (self ) -> FieldXmf | None :
708+ path = self .par . h5_output ( "DataBottom.xmf" )
709+ if path . is_file ():
710+ return FieldXmf ( path = path )
711+ return None
720712
721713 @cached_property
722- def _traxmf (self ) -> TracersXmf :
723- assert self .hdf5 is not None
724- return TracersXmf (
725- path = self . hdf5 / "DataTracers.xmf" ,
726- )
714+ def _traxmf (self ) -> TracersXmf | None :
715+ path = self .par . h5_output ( "DataTracers.xmf" )
716+ if path . is_file ():
717+ return TracersXmf ( path = path )
718+ return None
727719
728720 @cached_property
729721 def par (self ) -> StagyyPar :
@@ -732,15 +724,15 @@ def par(self) -> StagyyPar:
732724
733725 @cached_property
734726 def _rprof_and_times (self ) -> tuple [dict [int , DataFrame ], DataFrame | None ]:
735- rproffile = self .filename ("rprof.h5" )
727+ rproffile : Path | None
728+ rproffile = self .par .h5_output ("rprof.h5" )
736729 data = parsers .h5 .rprof .rprof (rproffile )
737730 if data [1 ] is not None :
738731 return data
739- rproffile = self .filename ("rprof.dat" )
740- if self .hdf5 and not rproffile .is_file ():
741- # check legacy folder as well
742- rproffile = self .filename ("rprof.dat" , force_legacy = True )
743- return parsers .txt .rprof (rproffile )
732+ rproffile = self ._find_file ("rprof.dat" )
733+ if rproffile is not None :
734+ return parsers .txt .rprof (rproffile )
735+ return {}, None
744736
745737 @property
746738 def rtimes (self ) -> DataFrame | None :
@@ -750,7 +742,7 @@ def rtimes(self) -> DataFrame | None:
750742 @cached_property
751743 def _files (self ) -> set [Path ]:
752744 """Set of found binary files output by StagYY."""
753- out_dir = self .par .legacy_output ("_ " ).parent
745+ out_dir = self .par .legacy_output ("" ).parent
754746 if out_dir .is_dir ():
755747 return set (out_dir .iterdir ())
756748 return set ()
@@ -767,32 +759,19 @@ def set_nfields_max(self, nfields: int | None) -> None:
767759 raise error .InvalidNfieldsError (nfields )
768760 self ._field_cache .resize (nfields )
769761
770- def filename (
771- self ,
772- fname : str ,
773- timestep : int | None = None ,
774- suffix : str = "" ,
775- force_legacy : bool = False ,
776- ) -> Path :
777- """Return name of StagYY output file.
778-
779- Args:
780- fname: name stem.
781- timestep: snapshot number if relevant.
782- suffix: optional suffix of file name.
783- force_legacy: force returning the legacy output path.
762+ def _find_file (self , fname : str ) -> Path | None :
763+ """Return path of StagYY output file if found.
784764
785- Returns:
786- the path of the output file constructed with the provided segments .
765+ This searches in the legacy folder first, and then the hdf5
766+ output folder .
787767 """
788- if timestep is not None :
789- fname += f"{ timestep :05d} "
790- fname += suffix
791- if not force_legacy and self .hdf5 :
792- fpath = self .par .h5_output (fname )
793- else :
794- fpath = self .par .legacy_output (f"_{ fname } " )
795- return fpath
768+ fpath = self .par .legacy_output (fname )
769+ if fpath .is_file ():
770+ return fpath
771+ fpath = self .par .h5_output (fname )
772+ if fpath .is_file ():
773+ return fpath
774+ return None
796775
797776 def _binfiles_set (self , isnap : int ) -> set [Path ]:
798777 """Set of existing binary files at a given snap.
@@ -804,8 +783,7 @@ def _binfiles_set(self, isnap: int) -> set[Path]:
804783 the set of output files available for this snapshot number.
805784 """
806785 possible_files = set (
807- self .filename (fstem , isnap , force_legacy = True )
808- for fstem in phyvars .FIELD_FILES
786+ self .par .legacy_output (fstem , isnap ) for fstem in phyvars .FIELD_FILES
809787 )
810788 return possible_files & self ._files
811789
@@ -815,6 +793,7 @@ def _field_cache(self) -> FieldCache:
815793
816794 @cached_property
817795 def _step_snap (self ) -> StepSnap :
818- if self .hdf5 is not None :
819- return StepSnapH5 (sdat = self )
796+ timeh5 = self .par .h5_output ("time_botT.h5" )
797+ if timeh5 .is_file ():
798+ return StepSnapH5 (timeh5 = timeh5 )
820799 return StepSnapLegacy (sdat = self )
0 commit comments