Skip to content

Commit 78b287a

Browse files
author
emason
committed
Introduction of SwirlSpeed object
1 parent 99b0580 commit 78b287a

File tree

4 files changed

+141
-48
lines changed

4 files changed

+141
-48
lines changed

eddy_tracker_configuration.yaml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,33 @@ DOMAIN:
1212
THE_DOMAIN: 'Global'
1313
#THE_DOMAIN = 'BlackSea'
1414
#THE_DOMAIN = 'MedSea' # not yet implemented
15-
LONMIN: -65. # -38.
16-
LONMAX: -5.5 # -25.
17-
LATMIN: 11.5 # 30.
18-
LATMAX: 38.5 # 38.
19-
DATE_STR: 19930101
20-
DATE_END: 20131231
15+
LONMIN: -70.
16+
LONMAX: -5.
17+
LATMIN: 5.
18+
LATMAX: 55.
19+
DATE_STR: 20020101
20+
DATE_END: 20020630
2121

2222
# Specify the AVISO product
2323
AVISO:
2424
AVISO_DT14: Yes # Use new AVISO DT14 data (e.g., Capet et al, 2014)
2525
AVISO_FILES: 'dt_global_twosat_msla_h_????????_20140106.nc'
26-
AVISO_DT14_SUBSAMP: Yes # subsample the dqily AVISO DT14
26+
AVISO_DT14_SUBSAMP: No # subsample the dqily AVISO DT14
2727
DAYS_BTWN_RECORDS: 7 # sampling rate (days)
2828

2929
PATHS:
3030
# Path to AVISO data
31-
#DATA_DIR: '/data/PVA/Externe/global/delayed-time/grids/msla/two-sat-merged/h/2002/'
32-
DATA_DIR: '/marula/emason/data/altimetry/global/delayed-time/grids/msla/two-sat-merged/h/'
31+
DATA_DIR: '/data/PVA/Externe/global/delayed-time/grids/msla/two-sat-merged/h/2002/'
32+
#DATA_DIR: '/marula/emason/data/altimetry/global/delayed-time/grids/msla/two-sat-merged/h/'
3333
# Path and filename of Chelton et al (1998) Rossby radius data
3434
# Obtain file from:
3535
# http://www-po.coas.oregonstate.edu/research/po/research/rossby_radius/
36-
#RW_PATH: '/homelocal/emason/rossrad.dat'
37-
RW_PATH: '/home/emason/data_tmp/chelton_eddies/rossrad.dat'
36+
RW_PATH: '/homelocal/emason/rossrad.dat'
37+
#RW_PATH: '/home/emason/data_tmp/chelton_eddies/rossrad.dat'
3838

3939
# Path for saving of outputs
40-
#SAVE_DIR: '/homelocal/emason/outputs/'
41-
# SAVE_DIR: '/marula/emason/aviso_eddy_tracking/fd0cdb4b2bd9/'
42-
SAVE_DIR: '/marula/emason/aviso_eddy_tracking/fd0cdb4b2bd9/'
40+
SAVE_DIR: '/homelocal/emason/outputs/'
41+
#SAVE_DIR: '/marula/emason/aviso_eddy_tracking/fd0cdb4b2bd9/'
4342

4443
# Reference Julian day (Julian date at Jan 1, 1992)
4544
JDAY_REFERENCE: 2448623.

make_eddy_track_AVISO.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
datestr2datetime, gaussian_resolution, \
3737
get_cax, collection_loop, track_eddies, \
3838
anim_figure, interpolate
39+
from py_eddy_tracker_amplitude import SwirlSpeed
3940
import make_eddy_tracker_list_obj as eddy_tracker
4041
from dateutil import parser
4142
from mpl_toolkits.basemap import Basemap
@@ -153,7 +154,7 @@ def set_index_padding(self, pad=2):
153154
around 2d variables.
154155
Padded matrices are needed only for geostrophic velocity computation.
155156
"""
156-
print '--- Setting padding indices with pad=%s' %pad
157+
print '--- Setting padding indices with PAD=%s' %pad
157158

158159
self.pad = pad
159160

@@ -1163,7 +1164,10 @@ def set_interp_coeffs(self, sla, uspd):
11631164
plt.axis('image')
11641165
plt.show()
11651166

1166-
1167+
# Set contour coordinates and indices for calculation of
1168+
# speed-based radius
1169+
A_eddy.swirl = SwirlSpeed(A_CS)
1170+
C_eddy.swirl = SwirlSpeed(C_CS)
11671171

11681172
# Now we loop over the CS collection
11691173
A_eddy.sign_type = 'Anticyclonic'

py_eddy_tracker_amplitude.py

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,82 @@ def debug_figure(self):
214214
lmi_j = lmi_j[0] + self.grd.jmin
215215
x_i, y_i = self.grd.lon()[lmi_j, lmi_i], self.grd.lat()[lmi_j, lmi_i]
216216
plt.scatter(x_i, y_i, c='gray')
217-
plt.show()
217+
plt.show()
218+
219+
220+
221+
class SwirlSpeed(object):
222+
"""
223+
"""
224+
def __init__(self, contour):
225+
"""
226+
ci : index to contours
227+
li : index to levels
228+
"""
229+
self.x = []
230+
self.y = []
231+
self.ci = []
232+
self.li = []
233+
234+
for lind, cont in enumerate(contour.collections):
235+
for cind, coll in enumerate(cont.get_paths()):
236+
self.x.append(coll.vertices[:, 0])
237+
self.y.append(coll.vertices[:, 1])
238+
thelen = len(coll.vertices[:, 0])
239+
self.ci.append([cind] * thelen)
240+
self.li.append([lind] * thelen)
241+
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)
248+
249+
self.nearesti = None
250+
self.dist = None
251+
self.lbool = None
252+
253+
254+
def _set_level_bool(self, thelevel):
255+
"""
256+
Set a boolean to select only values to a discrete
257+
contour level in self.li
258+
"""
259+
self.lbool = self.li == thelevel
260+
return self
261+
262+
263+
def set_dist_array_size(self, thelevel):
264+
"""
265+
"""
266+
self._set_level_bool(thelevel)
267+
self.dist = np.empty_like(self.li[self.lbool])
268+
return self
269+
270+
271+
def set_nearest_contour_index(self, xpt, ypt):
272+
"""
273+
"""
274+
self.dist[:] = (self.x[self.lbool] - xpt)**2
275+
self.dist += (self.y[self.lbool] - ypt)**2
276+
try:
277+
self.nearesti = self.dist.argmin()
278+
except:
279+
self.nearesti = None
280+
return self
281+
282+
283+
def get_index_nearest_path(self):
284+
"""
285+
"""
286+
ind = self.nearesti
287+
if ind is not None:
288+
return self.ci[self.lbool[ind]]
289+
else:
290+
return False
291+
292+
293+
294+
295+

py_eddy_tracker_classes.py

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -522,44 +522,56 @@ def get_uavg(Eddy, CS, collind, centlon_e, centlat_e, poly_eff,
522522
citer = np.nditer(CS.cvalues, flags=['c_index'])
523523
#print '************************************************'
524524
while not citer.finished:
525+
526+
## Get contour around centlon_e, centlat_e at level [collind:][iuavg]
527+
#segi, poly_i = eddy_tracker.find_nearest_contour(
528+
#CS.collections[citer.index], centlon_e, centlat_e)
529+
530+
531+
#
532+
Eddy.swirl.set_dist_array_size(citer.index)
533+
Eddy.swirl.set_nearest_contour_index(centlon_e, centlat_e)
534+
segi = Eddy.swirl.get_index_nearest_path()
535+
536+
537+
if segi:
538+
539+
poly_i = CS.collections[citer.index].get_paths()[segi]
525540

526-
# Get contour around centlon_e, centlat_e at level [collind:][iuavg]
527-
segi, poly_i = eddy_tracker.find_nearest_contour(
528-
CS.collections[citer.index], centlon_e, centlat_e)
541+
##print poly_ii is poly_i
529542

530-
if poly_i is not None:
543+
#if poly_i is not None:
531544

532-
# NOTE: contains_points requires matplotlib 1.3 +
533-
mask_i_sum = poly_i.contains_points(points).sum()
534545

535546
# 1. Ensure polygon_i is within polygon_e
536547
# 2. Ensure polygon_i contains point centlon_e, centlat_e
537548
# 3. Respect size range
538-
if np.all([poly_eff.contains_path(poly_i),
539-
poly_i.contains_point([centlon_e, centlat_e]),
540-
(mask_i_sum >= pixel_min and
541-
mask_i_sum <= Eddy.PIXEL_THRESHOLD[1])]):
542-
543-
seglon, seglat = poly_i.vertices[:, 0], poly_i.vertices[:, 1]
544-
seglon, seglat = eddy_tracker.uniform_resample(
545-
seglon, seglat, method='akima')
546-
547-
# Interpolate uspd to seglon, seglat, then get mean
548-
uavgseg = Eddy.uspd_coeffs.ev(seglat[:-1], seglon[:-1]).mean()
549-
#uavgseg = uavgseg
550-
#uavgseg = rbspline.ev(seglat[:-1], seglon[:-1]).mean()
551-
#uavgseg = uavgseg.mean()
552-
#print uavgseg
553-
#assert uavgseg == uavgsegsss, 'fffffffffffff'
554-
555-
if save_all_uavg:
556-
all_uavg.append(uavgseg)
549+
#if np.all([poly_eff.contains_path(poly_i),
550+
#poly_i.contains_point([centlon_e, centlat_e]),
551+
#(mask_i_sum >= pixel_min and
552+
#mask_i_sum <= Eddy.PIXEL_THRESHOLD[1])]):
553+
if poly_i.contains_point([centlon_e, centlat_e]):
554+
if poly_eff.contains_path(poly_i):
555+
# NOTE: contains_points requires matplotlib 1.3 +
556+
mask_i_sum = poly_i.contains_points(points).sum()
557+
if (mask_i_sum >= pixel_min and
558+
mask_i_sum <= Eddy.PIXEL_THRESHOLD[1]):
557559

558-
if (uavgseg >= uavg) and (mask_i_sum >= pixel_min):
559-
uavg = uavgseg.copy()
560-
theseglon, theseglat = seglon.copy(), seglat.copy()
561-
562-
inner_seglon, inner_seglat = seglon.copy(), seglat.copy()
560+
seglon, seglat = poly_i.vertices[:, 0], poly_i.vertices[:, 1]
561+
seglon, seglat = eddy_tracker.uniform_resample(
562+
seglon, seglat, method='akima')
563+
564+
# Interpolate uspd to seglon, seglat, then get mean
565+
uavgseg = Eddy.uspd_coeffs.ev(seglat[:-1], seglon[:-1]).mean()
566+
567+
if save_all_uavg:
568+
all_uavg.append(uavgseg)
569+
570+
if uavgseg >= uavg:
571+
uavg = uavgseg.copy()
572+
theseglon, theseglat = seglon.copy(), seglat.copy()
573+
574+
inner_seglon, inner_seglat = seglon.copy(), seglat.copy()
563575

564576
citer.iternext()
565577

@@ -747,7 +759,7 @@ def collection_loop(CS, grd, rtime, A_list_obj, C_list_obj,
747759
if VERBOSE:
748760
message = '------ doing collection %s, contour value %s'
749761
print message % (collind, CS.cvalues[collind])
750-
762+
751763
# Loop over individual CS contours (i.e., every eddy in field)
752764
for cont in coll.get_paths():
753765

0 commit comments

Comments
 (0)