Skip to content

Commit 43660f4

Browse files
committed
Cleaning of py_eddy_tracker_classes.py
1 parent a573f89 commit 43660f4

File tree

2 files changed

+40
-65
lines changed

2 files changed

+40
-65
lines changed

py_eddy_tracker_amplitude.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,9 @@ def set_nearest_contour_index(self, xpt, ypt):
280280
#print self.y[self.level_slice]
281281
self.dist = (self.x[self.level_slice] - xpt)**2
282282
self.dist += (self.y[self.level_slice] - ypt)**2
283-
#print 'self.dist',self.dist
284283
try:
285284
self.nearesti = self.dist.argmin()
286285
except:
287-
#print 'except'
288286
self.nearesti = None
289287
return self
290288

@@ -298,10 +296,8 @@ def get_index_nearest_path(self):
298296
for i, index_of_first_pt in enumerate(indices_of_first_pts):
299297
if (index_of_first_pt - indices_of_first_pts[0]) > self.nearesti:
300298
return i - 1
301-
#print '/////'
302299
return i
303300
else:
304-
#print '-----'
305301
return False
306302

307303

py_eddy_tracker_classes.py

Lines changed: 40 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,8 @@ def get_uavg(Eddy, CS, collind, centlon_e, centlat_e, poly_eff,
504504
any_inner_contours = False
505505

506506
citer = np.nditer(CS.cvalues, flags=['c_index'])
507-
#print '************************************************'
507+
508508
while not citer.finished:
509-
510-
#print '--------------' * 10
511-
#print '--------------' * 10
512-
#print '\nciter.index ::', citer.index
513509
## Get contour around centlon_e, centlat_e at level [collind:][iuavg]
514510
#segii, poly_i = eddy_tracker.find_nearest_contour(
515511
#CS.collections[citer.index], centlon_e, centlat_e)
@@ -518,7 +514,6 @@ def get_uavg(Eddy, CS, collind, centlon_e, centlat_e, poly_eff,
518514

519515
# Leave loop if no contours at level citer.index
520516
if Eddy.swirl.level_slice is None:
521-
#print '------------------------------------------'
522517
citer.iternext()
523518
continue
524519

@@ -561,13 +556,12 @@ def get_uavg(Eddy, CS, collind, centlon_e, centlat_e, poly_eff,
561556
citer.iternext()
562557

563558

564-
if any_inner_contours:
559+
if any_inner_contours: # set speed based contour parameters
565560
cx, cy = Eddy.M(theseglon, theseglat)
566-
# Get speed based eddy radius (eddy_radius_s)
567561
centx_s, centy_s, eddy_radius_s, junk = fit_circle(cx, cy)
568562
centlon_s, centlat_s = Eddy.M.projtran(centx_s, centy_s, inverse=True)
569563

570-
else:
564+
else: # use the effective contour
571565
centlon_s, centlat_s = centlon_e, centlat_e
572566
eddy_radius_s = eddy_radius_e
573567
inner_seglon, inner_seglat = theseglon, theseglat
@@ -576,6 +570,7 @@ def get_uavg(Eddy, CS, collind, centlon_e, centlat_e, poly_eff,
576570
if not save_all_uavg:
577571
return (uavg, centlon_s, centlat_s, eddy_radius_s,
578572
theseglon, theseglat, inner_seglon, inner_seglat)
573+
579574
else:
580575
return (uavg, centlon_s, centlat_s, eddy_radius_s,
581576
theseglon, theseglat, inner_seglon, inner_seglat, all_uavg)
@@ -775,14 +770,19 @@ def collection_loop(CS, grd, rtime, A_list_obj, C_list_obj,
775770

776771
elif 'SLA' in Eddy.DIAGNOSTIC_TYPE:
777772

773+
args = (Eddy, CS, collind,
774+
centlon_e, centlat_e,
775+
cont, grd, eddy_radius_e)
776+
778777
if not Eddy.TRACK_EXTRA_VARIABLES:
779-
uavg, centlon_s, centlat_s, eddy_radius_s,\
780-
contlon_s, contlat_s, inner_contlon, inner_contlat = get_uavg(Eddy, CS, collind,
781-
centlon_e, centlat_e, cont, grd, eddy_radius_e)
778+
(uavg, centlon_s, centlat_s,
779+
eddy_radius_s, contlon_s, contlat_s,
780+
inner_contlon, inner_contlat) = get_uavg(*args)
782781
else:
783-
uavg, centlon_s, centlat_s, eddy_radius_s,\
784-
contlon_s, contlat_s, inner_contlon, inner_contlat, uavg_profile = get_uavg(Eddy, CS, collind,
785-
centlon_e, centlat_e, cont, grd, eddy_radius_e, save_all_uavg=True)
782+
(uavg, centlon_s, centlat_s,
783+
eddy_radius_s, contlon_s, contlat_s,
784+
inner_contlon, inner_contlat,
785+
uavg_profile) = get_uavg(*args, save_all_uavg=True)
786786

787787

788788
centlon_lmi, centlat_lmi, junk, junk = fit_circle(inner_contlon,
@@ -800,8 +800,6 @@ def collection_loop(CS, grd, rtime, A_list_obj, C_list_obj,
800800
properties.rtime = rtime
801801
properties.teke = teke
802802

803-
804-
805803
# Update Q eddy properties
806804
if 'Q' in Eddy.DIAGNOSTIC_TYPE:
807805
# We pass eddy_radius_e as a dummy for eddy_radius_s
@@ -913,9 +911,9 @@ def track_eddies(Eddy, first_record):
913911
debug_dist = False
914912

915913
# We will need these in m for ellipse below
916-
old_x, old_y = Eddy.M(np.asarray(Eddy.old_lon), np.asarray(Eddy.old_lat))
917-
new_x, new_y = Eddy.M(np.asarray(Eddy.new_lon_tmp),
918-
np.asarray(Eddy.new_lat_tmp))
914+
old_x, old_y = Eddy.M(np.array(Eddy.old_lon), np.array(Eddy.old_lat))
915+
new_x, new_y = Eddy.M(np.array(Eddy.new_lon_tmp),
916+
np.array(Eddy.new_lat_tmp))
919917

920918
X_old = np.array([Eddy.old_lon, Eddy.old_lat]).T
921919
X_new = np.array([Eddy.new_lon_tmp, Eddy.new_lat_tmp]).T
@@ -1055,7 +1053,7 @@ def track_eddies(Eddy, first_record):
10551053
# corresponding new_eddy_inds set to False
10561054
new_eddy_inds[np.nonzero(Eddy.new_lon_tmp ==
10571055
Eddy.new_lon_tmp[new_ind])] = False
1058-
dist_mat[:,new_ind] = 1e9 # km
1056+
dist_mat[:, new_ind] = 1e9 # km
10591057

10601058

10611059
if Eddy.TRACK_EXTRA_VARIABLES:
@@ -1093,8 +1091,8 @@ def track_eddies(Eddy, first_record):
10931091

10941092
# Choice of using effective or speed-based...
10951093
delta_area = np.r_[delta_area,
1096-
np.abs(np.diff([np.pi*(Eddy.old_radii_e[old_ind]**2),
1097-
np.pi*(new_rd_e[i]**2)]))]
1094+
np.abs(np.diff([np.pi * (Eddy.old_radii_e[old_ind]**2),
1095+
np.pi * (new_rd_e[i]**2)]))]
10981096
delta_amp = np.r_[delta_amp,
10991097
np.abs(np.diff([Eddy.old_amp[old_ind], new_am[i]]))]
11001098

@@ -1147,7 +1145,7 @@ def track_eddies(Eddy, first_record):
11471145

11481146
# Use backup_ind to reinsert distances into dist_mat for the unused eddy/eddies
11491147
for i, bind in enumerate(backup_ind[dx_unused]):
1150-
dist_mat[:,bind] = dist_mat_copy[:,bind]
1148+
dist_mat[:, bind] = dist_mat_copy[:, bind]
11511149

11521150
if debug_dist:
11531151
print 'backup_ind[dx_unused].shape',backup_ind[dx_unused].shape
@@ -1229,10 +1227,14 @@ def accounting(Eddy, old_ind, centlon, centlat,
12291227
new_eddy : flag indicating a new eddy
12301228
first_record : flag indicating that we're on the first record
12311229
"""
1232-
if first_record: # is True then all eddies are new...
1230+
if first_record: # is True then all eddies are new
1231+
new_eddy = True
12331232
if Eddy.VERBOSE:
12341233
print '------ writing first record'
1235-
new_eddy = True
1234+
1235+
kwargs = {'temp':cent_temp, 'salt':cent_salt,
1236+
'contour_e':contour_e, 'contour_s':contour_s,
1237+
'uavg_profile':uavg_profile, 'shape_error':shape_error}
12361238

12371239
if not new_eddy: # it's an old (i.e., active) eddy
12381240

@@ -1257,19 +1259,7 @@ def accounting(Eddy, old_ind, centlon, centlat,
12571259
args = (old_ind, centlon, centlat, rtime, uavg, teke,
12581260
eddy_radius_s, eddy_radius_e, amplitude)
12591261

1260-
if 'ROMS' in Eddy.DATATYPE:
1261-
1262-
Eddy.update_track(*args,
1263-
temp=cent_temp, salt=cent_salt,
1264-
contour_e=contour_e, contour_s=contour_s,
1265-
uavg_profile=uavg_profile, shape_error=shape_error)
1266-
1267-
elif 'AVISO' in Eddy.DATATYPE:
1268-
1269-
Eddy.update_track(*args,
1270-
temp=None, salt=None,
1271-
contour_e=contour_e, contour_s=contour_s,
1272-
uavg_profile=uavg_profile, shape_error=shape_error)
1262+
Eddy.update_track(*args, **kwargs)
12731263

12741264
else: # it's a new eddy
12751265

@@ -1298,19 +1288,8 @@ def accounting(Eddy, old_ind, centlon, centlat,
12981288

12991289
args = (centlon, centlat, rtime, uavg, teke,
13001290
eddy_radius_s, eddy_radius_e, amplitude)
1301-
kwargs = {'contour_e':contour_e, 'contour_s':contour_s,
1302-
'uavg_profile':uavg_profile, 'shape_error':shape_error}
13031291

1304-
if 'ROMS' in Eddy.DATATYPE:
1305-
1306-
kwargs['temp'] = cent_temp
1307-
kwargs['salt'] = cent_salt
1308-
1309-
Eddy.add_new_track(*args, **kwargs)
1310-
1311-
elif 'AVISO' in Eddy.DATATYPE:
1312-
1313-
Eddy.add_new_track(*args, **kwargs)
1292+
Eddy.add_new_track(*args, **kwargs)
13141293

13151294
Eddy.index += 1
13161295

@@ -1363,14 +1342,14 @@ def hann2d_fast(var, ni, nj):
13631342
#print 'jsz, isz',jsz, isz
13641343
var_ext = np.ma.zeros((nj, ni)) # add 1-more line parallell to
13651344
var_ext[1:-1, 1:-1] = var # each of 4-sides
1366-
var_ext[1:-1, 0] = var[:,0] # duplicate W-side
1367-
var_ext[1:-1,-1] = var[:,-1] # duplicate E-side
1368-
var_ext[0,1:-1] = var[0,:] # duplicate N-side
1369-
var_ext[-1,1:-1] = var[-1,:] # duplicate S-side
1370-
var_ext[0,0] = np.nan # NW-corner
1371-
var_ext[0,-1] = np.nan # NE-corner
1372-
var_ext[-1,0] = np.nan # SW-corner
1373-
var_ext[-1,-1] = np.nan # SE-corner
1345+
var_ext[1:-1, 0] = var[:, 0] # duplicate W-side
1346+
var_ext[1:-1, -1] = var[:, -1] # duplicate E-side
1347+
var_ext[0, 1:-1] = var[0] # duplicate N-side
1348+
var_ext[-1, 1:-1] = var[-1] # duplicate S-side
1349+
var_ext[0, 0] = np.nan # NW-corner
1350+
var_ext[0, -1] = np.nan # NE-corner
1351+
var_ext[-1, 0] = np.nan # SW-corner
1352+
var_ext[-1, -1] = np.nan # SE-corner
13741353

13751354
# npts is used to count number of valid neighbors
13761355
npts = ne.evaluate('var_ext * 0. + 1.')
@@ -1383,7 +1362,7 @@ def hann2d_fast(var, ni, nj):
13831362
cc = np.ma.zeros((var.shape))
13841363
varS = np.ma.zeros((var.shape))
13851364

1386-
cc = npts[1:nj-1, 1:ni-1] * (npts[0:nj-2, 1:ni-1] + npts[2:nj, 1:ni-1] +
1365+
cc = npts[1:nj-1, 1:ni-1] * (npts[0:nj-2, 1:ni-1] + npts[2:nj, 1:ni-1] +
13871366
npts[1:nj-1, 0:ni-2] + npts[1:nj-1, 2:ni])
13881367

13891368
varS = (var_ext[0:nj-2, 1:ni-1] + var_ext[2:nj, 1:ni-1] +
@@ -1405,7 +1384,7 @@ def hann2d_fast(var, ni, nj):
14051384

14061385
def get_circle(x0, y0, r, npts):
14071386
"""
1408-
Return points on a circle, with specified (x0,y0) center and radius
1387+
Return points on a circle, with specified (x0, y0) center and radius
14091388
(and optional number of points too!).
14101389
14111390
Input : 1 - x0, scalar, center X of circle

0 commit comments

Comments
 (0)