Skip to content

Commit a453d5a

Browse files
committed
Plot any scalar field with plate info
eta was hard-coded as the scalar field to plot with continents and plate limits. This commit abstracts and generalize this plot to any scalar field.
1 parent 2a72177 commit a453d5a

File tree

2 files changed

+50
-52
lines changed

2 files changed

+50
-52
lines changed

stagpy/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ def _index_collection(arg):
182182
Conf('c,eta,sc', True, 'o',
183183
{'nargs': '?', 'const': '', 'type': str},
184184
True, 'variables to plot (see stagpy var)')),
185+
('field',
186+
Conf('eta', True, None, {},
187+
True, 'field variable to plot with plates info')),
185188
('vzcheck', switch_opt(False, None,
186189
'activate Colin\'s version with vz checking')),
187190
('timeprofile', switch_opt(False, None,

stagpy/plates.py

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,51 @@ def set_of_vars(arg_plot):
556556
return set(var for var in arg_plot.split(',') if var in phyvars.PLATES)
557557

558558

559+
def plot_scalar_field(step, fieldname, ridges, trenches):
560+
"""Plot scalar field with plate information."""
561+
fig, axis, _, _ = field.plot_scalar(step, fieldname)
562+
563+
# plotting continents
564+
concfld = step.fields['c'].values[0, :, :, 0]
565+
continentsfld = np.ma.masked_where(
566+
concfld < 3, concfld) # plotting continents, to-do
567+
continentsfld = continentsfld / continentsfld
568+
cbar = conf.field.colorbar
569+
conf.field.colorbar = False
570+
field.plot_scalar(step, 'c', continentsfld, axis,
571+
cmap='cool_r', vmin=0, vmax=0)
572+
cmap2 = plt.cm.ocean
573+
cmap2.set_over('m')
574+
conf.field.colorbar = cbar
575+
576+
# plotting velocity vectors
577+
field.plot_vec(axis, step, 'v')
578+
579+
# Put arrow where ridges and trenches are
580+
plot_plate_limits_field(axis, step.geom.rcmb, ridges, trenches)
581+
582+
saveplot(fig, f'plates_{fieldname}', step.isnap,
583+
close=conf.plates.zoom is None)
584+
585+
# Zoom
586+
if conf.plates.zoom is not None:
587+
if not 0 <= conf.plates.zoom <= 360:
588+
raise error.InvalidZoomError(conf.plates.zoom)
589+
if 45 < conf.plates.zoom <= 135:
590+
ladd, radd, uadd, dadd = 0.8, 0.8, 0.05, 0.1
591+
elif 135 < conf.plates.zoom <= 225:
592+
ladd, radd, uadd, dadd = 0.05, 0.1, 0.8, 0.8
593+
elif 225 < conf.plates.zoom <= 315:
594+
ladd, radd, uadd, dadd = 0.8, 0.8, 0.1, 0.05
595+
else: # >315 or <=45
596+
ladd, radd, uadd, dadd = 0.1, 0.05, 0.8, 0.8
597+
xzoom = (step.geom.rcmb + 1) * np.cos(np.radians(conf.plates.zoom))
598+
yzoom = (step.geom.rcmb + 1) * np.sin(np.radians(conf.plates.zoom))
599+
axis.set_xlim(xzoom - ladd, xzoom + radd)
600+
axis.set_ylim(yzoom - dadd, yzoom + uadd)
601+
saveplot(fig, f'plates_zoom_{fieldname}', step.isnap)
602+
603+
559604
def main_plates(sdat):
560605
"""Plot several plates information."""
561606
# averaged horizontal surface velocity needed for redimensionalisation
@@ -600,58 +645,8 @@ def main_plates(sdat):
600645
plot_plates(step, time, vrms_surface, trenches, ridges,
601646
agetrenches, topo, fids)
602647

603-
# prepare for continent plotting
604-
concfld = step.fields['c'].values[0, :, :, 0]
605-
continentsfld = np.ma.masked_where(
606-
concfld < 3, concfld) # plotting continents, to-do
607-
continentsfld = continentsfld / continentsfld
608-
609-
# plot viscosity field with position of trenches and ridges
610-
etamin, _ = sdat.scale(1e-2, 'Pa')
611-
etamax, _ = sdat.scale(sdat.par['viscosity']['eta_max'], 'Pa')
612-
fig, axis, _, _ = field.plot_scalar(step, 'eta',
613-
vmin=etamin, vmax=etamax)
614-
615-
# plotting continents
616-
cbar = conf.field.colorbar
617-
conf.field.colorbar = False
618-
field.plot_scalar(step, 'c', continentsfld, axis,
619-
cmap='cool_r', vmin=0, vmax=0)
620-
cmap2 = plt.cm.ocean
621-
cmap2.set_over('m')
622-
conf.field.colorbar = cbar
623-
624-
# plotting velocity vectors
625-
field.plot_vec(axis, step, 'v')
626-
627-
# Annotation with time and step
628-
axis.text(1., 0.9, str(round(time, 0)) + ' My',
629-
transform=axis.transAxes)
630-
axis.text(1., 0.1, str(timestep),
631-
transform=axis.transAxes)
632-
633-
# Put arrow where ridges and trenches are
634-
plot_plate_limits_field(axis, rcmb, ridges, trenches)
635-
636-
saveplot(fig, 'eta', timestep, close=conf.plates.zoom is None)
637-
638-
# Zoom
639-
if conf.plates.zoom is not None:
640-
if not 0 <= conf.plates.zoom <= 360:
641-
raise error.InvalidZoomError(conf.plates.zoom)
642-
if 45 < conf.plates.zoom <= 135:
643-
ladd, radd, uadd, dadd = 0.8, 0.8, 0.05, 0.1
644-
elif 135 < conf.plates.zoom <= 225:
645-
ladd, radd, uadd, dadd = 0.05, 0.1, 0.8, 0.8
646-
elif 225 < conf.plates.zoom <= 315:
647-
ladd, radd, uadd, dadd = 0.8, 0.8, 0.1, 0.05
648-
else: # >315 or <=45
649-
ladd, radd, uadd, dadd = 0.1, 0.05, 0.8, 0.8
650-
xzoom = (rcmb + 1) * np.cos(np.radians(conf.plates.zoom))
651-
yzoom = (rcmb + 1) * np.sin(np.radians(conf.plates.zoom))
652-
axis.set_xlim(xzoom - ladd, xzoom + radd)
653-
axis.set_ylim(yzoom - dadd, yzoom + uadd)
654-
saveplot(fig, 'etazoom', timestep)
648+
# plot scalar field with position of trenches and ridges
649+
plot_scalar_field(step, conf.plates.field, ridges, trenches)
655650

656651
# plot stress field with position of trenches and ridges
657652
if 'str' in conf.plates.plot:

0 commit comments

Comments
 (0)