Skip to content

Commit 7662ea7

Browse files
committed
Version 2.0.3
1 parent 355126d commit 7662ea7

7 files changed

+89
-86
lines changed

haversine.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module haversine
2727
!
2828
! If you have ifort on your system, change 'gfortran' to 'intelem'!
2929
!
30-
! Version 2.0.1
30+
! Version 2.0.3
3131
!
3232
!===========================================================================
3333
implicit none

make_eddy_track_AVISO.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
make_eddy_track_AVISO.py
2626
27-
Version 2.0.1
27+
Version 2.0.3
2828
2929
3030
Scroll down to line ~640 to get started
@@ -87,7 +87,6 @@ class PyEddyTracker (object):
8787
def __init__(self):
8888
"""
8989
Set some constants
90-
9190
*ZERO_CROSSING*:
9291
Boolean, *True* if THE_DOMAIN crosses 0 degree meridian
9392
"""
@@ -318,15 +317,15 @@ def get_AVISO_f_pm_pn(self):
318317
# Get pm and pn
319318
pm = np.zeros_like(self.lonpad())
320319
pm[:, 1:-1] = self.haversine_dist(lonu[:, :-1], latu[:, :-1],
321-
lonu[:, 1:], latu[:, 1:])
320+
lonu[:, 1:], latu[:, 1:])
322321
pm[:, 0] = pm[:, 1]
323322
pm[:, -1] = pm[:, -2]
324323
self._dx = pm
325324
self._pm = np.reciprocal(pm)
326325

327326
pn = np.zeros_like(self.lonpad())
328327
pn[1:-1] = self.haversine_dist(lonv[:-1], latv[:-1],
329-
lonv[1:], latv[1:])
328+
lonv[1:], latv[1:])
330329
pn[0] = pn[1]
331330
pn[-1] = pn[-2]
332331
self._dy = pn
@@ -499,7 +498,7 @@ def __init__(self, AVISO_FILE, THE_DOMAIN, PRODUCT,
499498
Initialise the grid object
500499
"""
501500
super(AvisoGrid, self).__init__()
502-
print '\nInitialising the *AVISO_grid*'
501+
print('\nInitialising the *AVISO_grid*')
503502
self.THE_DOMAIN = THE_DOMAIN
504503
if 'AVISO' in PRODUCT:
505504
self.PRODUCT = 'AVISO'
@@ -601,7 +600,6 @@ def get_AVISO_data(self, AVISO_FILE):
601600

602601
try: # Extrapolate over land points with fillmask
603602
zeta = fillmask(zeta, self.mask == 1)
604-
#zeta = fillmask(zeta, 1 + (-1 * zeta.mask))
605603
except Exception: # In case no landpoints
606604
zeta = np.ma.masked_array(zeta)
607605
return zeta.astype(np.float64)
@@ -847,7 +845,7 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
847845
else:
848846
PRODUCT = 'AVISO_DT10'
849847
DAYS_BTWN_RECORDS = 7. # old seven day AVISO
850-
848+
config['DAYS_BTWN_RECORDS'] = DAYS_BTWN_RECORDS
851849
AVISO_FILES = config['AVISO']['AVISO_FILES']
852850

853851
#TRACK_DURATION_MIN = config['TRACK_DURATION_MIN']
@@ -972,10 +970,10 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
972970

973971
# See Chelton section B2 (0.4 degree radius)
974972
# These should give 8 and 1000 for 0.25 deg resolution
975-
PIXMIN = np.round((np.pi * config['RADMIN']**2) /
976-
sla_grd.get_resolution()**2)
977-
PIXMAX = np.round((np.pi * config['RADMAX']**2) /
978-
sla_grd.get_resolution()**2)
973+
PIXMIN = np.round((np.pi * config['RADMIN'] ** 2) /
974+
sla_grd.get_resolution() ** 2)
975+
PIXMAX = np.round((np.pi * config['RADMAX'] ** 2) /
976+
sla_grd.get_resolution() ** 2)
979977
print '--- Pixel range = %s-%s' % (np.int(PIXMIN),
980978
np.int(PIXMAX))
981979

@@ -1093,7 +1091,7 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
10931091
xi / sla_grd.f()[sla_grd.jup0:sla_grd.jup1,
10941092
sla_grd.iup0:sla_grd.iup1])
10951093

1096-
xicopy = np.ma.copy(xi)
1094+
xicopy = xi.copy()
10971095

10981096
elif 'SLA' in DIAGNOSTIC_TYPE:
10991097

@@ -1103,11 +1101,11 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
11031101
C_eddy.slacopy = sla.copy()
11041102

11051103
# Get scalar speed
1106-
uspd = np.sqrt(sla_grd.u**2 + sla_grd.v**2)
1104+
uspd = np.sqrt(sla_grd.u ** 2 + sla_grd.v ** 2)
11071105
uspd = np.ma.masked_where(
11081106
sla_grd.mask[sla_grd.jup0:sla_grd.jup1,
11091107
sla_grd.iup0:sla_grd.iup1] == 0,
1110-
uspd)
1108+
uspd)
11111109
A_eddy.uspd = uspd.copy()
11121110
C_eddy.uspd = uspd.copy()
11131111

@@ -1121,7 +1119,7 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
11211119
# Get contours of Q/sla parameter
11221120
if 'first_record' not in locals():
11231121

1124-
print '------ processing SLA contours for eddies'
1122+
print('------ processing SLA contours for eddies')
11251123
contfig = plt.figure(99)
11261124
ax = contfig.add_subplot(111)
11271125

@@ -1252,7 +1250,7 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
12521250
A_eddy.set_old_variables()
12531251
C_eddy.set_old_variables()
12541252
START = False
1255-
print '------ tracking eddies'
1253+
print('------ tracking eddies')
12561254
else:
12571255
first_record = False
12581256

@@ -1278,9 +1276,9 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
12781276
if not first_record:
12791277

12801278
if A_eddy.VERBOSE:
1281-
print '--- saving to nc', A_eddy.SAVE_DIR
1282-
print '--- saving to nc', C_eddy.SAVE_DIR
1283-
print '+++'
1279+
print('--- saving to nc', A_eddy.SAVE_DIR)
1280+
print('--- saving to nc', C_eddy.SAVE_DIR)
1281+
print('+++')
12841282

12851283
A_eddy.write2netcdf(rtime)
12861284
C_eddy.write2netcdf(rtime)

make_eddy_track_ROMS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
make_eddy_track_ROMS.py
2626
27-
Version 2.0.0
27+
Version 2.0.3
2828
2929
3030

make_eddy_tracker_list_obj.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
2626
make_eddy_tracker_list_obj.py
2727
28-
Version 2.0.1
28+
Version 2.0.3
2929
3030
3131
===========================================================================
@@ -483,7 +483,7 @@ def get_active_tracks(self, rtime):
483483
active_tracks.append(i)
484484
return active_tracks
485485

486-
def get_inactive_tracks(self, rtime):
486+
def get_inactive_tracks(self, rtime, stopper=0):
487487
"""
488488
Return list of indices to inactive tracks.
489489
This call also identifies and removes
@@ -495,6 +495,15 @@ def get_inactive_tracks(self, rtime):
495495
inactive_tracks.append(i)
496496
return inactive_tracks
497497

498+
def kill_all_tracks(self):
499+
"""
500+
Mark all tracks as not alive
501+
"""
502+
for track in self.tracklist:
503+
track.alive = False
504+
print('------ all %s tracks killed for final saving'
505+
% self.SIGN_TYPE.replace('one', 'onic').lower())
506+
498507
def create_netcdf(self, directory, savedir,
499508
grd=None, YMIN=None, YMAX=None,
500509
MMIN=None, MMAX=None, MODEL=None,
@@ -742,13 +751,17 @@ def _remove_inactive_tracks(self):
742751
self.tracklist = tracklist.tolist()
743752
return alive_inds
744753

745-
def write2netcdf(self, rtime):
754+
def write2netcdf(self, rtime, stopper=0):
746755
"""
747756
Write inactive tracks to netcdf file.
748757
'ncind' is important because prevents writing of
749758
already written tracks.
750759
Each inactive track is 'emptied' after saving
760+
761+
rtime - current timestamp
762+
stopper - dummy value (either 0 or 1)
751763
"""
764+
rtime += stopper
752765
tracks2save = np.array([self.get_inactive_tracks(rtime)])
753766
DBR = self.DAYS_BTWN_RECORDS
754767

@@ -833,7 +846,12 @@ def write2netcdf(self, rtime):
833846
self.ncind += tsize
834847
self.ch_index += 1
835848
nc.sync()
836-
849+
850+
# Print final message and return
851+
if stopper:
852+
print('All %ss saved' % self.SIGN_TYPE.replace('one', 'onic').lower())
853+
return
854+
837855
# Get index to first currently active track
838856
#try:
839857
#lasti = self.get_active_tracks(rtime)[0]

py_eddy_tracker_classes.py

Lines changed: 44 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
py_eddy_tracker_classes.py
2626
27-
Version 2.0.1
27+
Version 2.0.3
2828
===========================================================================
2929
3030
@@ -376,7 +376,7 @@ def fit_circle(xvec, yvec):
376376

377377
# Indices of polygon points outside circle
378378
# p_inon_? : polygon x or y points inside & on the circle
379-
pout_id = np.nonzero(dist_poly > r)
379+
pout_id = (dist_poly > r).nonzero()
380380

381381
p_inon_x = xvec # init
382382
p_inon_y = yvec # init
@@ -954,9 +954,10 @@ def track_eddies(Eddy, first_record):
954954
new_cntr_e, new_cntr_s, new_uavg_prf = [], [], []
955955
new_shp_err = np.array([])
956956

957-
new_inds, backup_ind, backup_dist = np.array([], dtype=np.int16), \
958-
np.array([], dtype=np.int16), \
959-
np.array([])
957+
#new_inds, backup_ind, backup_dist = np.array([], dtype=np.int16), \
958+
#np.array([], dtype=np.int16), \
959+
#np.array([])
960+
backup_ind = np.array([], dtype=np.int16)
960961

961962
'''
962963
# See http://stackoverflow.com/questions/11528078/determining-duplicate-values-in-an-array
@@ -983,6 +984,7 @@ def track_eddies(Eddy, first_record):
983984
plt.xlabel('new')
984985
plt.ylabel('old')
985986
plt.title('original')
987+
plt.show()
986988

987989
# Make an ellipse at current old_eddy location
988990
# (See CSS11 sec. B4, pg. 208)
@@ -997,7 +999,7 @@ def track_eddies(Eddy, first_record):
997999
for new_ind in new_sparse_inds:
9981000

9991001
new_dist = dist_mat[old_ind, new_ind]
1000-
1002+
10011003
within_range = False
10021004
#print far_away, Eddy.search_ellipse.rw_c_mod, new_dist
10031005
if new_dist < Eddy.search_ellipse.rw_c_mod:#far_away:
@@ -1018,54 +1020,38 @@ def track_eddies(Eddy, first_record):
10181020

10191021
# Pass only the eddies within ellipse or sep_dist
10201022
if within_range:
1023+
1024+
dist_arr = np.r_[dist_arr, new_dist]
1025+
new_ln.append(Eddy.new_lon_tmp[new_ind])
1026+
new_lt.append(Eddy.new_lat_tmp[new_ind])
1027+
new_rd_s.append(Eddy.new_radii_tmp_s[new_ind])
1028+
new_rd_e.append(Eddy.new_radii_tmp_e[new_ind])
1029+
new_am.append(Eddy.new_amp_tmp[new_ind])
1030+
new_Ua.append(Eddy.new_uavg_tmp[new_ind])
1031+
new_ek.append(Eddy.new_teke_tmp[new_ind])
1032+
new_tm.append(Eddy.new_time_tmp[new_ind])
10211033

1022-
old_amplitude[:] = Eddy.old_amp[old_ind]
1023-
new_amplitude[:] = Eddy.new_amp_tmp[new_ind]
1024-
1025-
# Following CSS11, we use effective radius rather than speed based...
1026-
old_area[:] = Eddy.old_radii_s[old_ind]**2
1027-
old_area *= np.pi
1028-
new_area[:] = Eddy.new_radii_tmp_s[new_ind]**2
1029-
new_area *= np.pi
1030-
1031-
# Pass only the eddies within min and max times old amplitude
1032-
# and area (KCCMC11 and CSS11 use 0.25 and 2.5, respectively)
1033-
if (new_amplitude >= (Eddy.EVOLVE_AMP_MIN * old_amplitude) and
1034-
new_amplitude <= (Eddy.EVOLVE_AMP_MAX * old_amplitude)) and \
1035-
(new_area >= (Eddy.EVOLVE_AREA_MIN * old_area) and
1036-
new_area <= (Eddy.EVOLVE_AREA_MAX * old_area)):
1037-
1038-
dist_arr = np.r_[dist_arr, new_dist]
1039-
new_ln.append(Eddy.new_lon_tmp[new_ind])
1040-
new_lt.append(Eddy.new_lat_tmp[new_ind])
1041-
new_rd_s.append(Eddy.new_radii_tmp_s[new_ind])
1042-
new_rd_e.append(Eddy.new_radii_tmp_e[new_ind])
1043-
new_am.append(Eddy.new_amp_tmp[new_ind])
1044-
new_Ua.append(Eddy.new_uavg_tmp[new_ind])
1045-
new_ek.append(Eddy.new_teke_tmp[new_ind])
1046-
new_tm.append(Eddy.new_time_tmp[new_ind])
1047-
1048-
if 'ROMS' in Eddy.PRODUCT:
1049-
#new_tp = np.r_[new_tp, Eddy.new_temp_tmp[new_ind]]
1050-
#new_st = np.r_[new_st, Eddy.new_salt_tmp[new_ind]]
1051-
pass
1052-
1053-
if Eddy.TRACK_EXTRA_VARIABLES:
1054-
new_cntr_e.append(Eddy.new_contour_e_tmp[new_ind])
1055-
new_cntr_s.append(Eddy.new_contour_s_tmp[new_ind])
1056-
new_uavg_prf.append(Eddy.new_uavg_profile_tmp[new_ind])
1057-
new_shp_err = np.r_[new_shp_err,
1058-
Eddy.new_shape_error_tmp[new_ind]]
1059-
1060-
new_inds = np.r_[new_inds, new_ind]
1061-
backup_ind = np.r_[backup_ind, new_ind]
1062-
1063-
# An old (active) eddy has been detected, so
1064-
# corresponding new_eddy_inds set to False
1065-
new_eddy_inds[np.nonzero(Eddy.new_lon_tmp ==
1066-
Eddy.new_lon_tmp[new_ind])] = False
1067-
1068-
dist_mat[:, new_ind] = far_away # km
1034+
1035+
if 'ROMS' in Eddy.PRODUCT:
1036+
#new_tp = np.r_[new_tp, Eddy.new_temp_tmp[new_ind]]
1037+
#new_st = np.r_[new_st, Eddy.new_salt_tmp[new_ind]]
1038+
pass
1039+
1040+
if Eddy.TRACK_EXTRA_VARIABLES:
1041+
new_cntr_e.append(Eddy.new_contour_e_tmp[new_ind])
1042+
new_cntr_s.append(Eddy.new_contour_s_tmp[new_ind])
1043+
new_uavg_prf.append(Eddy.new_uavg_profile_tmp[new_ind])
1044+
new_shp_err = np.r_[new_shp_err,
1045+
Eddy.new_shape_error_tmp[new_ind]]
1046+
1047+
backup_ind = np.r_[backup_ind, new_ind]
1048+
1049+
# An old (active) eddy has been detected, so
1050+
# corresponding new_eddy_inds set to False
1051+
new_eddy_inds[np.nonzero(Eddy.new_lon_tmp ==
1052+
Eddy.new_lon_tmp[new_ind])] = False
1053+
1054+
dist_mat[:, new_ind] = far_away # km
10691055

10701056
if Eddy.TRACK_EXTRA_VARIABLES:
10711057
kwargs = {'contour_e': new_cntr_e, 'contour_s': new_cntr_s,
@@ -1075,7 +1061,6 @@ def track_eddies(Eddy, first_record):
10751061

10761062
# Only one eddy within range
10771063
if dist_arr.size == 1: # then update the eddy track only
1078-
10791064
# Use index 0 here because type is list and we want the scalar
10801065
args = (Eddy, old_ind, new_ln[0], new_lt[0], new_rd_s[0],
10811066
new_rd_e[0], new_am[0], new_Ua[0], new_ek[0], new_tm[0],
@@ -1103,8 +1088,8 @@ def track_eddies(Eddy, first_record):
11031088

11041089
# Choice of using effective or speed-based...
11051090
delta_area_tmp = np.array([np.pi *
1106-
(Eddy.old_radii_e[old_ind]**2),
1107-
np.pi * (new_rd_e[i]**2)]).ptp()
1091+
(Eddy.old_radii_e[old_ind] ** 2),
1092+
np.pi * (new_rd_e[i] ** 2)]).ptp()
11081093
delta_amp_tmp = np.array([Eddy.old_amp[old_ind],
11091094
new_am[i]]).ptp()
11101095
delta_area = np.r_[delta_area, delta_area_tmp]
@@ -1120,9 +1105,9 @@ def track_eddies(Eddy, first_record):
11201105
#np.abs(np.diff([Eddy.old_salt[old_ind], new_st[i]]))]
11211106

11221107
# This from Penven etal (2005)
1123-
deltaX = np.sqrt((delta_area / AREA0)**2 +
1124-
(delta_amp / AMP0)**2 +
1125-
(dist_arr / DIST0)**2)
1108+
deltaX = np.sqrt((delta_area / AREA0) ** 2 +
1109+
(delta_amp / AMP0) ** 2 +
1110+
(dist_arr / DIST0) ** 2)
11261111

11271112
dx = deltaX.argsort()
11281113
dx0 = dx[0] # index to the nearest eddy

py_eddy_tracker_property_classes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
2626
py_eddy_tracker_amplitude.py
2727
28-
Version 2.0.1
28+
Version 2.0.3
2929
3030
3131
===========================================================================
@@ -297,6 +297,8 @@ def debug_figure(self, grd):
297297
#cmin, cmax = (self.sla.min(), self.sla.max())
298298
cm = plt.cm.gist_ncar
299299
#cm = plt.cm.hsv
300+
print self.h0_check.shape
301+
print self.contlon.shape
300302

301303
plt.title('Local max/min count: %s, Amp: %s' % (
302304
self.local_extrema, self.amplitude))

0 commit comments

Comments
 (0)