Skip to content

Commit a9f3ad2

Browse files
committed
Group IO in _write_trench_diagnostics
1 parent f562142 commit a9f3ad2

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

stagpy/plates.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ def detect_plates(step):
7575

7676
indsurf = _isurf(step)
7777

78-
# vphi at cell-center
79-
vph2 = 0.5 * (vphi[1:] + vphi[:-1])
8078
# dvphi/dphi at cell-center
8179
dvph2 = np.diff(vphi[:, indsurf]) / (ph_coord[1] - ph_coord[0])
8280

@@ -88,7 +86,6 @@ def detect_plates(step):
8886
argless_dv = argrelextrema(
8987
pom2, np.less, order=trench_span, mode='wrap')[0]
9088
trench = ph_coord[argless_dv]
91-
v_trenches = vph2[argless_dv, indsurf]
9289

9390
# finding ridges
9491
pom2 = np.copy(dvph2)
@@ -109,7 +106,7 @@ def detect_plates(step):
109106
if argdel:
110107
ridge = np.delete(ridge, np.array(argdel))
111108

112-
return trench, ridge, argless_dv, v_trenches
109+
return trench, ridge, argless_dv
113110

114111

115112
def plot_plate_limits(axis, ridges, trenches):
@@ -235,14 +232,43 @@ def plot_at_surface(snap, names, trenches, ridges):
235232
saveplot(fig, fname, snap.isnap)
236233

237234

238-
def _write_trench_diagnostics(step, time, trench, agetrench, fids):
239-
"""Handle plotting stuff."""
235+
def _write_trench_diagnostics(step, vrms_surf, itrenches, fids):
236+
"""Print out some trench diagnostics."""
237+
time = step.time * vrms_surf *\
238+
conf.scaling.ttransit / conf.scaling.yearins / 1.e6
239+
isurf = _isurf(step)
240+
trenches = step.geom.p_centers[itrenches]
241+
242+
# vphi at trenches
243+
vphi = step.fields['v2'].values[0, :, isurf, 0]
244+
vphi = (vphi[1:] + vphi[:-1]) / 2
245+
v_trenches = vphi[itrenches]
246+
247+
if 'age' in step.fields:
248+
agefld = step.fields['age'].values[0, :, isurf, 0]
249+
age_surface = np.ma.masked_where(agefld < 1.e-5, agefld)
250+
age_surface_dim = age_surface * vrms_surf *\
251+
conf.scaling.ttransit / conf.scaling.yearins / 1.e6
252+
agetrenches = age_surface_dim[itrenches] # age at the trench
253+
else:
254+
agetrenches = np.zeros(len(itrenches))
255+
256+
# writing the output into a file, all time steps are in one file
257+
for itrench in range(len(trenches)):
258+
fids[0].write("%7.0f %11.7f %10.6f %9.2f %9.2f \n" % (
259+
step.isnap,
260+
step.time,
261+
trenches[itrench],
262+
v_trenches[itrench],
263+
agetrenches[itrench]
264+
))
265+
240266
phi_cont = step.geom.p_centers[_continents_location(step)]
241267

242268
distance_subd = []
243269
ph_cont_subd = []
244270

245-
for trench_i in trench:
271+
for trench_i in trenches:
246272
# compute distance between subduction and continent
247273
angdistance1 = np.abs(phi_cont - trench_i)
248274
angdistance2 = 2 * np.pi - angdistance1
@@ -259,9 +285,9 @@ def _write_trench_diagnostics(step, time, trench, agetrench, fids):
259285
step.time,
260286
time,
261287
distance_subd[isubd],
262-
trench[isubd],
288+
trenches[isubd],
263289
ph_cont_subd[isubd],
264-
agetrench[isubd],
290+
agetrenches[isubd],
265291
))
266292

267293

@@ -312,7 +338,7 @@ def main_plates(sdat):
312338
"""Plot several plates information."""
313339
# averaged horizontal surface velocity needed for redimensionalisation
314340
isurf = _isurf(next(iter(sdat.walk)))
315-
vrms_surface = sdat.walk.filter(rprofs=True)\
341+
vrms_surf = sdat.walk.filter(rprofs=True)\
316342
.rprofs_averaged['vhrms'].values[isurf]
317343

318344
# determine names of files
@@ -326,35 +352,9 @@ def main_plates(sdat):
326352

327353
for step in sdat.walk.filter(fields=['T']):
328354
# could check other fields too
329-
timestep = step.isnap
330-
print('Treating snapshot', timestep)
331-
332-
time = step.time * vrms_surface *\
333-
conf.scaling.ttransit / conf.scaling.yearins / 1.e6
334-
trenches, ridges, itrenches, v_trenches = detect_plates(step)
335-
336-
if 'age' in step.fields:
337-
agefld = step.fields['age'].values[0, :, :, 0]
338-
age_surface = np.ma.masked_where(agefld[:, isurf] < 1.e-5,
339-
agefld[:, isurf])
340-
age_surface_dim = age_surface * vrms_surface *\
341-
conf.scaling.ttransit / conf.scaling.yearins / 1.e6
342-
agetrenches = age_surface_dim[itrenches] # age at the trench
343-
else:
344-
agetrenches = np.zeros(len(itrenches))
345-
346-
# writing the output into a file, all time steps are in one file
347-
for itrench in range(len(trenches)):
348-
fids[0].write("%7.0f %11.7f %10.6f %9.2f %9.2f \n" % (
349-
step.isnap,
350-
step.time,
351-
trenches[itrench],
352-
v_trenches[itrench],
353-
agetrenches[itrench]
354-
))
355-
356-
_write_trench_diagnostics(step, time, trenches, agetrenches, fids)
355+
trenches, ridges, itrenches = detect_plates(step)
357356

357+
_write_trench_diagnostics(step, vrms_surf, itrenches, fids)
358358
plot_at_surface(step, conf.plates.plot, trenches, ridges)
359359
plot_scalar_field(step, conf.plates.field, ridges, trenches)
360360

0 commit comments

Comments
 (0)