Skip to content

Commit 09fff40

Browse files
committed
Bump loam to 0.7.0
1 parent 0fa5200 commit 09fff40

File tree

6 files changed

+67
-91
lines changed

6 files changed

+67
-91
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ include_package_data = true
2929
packages =
3030
find:
3131
install_requires =
32-
loam>=0.6.0,<0.7.0
32+
loam>=0.7.0,<0.8.0
3333
f90nml>=1.3.1
3434
setuptools_scm>=6.3.2
3535
numpy>=1.19

stagpy/args.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import importlib.resources as imlr
77
import typing
88

9-
from loam.tools import create_complete_files
109
from loam.cli import Subcmd, CLIManager
1110
import matplotlib.pyplot as plt
1211
import matplotlib.style as mpls
@@ -37,20 +36,19 @@ def _bare_cmd() -> None:
3736

3837
def _load_mplstyle() -> None:
3938
"""Try to load conf.plot.mplstyle matplotlib style."""
40-
if conf.plot.mplstyle:
41-
for style in conf.plot.mplstyle.split():
42-
style_fname = style + ".mplstyle"
43-
if not ISOLATED:
44-
stfile = config.CONFIG_DIR / style_fname
45-
if stfile.is_file():
46-
mpls.use(str(stfile))
47-
continue
48-
# try packaged version
49-
if imlr.is_resource(_styles, style_fname):
50-
with imlr.path(_styles, style_fname) as stfile:
51-
mpls.use(str(stfile))
52-
continue
53-
mpls.use(style)
39+
for style in conf.plot.mplstyle:
40+
style_fname = style + ".mplstyle"
41+
if not ISOLATED:
42+
stfile = config.CONFIG_DIR / style_fname
43+
if stfile.is_file():
44+
mpls.use(str(stfile))
45+
continue
46+
# try packaged version
47+
if imlr.is_resource(_styles, style_fname):
48+
with imlr.path(_styles, style_fname) as stfile:
49+
mpls.use(str(stfile))
50+
continue
51+
mpls.use(style)
5452
if conf.plot.xkcd:
5553
plt.xkcd()
5654

@@ -83,7 +81,12 @@ def parse_args(arglist: Optional[List[str]] = None) -> Callable[[], None]:
8381
"""
8482
climan = CLIManager(conf, **SUB_CMDS)
8583

86-
create_complete_files(climan, CONFIG_DIR, 'stagpy', zsh_sourceable=True)
84+
bash_script = CONFIG_DIR / "bash" / "stagpy.sh"
85+
bash_script.parent.mkdir(parents=True, exist_ok=True)
86+
climan.bash_complete(bash_script, "stagpy")
87+
zsh_script = CONFIG_DIR / "zsh" / "_stagpy.sh"
88+
zsh_script.parent.mkdir(parents=True, exist_ok=True)
89+
climan.zsh_complete(zsh_script, "stagpy", sourceable=True)
8790

8891
cmd_args = climan.parse_args(arglist)
8992
sub_cmd = cmd_args.loam_sub_name

stagpy/config.py

Lines changed: 43 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
from typing import Sequence, Union, Optional, Dict
1111

1212
from loam.base import entry, Section, ConfigBase
13+
from loam.collections import TupleEntry, MaybeEntry
1314
from loam import tools
1415
from loam.tools import switch_opt, command_flag, path_entry
15-
import loam.parsers
16+
import loam.parsers as lprs
1617

1718

18-
_index_collection = loam.parsers.tuple_of(loam.parsers.slice_or_int_parser)
19-
_float_list = loam.parsers.tuple_of(float)
19+
_indices = TupleEntry(inner_from_toml=lprs.slice_or_int_parser)
2020

2121
HOME_DIR = Path.home()
2222
CONFIG_DIR = HOME_DIR / '.config' / 'stagpy'
@@ -41,40 +41,29 @@ class Core(Section):
4141
doc='output file name prefix')
4242
shortname: bool = switch_opt(
4343
False, None, "output file name is only prefix")
44-
timesteps: Optional[Sequence[Union[int, slice]]] = entry(
45-
val_factory=lambda: None, cli_short='t', in_file=False,
46-
doc="timesteps slice",
47-
cli_kwargs={'nargs': '?', 'const': ''}, from_str=_index_collection)
48-
snapshots: Optional[Sequence[Union[int, slice]]] = entry(
49-
val_factory=lambda: None, cli_short='s', in_file=False,
50-
doc="snapshots slice",
51-
cli_kwargs={'nargs': '?', 'const': ''}, from_str=_index_collection)
44+
timesteps: Sequence[Union[int, slice]] = _indices.entry(
45+
doc="timesteps slice", in_file=False, cli_short="t")
46+
snapshots: Sequence[Union[int, slice]] = _indices.entry(
47+
default=[-1], doc="snapshots slice", in_file=False, cli_short='s')
5248

5349

5450
@dataclass
5551
class Plot(Section):
5652
"""Options to tweak plots."""
5753

58-
ratio: Optional[float] = entry(
59-
val_factory=lambda: None, in_file=False, from_str=float,
60-
doc="force aspect ratio of field plot",
61-
cli_kwargs={'nargs': '?', 'const': 0.6})
54+
ratio: Optional[float] = MaybeEntry(float).entry(
55+
doc="force aspect ratio of field plot", in_file=False)
6256
raster: bool = switch_opt(True, None, "rasterize field plots")
6357
format: str = entry(val="pdf", doc="figure format (pdf, eps, svg, png)")
64-
vmin: Optional[float] = entry(
65-
val_factory=lambda: None, in_file=False, from_str=float,
66-
doc="minimal value on plot")
67-
vmax: Optional[float] = entry(
68-
val_factory=lambda: None, in_file=False, from_str=float,
69-
doc="maximal value on plot")
58+
vmin: Optional[float] = MaybeEntry(float).entry(
59+
doc="minimal value on plot", in_file=False)
60+
vmax: Optional[float] = MaybeEntry(float).entry(
61+
doc="maximal value on plot", in_file=False)
7062
cminmax: bool = switch_opt(False, 'C', 'constant min max across plots')
71-
isolines: Optional[Sequence[float]] = entry(
72-
val_factory=lambda: None, in_file=False, from_str=_float_list,
73-
doc="arbitrary isoline value, comma separated")
74-
mplstyle: str = entry(
75-
val="stagpy-paper", in_file=False,
76-
cli_kwargs={'nargs': '?', 'const': ''},
77-
doc="matplotlib style")
63+
isolines: Sequence[float] = TupleEntry(float).entry(
64+
doc="list of isoline values", in_file=False)
65+
mplstyle: Sequence[str] = TupleEntry(str).entry(
66+
default="stagpy-paper", doc="list of matplotlib styles", in_file=False)
7867
xkcd: bool = command_flag("use the xkcd style")
7968

8069

@@ -104,23 +93,19 @@ class Field(Section):
10493
doc="variables to plot (see stagpy var)")
10594
perturbation: bool = switch_opt(
10695
False, None, "plot departure from average profile")
107-
shift: Optional[int] = entry(
108-
val_factory=lambda: None, in_file=False, from_str=int,
109-
doc="shift plot horizontally")
96+
shift: Optional[int] = MaybeEntry(int).entry(
97+
doc="shift plot horizontally", in_file=False)
11098
timelabel: bool = switch_opt(False, None, "add label with time")
11199
interpolate: bool = switch_opt(False, None, "apply Gouraud shading")
112100
colorbar: bool = switch_opt(True, None, "add color bar to plot")
113-
ix: Optional[int] = entry(
114-
val_factory=lambda: None, in_file=False, from_str=int,
115-
doc="x-index of slice for 3D fields")
116-
iy: Optional[int] = entry(
117-
val_factory=lambda: None, in_file=False, from_str=int,
118-
doc="y-index of slice for 3D fields")
119-
iz: Optional[int] = entry(
120-
val_factory=lambda: None, in_file=False, from_str=int,
121-
doc="z-index of slice for 3D fields")
122-
isocolors: str = entry(
123-
val="", doc="comma-separated list of colors for isolines")
101+
ix: Optional[int] = MaybeEntry(int).entry(
102+
doc="x-index of slice for 3D fields", in_file=False)
103+
iy: Optional[int] = MaybeEntry(int).entry(
104+
doc="y-index of slice for 3D fields", in_file=False)
105+
iz: Optional[int] = MaybeEntry(int).entry(
106+
doc="z-index of slice for 3D fields", in_file=False)
107+
isocolors: Sequence[str] = TupleEntry(str).entry(
108+
doc="list of colors for isolines")
124109
cmap: Dict[str, str] = entry(
125110
val_factory=lambda: {
126111
'T': 'RdBu_r',
@@ -154,28 +139,20 @@ class Time(Section):
154139
cli_kwargs={'nargs': '?', 'const': ''},
155140
doc="variables to plot (see stagpy var)")
156141
style: str = entry(val='-', doc="matplotlib line style")
157-
compstat: str = entry(
158-
val='', in_file=False,
159-
cli_kwargs={'nargs': '?', 'const': ''},
160-
doc="compute mean and rms of listed variables")
161-
tstart: Optional[float] = entry(
162-
val_factory=lambda: None, in_file=False, from_str=float,
163-
doc="beginning time")
164-
tend: Optional[float] = entry(
165-
val_factory=lambda: None, in_file=False, from_str=float,
166-
doc="end time")
167-
fraction: Optional[float] = entry(
168-
val_factory=lambda: None, in_file=False, from_str=float,
169-
doc="ending fraction of series to process")
170-
marktimes: Sequence[float] = entry(
171-
val_str="", in_file=False, cli_short='M', from_str=_float_list,
172-
doc="list of times where to put a mark")
173-
marksteps: Sequence[Union[int, slice]] = entry(
174-
val_str="", cli_short='T', in_file=False, from_str=_index_collection,
175-
doc="list of steps where to put a mark")
176-
marksnaps: Sequence[Union[int, slice]] = entry(
177-
val_str="", cli_short='S', in_file=False, from_str=_index_collection,
178-
doc="list of snaps where to put a mark")
142+
compstat: Sequence[str] = TupleEntry(str).entry(
143+
doc="compute mean and rms of listed variables", in_file=False)
144+
tstart: Optional[float] = MaybeEntry(float).entry(
145+
doc="beginning time", in_file=False)
146+
tend: Optional[float] = MaybeEntry(float).entry(
147+
doc="end time", in_file=False)
148+
fraction: Optional[float] = MaybeEntry(float).entry(
149+
doc="ending fraction of series to process", in_file=False)
150+
marktimes: Sequence[float] = TupleEntry(float).entry(
151+
doc="list of times where to put a mark", in_file=False, cli_short='M')
152+
marksteps: Sequence[Union[int, slice]] = _indices.entry(
153+
doc="list of steps where to put a mark", in_file=False, cli_short='T')
154+
marksnaps: Sequence[Union[int, slice]] = _indices.entry(
155+
doc="list of snaps where to put a mark", in_file=False, cli_short='S')
179156

180157

181158
@dataclass
@@ -207,9 +184,8 @@ class Plates(Section):
207184
False, None, "plot number of plates as function of time")
208185
distribution: bool = switch_opt(
209186
False, None, "plot plate size distribution")
210-
zoom: Optional[float] = entry(
211-
val_factory=lambda: None, in_file=False, from_str=float,
212-
doc="zoom around surface")
187+
zoom: Optional[float] = MaybeEntry(float).entry(
188+
doc="zoom around surface", in_file=False)
213189

214190

215191
@dataclass

stagpy/field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def plot_iso(axis: Axes, step: Step, var: str,
285285
fld = np.roll(fld, conf.field.shift, axis=0)
286286
extra_opts: Dict[str, Any] = dict(linewidths=1)
287287
if 'cmap' not in extra and conf.field.isocolors:
288-
extra_opts['colors'] = conf.field.isocolors.split(',')
288+
extra_opts['colors'] = conf.field.isocolors
289289
elif 'colors' not in extra:
290290
extra_opts['cmap'] = conf.field.cmap.get(var)
291291
if conf.plot.isolines:

stagpy/stagyydata.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,11 +823,9 @@ def walk(self) -> _StepsView:
823823
conf.core.snapshots: the slice of snapshots.
824824
conf.core.timesteps: the slice of timesteps.
825825
"""
826-
if conf.core.snapshots:
827-
return self.snaps[conf.core.snapshots]
828-
elif conf.core.timesteps:
826+
if conf.core.timesteps:
829827
return self.steps[conf.core.timesteps]
830-
return self.snaps[-1, ]
828+
return self.snaps[conf.core.snapshots]
831829

832830
@property
833831
def nfields_max(self) -> Optional[int]:

stagpy/time_series.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def cmd() -> None:
136136
plot_time_series(sdat, conf.time.plot)
137137

138138
if conf.time.compstat:
139-
names = conf.time.compstat.replace(',', ' ').split()
140-
stats = compstat(sdat, *names, tstart=conf.time.tstart,
139+
stats = compstat(sdat, *conf.time.compstat, tstart=conf.time.tstart,
141140
tend=conf.time.tend)
142141
stats.to_csv('statistics.dat')

0 commit comments

Comments
 (0)