Skip to content

Commit f562142

Browse files
committed
Simplify _write_trench_diagnostics
Remove several unnecessary variables.
1 parent 8dd18c3 commit f562142

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

stagpy/plates.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -237,41 +237,31 @@ def plot_at_surface(snap, names, trenches, ridges):
237237

238238
def _write_trench_diagnostics(step, time, trench, agetrench, fids):
239239
"""Handle plotting stuff."""
240-
timestep = step.isnap
241-
ph_coord = step.geom.p_centers
242-
continents = _continents_location(step)
240+
phi_cont = step.geom.p_centers[_continents_location(step)]
243241

244-
times_subd = []
245-
age_subd = []
246242
distance_subd = []
247-
ph_trench_subd = []
248243
ph_cont_subd = []
249-
if step.sdat.par['switches']['cont_tracers']:
250-
for i, trench_i in enumerate(trench):
251-
# detection of the distance in between subduction and continent
252-
angdistance1 = abs(ph_coord[continents] - trench_i)
253-
angdistance2 = 2. * np.pi - angdistance1
254-
angdistance = np.minimum(angdistance1, angdistance2)
255-
distancecont = min(angdistance)
256-
argdistancecont = np.argmin(angdistance)
257-
continentpos = ph_coord[continents][argdistancecont]
258-
259-
ph_trench_subd.append(trench_i)
260-
age_subd.append(agetrench[i])
261-
ph_cont_subd.append(continentpos)
262-
distance_subd.append(distancecont)
263-
times_subd.append(step.time)
244+
245+
for trench_i in trench:
246+
# compute distance between subduction and continent
247+
angdistance1 = np.abs(phi_cont - trench_i)
248+
angdistance2 = 2 * np.pi - angdistance1
249+
angdistance = np.minimum(angdistance1, angdistance2)
250+
i_closest = np.argmin(angdistance)
251+
252+
ph_cont_subd.append(phi_cont[i_closest])
253+
distance_subd.append(angdistance[i_closest])
264254

265255
# writing the output into a file, all time steps are in one file
266-
for isubd in np.arange(len(distance_subd)):
256+
for isubd in range(len(distance_subd)):
267257
fids[1].write("%6.0f %11.7f %11.3f %10.6f %10.6f %10.6f %11.3f\n" % (
268-
timestep,
269-
times_subd[isubd],
258+
step.isnap,
259+
step.time,
270260
time,
271261
distance_subd[isubd],
272-
ph_trench_subd[isubd],
262+
trench[isubd],
273263
ph_cont_subd[isubd],
274-
age_subd[isubd],
264+
agetrench[isubd],
275265
))
276266

277267

0 commit comments

Comments
 (0)