Skip to content

Commit ee1b903

Browse files
committed
Step.fields, sfields, tracers, rprofs are cached properties
1 parent 0ec157c commit ee1b903

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/stagpy/step.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -614,27 +614,43 @@ class Step:
614614
Attributes:
615615
istep (int): the index of the time step that the instance represents.
616616
sdat (StagyyData): the owner of the `Step` instance.
617-
fields (Fields): fields available at this time step.
618-
sfields (Fields): surface fields available at this time
619-
step.
620-
tracers (Tracers): tracers available at this time step.
621617
"""
622618

623619
def __init__(self, istep: int, sdat: StagyyData):
624620
self.istep = istep
625621
self.sdat = sdat
626-
self.fields = Fields(
622+
623+
@cached_property
624+
def fields(self) -> Fields:
625+
"""Fields available at this time step."""
626+
return Fields(
627627
self,
628628
phyvars.FIELD,
629629
phyvars.FIELD_EXTRA,
630630
phyvars.FIELD_FILES,
631631
phyvars.FIELD_FILES_H5,
632632
)
633-
self.sfields = Fields(
634-
self, phyvars.SFIELD, {}, phyvars.SFIELD_FILES, phyvars.SFIELD_FILES_H5
633+
634+
@cached_property
635+
def sfields(self) -> Fields:
636+
"""Surface fields available at this time step."""
637+
return Fields(
638+
self,
639+
phyvars.SFIELD,
640+
{},
641+
phyvars.SFIELD_FILES,
642+
phyvars.SFIELD_FILES_H5,
635643
)
636-
self.tracers = Tracers(self)
637-
self.rprofs = RprofsInstant(self)
644+
645+
@cached_property
646+
def tracers(self) -> Tracers:
647+
"""Tracer information available at this time step."""
648+
return Tracers(self)
649+
650+
@cached_property
651+
def rprofs(self) -> RprofsInstant:
652+
"""Radial profiles available at this time step."""
653+
return RprofsInstant(self)
638654

639655
def __repr__(self) -> str:
640656
if self.isnap is not None:

0 commit comments

Comments
 (0)