Skip to content

Commit f67fbd6

Browse files
committed
allow ignoring parameters.dat
This can be useful with runs of StagYY predating v1.2.6 for which parameters.dat contained values polluted by `check_*` subroutines.
1 parent 985a105 commit f67fbd6

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

stagpy/parfile.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ def _update(self, par_new: StagyyPar) -> None:
4646
self.nml[section] = content
4747

4848
@staticmethod
49-
def from_main_par(parfile: Path) -> StagyyPar:
49+
def from_main_par(parfile: Path, read_parameters_dat: bool = True) -> StagyyPar:
5050
"""Read StagYY namelist `parfile`.
5151
5252
The namelist is populated in order with:
5353
5454
- `par_name_defaultparameters` if it is defined in `parfile`;
5555
- `par_file` itself;
56-
- `parameters.dat` if it can be found in the StagYY output directories.
56+
- `parameters.dat` if it can be found in the StagYY output directories
57+
and `read_parameters_dat` is `True`.
5758
"""
5859
par_main = StagyyPar._from_file(parfile)
5960
if "default_parameters_parfile" in par_main.nml:
@@ -66,12 +67,13 @@ def from_main_par(parfile: Path) -> StagyyPar:
6667
par_dflt._update(par_main)
6768
par_main = StagyyPar(nml=par_dflt.nml, root=par_main.root)
6869

69-
outfile = par_main.legacy_output("_parameters.dat")
70-
if outfile.is_file():
71-
par_main._update(StagyyPar._from_file(outfile))
72-
outfile = par_main.h5_output("parameters.dat")
73-
if outfile.is_file():
74-
par_main._update(StagyyPar._from_file(outfile))
70+
if read_parameters_dat:
71+
outfile = par_main.legacy_output("_parameters.dat")
72+
if outfile.is_file():
73+
par_main._update(StagyyPar._from_file(outfile))
74+
outfile = par_main.h5_output("parameters.dat")
75+
if outfile.is_file():
76+
par_main._update(StagyyPar._from_file(outfile))
7577
return par_main
7678

7779
def get(self, section: str, option: str, default: T) -> T:

stagpy/stagyydata.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,21 +651,27 @@ class StagyyData:
651651
directory containing the par file, or the path of the par file. If
652652
the path given is a directory, the path of the par file is assumed
653653
to be path/par.
654+
read_parameters_dat: read `parameters.dat` file produced by StagYY. This
655+
flag can be switched off to ignore this file. This is intended for
656+
runs of StagYY that predate version 1.2.6 for which the
657+
`parameters.dat` file contained some values affected by internal
658+
logic.
654659
655660
Attributes:
656661
steps (Steps): collection of time steps.
657662
snaps (Snaps): collection of snapshots.
658663
refstate (Refstate): reference state profiles.
659664
"""
660665

661-
def __init__(self, path: PathLike):
666+
def __init__(self, path: PathLike, read_parameters_dat: bool = True):
662667
self._parpath = Path(path)
663668
if not self._parpath.is_file():
664669
self._parpath /= "par"
665670
self.refstate = Refstate(self)
666671
self.tseries = Tseries(self)
667672
self.steps = Steps(self)
668673
self.snaps = Snaps(self)
674+
self._read_parameters_dat = read_parameters_dat
669675
self._nfields_max: Optional[int] = 50
670676
# list of (istep, field_name) in memory
671677
self._collected_fields: list[tuple[int, str]] = []
@@ -723,7 +729,7 @@ def _traxmf(self) -> TracersXmf:
723729
@cached_property
724730
def par(self) -> StagyyPar:
725731
"""Content of par file."""
726-
return StagyyPar.from_main_par(self.parpath)
732+
return StagyyPar.from_main_par(self.parpath, self._read_parameters_dat)
727733

728734
@cached_property
729735
def _rprof_and_times(self) -> tuple[dict[int, DataFrame], Optional[DataFrame]]:

0 commit comments

Comments
 (0)