@@ -65,7 +65,8 @@ def detect_plates(snap, vz_thres_ratio=0):
6565 if itrenches .size and iridges .size :
6666 for i , iridge in enumerate (iridges ):
6767 mdistance = np .amin (np .abs (phi_trenches - phi [iridge ]))
68- if mdistance < 0.016 :
68+ phi_span = snap .geom .p_walls [- 1 ] - snap .geom .p_walls [0 ]
69+ if mdistance < 2.5e-3 * phi_span :
6970 argdel .append (i )
7071 if argdel :
7172 iridges = np .delete (iridges , argdel )
@@ -90,22 +91,32 @@ def _plot_plate_limits(axis, trenches, ridges):
9091 axis .axvline (x = ridge , color = 'green' , ls = 'dashed' , alpha = 0.4 )
9192
9293
93- def _plot_plate_limits_field (axis , rcmb , trenches , ridges ):
94+ def _annot_pos (geom , iphi ):
95+ """Position of arrows to mark limit positions."""
96+ phi = geom .p_centers [iphi ]
97+ rtot = geom .r_walls [- 1 ]
98+ thick = rtot - geom .rcmb
99+ r_beg = rtot + 0.02 * thick
100+ r_end = rtot + 0.35 * thick
101+ if geom .cartesian :
102+ return (phi , r_beg ), (phi , r_end )
103+ # spherical to cartesian
104+ p_beg = r_beg * np .cos (phi ), r_beg * np .sin (phi )
105+ p_end = r_end * np .cos (phi ), r_end * np .sin (phi )
106+ return p_beg , p_end
107+
108+
109+ def _plot_plate_limits_field (axis , snap ):
94110 """Plot arrows designating ridges and trenches in 2D field plots."""
95- for trench in trenches :
96- xxd = (rcmb + 1.02 ) * np .cos (trench ) # arrow begin
97- yyd = (rcmb + 1.02 ) * np .sin (trench ) # arrow begin
98- xxt = (rcmb + 1.35 ) * np .cos (trench ) # arrow end
99- yyt = (rcmb + 1.35 ) * np .sin (trench ) # arrow end
100- axis .annotate ('' , xy = (xxd , yyd ), xytext = (xxt , yyt ),
111+ itrenches , iridges = detect_plates (snap , conf .plates .vzratio )
112+ for itrench in itrenches :
113+ p_beg , p_end = _annot_pos (snap .geom , itrench )
114+ axis .annotate ('' , xy = p_beg , xytext = p_end ,
101115 arrowprops = dict (facecolor = 'red' , shrink = 0.05 ),
102116 annotation_clip = False )
103- for ridge in ridges :
104- xxd = (rcmb + 1.02 ) * np .cos (ridge )
105- yyd = (rcmb + 1.02 ) * np .sin (ridge )
106- xxt = (rcmb + 1.35 ) * np .cos (ridge )
107- yyt = (rcmb + 1.35 ) * np .sin (ridge )
108- axis .annotate ('' , xy = (xxd , yyd ), xytext = (xxt , yyt ),
117+ for iridge in iridges :
118+ p_beg , p_end = _annot_pos (snap .geom , iridge )
119+ axis .annotate ('' , xy = p_beg , xytext = p_end ,
109120 arrowprops = dict (facecolor = 'green' , shrink = 0.05 ),
110121 annotation_clip = False )
111122
@@ -114,11 +125,10 @@ def _isurf(snap):
114125 """Return index of surface accounting for air layer."""
115126 if snap .sdat .par ['boundaries' ]['air_layer' ]:
116127 dsa = snap .sdat .par ['boundaries' ]['air_thickness' ]
117- # we are a bit below the surface; delete "-some number" to be just
118- # below the surface (that is considered plane here); should check if
119- # in the thermal boundary layer
120- isurf = np .argmin (
121- np .abs (1 - dsa - snap .geom .r_centers + snap .geom .rcmb )) - 4
128+ # Remove arbitrary margin to be below the surface.
129+ # Should check if in the thermal boundary layer.
130+ rtot = snap .geom .r_walls [- 1 ]
131+ isurf = snap .geom .at_r (rtot - dsa ) - 4
122132 else :
123133 isurf = - 1
124134 return isurf
@@ -138,9 +148,12 @@ def _surf_diag(snap, name):
138148 return Field (field [0 , :, isurf , 0 ], meta )
139149 if name == 'dv2' :
140150 vphi = snap .fields ['v2' ].values [0 , :, isurf , 0 ]
141- dvphi = np .diff (vphi ) / (snap .geom .r_centers [isurf ] *
142- np .diff (snap .geom .p_walls ))
143- return Field (dvphi , phyvars .Varf (r"$dv_\phi/d\phi$" , '1/s' ))
151+ if snap .geom .cartesian :
152+ dvphi = np .diff (vphi ) / np .diff (snap .geom .p_walls )
153+ else :
154+ dvphi = np .diff (vphi ) / (snap .geom .r_centers [isurf ] *
155+ np .diff (snap .geom .p_walls ))
156+ return Field (dvphi , phyvars .Varf (r"$dv_\phi/rd\phi$" , '1/s' ))
144157 raise error .UnknownVarError (name )
145158
146159
@@ -291,10 +304,7 @@ def plot_scalar_field(snap, fieldname):
291304 field .plot_vec (axis , snap , 'sx' if conf .plates .stress else 'v' )
292305
293306 # Put arrow where ridges and trenches are
294- phi = snap .geom .p_centers
295- itrenches , iridges = detect_plates (snap , conf .plates .vzratio )
296- _plot_plate_limits_field (axis , snap .geom .rcmb ,
297- phi [itrenches ], phi [iridges ])
307+ _plot_plate_limits_field (axis , snap )
298308
299309 saveplot (fig , f'plates_{ fieldname } ' , snap .isnap ,
300310 close = conf .plates .zoom is None )
0 commit comments