Skip to content

Commit 2fe51c4

Browse files
committed
isurf and icont abstracted in function
1 parent 1973fcc commit 2fe51c4

File tree

1 file changed

+22
-45
lines changed

1 file changed

+22
-45
lines changed

stagpy/plates.py

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,7 @@ def detect_plates(step, vrms_surface, fids, time):
7171
vphi = step.fields['v2'].values[0, :, :, 0]
7272
ph_coord = step.geom.p_centers
7373

74-
if step.sdat.par['boundaries']['air_layer']:
75-
dsa = step.sdat.par['boundaries']['air_thickness']
76-
# we are a bit below the surface; should check if you are in the
77-
# thermal boundary layer
78-
indsurf = np.argmin(
79-
np.abs(1 - dsa - step.geom.r_centers + step.geom.rcmb)) - 4
80-
else:
81-
indsurf = -1
74+
indsurf, _ = _isurf_icont(step)
8275

8376
# vphi at cell-center
8477
vph2 = 0.5 * (vphi[1:] + vphi[:-1])
@@ -174,6 +167,23 @@ def plot_plate_limits_field(axis, rcmb, ridges, trenches):
174167
arrowprops=dict(facecolor='green', shrink=0.05))
175168

176169

170+
def _isurf_icont(snap):
171+
"""Return index of surface and of continent detection."""
172+
if snap.sdat.par['boundaries']['air_layer']:
173+
dsa = snap.sdat.par['boundaries']['air_thickness']
174+
# we are a bit below the surface; delete "-some number" to be just
175+
# below the surface (that is considered plane here); should check if
176+
# in the thermal boundary layer
177+
isurf = np.argmin(
178+
np.abs(1 - dsa - snap.geom.r_centers + snap.geom.rcmb)) - 4
179+
# depth to detect the continents
180+
icont = isurf - 6
181+
else:
182+
isurf = -1
183+
icont = -1
184+
return isurf, icont
185+
186+
177187
def plot_plates(step, time, vrms_surface, trench, ridge, agetrench,
178188
topo, fids):
179189
"""Handle plotting stuff."""
@@ -182,21 +192,7 @@ def plot_plates(step, time, vrms_surface, trench, ridge, agetrench,
182192
concfld = step.fields['c'].values[0, :, :, 0]
183193
timestep = step.isnap
184194

185-
if step.sdat.par['boundaries']['air_layer']:
186-
dsa = step.sdat.par['boundaries']['air_thickness']
187-
# we are a bit below the surface; delete "-some number"
188-
# to be just below
189-
# the surface (that is considered plane here); should check if you are
190-
# in the thermal boundary layer
191-
indsurf = np.argmin(
192-
np.abs(1 - dsa - step.geom.r_centers + step.geom.rcmb)) - 4
193-
# depth to detect the continents
194-
indcont = np.argmin(
195-
np.abs(1 - dsa - step.geom.r_centers + step.geom.rcmb)) - 10
196-
else:
197-
indsurf = -1
198-
indcont = -1 # depth to detect continents
199-
195+
indsurf, indcont = _isurf_icont(step)
200196
if step.sdat.par['boundaries']['air_layer'] and\
201197
not step.sdat.par['continents']['proterozoic_belts']:
202198
continents = np.ma.masked_where(
@@ -479,16 +475,7 @@ def lithospheric_stress(step, trench, ridge, time):
479475

480476
# position of continents
481477
concfld = step.fields['c'].values[0, :, :, 0]
482-
if step.sdat.par['boundaries']['air_layer']:
483-
# we are a bit below the surface; delete "-some number"
484-
# to be just below
485-
dsa = step.sdat.par['boundaries']['air_thickness']
486-
# depth to detect the continents
487-
indcont = np.argmin(
488-
np.abs(1 - dsa - step.geom.r_centers + step.geom.rcmb)) - 10
489-
else:
490-
# depth to detect continents
491-
indcont = -1
478+
_, indcont = _isurf_icont(step)
492479
if step.sdat.par['boundaries']['air_layer'] and\
493480
not step.sdat.par['continents']['proterozoic_belts']:
494481
continents = np.ma.masked_where(
@@ -606,15 +593,8 @@ def main_plates(sdat):
606593
# averaged horizontal surface velocity needed for redimensionalisation
607594
uprof_averaged, radius, _ = sdat.walk.filter(rprofs=True)\
608595
.rprofs_averaged['vhrms']
609-
if sdat.par['boundaries']['air_layer']:
610-
dsa = sdat.par['boundaries']['air_thickness']
611-
isurf = np.argmin(abs(radius - radius[-1] + dsa))
612-
vrms_surface = uprof_averaged[isurf]
613-
isurf = np.argmin(abs((1 - dsa) - radius))
614-
isurf -= 4 # why different isurf for the rest?
615-
else:
616-
isurf = -1
617-
vrms_surface = uprof_averaged[isurf]
596+
isurf, _ = _isurf_icont(next(iter(sdat.walk)))
597+
vrms_surface = uprof_averaged[isurf]
618598

619599
# determine names of files
620600
fnames = ['plate_velocity', 'distance_subd']
@@ -633,9 +613,6 @@ def main_plates(sdat):
633613
# topography
634614
fname = sdat.filename('sc', timestep=timestep, suffix='.dat')
635615
topo = np.genfromtxt(str(fname))
636-
# rescaling topography!
637-
if sdat.par['boundaries']['air_layer']:
638-
topo[:, 1] = topo[:, 1] / (1. - dsa)
639616

640617
time = step.time * vrms_surface *\
641618
conf.scaling.ttransit / conf.scaling.yearins / 1.e6

0 commit comments

Comments
 (0)