@@ -514,7 +514,7 @@ def __init__(self, DATATYPE, TRACK_DURATION_MIN, TRACK_EXTRA_VARIABLES):
514
514
self .index = 0 # counter
515
515
self .ncind = 0 # index to write to nc files, will increase and increase...
516
516
self .ch_index = 0 # index for Chelton style nc files
517
-
517
+ self . PAD = 2
518
518
# Check for a correct configuration
519
519
assert DATATYPE in ('ROMS' , 'AVISO' ), "Unknown string in 'DATATYPE' parameter"
520
520
@@ -956,7 +956,7 @@ def write2netcdf(self, rtime):
956
956
self ._reduce_inactive_tracks ()
957
957
958
958
# Update old_lon and old_lat...
959
- self .old_lon = list ( self .new_lon [lasti :])
959
+ self .old_lon = self .new_lon [lasti :]
960
960
self .old_lat = self .new_lat [lasti :]
961
961
self .old_radii_s = self .new_radii_s [lasti :]
962
962
self .old_radii_e = self .new_radii_e [lasti :]
@@ -1003,7 +1003,8 @@ def get_distances(self, centlon, centlat):
1003
1003
clat = self .old_lat .copy ()
1004
1004
clon .fill (centlon )
1005
1005
clat .fill (centlat )
1006
- return haversine_distance_vector (clon , clat , self .old_lon , self .old_lat )
1006
+ return haversine_distance_vector (clon , clat ,
1007
+ self .old_lon , self .old_lat )
1007
1008
1008
1009
1009
1010
def insert_at_index (self , xarr , ind , x ):
@@ -1028,90 +1029,93 @@ def insert_at_index(self, xarr, ind, x):
1028
1029
try :
1029
1030
self .new_lon [ind ] = x
1030
1031
except :
1031
- self .new_lon .extend ([0 ] * (ind - len (self .new_lon ) + 1 ))
1032
+ self .new_lon .extend ([0 ] *
1033
+ (ind - len (self .new_lon ) + 1 ))
1032
1034
self .new_lon [ind ] = x
1033
1035
elif strcompare ('new_lat' , xarr ):
1034
1036
try :
1035
1037
self .new_lat [ind ] = x
1036
1038
except :
1037
- self .new_lat .extend ([0 ] * (ind - len (self .new_lat ) + 1 ))
1039
+ self .new_lat .extend ([0 ] *
1040
+ (ind - len (self .new_lat ) + 1 ))
1038
1041
self .new_lat [ind ] = x
1039
1042
elif strcompare ('new_radii_s' , xarr ):
1040
1043
try :
1041
1044
self .new_radii_s [ind ] = x
1042
1045
except :
1043
- self .new_radii_s .extend ([0 ] * (ind - len (self .new_radii_s ) + 1 ))
1046
+ self .new_radii_s .extend ([0 ] *
1047
+ (ind - len (self .new_radii_s ) + 1 ))
1044
1048
self .new_radii_s [ind ] = x
1045
1049
elif strcompare ('new_radii_e' , xarr ):
1046
1050
try :
1047
1051
self .new_radii_e [ind ] = x
1048
1052
except :
1049
- self .new_radii_e .extend ([0 ] * (ind - len (self .new_radii_e ) + 1 ))
1053
+ self .new_radii_e .extend ([0 ] *
1054
+ (ind - len (self .new_radii_e ) + 1 ))
1050
1055
self .new_radii_e [ind ] = x
1051
1056
elif strcompare ('new_amp' , xarr ):
1052
1057
try :
1053
1058
self .new_amp [ind ] = x
1054
1059
except :
1055
- self .new_amp .extend ([0 ] * (ind - len (self .new_amp ) + 1 ))
1060
+ self .new_amp .extend ([0 ] *
1061
+ (ind - len (self .new_amp ) + 1 ))
1056
1062
self .new_amp [ind ] = x
1057
1063
elif strcompare ('new_uavg' , xarr ):
1058
1064
try :
1059
1065
self .new_uavg [ind ] = x
1060
1066
except :
1061
- self .new_uavg .extend ([0 ] * (ind - len (self .new_uavg ) + 1 ))
1067
+ self .new_uavg .extend ([0 ] *
1068
+ (ind - len (self .new_uavg ) + 1 ))
1062
1069
self .new_uavg [ind ] = x
1063
1070
elif strcompare ('new_teke' , xarr ):
1064
1071
try :
1065
1072
self .new_teke [ind ] = x
1066
1073
except :
1067
- self .new_teke .extend ([0 ] * (ind - len (self .new_teke ) + 1 ))
1074
+ self .new_teke .extend ([0 ] *
1075
+ (ind - len (self .new_teke ) + 1 ))
1068
1076
self .new_teke [ind ] = x
1069
1077
elif strcompare ('new_temp' , xarr ):
1070
1078
try :
1071
1079
self .new_temp [ind ] = x
1072
1080
except :
1073
- self .new_temp .extend ([0 ] * (ind - len (self .new_temp ) + 1 ))
1081
+ self .new_temp .extend ([0 ] *
1082
+ (ind - len (self .new_temp ) + 1 ))
1074
1083
self .new_temp [ind ] = x
1075
1084
elif strcompare ('new_salt' , xarr ):
1076
1085
try :
1077
1086
self .new_salt [ind ] = x
1078
1087
except :
1079
- self .new_salt .extend ([0 ] * (ind - len (self .new_salt ) + 1 ))
1088
+ self .new_salt .extend ([0 ] *
1089
+ (ind - len (self .new_salt ) + 1 ))
1080
1090
self .new_salt [ind ] = x
1081
1091
elif strcompare ('new_shape_error' , xarr ):
1082
1092
try :
1083
1093
self .new_shape_error [ind ] = x
1084
1094
except :
1085
- self .new_shape_error .extend ([0 ] * (ind - len (self .new_shape_error ) + 1 ))
1095
+ self .new_shape_error .extend ([0 ] *
1096
+ (ind - len (self .new_shape_error ) + 1 ))
1086
1097
self .new_shape_error [ind ] = x
1087
- #elif strcompare('new_bounds', xarr):
1088
- #if ind < tmp.shape[0]:
1089
- #newsize = tmp.size
1090
- #else:
1091
- #newsize = ind + 1
1092
- #self.new_bounds = np.zeros((newsize, 4))
1093
- #self.new_bounds[:tmp.shape[0]] = tmp
1094
- #self.new_bounds[ind] = x
1095
-
1096
1098
1097
1099
elif strcompare ('new_contour_e' , xarr ):
1098
1100
try :
1099
1101
self .new_contour_e [ind ] = x
1100
1102
except :
1101
- # self.new_contour_e += [0] * (ind - len(self.new_contour_e) + 1)
1102
- self . new_contour_e . append ([ 0 ] * (ind - len (self .new_contour_e ) + 1 ))
1103
+ self .new_contour_e . append ( [0 ] *
1104
+ (ind - len (self .new_contour_e ) + 1 ))
1103
1105
self .new_contour_e [ind ] = x
1104
1106
elif strcompare ('new_contour_s' , xarr ):
1105
1107
try :
1106
1108
self .new_contour_s [ind ] = x
1107
1109
except :
1108
- self .new_contour_s .append ([0 ] * (ind - len (self .new_contour_s ) + 1 ))
1110
+ self .new_contour_s .append ([0 ] *
1111
+ (ind - len (self .new_contour_s ) + 1 ))
1109
1112
self .new_contour_s [ind ] = x
1110
1113
elif strcompare ('new_uavg_profile' , xarr ):
1111
1114
try :
1112
1115
self .new_uavg_profile [ind ] = x
1113
1116
except :
1114
- self .new_uavg_profile .append ([0 ] * (ind - len (self .new_uavg_profile ) + 1 ))
1117
+ self .new_uavg_profile .append ([0 ] *
1118
+ (ind - len (self .new_uavg_profile ) + 1 ))
1115
1119
self .new_uavg_profile [ind ] = x
1116
1120
else :
1117
1121
raise Exception
@@ -1148,7 +1152,7 @@ def insert_at_index(self, xarr, ind, x):
1148
1152
#self.jmax = np.max([a_j, b_j, c_j, d_j]) + 5
1149
1153
#return self
1150
1154
1151
- def set_bounds (self , contlon , contlat , radius , i , j , grd ):
1155
+ def set_bounds (self , contlon , contlat , grd ):
1152
1156
"""
1153
1157
Get indices to a bounding box around the eddy
1154
1158
WARNING won't work for a rotated grid
@@ -1164,18 +1168,19 @@ def set_bounds(self, contlon, contlat, radius, i, j, grd):
1164
1168
jarr = np .array ([bl_j , tl_j , br_j , tr_j ])
1165
1169
self .imin , self .imax = iarr .min (), iarr .max ()
1166
1170
self .jmin , self .jmax = jarr .min (), jarr .max ()
1167
- pad = 2
1171
+
1168
1172
# For indexing the mins must not be less than zero
1169
- self .imin = np .maximum (self .imin - pad , 0 )
1170
- self .jmin = np .maximum (self .jmin - pad , 0 )
1171
- self .imax += pad + 1
1172
- self .jmax += pad + 1
1173
+ self .imin = np .maximum (self .imin - self . PAD , 0 )
1174
+ self .jmin = np .maximum (self .jmin - self . PAD , 0 )
1175
+ self .imax += self . PAD + 1
1176
+ self .jmax += self . PAD + 1
1173
1177
return self
1174
1178
1175
1179
1176
1180
def set_mask_eff (self , contour , grd ):
1177
1181
"""
1178
- Set points within bounding box around eddy and calculate mask
1182
+ Set points within bounding box around eddy and calculate
1183
+ mask for effective contour
1179
1184
"""
1180
1185
self .points = np .array ([grd .lon ()[self .jmin :self .jmax ,
1181
1186
self .imin :self .imax ].ravel (),
@@ -1296,7 +1301,8 @@ def _get_rlongwave_spd(self, x, y):
1296
1301
class SearchEllipse (object ):
1297
1302
1298
1303
def __init__ (self , domain , DAYS_BTWN_RECORDS , rw_path , limits ):
1299
- """Class to construct a search ellipse/circle around a specified point.
1304
+ """
1305
+ Class to construct a search ellipse/circle around a specified point.
1300
1306
1301
1307
"""
1302
1308
self .domain = domain
@@ -1333,13 +1339,13 @@ def _set_global_ellipse(self):
1333
1339
"""
1334
1340
self ._set_east_ellipse ()._set_west_ellipse ()
1335
1341
e_verts = self .east_ellipse .get_verts ()
1336
- e_size = e_verts [:,0 ].size
1342
+ e_size = e_verts [:, 0 ].size
1337
1343
e_size *= 0.5
1338
1344
w_verts = self .west_ellipse .get_verts ()
1339
- w_size = w_verts [:,0 ].size
1345
+ w_size = w_verts [:, 0 ].size
1340
1346
w_size *= 0.5
1341
- ew_x = np .hstack ((e_verts [:e_size ,0 ], w_verts [w_size :,0 ]))
1342
- ew_y = np .hstack ((e_verts [:e_size ,1 ], w_verts [w_size :,1 ]))
1347
+ ew_x = np .hstack ((e_verts [:e_size , 0 ], w_verts [w_size :, 0 ]))
1348
+ ew_y = np .hstack ((e_verts [:e_size , 1 ], w_verts [w_size :, 1 ]))
1343
1349
self .ellipse_path = path .Path (np .array ([ew_x , ew_y ]).T )
1344
1350
return self #.ellipse_path
1345
1351
@@ -1350,8 +1356,8 @@ def _set_black_sea_ellipse(self):
1350
1356
self .black_sea_ellipse = patch .Ellipse ((self .x , self .y ),
1351
1357
2. * self .rw_d_mod , 2. * self .rw_d_mod )
1352
1358
verts = self .black_sea_ellipse .get_verts ()
1353
- self .ellipse_path = path .Path (np .array ([verts [:,0 ],
1354
- verts [:,1 ]]).T )
1359
+ self .ellipse_path = path .Path (np .array ([verts [:, 0 ],
1360
+ verts [:, 1 ]]).T )
1355
1361
return self
1356
1362
1357
1363
@@ -1362,15 +1368,17 @@ def set_search_ellipse(self, x, y):
1362
1368
self .y = y
1363
1369
1364
1370
if self .domain in ('Global' , 'ROMS' ):
1365
- self .rw_d [:] = self .rwv .get_rwdistance (x , y , self .DAYS_BTWN_RECORDS )
1371
+ self .rw_d [:] = self .rwv .get_rwdistance (x , y ,
1372
+ self .DAYS_BTWN_RECORDS )
1366
1373
self .rw_d_mod [:] = 1.75
1367
1374
self .rw_d_mod *= self .rw_d
1368
1375
self .rw_d_mod [:] = np .maximum (self .rw_d_mod , self .n_s_minor )
1369
1376
self .rw_d_mod *= 2.
1370
1377
self ._set_global_ellipse ()
1371
1378
elif 'BlackSea' in self .domain :
1372
1379
self .rw_d_mod [:] = 1.75
1373
- self .rw_d [:] = self .rwv .get_rwdistance (x , y , self .DAYS_BTWN_RECORDS )
1380
+ self .rw_d [:] = self .rwv .get_rwdistance (x , y ,
1381
+ self .DAYS_BTWN_RECORDS )
1374
1382
self .rw_d_mod *= self .rw_d
1375
1383
self ._set_black_sea_ellipse ()
1376
1384
else : Exception
@@ -1386,10 +1394,8 @@ def view_search_ellipse(self, Eddy):
1386
1394
ax = plt .subplot (111 )
1387
1395
ax .set_title ('Rossby def. rad %s m' % self .rw_d [0 ])
1388
1396
Eddy .M .scatter (self .x , self .y , c = 'b' )
1389
- #Eddy.M.plot(ee[:,0], ee[:,1], 'b')
1390
- #Eddy.M.plot(ww[:,0], ww[:,1], 'g')
1391
- Eddy .M .plot (self .ellipse_path .vertices [:,0 ],
1392
- self .ellipse_path .vertices [:,1 ], 'r' )
1397
+ Eddy .M .plot (self .ellipse_path .vertices [:, 0 ],
1398
+ self .ellipse_path .vertices [:, 1 ], 'r' )
1393
1399
Eddy .M .drawcoastlines ()
1394
1400
plt .show ()
1395
1401
0 commit comments