Skip to content

Commit a573f89

Browse files
committed
Updates to SwirlSpeed object
1 parent 78b287a commit a573f89

File tree

5 files changed

+215
-230
lines changed

5 files changed

+215
-230
lines changed

eddy_tracker_configuration.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ DOMAIN:
1212
THE_DOMAIN: 'Global'
1313
#THE_DOMAIN = 'BlackSea'
1414
#THE_DOMAIN = 'MedSea' # not yet implemented
15-
LONMIN: -70.
15+
LONMIN: -40.
1616
LONMAX: -5.
17-
LATMIN: 5.
18-
LATMAX: 55.
17+
LATMIN: 20.
18+
LATMAX: 30.
1919
DATE_STR: 20020101
20-
DATE_END: 20020630
20+
DATE_END: 20020331
2121

2222
# Specify the AVISO product
2323
AVISO:
@@ -37,6 +37,9 @@ PATHS:
3737
#RW_PATH: '/home/emason/data_tmp/chelton_eddies/rossrad.dat'
3838

3939
# Path for saving of outputs
40+
# SAVE_DIR: '/homelocal/emason/outputs/before_swirl/'
41+
# SAVE_DIR: '/homelocal/emason/outputs/after_swirl/'
42+
# SAVE_DIR: '/homelocal/emason/outputs/after_swirl_slice/'
4043
SAVE_DIR: '/homelocal/emason/outputs/'
4144
#SAVE_DIR: '/marula/emason/aviso_eddy_tracking/fd0cdb4b2bd9/'
4245

make_eddy_track_AVISO.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ def set_interp_coeffs(self, sla, uspd):
11681168
# speed-based radius
11691169
A_eddy.swirl = SwirlSpeed(A_CS)
11701170
C_eddy.swirl = SwirlSpeed(C_CS)
1171-
1171+
11721172
# Now we loop over the CS collection
11731173
A_eddy.sign_type = 'Anticyclonic'
11741174
C_eddy.sign_type = 'Cyclonic'

make_eddy_tracker_list_obj.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ def find_nearest_contour(contcoll, x, y):
344344
dss = lc[:,1] - y
345345
dss **= 2
346346
ds += dss
347+
#print 'ds', ds
347348
d = ds.min()
348349
if d < dmin:
349350
dmin = d

py_eddy_tracker_amplitude.py

Lines changed: 154 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -226,70 +226,196 @@ def __init__(self, contour):
226226
ci : index to contours
227227
li : index to levels
228228
"""
229-
self.x = []
230-
self.y = []
231-
self.ci = []
232-
self.li = []
229+
x = []
230+
y = []
231+
ci = []
232+
li = []
233233

234234
for lind, cont in enumerate(contour.collections):
235235
for cind, coll in enumerate(cont.get_paths()):
236-
self.x.append(coll.vertices[:, 0])
237-
self.y.append(coll.vertices[:, 1])
236+
x.append(coll.vertices[:, 0])
237+
y.append(coll.vertices[:, 1])
238238
thelen = len(coll.vertices[:, 0])
239-
self.ci.append([cind] * thelen)
240-
self.li.append([lind] * thelen)
239+
ci.append(thelen)
240+
#ci.append(coll.vertices.shape[1])
241+
li.append(len(cont.get_paths()))
241242

242-
self.x = np.array([val for sublist in self.x for val in sublist])
243-
self.y = np.array([val for sublist in self.y for val in sublist])
244-
self.ci = np.array([val for sublist in self.ci for val in sublist],
245-
dtype=np.int)
246-
self.li = np.array([val for sublist in self.li for val in sublist],
247-
dtype=np.int)
243+
self.x = np.array([val for sublist in x for val in sublist])
244+
self.y = np.array([val for sublist in y for val in sublist])
245+
self.nb_pt_per_c = np.array(ci)
246+
self.ci = self.nb_pt_per_c.cumsum() - self.nb_pt_per_c
247+
self.nb_c_per_l = np.array(li)
248+
self.li = self.nb_c_per_l.cumsum() - self.nb_c_per_l
248249

249250
self.nearesti = None
250-
self.dist = None
251-
self.lbool = None
251+
self.level_slice = None
252252

253253

254-
def _set_level_bool(self, thelevel):
254+
def _set_level_slice(self, thelevel):
255255
"""
256-
Set a boolean to select only values to a discrete
257-
contour level in self.li
256+
Set slices
258257
"""
259-
self.lbool = self.li == thelevel
258+
if self.nb_c_per_l[thelevel] == 0:
259+
self.level_slice = None
260+
else:
261+
self.level_view_of_contour = slice(self.li[thelevel],
262+
self.li[thelevel] + self.nb_c_per_l[thelevel])
263+
nb_pts = self.nb_pt_per_c[self.level_view_of_contour].sum()
264+
self.level_slice = slice(self.ci[self.li[thelevel]],
265+
self.ci[self.li[thelevel]] + nb_pts)
260266
return self
261267

262268

263269
def set_dist_array_size(self, thelevel):
264270
"""
265271
"""
266-
self._set_level_bool(thelevel)
267-
self.dist = np.empty_like(self.li[self.lbool])
272+
self._set_level_slice(thelevel)
268273
return self
269274

270275

271276
def set_nearest_contour_index(self, xpt, ypt):
272277
"""
273278
"""
274-
self.dist[:] = (self.x[self.lbool] - xpt)**2
275-
self.dist += (self.y[self.lbool] - ypt)**2
279+
#print self.x[self.level_slice]
280+
#print self.y[self.level_slice]
281+
self.dist = (self.x[self.level_slice] - xpt)**2
282+
self.dist += (self.y[self.level_slice] - ypt)**2
283+
#print 'self.dist',self.dist
276284
try:
277285
self.nearesti = self.dist.argmin()
278286
except:
287+
#print 'except'
279288
self.nearesti = None
280289
return self
281290

282291

283292
def get_index_nearest_path(self):
284293
"""
285294
"""
286-
ind = self.nearesti
287-
if ind is not None:
288-
return self.ci[self.lbool[ind]]
295+
if self.nearesti is not None:
296+
#print self.level_view_of_contour
297+
indices_of_first_pts = self.ci[self.level_view_of_contour]
298+
for i, index_of_first_pt in enumerate(indices_of_first_pts):
299+
if (index_of_first_pt - indices_of_first_pts[0]) > self.nearesti:
300+
return i - 1
301+
#print '/////'
302+
return i
289303
else:
304+
#print '-----'
290305
return False
291306

292307

308+
#def get_uavg(self, Eddy, CS, collind, centlon_e, centlat_e, poly_eff,
309+
#grd, eddy_radius_e, properties, save_all_uavg=False):
310+
#"""
311+
#Calculate geostrophic speed around successive contours
312+
#Returns the average
313+
314+
#If save_all_uavg == True we want uavg for every contour
315+
#"""
316+
## Unpack indices for convenience
317+
#imin, imax, jmin, jmax = Eddy.imin, Eddy.imax, Eddy.jmin, Eddy.jmax
318+
319+
#points = np.array([grd.lon()[jmin:jmax, imin:imax].ravel(),
320+
#grd.lat()[jmin:jmax, imin:imax].ravel()]).T
321+
322+
## First contour is the outer one (effective)
323+
#theseglon, theseglat = poly_eff.vertices[:, 0].copy(), \
324+
#poly_eff.vertices[:, 1].copy()
325+
326+
#theseglon, theseglat = eddy_tracker.uniform_resample(
327+
#theseglon, theseglat, method='akima')
328+
329+
#uavg = Eddy.uspd_coeffs.ev(theseglat[:-1], theseglon[:-1]).mean()
293330

331+
#if save_all_uavg:
332+
#all_uavg = [uavg]
333+
#pixel_min = 1 # iterate until 1 pixel
294334

295-
335+
#else:
336+
## Iterate until PIXEL_THRESHOLD[0] number of pixels
337+
#pixel_min = Eddy.PIXEL_THRESHOLD[0]
338+
339+
##start = True
340+
#citer = np.nditer(CS.cvalues, flags=['c_index'])
341+
##print '************************************************'
342+
#while not citer.finished:
343+
344+
### Get contour around centlon_e, centlat_e at level [collind:][iuavg]
345+
##segi, poly_i = eddy_tracker.find_nearest_contour(
346+
##CS.collections[citer.index], centlon_e, centlat_e)
347+
348+
349+
##
350+
#self.swirl.set_dist_array_size(citer.index)
351+
#self.swirl.set_nearest_contour_index(centlon_e, centlat_e)
352+
#segi = Eddy.swirl.get_index_nearest_path()
353+
354+
355+
#if segi:
356+
357+
#poly_i = CS.collections[citer.index].get_paths()[segi]
358+
359+
###print poly_ii is poly_i
360+
361+
##if poly_i is not None:
362+
363+
364+
## 1. Ensure polygon_i is within polygon_e
365+
## 2. Ensure polygon_i contains point centlon_e, centlat_e
366+
## 3. Respect size range
367+
##if np.all([poly_eff.contains_path(poly_i),
368+
##poly_i.contains_point([centlon_e, centlat_e]),
369+
##(mask_i_sum >= pixel_min and
370+
##mask_i_sum <= Eddy.PIXEL_THRESHOLD[1])]):
371+
#if poly_i.contains_point([centlon_e, centlat_e]):
372+
373+
#if poly_eff.contains_path(poly_i):
374+
375+
## NOTE: contains_points requires matplotlib 1.3 +
376+
#mask_i_sum = poly_i.contains_points(points).sum()
377+
#if (mask_i_sum >= pixel_min and
378+
#mask_i_sum <= Eddy.PIXEL_THRESHOLD[1]):
379+
380+
#seglon, seglat = poly_i.vertices[:, 0], poly_i.vertices[:, 1]
381+
#seglon, seglat = eddy_tracker.uniform_resample(
382+
#seglon, seglat, method='akima')
383+
384+
## Interpolate uspd to seglon, seglat, then get mean
385+
#uavgseg = Eddy.uspd_coeffs.ev(seglat[:-1], seglon[:-1]).mean()
386+
387+
#if save_all_uavg:
388+
#all_uavg.append(uavgseg)
389+
390+
#if uavgseg >= uavg:
391+
#uavg = uavgseg.copy()
392+
#theseglon, theseglat = seglon.copy(), seglat.copy()
393+
394+
#inner_seglon, inner_seglat = seglon.copy(), seglat.copy()
395+
396+
#citer.iternext()
397+
398+
#try: # Assuming interior contours have been found
399+
400+
#cx, cy = Eddy.M(theseglon, theseglat)
401+
## Speed based eddy radius (eddy_radius_s)
402+
#centx_s, centy_s, eddy_radius_s, junk = fit_circle(cx, cy)
403+
#centlon_s, centlat_s = Eddy.M.projtran(centx_s, centy_s, inverse=True)
404+
#if not save_all_uavg:
405+
#return (uavg, centlon_s, centlat_s, eddy_radius_s,
406+
#theseglon, theseglat, inner_seglon, inner_seglat)
407+
#else:
408+
#return (uavg, centlon_s, centlat_s, eddy_radius_s,
409+
#theseglon, theseglat, inner_seglon, inner_seglat, all_uavg)
410+
411+
#except Exception: # If no interior contours found, use eddy_radius_e
412+
413+
#if not save_all_uavg:
414+
#return (uavg, centlon_e, centlat_e, eddy_radius_e,
415+
#theseglon, theseglat, theseglon, theseglat)
416+
#else:
417+
#return (uavg, centlon_e, centlat_e, eddy_radius_e,
418+
#theseglon, theseglat, theseglon, theseglat, all_uavg)
419+
420+
421+

0 commit comments

Comments
 (0)