Skip to content

Commit df7313d

Browse files
authored
Merge pull request #78 from StagPython/plates-refactor
Refactor plates module and expose a public API This PR is a full refactoring of the plates module to make it easier to maintain, expand, and use in a user script. The main improvements are: * `detect_plates` and `detect_plates_vzcheck` are merged in one routine `detect_plates`. * New command line arguments `--vzratio`, `+-distribution` and `+-nbplates` allow the user to switch on the use of `vzabs` when detecting plate limits, plotting of plate size distribution, and plotting of number of plates as a function of time. * the new `+-continents` argument switches the detection of continents and the related decorations on plots. * `-o/--plot` now works in a similar way to eponym options of `field`, `rprof`, and `time` subcommands. The `plates` subcommand plots the requested surface diagnostics. The later can be surface fields, fields, or `"dv2"` (which is `d(vphi)/dphi`). * the public api of the plates module (`detect_plates` and two plotting routines `plot_at_surface` and `plot_scalar_field`) is documented and available in user scripts.
2 parents 1912bb2 + 3048969 commit df7313d

File tree

8 files changed

+314
-789
lines changed

8 files changed

+314
-789
lines changed

docs/sources/apiref/phyvars.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,6 @@ phyvars
8585
Dictionary of time series that StagPy can compute. Keys are the variable
8686
names, values are :class:`Vart` instances.
8787

88-
.. class:: Varp
89-
90-
:class:`collections.namedtuple` whose instances hold metadata of
91-
plate variables. It defines the following fields:
92-
93-
- **description** (*str*): short description of the variable.
94-
95-
.. data:: PLATES
96-
:annotation: = {platevar: Varp()}
97-
98-
Dictionary of plate variables output by StagYY. Keys are the variable
99-
names, values are :class:`Varp` instances.
100-
10188
.. data:: SCALES
10289
:annotation: = {dimstr: func}
10390

docs/sources/apiref/plates.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ plates
22
======
33

44
.. automodule:: stagpy.plates
5-
:members: cmd
5+
:members:

stagpy/commands.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ def var_cmd():
142142
print('refstate:')
143143
_layout(phyvars.REFSTATE, {})
144144
print()
145-
if print_all or conf.var.plates:
146-
print('plates:')
147-
_layout(phyvars.PLATES, {})
148145

149146

150147
def version_cmd():

stagpy/config.py

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -179,38 +179,27 @@ def _index_collection(arg):
179179

180180
CONF_DEF['plates'] = OrderedDict((
181181
('plot',
182-
Conf('c,eta,sc', True, 'o',
183-
{'nargs': '?', 'const': '', 'type': str},
184-
True, 'variables to plot (see stagpy var)')),
185-
('vzcheck', switch_opt(False, None,
186-
'activate Colin\'s version with vz checking')),
187-
('timeprofile', switch_opt(False, None,
188-
'nb of plates as function of time')),
182+
Conf('c.T.v2-v2.dv2-v2.topo_top', True, 'o',
183+
{'nargs': '?', 'const': '', 'type': str}, True,
184+
'variables to plot, can be a surface field, field, or dv2')),
185+
('field',
186+
Conf('eta', True, None, {},
187+
True, 'field variable to plot with plates info')),
188+
('stress', switch_opt(
189+
False, None,
190+
'Plot deviatoric stress instead of velocity on field plots')),
191+
('continents', switch_opt(True, None,
192+
'Whether to shade continents on plots')),
193+
('vzratio',
194+
Conf(0., True, None, {}, True,
195+
'Ratio of mean vzabs used as threshold for plates limits')),
196+
('nbplates', switch_opt(False, None,
197+
'Plot number of plates as function of time')),
198+
('distribution', switch_opt(False, None,
199+
'Plot plate size distribution')),
189200
('zoom',
190201
Conf(None, True, None, {'type': float},
191202
False, 'zoom around surface')),
192-
('topomin', Conf(-40, False, None, {},
193-
True, 'min topography in plots')),
194-
('topomax', Conf(100, False, None, {},
195-
True, 'max topography in plots')),
196-
('agemin', Conf(-50, False, None, {},
197-
True, 'min age in plots')),
198-
('agemax', Conf(500, False, None, {},
199-
True, 'max age in plots')),
200-
('vmin', Conf(-5000, False, None, {},
201-
True, 'min velocity in plots')),
202-
('vmax', Conf(5000, False, None, {},
203-
True, 'max velocity in plots')),
204-
('dvmin', Conf(-250000, False, None, {},
205-
True, 'min velocity derivative in plots')),
206-
('dvmax', Conf(150000, False, None, {},
207-
True, 'max velocity derivative in plots')),
208-
('stressmin', Conf(0, False, None, {},
209-
True, 'min stress in plots')),
210-
('stressmax', Conf(800, False, None, {},
211-
True, 'max stress in plots')),
212-
('lstressmax', Conf(50, False, None, {},
213-
True, 'max lithospheric stress in plots')),
214203
))
215204

216205
CONF_DEF['info'] = OrderedDict((
@@ -229,8 +218,6 @@ def _index_collection(arg):
229218
False, 'print time variables')),
230219
('refstate', Conf(None, True, None, {'action': 'store_true'},
231220
False, 'print refstate variables')),
232-
('plates', Conf(None, True, None, {'action': 'store_true'},
233-
False, 'print plates variables')),
234221
))
235222

236223
CONF_DEF['config'] = config_conf_section()

stagpy/error.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,6 @@ def __init__(self, zoom):
163163
super().__init__(f'Zoom angle should be in [0,360] (received {zoom})')
164164

165165

166-
class StagnantLidError(StagpyError):
167-
"""Raised when unexpected stagnant lid regime is found.
168-
169-
Args:
170-
sdat (:class:`~stagpy.stagyydata.StagyyData`): the StagyyData
171-
instance for which a stagnant lid regime was found.
172-
173-
Attributes:
174-
sdat (:class:`~stagpy.stagyydata.StagyyData`): the StagyyData
175-
instance for which a stagnant lid regime was found.
176-
"""
177-
178-
def __init__(self, sdat):
179-
self.sdat = sdat
180-
super().__init__(f'Stagnant lid regime for {sdat}')
181-
182-
183166
class MissingDataError(StagpyError, KeyError):
184167
"""Raised when requested data is not present in output."""
185168

stagpy/phyvars.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,6 @@
262262
('grav', Varr('Gravity', 'Gravity', 'm/s2')),
263263
))
264264

265-
Varp = namedtuple('Varp', ['description'])
266-
PLATES = OrderedDict((
267-
('c', Varp('Composition')),
268-
('eta', Varp('Viscosity')),
269-
('sc', Varp('Topography')),
270-
('age', Varp('Age')),
271-
('str', Varp('Stress')),
272-
('sx', Varp('Principal deviatoric stress')),
273-
('ed', Varp('Strain rate')),
274-
))
275-
276265
SCALES = {
277266
'm': attrgetter('length'),
278267
'kg/m3': attrgetter('density'),

0 commit comments

Comments
 (0)