Skip to content

Commit 494a02e

Browse files
committed
New _StepsView.stepstr property
This can be used to name output files depending on which timesteps were requested when relevant.
1 parent 05a48ea commit 494a02e

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

stagpy/rprof.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
"""Plot radial profiles."""
2-
import re
3-
42
import matplotlib.pyplot as plt
53

64
from . import conf, misc
@@ -17,10 +15,7 @@ def plot_rprofs(rprofs, lovs):
1715
produced by :func:`stagpy.misc.list_of_vars`.
1816
"""
1917
try:
20-
stepstr = repr(rprofs.steps)
21-
reg = re.compile(
22-
r'^StagyyData\(.*\)\.(steps|snaps)\[(.*)\](?:.filter\(.*\))?$')
23-
stepstr = '_'.join(reg.match(stepstr).groups())
18+
stepstr = rprofs.steps.stepstr
2419
except AttributeError:
2520
stepstr = str(rprofs.step.istep)
2621
sdat = rprofs.step.sdat

stagpy/stagyydata.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,25 @@ def rprofs_averaged(self):
547547
self._rprofs_averaged = _RprofsAveraged(self)
548548
return self._rprofs_averaged
549549

550-
def __repr__(self):
551-
rep = repr(self._col)
550+
@crop
551+
def stepstr(self):
552+
"""String representation of the requested set of steps."""
552553
items = []
554+
no_slice = True
553555
for item in self._items:
554556
if isinstance(item, slice):
555557
items.append('{}:{}:{}'.format(*item.indices(len(self._col))))
558+
no_slice = False
556559
else:
557560
items.append(repr(item))
558-
rep += '[{}]'.format(','.join(items))
561+
item_str = ','.join(items)
562+
if no_slice and len(items) == 1:
563+
item_str += ','
564+
colstr = repr(self._col).rsplit('.', maxsplit=1)[-1]
565+
return f'{colstr}[{item_str}]'
566+
567+
def __repr__(self):
568+
rep = f'{self._col.sdat!r}.{self.stepstr}'
559569
flts = []
560570
for flt in ('snap', 'rprofs', 'fields'):
561571
if self._flt[flt]:

0 commit comments

Comments
 (0)