Skip to content

Commit b83c88f

Browse files
committed
Rename misc module to _helpers
There is no reason to expose those functions in the public API. `rprof.plot_rprofs` as well as `time_series.plot_time_series` now take a string to specify the variables to plot (akin to the `--plot` command line option of the `rprof` and `tseries` subcommands).
1 parent dfd3153 commit b83c88f

File tree

13 files changed

+57
-69
lines changed

13 files changed

+57
-69
lines changed

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Welcome to StagPy's documentation!
4343
sources/apiref/config
4444
sources/apiref/error
4545
sources/apiref/field
46-
sources/apiref/misc
4746
sources/apiref/parfile
4847
sources/apiref/phyvars
4948
sources/apiref/plates

docs/sources/apiref/misc.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

stagpy/misc.py renamed to stagpy/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Miscellaneous definitions."""
1+
"""Various helper functions and classes."""
22

33
from inspect import getdoc
44

stagpy/_step.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import numpy as np
1414

15-
from . import error, misc, phyvars, stagyyparsers
16-
from .misc import CachedReadOnlyProperty as crop
15+
from . import error, phyvars, stagyyparsers, _helpers
16+
from ._helpers import CachedReadOnlyProperty as crop
1717

1818

1919
class _Geometry:
@@ -440,7 +440,7 @@ def __getitem__(self, name):
440440
elif name in phyvars.RPROF_EXTRA:
441441
meta = phyvars.RPROF_EXTRA[name]
442442
rprof, rad = meta.description(step)
443-
meta = phyvars.Varr(misc.baredoc(meta.description),
443+
meta = phyvars.Varr(_helpers.baredoc(meta.description),
444444
meta.kind, meta.dim)
445445
self._cached_extra[name] = rprof, rad, meta
446446
else:

stagpy/args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from . import __doc__ as doc_module
1010
from . import conf, PARSING_OUT, load_mplstyle
1111
from . import commands, field, rprof, time_series, refstate, plates
12-
from .misc import baredoc
12+
from ._helpers import baredoc
1313
from .config import CONFIG_DIR
1414

1515

stagpy/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from . import conf, phyvars, __version__
1313
from . import stagyydata
1414
from .config import CONFIG_FILE, CONFIG_LOCAL
15-
from .misc import baredoc
15+
from ._helpers import baredoc
1616

1717

1818
def info_cmd():

stagpy/field.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import matplotlib.patches as mpat
99
from mpl_toolkits.axes_grid1 import make_axes_locatable
1010

11-
from . import conf, misc, phyvars
11+
from . import conf, phyvars, _helpers
1212
from .error import NotAvailableError
1313
from .stagyydata import StagyyData
1414

@@ -166,7 +166,7 @@ def plot_scalar(step, var, field=None, axis=None, **extra):
166166
meta = phyvars.FIELD[var]
167167
else:
168168
meta = phyvars.FIELD_EXTRA[var]
169-
meta = phyvars.Varf(misc.baredoc(meta.description), meta.dim)
169+
meta = phyvars.Varf(_helpers.baredoc(meta.description), meta.dim)
170170
if step.geom.threed and step.geom.spherical:
171171
raise NotAvailableError(
172172
'plot_scalar not implemented for 3D spherical geometry')
@@ -318,7 +318,7 @@ def cmd():
318318
conf.core
319319
"""
320320
sdat = StagyyData()
321-
lovs = misc.list_of_vars(conf.field.plot)
321+
lovs = _helpers.list_of_vars(conf.field.plot)
322322
# no more than two fields in a subplot
323323
lovs = [[slov[:2] for slov in plov] for plov in lovs]
324324
minmax = {}
@@ -346,9 +346,9 @@ def cmd():
346346
plot_vec(axis, step, var[1])
347347
if conf.field.timelabel:
348348
time, unit = sdat.scale(step.timeinfo['t'], 's')
349-
time = misc.scilabel(time)
349+
time = _helpers.scilabel(time)
350350
axes[0, 0].text(0.02, 1.02, f'$t={time}$ {unit}',
351351
transform=axes[0, 0].transAxes)
352352
oname = '_'.join(chain.from_iterable(vfig))
353353
plt.tight_layout(w_pad=3)
354-
misc.saveplot(fig, oname, step.isnap)
354+
_helpers.saveplot(fig, oname, step.isnap)

stagpy/plates.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import numpy as np
77
from scipy.signal import argrelextrema
88

9-
from . import conf, error, field, misc, phyvars
9+
from . import conf, error, field, phyvars
10+
from ._helpers import saveplot
1011
from .stagyydata import StagyyData
1112

1213

@@ -283,7 +284,7 @@ def plot_plates(step, time, vrms_surface, trench, ridge, agetrench,
283284
plot_plate_limits(ax3, ridge, trench, conf.plates.vmin,
284285
conf.plates.vmax)
285286

286-
misc.saveplot(fig0, 'sveltempconc', timestep)
287+
saveplot(fig0, 'sveltempconc', timestep)
287288

288289
# plotting velocity and velocity derivative
289290
fig0, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(12, 8))
@@ -314,7 +315,7 @@ def plot_plates(step, time, vrms_surface, trench, ridge, agetrench,
314315
conf.plates.dvmax, facecolor='#8b6914', alpha=0.2)
315316
ax2.set_ylim(conf.plates.dvmin, conf.plates.dvmax)
316317

317-
misc.saveplot(fig0, 'sveldvel', timestep)
318+
saveplot(fig0, 'sveldvel', timestep)
318319

319320
# plotting velocity and second invariant of stress
320321
if 'str' in conf.plates.plot:
@@ -350,7 +351,7 @@ def plot_plates(step, time, vrms_surface, trench, ridge, agetrench,
350351
conf.plates.dvmax,
351352
facecolor='#8B6914', alpha=0.2)
352353

353-
misc.saveplot(fig0, 'svelstress', timestep)
354+
saveplot(fig0, 'svelstress', timestep)
354355

355356
# plotting velocity
356357
fig1, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(12, 8))
@@ -449,7 +450,7 @@ def plot_plates(step, time, vrms_surface, trench, ridge, agetrench,
449450
plot_plate_limits(ax2, ridge, trench, conf.plates.topomin,
450451
conf.plates.topomax)
451452
ax1.set_title(timestep)
452-
misc.saveplot(fig1, 'sveltopo', timestep)
453+
saveplot(fig1, 'sveltopo', timestep)
453454

454455
if 'age' in conf.plates.plot:
455456
ax4.set_ylabel("Seafloor age [My]")
@@ -463,7 +464,7 @@ def plot_plates(step, time, vrms_surface, trench, ridge, agetrench,
463464
plot_plate_limits(ax4, ridge, trench, conf.plates.agemin,
464465
conf.plates.agemax)
465466
ax3.set_title(timestep)
466-
misc.saveplot(fig2, 'svelage', timestep)
467+
saveplot(fig2, 'svelage', timestep)
467468

468469
# writing the output into a file, all time steps are in one file
469470
for isubd in np.arange(len(distance_subd)):
@@ -505,7 +506,7 @@ def lithospheric_stress(step, trench, ridge, time):
505506
# Annotation with time and step
506507
axis.text(1., 0.9, str(round(time, 0)) + ' My', transform=axis.transAxes)
507508
axis.text(1., 0.1, str(timestep), transform=axis.transAxes)
508-
misc.saveplot(fig, 'lith', timestep)
509+
saveplot(fig, 'lith', timestep)
509510

510511
# velocity
511512
vphi = step.fields['v2'][0, :, :, 0]
@@ -576,7 +577,7 @@ def lithospheric_stress(step, trench, ridge, time):
576577
conf.plates.lstressmax, facecolor='#8b6914', alpha=0.2)
577578
ax2.set_ylim(conf.plates.stressmin, conf.plates.lstressmax)
578579

579-
misc.saveplot(fig0, 'svelslith', timestep)
580+
saveplot(fig0, 'svelslith', timestep)
580581

581582

582583
def set_of_vars(arg_plot):
@@ -686,7 +687,7 @@ def main_plates(sdat):
686687
# Put arrow where ridges and trenches are
687688
plot_plate_limits_field(axis, rcmb, ridges, trenches)
688689

689-
misc.saveplot(fig, 'eta', timestep, close=False)
690+
saveplot(fig, 'eta', timestep, close=conf.plates.zoom is None)
690691

691692
# Zoom
692693
if conf.plates.zoom is not None:
@@ -704,8 +705,7 @@ def main_plates(sdat):
704705
yzoom = (rcmb + 1) * np.sin(np.radians(conf.plates.zoom))
705706
axis.set_xlim(xzoom - ladd, xzoom + radd)
706707
axis.set_ylim(yzoom - dadd, yzoom + uadd)
707-
misc.saveplot(fig, 'etazoom', timestep, close=False)
708-
plt.close(fig)
708+
saveplot(fig, 'etazoom', timestep)
709709

710710
# plot stress field with position of trenches and ridges
711711
if 'str' in conf.plates.plot:
@@ -721,14 +721,13 @@ def main_plates(sdat):
721721
# Put arrow where ridges and trenches are
722722
plot_plate_limits_field(axis, rcmb, ridges, trenches)
723723

724-
misc.saveplot(fig, 's', timestep, close=False)
724+
saveplot(fig, 's', timestep, close=conf.plates.zoom is None)
725725

726726
# Zoom
727727
if conf.plates.zoom is not None:
728728
axis.set_xlim(xzoom - ladd, xzoom + radd)
729729
axis.set_ylim(yzoom - dadd, yzoom + uadd)
730-
misc.saveplot(fig, 'szoom', timestep, close=False)
731-
plt.close(fig)
730+
saveplot(fig, 'szoom', timestep)
732731

733732
# calculate stresses in the lithosphere
734733
lithospheric_stress(step, trenches, ridges, time)
@@ -759,7 +758,7 @@ def main_plates(sdat):
759758
# Put arrow where ridges and trenches are
760759
plot_plate_limits_field(axis, rcmb, ridges, trenches)
761760

762-
misc.saveplot(fig, 'sx', timestep)
761+
saveplot(fig, 'sx', timestep)
763762

764763

765764
def cmd():
@@ -814,7 +813,7 @@ def cmd():
814813
plt.hist(sizeplates, 10, (0, nphi / 2))
815814
plt.subplot(224)
816815
plt.plot(water_profile)
817-
misc.saveplot(fig, 'plates', step.isnap)
816+
saveplot(fig, 'plates', step.isnap)
818817

819818
nb_plates.append(len(limits))
820819

@@ -829,4 +828,4 @@ def cmd():
829828
plt.plot(time, nb_plates)
830829
plt.subplot(122)
831830
plt.plot(time, ch2o)
832-
misc.saveplot(figt, f'plates_{istart}_{iend}')
831+
saveplot(figt, f'plates_{istart}_{iend}')

stagpy/refstate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import matplotlib.pyplot as plt
44

5-
from . import conf, misc
5+
from . import conf, _helpers
66
from .phyvars import REFSTATE
77
from .stagyydata import StagyyData
88

@@ -31,7 +31,7 @@ def plot_ref(sdat, var):
3131
axis.set_ylabel('z Position')
3232
if len(adbts) > 2:
3333
axis.legend()
34-
misc.saveplot(fig, f'refstate_{var}')
34+
_helpers.saveplot(fig, f'refstate_{var}')
3535

3636

3737
def cmd():

stagpy/rprof.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
"""Plot radial profiles."""
22
import matplotlib.pyplot as plt
33

4-
from . import conf, misc
4+
from . import conf, _helpers
55
from .stagyydata import StagyyData
66

77

8-
def plot_rprofs(rprofs, lovs):
8+
def plot_rprofs(rprofs, names):
99
"""Plot requested radial profiles.
1010
1111
Args:
1212
rprofs (:class:`~stagpy._step._Rprofs`): a radial profile viewer
1313
such as :attr:`Step.rprofs` and :attr:`_StepsView.rprofs_averaged`.
14-
lovs (nested list of str): nested list of profile names such as the one
15-
produced by :func:`stagpy.misc.list_of_vars`.
14+
names (str): profile names separated by ``-`` (figures), ``.``
15+
(subplots) and ``,`` (same subplot).
1616
"""
1717
try:
1818
stepstr = rprofs.steps.stepstr
1919
except AttributeError:
2020
stepstr = str(rprofs.step.istep)
2121
sdat = rprofs.step.sdat
2222

23-
for vfig in lovs:
23+
for vfig in _helpers.list_of_vars(names):
2424
fig, axes = plt.subplots(ncols=len(vfig), sharey=True,
2525
figsize=(4 * len(vfig), 6))
2626
axes = [axes] if len(vfig) == 1 else axes
@@ -56,7 +56,7 @@ def plot_rprofs(rprofs, lovs):
5656
_, unit = sdat.scale(1, 'm')
5757
ylabel += f' ({unit})' if unit else ''
5858
axes[0].set_ylabel(ylabel)
59-
misc.saveplot(fig, fname + stepstr)
59+
_helpers.saveplot(fig, fname + stepstr)
6060

6161

6262
def plot_grid(step):
@@ -79,7 +79,7 @@ def plot_grid(step):
7979
ax2.set_ylabel('$dr$' + unit)
8080
ax2.set_xlim([-0.5, len(rad) - 0.5])
8181
ax2.set_xlabel('Cell number')
82-
misc.saveplot(fig, 'grid', step.istep)
82+
_helpers.saveplot(fig, 'grid', step.istep)
8383

8484

8585
def cmd():
@@ -95,12 +95,8 @@ def cmd():
9595
for step in sdat.walk.filter(rprofs=True):
9696
plot_grid(step)
9797

98-
lovs = misc.list_of_vars(conf.rprof.plot)
99-
if not lovs:
100-
return
101-
10298
if conf.rprof.average:
103-
plot_rprofs(sdat.walk.rprofs_averaged, lovs)
99+
plot_rprofs(sdat.walk.rprofs_averaged, conf.rprof.plot)
104100
else:
105101
for step in sdat.walk.filter(rprofs=True):
106-
plot_rprofs(step.rprofs, lovs)
102+
plot_rprofs(step.rprofs, conf.rprof.plot)

0 commit comments

Comments
 (0)