Skip to content

Commit fe897f5

Browse files
author
adelepoulle
committed
Fix for speed grid
1 parent aa62baf commit fe897f5

File tree

3 files changed

+37
-43
lines changed

3 files changed

+37
-43
lines changed

src/py_eddy_tracker/grid/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,21 +369,17 @@ def set_geostrophic_velocity(self, zeta):
369369
surface from variables f, zeta, p_m, p_n...
370370
Note: output at rho points
371371
"""
372-
gof = self.gof.view()
373-
374-
vmask = self.vmask.view()
375372
zeta1, zeta2 = zeta.data[1:].view(), zeta.data[:-1].view()
376373
pn1, pn2 = self.p_n[1:].view(), self.p_n[:-1].view()
377-
self.upad[:] = self.v2rho_2d(vmask * (zeta1 - zeta2) *
378-
0.5 * (pn1 + pn2))
379-
self.upad *= -gof
374+
self.upad[:] = self.v2rho_2d(
375+
np.ma.array((zeta1 - zeta2) * 0.5 * (pn1 + pn2), mask= self.vmask))
376+
self.upad *= -self.gof
380377

381-
umask = self.umask.view()
382378
zeta1, zeta2 = zeta.data[:, 1:].view(), zeta.data[:, :-1].view()
383379
pm1, pm2 = self.p_m[:, 1:].view(), self.p_m[:, :-1].view()
384-
self.vpad[:] = self.u2rho_2d(umask * (zeta1 - zeta2) *
385-
0.5 * (pm1 + pm2))
386-
self.vpad *= gof
380+
self.vpad[:] = self.u2rho_2d(
381+
np.ma.array((zeta1 - zeta2) *0.5 * (pm1 + pm2), mask=self.umask))
382+
self.vpad *= self.gof
387383
return self
388384

389385
def set_u_v_eke(self, pad=2):

src/py_eddy_tracker/property_functions.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from .tracking_objects import uniform_resample, nearest
3737
from .observations import EddiesObservations
3838
from .property_objects import Amplitude
39-
from .tools import distance, winding_number_poly, fit_circle_c
39+
from .tools import distance, winding_number_poly, fit_circle_c, poly_contain_poly
4040
from matplotlib.path import Path as BasePath
4141
from scipy.interpolate import griddata
4242

@@ -166,7 +166,6 @@ def get_uavg(eddy, contours, centlon_e, centlat_e, poly_eff, grd,
166166

167167
if 'RectBivariate' in eddy.interp_method:
168168
uavg = eddy.uspd_coeffs.ev(theseglat[1:], theseglon[1:]).mean()
169-
170169
elif 'griddata' in eddy.interp_method:
171170
uspd1d = eddy.uspd[eddy.slice_j, eddy.slice_i].ravel()
172171
uavg = griddata(points, uspd1d,
@@ -201,7 +200,6 @@ def get_uavg(eddy, contours, centlon_e, centlat_e, poly_eff, grd,
201200
# Leave loop if no contours at level citer.index
202201
theindex = eddy.swirl.get_index_nearest_path(
203202
corrected_coll_index, centlon_e, centlat_e)
204-
205203
if theindex is None:
206204
continue
207205

@@ -212,15 +210,14 @@ def get_uavg(eddy, contours, centlon_e, centlat_e, poly_eff, grd,
212210
continue
213211

214212
# 2. Ensure polygon_i is within polygon_e
215-
if not poly_eff.contains_path(poly_i):
213+
if not poly_contain_poly(poly_eff.vertices, poly_i.vertices):
216214
continue
217215

218216
# 3. Respect size range
219217
mask_i_sum = poly_i.contains_points(points).sum()
220218
if not (mask_i_sum >= pixel_min and
221219
mask_i_sum <= eddy.pixel_threshold[1]):
222220
continue
223-
224221
any_inner_contours = True
225222

226223
seglon, seglat = (poly_i.vertices[:, 0], poly_i.vertices[:, 1])
@@ -249,27 +246,14 @@ def get_uavg(eddy, contours, centlon_e, centlat_e, poly_eff, grd,
249246

250247
if not any_inner_contours:
251248
# set speed based contour parameters
252-
# proj = Proj('+proj=aeqd +lat_0=%s +lon_0=%s'
253-
# % (theseglat.mean(), theseglon.mean()))
254-
# cx, cy = proj(theseglon, theseglat)
255-
# # cx, cy = eddy.m_val(theseglon, theseglat)
256-
# centx_s, centy_s, eddy_radius_s, junk = fit_circle(cx, cy)
257-
# centlon_s, centlat_s = proj(centx_s, centy_s, inverse=True)
258-
# # centlon_s, centlat_s = eddy.m_val(centx_s, centy_s, inverse=True)
259-
260-
# else: # use the effective contour
261-
# centlon_s, centlat_s = centlon_e, centlat_e
262-
# eddy_radius_s = eddy_radius_e
263249
inner_seglon, inner_seglat = theseglon, theseglat
264250

265251
if not save_all_uavg:
266-
# return (uavg, centlon_s, centlat_s, eddy_radius_s,
267-
# theseglon, theseglat, inner_seglon, inner_seglat)
268-
return (uavg, theseglon, theseglat, inner_seglon, inner_seglat)
269-
252+
return (uavg, theseglon, theseglat,
253+
inner_seglon, inner_seglat, any_inner_contours)
270254
else:
271-
return (uavg, theseglon, theseglat, inner_seglon, inner_seglat,
272-
all_uavg)
255+
return (uavg, theseglon, theseglat,
256+
inner_seglon, inner_seglat, any_inner_contours, all_uavg)
273257

274258

275259
def isvalid(self):
@@ -438,8 +422,6 @@ def collection_loop(contours, grd, rtime, a_list_obj, c_list_obj,
438422
if 'Q' in eddy.diagnostic_type:
439423
# KCCMC11
440424
# Note, eddy amplitude == max(abs(vort/f)) within eddy,
441-
# amplitude = np.abs(x_i[jmin:jmax,imin:imax
442-
# ].flat[mask_eff]).max()
443425
amplitude = np.abs(x_i[eddy.slice_j, eddy.slice_i
444426
][eddy.mask_eff]).max()
445427

@@ -475,19 +457,15 @@ def collection_loop(contours, grd, rtime, a_list_obj, c_list_obj,
475457
#~ if eddy.track_array_variables > 0:
476458

477459
if not eddy.track_extra_variables:
478-
# (uavg, centlon_s, centlat_s,
479-
# eddy_radius_s, contlon_s, contlat_s,
480-
# inner_contlon, inner_contlat) = get_uavg(*args)
481460
(uavg, contlon_s, contlat_s,
482-
inner_contlon, inner_contlat) = get_uavg(*args)
461+
inner_contlon, inner_contlat,
462+
any_inner_contours
463+
) = get_uavg(*args)
483464
else:
484-
# (uavg, centlon_s, centlat_s,
485-
# eddy_radius_s, contlon_s, contlat_s,
486-
# inner_contlon, inner_contlat,
487-
# uavg_profile) = get_uavg(*args, save_all_uavg=True)
488465
(uavg, contlon_s, contlat_s,
489466
inner_contlon, inner_contlat,
490-
uavg_profile) = get_uavg(
467+
any_inner_contours, uavg_profile
468+
) = get_uavg(
491469
*args, save_all_uavg=True)
492470

493471
# Use azimuth equal projection for radius

src/py_eddy_tracker/tools.pyx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,26 @@ cdef is_left(
132132
return product > 0
133133

134134

135+
@wraparound(False)
136+
@boundscheck(False)
137+
def poly_contain_poly(
138+
ndarray[DTYPE_coord, ndim=2] xy_poly_out,
139+
ndarray[DTYPE_coord, ndim=2] xy_poly_in
140+
):
141+
cdef DTYPE_ui i_elt, nb_elt
142+
cdef int wn = 0
143+
nb_elt = xy_poly_in.shape[0]
144+
for i_elt from 0 <= i_elt < (nb_elt):
145+
wn = winding_number_poly(
146+
xy_poly_in[i_elt, 0],
147+
xy_poly_in[i_elt, 1],
148+
xy_poly_out
149+
)
150+
if wn ==0:
151+
return False
152+
return True
153+
154+
135155
@wraparound(False)
136156
@boundscheck(False)
137157
def winding_number_poly(

0 commit comments

Comments
 (0)