Skip to content

Commit 7ae5615

Browse files
committed
make_eddy_track_CLS.py fixed
1 parent b39af03 commit 7ae5615

File tree

5 files changed

+124
-102
lines changed

5 files changed

+124
-102
lines changed

eddy_tracker_configuration.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ DOMAIN:
2424
AVISO:
2525
AVISO_DT14: Yes # Use new AVISO DT14 data (e.g., Capet et al, 2014)
2626
AVISO_FILES: 'dt_global_twosat_msla_h_????????_20140106.nc'
27+
#AVISO_FILES: 'dt_ref_global_merged_msla_h_qd_????????_????????_????????.nc'
2728
AVISO_DT14_SUBSAMP: No # subsample the daily AVISO DT14
2829
DAYS_BTWN_RECORDS: 7 # sampling rate (days)
2930

@@ -76,7 +77,7 @@ SMOOTHING_Q:
7677
SMOOTH_FAC: 5 # number of passes
7778

7879
# Min and max permitted eddy radii [degrees] and amplitudes (cm)
79-
RADMIN: 0.35 # CSS11 recommend ~50 km minimum
80+
RADMIN: 0.35 # 0.4 for DT10, 0.35 for DT14
8081
RADMAX: 4.461
8182
AMPMIN: 1.
8283
AMPMAX: 150.
@@ -108,7 +109,7 @@ EVOLVE_AREA_MAX: 500 # max change in area
108109

109110

110111
# Make figures for animations
111-
SAVE_FIGURES: Yes
112+
SAVE_FIGURES: No
112113

113114

114115
# Define track_extra_variables to track and save:
@@ -118,9 +119,10 @@ SAVE_FIGURES: Yes
118119
# - profiles of swirl velocity from effective contour inwards
119120
# Useful for working with ARGO data
120121
TRACK_EXTRA_VARIABLES: No
121-
122-
# INTERP_METHOD: 'RectBivariate'
123-
INTERP_METHOD: 'griddata'
122+
123+
# 'RectBivariate' is faster
124+
INTERP_METHOD: 'RectBivariate'
125+
#INTERP_METHOD: 'griddata'
124126

125127

126128

make_eddy_track_AVISO.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
Scroll down to line ~640 to get started
3131
===============================================================================
3232
"""
33-
from matplotlib import use as mpl_use
34-
mpl_use('Agg')
33+
#from matplotlib import use as mpl_use
34+
#mpl_use('Agg')
3535
import sys
3636
import glob as glob
3737
from py_eddy_tracker_classes import plt, np, dt, Dataset, time, \
@@ -520,9 +520,10 @@ def __init__(self, AVISO_FILE, THE_DOMAIN, PRODUCT,
520520

521521
def __getstate__(self):
522522
"""
523-
Needed for Pickle
523+
Remove refernces to unwanted attributes in self.
524+
This reduces the size of saved cPickle objects.
524525
"""
525-
print '--- removing unwanted attributes'
526+
#print '--- removing unwanted attributes'
526527
pops = ('Mx', 'My', '_f', '_angle', '_dx', '_dy', '_gof', '_lon',
527528
'_lat', '_pm', '_pn', '_umask', '_vmask', 'eke', 'u', 'v',
528529
'mask')
@@ -1232,7 +1233,7 @@ def set_interp_coeffs(self, sla, uspd):
12321233

12331234
# Track the eddies
12341235
A_eddy = track_eddies(A_eddy, first_record)
1235-
C_eddy = track_eddies(C_eddy, first_record)
1236+
#C_eddy = track_eddies(C_eddy, first_record)
12361237

12371238
if SAVE_FIGURES: # Make figures for animations
12381239

@@ -1259,7 +1260,9 @@ def set_interp_coeffs(self, sla, uspd):
12591260
print '+++'
12601261

12611262
A_eddy.write2netcdf(rtime)
1262-
C_eddy.write2netcdf(rtime)
1263+
#print '______________________eddy.index', A_eddy.index
1264+
#print '______________________eddy.ncind', A_eddy.ncind
1265+
#C_eddy.write2netcdf(rtime)
12631266

12641267
if str(DATE_END) in AVISO_FILE:
12651268
active = False

make_eddy_track_CLS.py

Lines changed: 78 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -41,83 +41,94 @@
4141

4242
if __name__ == '__main__':
4343

44-
DATA_DIR = '/data/OCE_ETU/MSA/emason/Global_DT10/'
44+
TRACK_DURATION_MIN = 28
45+
46+
#DATA_DIR = '/data/OCE_ETU/MSA/emason/Global_DT10/'
47+
DATA_DIR = '/Users/emason/mercurial_projects/py-eddy-tracker-cls/py-eddy-tracker-cls/outputs/'
4548

4649
A_PKL_FILES = 'A_eddy_????????.pkl'
47-
C_PKL_FILES = 'C_eddy_????????.pkl'
50+
#C_PKL_FILES = 'C_eddy_????????.pkl'
4851

49-
A_PKL_FILES = sorted(glob.glob(DATA_DIR + A_PKL_FILES))
50-
C_PKL_FILES = sorted(glob.glob(DATA_DIR + C_PKL_FILES))
52+
PKL_FILES = glob.glob(DATA_DIR + A_PKL_FILES)
53+
PKL_FILES.sort()
54+
#C_PKL_FILES = glob.glob(DATA_DIR + C_PKL_FILES)
5155

52-
for PKL_FILES in (A_PKL_FILES, C_PKL_FILES):
56+
for active, PKL_FILE in enumerate(PKL_FILES):
5357

54-
for active, PKL_FILE in enumerate(PKL_FILES):
58+
print PKL_FILE
59+
60+
try: del eddy
61+
except: pass
62+
63+
# Unpickle
64+
with open(PKL_FILE, 'rb') as the_pickle:
65+
eddy = pickle.load(the_pickle)
66+
print '--- loaded %s' % PKL_FILE
5567

56-
print PKL_FILE
68+
#print 'eddy.index', eddy.index
69+
eddy.savedir = DATA_DIR + eddy.savedir.rpartition('/')[-1]
5770

58-
# Unpickle
59-
with open(PKL_FILE, 'rb') as the_pickle:
60-
eddy = pickle.load(the_pickle)
61-
print '--- loaded %s' % PKL_FILE
71+
eddy.TRACK_DURATION_MIN = TRACK_DURATION_MIN
6272

63-
#print 'eddy.index', eddy.index
64-
eddy.savedir = DATA_DIR + eddy.savedir.rpartition('/')[-1]
73+
if active:
6574

66-
eddy.TRACK_DURATION_MIN = 10
67-
68-
if active:
69-
70-
first_record = False
71-
72-
eddy.new_list = False
73-
eddy.tracklist = tracklist.tolist()
75+
eddy.new_list = False
76+
eddy.tracklist = tracklist#.tolist()
7477

78+
try:
7579
eddy.index = index
7680
eddy.ch_index = ch_index
81+
#eddy.ncind = ncind
82+
except:
83+
pass
84+
eddy.old_lon = old_lon
85+
eddy.old_lat = old_lat
86+
eddy.old_amp = old_amp
87+
eddy.old_uavg = old_uavg
88+
eddy.old_radii_s = old_radii_s
89+
eddy.old_radii_e = old_radii_e
90+
eddy.old_teke = old_teke
91+
92+
eddy = track_eddies(eddy, first_record)
93+
94+
try:
7795
eddy.ncind = ncind
78-
79-
eddy.old_lon = old_lon
80-
eddy.old_lat = old_lat
81-
eddy.old_amp = old_amp
82-
eddy.old_uavg = old_uavg
83-
eddy.old_radii_s = old_radii_s
84-
eddy.old_radii_e = old_radii_e
85-
eddy.old_teke = old_teke
86-
#eddy.old_temp = old_temp
87-
#eddy.old_salt = old_salt
88-
89-
eddy = track_eddies(eddy, first_record)
90-
tracklist = np.copy(eddy.tracklist)
91-
92-
else:
93-
94-
first_record = True
95-
96-
eddy.create_netcdf(DATA_DIR, eddy.savedir)
97-
eddy.set_old_variables()
98-
99-
eddy = track_eddies(eddy, first_record)
100-
tracklist = np.copy(eddy.tracklist)
101-
102-
print 'eddy.index', eddy.index
103-
print len(eddy.tracklist)
104-
105-
if not first_record:
106-
print eddy.new_time_tmp[0]
107-
eddy.write2netcdf(eddy.new_time_tmp[0])
108-
109-
index = eddy.index
110-
ch_index = eddy.ch_index
111-
ncind = eddy.ncind
112-
113-
old_lon = eddy.old_lon
114-
old_lat = eddy.old_lat
115-
old_amp = eddy.old_amp
116-
old_uavg = eddy.old_uavg
117-
old_radii_s = eddy.old_radii_s
118-
old_radii_e = eddy.old_radii_e
119-
old_teke = eddy.old_teke
120-
#old_temp = eddy.old_temp
121-
#old_salt = eddy.old_salt
122-
123-
#eddy.reset_holding_variables()
96+
except:
97+
pass
98+
99+
else:
100+
101+
eddy.create_netcdf(DATA_DIR, eddy.savedir)
102+
eddy.set_old_variables()
103+
first_record = True
104+
eddy = track_eddies(eddy, first_record)
105+
first_record = False
106+
tracklist = eddy.tracklist
107+
108+
if not first_record:
109+
110+
#print eddy.new_time_tmp[0]
111+
112+
eddy.write2netcdf(eddy.new_time_tmp[0])
113+
# tracklist is modified by write2netcdf, so
114+
# place update just after
115+
tracklist = eddy.tracklist
116+
ncind = np.copy(eddy.ncind)
117+
ch_index = np.copy(eddy.ch_index)
118+
index = np.copy(eddy.index)
119+
120+
#print '______________________eddy.index', eddy.index
121+
#print '______________________eddy.ncind', eddy.ncind
122+
123+
old_lon = eddy.old_lon
124+
#print '______________________eddy.old_lon', eddy.old_lon
125+
old_lat = eddy.old_lat
126+
old_amp = eddy.old_amp
127+
old_uavg = eddy.old_uavg
128+
old_radii_s = eddy.old_radii_s
129+
old_radii_e = eddy.old_radii_e
130+
old_teke = eddy.old_teke
131+
#old_temp = eddy.old_temp
132+
#old_salt = eddy.old_salt
133+
134+
eddy.reset_holding_variables()

make_eddy_tracker_list_obj.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,13 @@ class Track (object):
182182
dayzero - True at first appearance of eddy
183183
"""
184184

185-
def __init__(self, eddy_index, DATATYPE, lon, lat, time, uavg, teke,
185+
def __init__(self, DATATYPE, lon, lat, time, uavg, teke,
186186
radius_s, radius_e, amplitude, temp=None, salt=None,
187187
save_extras=False, contour_e=None, contour_s=None,
188188
uavg_profile=None, shape_error=None):
189189

190-
self.eddy_index = eddy_index
190+
#self.eddy_index = eddy_index
191191
self.DATATYPE = DATATYPE
192-
#self.lon = np.atleast_1d(lon)
193192
self.lon = [lon]
194193
self.lat = [lat]
195194
self.ocean_time = [time]
@@ -264,7 +263,7 @@ class TrackList (object):
264263
qparameter: Q parameter range used for contours
265264
new_lon, new_lat: new lon/lat centroids
266265
old_lon, old_lat: old lon/lat centroids
267-
eddy_index: index of eddy in track_list
266+
index: index of eddy in track_list
268267
"""
269268
#def __init__(self, DATATYPE, TRACK_DURATION_MIN, TRACK_EXTRA_VARIABLES):
270269
def __init__(self, DATATYPE, SIGN_TYPE, SAVE_DIR, grd, search_ellipse,
@@ -339,28 +338,29 @@ def __init__(self, DATATYPE, SIGN_TYPE, SAVE_DIR, grd, search_ellipse,
339338
self.sla = None
340339
self.slacopy = None
341340

342-
self.new_lon = [] #np.array([])
343-
self.new_lat = []
341+
self.new_lon = []
342+
self.new_lat = []
344343
self.new_radii_s = []
345344
self.new_radii_e = []
346-
self.new_amp = []
347-
self.new_uavg = []
348-
self.new_teke = []
345+
self.new_amp = []
346+
self.new_uavg = []
347+
self.new_teke = []
349348
if 'ROMS' in self.DATATYPE:
350349
self.new_temp = []
351350
self.new_salt = []
352-
self.new_time = []
353-
self.old_lon = []
354-
self.old_lat = []
355-
self.old_radii_s = []
356-
self.old_radii_e = []
357-
self.old_amp = []
358-
self.old_uavg = []
359-
self.old_teke = []
351+
# NOTE check if new_time and old_time are necessary...
352+
self.new_time = []
353+
self.old_lon = []
354+
self.old_lat = []
355+
self.old_radii_s = []
356+
self.old_radii_e = []
357+
self.old_amp = []
358+
self.old_uavg = []
359+
self.old_teke = []
360360
if 'ROMS' in self.DATATYPE:
361361
self.old_temp = []
362362
self.old_salt = []
363-
self.old_time = []
363+
self.old_time = []
364364
if self.TRACK_EXTRA_VARIABLES:
365365
self.new_contour_e = []
366366
self.new_contour_s = []
@@ -386,7 +386,7 @@ def __getstate__(self):
386386
"""
387387
Needed for Pickle
388388
"""
389-
print '--- removing unwanted attributes'
389+
#print '--- removing unwanted attributes'
390390
pops = ('uspd', 'uspd_coeffs', 'sla_coeffs', 'points',
391391
'circlon', 'circlat', 'sla', 'slacopy')
392392
result = self.__dict__.copy()
@@ -401,7 +401,7 @@ def add_new_track(self, lon, lat, time, uavg, teke,
401401
"""
402402
Append a new 'track' object to the list
403403
"""
404-
self.tracklist.append(Track(self.index, self.DATATYPE,
404+
self.tracklist.append(Track(self.DATATYPE,
405405
lon, lat, time, uavg, teke,
406406
radius_s, radius_e, amplitude,
407407
temp, salt, self.TRACK_EXTRA_VARIABLES,
@@ -841,11 +841,14 @@ def write2netcdf(self, rtime):
841841
self.ncind += tsize
842842
self.ch_index += 1
843843
nc.sync()
844-
844+
845+
#print 'eddy.ncind', self.ncind
846+
845847
# Get index to first currently active track
846848
try:
847849
lasti = self.get_active_tracks(rtime)[0]
848-
850+
#print '__________________lasti', lasti
851+
#print '__________________rtime', rtime
849852
except Exception:
850853
lasti = None
851854

@@ -859,6 +862,7 @@ def write2netcdf(self, rtime):
859862

860863
# Update old_lon and old_lat...
861864
self.old_lon = self.new_lon[lasti:]
865+
#print '______________________self.old_lon', self.old_lon
862866
self.old_lat = self.new_lat[lasti:]
863867
self.old_radii_s = self.new_radii_s[lasti:]
864868
self.old_radii_e = self.new_radii_e[lasti:]

py_eddy_tracker_classes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,9 @@ def track_eddies(Eddy, first_record):
877877

878878
haversine.distance_matrix(X_old, X_new, dist_mat)
879879
dist_mat = np.ascontiguousarray(dist_mat)
880-
880+
881+
#print '+++++++++++++ X_old.mean()', X_old.mean()
882+
881883
dist_mat_copy = dist_mat.copy()
882884

883885
# *new_eddy_inds* contains indices to every newly identified eddy
@@ -1148,7 +1150,7 @@ def track_eddies(Eddy, first_record):
11481150
# Now we need to add new eddies defined by new_eddy_inds
11491151
if np.any(new_eddy_inds):
11501152

1151-
if True:
1153+
if False:
11521154
print '------adding %s new eddies' % new_eddy_inds.sum()
11531155

11541156
for neind, a_new_eddy in enumerate(new_eddy_inds):

0 commit comments

Comments
 (0)