1010from typing import Sequence , Union , Optional , Dict
1111
1212from loam .base import entry , Section , ConfigBase
13+ from loam .collections import TupleEntry , MaybeEntry
1314from loam import tools
1415from 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
2121HOME_DIR = Path .home ()
2222CONFIG_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
5551class 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
0 commit comments