Skip to content

Commit 0bcd3f0

Browse files
committed
StagyyData: steps, snaps, tseries, refstate are cached properties
1 parent c18f55a commit 0bcd3f0

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/stagpy/stagyydata.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -651,21 +651,12 @@ class StagyyData:
651651
runs of StagYY that predate version 1.2.6 for which the
652652
`parameters.dat` file contained some values affected by internal
653653
logic.
654-
655-
Attributes:
656-
steps (Steps): collection of time steps.
657-
snaps (Snaps): collection of snapshots.
658-
refstate (Refstate): reference state profiles.
659654
"""
660655

661656
def __init__(self, path: PathLike, read_parameters_dat: bool = True):
662657
self._parpath = Path(path)
663658
if not self._parpath.is_file():
664659
self._parpath /= "par"
665-
self.refstate = Refstate(self)
666-
self.tseries = Tseries(self)
667-
self.steps = Steps(self)
668-
self.snaps = Snaps(self)
669660
self._read_parameters_dat = read_parameters_dat
670661

671662
def __repr__(self) -> str:
@@ -690,6 +681,26 @@ def hdf5(self) -> Path | None:
690681
h5xmf = self.par.h5_output("Data.xmf")
691682
return h5xmf.parent if h5xmf.is_file() else None
692683

684+
@cached_property
685+
def steps(self) -> Steps:
686+
"""Collection of time steps."""
687+
return Steps(self)
688+
689+
@cached_property
690+
def snaps(self) -> Snaps:
691+
"""Collection of snapshots."""
692+
return Snaps(self)
693+
694+
@cached_property
695+
def tseries(self) -> Tseries:
696+
"""Time series data."""
697+
return Tseries(self)
698+
699+
@cached_property
700+
def refstate(self) -> Refstate:
701+
"""Reference state profiles."""
702+
return Refstate(self)
703+
693704
@cached_property
694705
def _dataxmf(self) -> FieldXmf:
695706
assert self.hdf5 is not None

0 commit comments

Comments
 (0)