@@ -94,9 +94,9 @@ def do_basemap(M, ax):
94
94
else :
95
95
stride = 2
96
96
M .drawparallels (np .arange (- 90 , 90 + stride , stride ),
97
- labels = [1 ,0 , 0 , 0 ], linewidth = 0.25 , size = 8 , ax = ax )
97
+ labels = [1 , 0 , 0 , 0 ], linewidth = 0.25 , size = 8 , ax = ax )
98
98
M .drawmeridians (np .arange (- 360 , 360 + stride , stride ),
99
- labels = [0 ,0 , 0 , 1 ], linewidth = 0.25 , size = 8 , ax = ax )
99
+ labels = [0 , 0 , 0 , 1 ], linewidth = 0.25 , size = 8 , ax = ax )
100
100
M .fillcontinents ('k' , ax = ax )
101
101
M .drawcoastlines (linewidth = 0.5 , ax = ax )
102
102
return
@@ -170,8 +170,8 @@ def get_cax(subplot, dx=0, width=.015, position='r'):
170
170
171
171
def oceantime2ymd (ocean_time , integer = False ):
172
172
"""
173
- Return strings y, m, d given ocean_time (seconds)
174
- If integer == True return integer rather than string
173
+ Return strings *yea*r, *month*, *day* given ocean_time (seconds)
174
+ If kwarg *integer*==* True* return integers rather than strings.
175
175
"""
176
176
if np .isscalar (ocean_time ):
177
177
ocean_time = np .array ([ocean_time ])
@@ -184,12 +184,12 @@ def oceantime2ymd(ocean_time, integer=False):
184
184
day = (day .astype (np .int16 ) + 1 )[0 ]
185
185
if not integer :
186
186
year = str (year )
187
- month = str (month )
188
- day = str (day )
189
187
if len (year ) < 2 :
190
188
year = year .zfill (2 )
189
+ month = str (month )
191
190
if len (month ) < 2 :
192
191
month = month .zfill (2 )
192
+ day = str (day )
193
193
if len (day ) < 2 :
194
194
day = day .zfill (2 )
195
195
return year , month , day
@@ -243,21 +243,21 @@ def vort(u, v, dx, dy):
243
243
mn_p = np .zeros ((M , L ))
244
244
uom = np .zeros ((M , Lp ))
245
245
von = np .zeros ((Mp , L ))
246
- uom = 2. * u / (pm [:,:L ] + pm [:,1 :Lp ])
247
- uon = 2. * u / (pn [:,:L ] + pn [:,1 :Lp ])
248
- von = 2. * v / (pn [:M ,: ] + pn [1 :Mp ,: ])
249
- vom = 2. * v / (pm [:M ,: ] + pm [1 :Mp ,: ])
246
+ uom = 2. * u / (pm [:, :L ] + pm [:, 1 :Lp ])
247
+ uon = 2. * u / (pn [:, :L ] + pn [:, 1 :Lp ])
248
+ von = 2. * v / (pn [:M ] + pn [1 :Mp ])
249
+ vom = 2. * v / (pm [:M ] + pm [1 :Mp ])
250
250
mn = pm * pn
251
- mn_p = quart_interp (mn [:M , :L ], mn [:M , 1 :Lp ],
251
+ mn_p = quart_interp (mn [:M , :L ], mn [:M , 1 :Lp ],
252
252
mn [1 :Mp ,1 :Lp ], mn [1 :Mp , :L ])
253
253
# Sigma_T
254
254
ST = mn * psi2rho (von [:,1 :Lp ] - von [:,:L ] + uom [1 :Mp ,:] - uom [:M ,:])
255
255
# Sigma_N
256
256
SN = np .zeros ((Mp ,Lp ))
257
- SN [1 :- 1 ,1 :- 1 ] = mn [1 :- 1 ,1 :- 1 ] * (uon [1 :- 1 ,1 :] \
258
- - uon [1 :- 1 ,:- 1 ] \
259
- - vom [1 :,1 :- 1 ] \
260
- + vom [:- 1 ,1 :- 1 ])
257
+ SN [1 :- 1 ,1 :- 1 ] = mn [1 :- 1 ,1 :- 1 ] * (uon [1 :- 1 , 1 :] \
258
+ - uon [1 :- 1 , :- 1 ] \
259
+ - vom [1 :, 1 :- 1 ] \
260
+ + vom [:- 1 , 1 :- 1 ])
261
261
# Relative vorticity
262
262
xi = vorticity (u , v , pm , pn )
263
263
# Okubo
@@ -828,9 +828,7 @@ def track_eddies(Eddy, first_record):
828
828
"""
829
829
Track the eddies. First a distance matrix is calculated between
830
830
all new and old eddies. Then loop through each old eddy, sorting the
831
- distances and selecting that/those within range.
832
- This is not so slow, surprisingly, it's the main loops over
833
- the contours which are slow
831
+ distances, and selecting that/those within range.
834
832
"""
835
833
DIST0 = Eddy .DIST0
836
834
AMP0 = Eddy .AMP0
@@ -841,7 +839,10 @@ def track_eddies(Eddy, first_record):
841
839
# True to debug
842
840
debug_dist = False
843
841
844
- # We will need these in m for ellipse below
842
+
843
+ far_away = 1e9
844
+
845
+ # We will need these in m for ellipse method below
845
846
old_x , old_y = Eddy .M (np .array (Eddy .old_lon ), np .array (Eddy .old_lat ))
846
847
new_x , new_y = Eddy .M (np .array (Eddy .new_lon_tmp ),
847
848
np .array (Eddy .new_lat_tmp ))
@@ -868,7 +869,12 @@ def track_eddies(Eddy, first_record):
868
869
869
870
dist_mat_copy = dist_mat .copy ()
870
871
871
- new_eddy_inds = np .ones (len (Eddy .new_lon_tmp ), dtype = bool )
872
+ # *new_eddy_inds* contains indices to every newly identified eddy
873
+ # that are initially set to True on the assumption that it is a new
874
+ # eddy, i.e, it has just been born.
875
+ # Later some will be set to False, indicating it is a contination
876
+ # of an existing eddy.
877
+ new_eddy_inds = np .ones_like (new_x , dtype = bool )
872
878
new_eddy = False
873
879
874
880
old_area = np .empty (1 )
@@ -906,14 +912,20 @@ def track_eddies(Eddy, first_record):
906
912
np .unique (dist_mat [old_ind ],
907
913
return_index = True )[1 ])
908
914
# Move non_unique_inds far away
909
- dist_mat [old_ind ][non_unique_inds ] = 1e9 # km
915
+ dist_mat [old_ind ][non_unique_inds ] = far_away # km
910
916
911
917
if debug_dist :
912
- plt .clf ()
913
- plt .subplot (131 )
914
- plt .imshow (dist_mat_copy , interpolation = 'none' ,
915
- origin = 'lower' , cmap = plt .cm .Accent )
916
- plt .clim (0 , 5e6 )
918
+
919
+ debug_distmax = 5e6
920
+ debug_cmap = plt .cm .Set3
921
+
922
+ fig = plt .figure (225 )
923
+ #plt.clf()
924
+ debug_ax = fig .add_subplot (131 )
925
+ im = plt .imshow (dist_mat_copy , interpolation = 'none' ,
926
+ origin = 'lower' , cmap = debug_cmap )
927
+ im .cmap .set_over ('k' )
928
+ im .set_clim (0 , debug_distmax )
917
929
plt .colorbar ()
918
930
plt .xlabel ('new' )
919
931
plt .ylabel ('old' )
@@ -929,22 +941,26 @@ def track_eddies(Eddy, first_record):
929
941
930
942
# Loop over separation distances between old and new
931
943
for new_ind , new_dist in enumerate (dist_mat [old_ind ]):
944
+
945
+ sep_proceed = False
932
946
933
- if 'ellipse' in Eddy .SEPARATION_METHOD :
934
- if Eddy .search_ellipse .ellipse_path .contains_point (
935
- (new_x [new_ind ], new_y [new_ind ])):
936
- sep_proceed = True
947
+ if new_dist < far_away :
948
+
949
+ if 'ellipse' in Eddy .SEPARATION_METHOD :
950
+ if Eddy .search_ellipse .ellipse_path .contains_point (
951
+ (new_x [new_ind ], new_y [new_ind ])):
952
+ sep_proceed = True
953
+ #else:
954
+ #sep_proceed = False
955
+
956
+ elif 'sum_radii' in Eddy .SEPARATION_METHOD :
957
+ sep_dist = Eddy .new_radii_tmp_e [new_ind ]
958
+ sep_dist += Eddy .old_radii_e [old_ind ]
959
+ sep_dist *= Eddy .sep_dist_fac
960
+ sep_proceed = new_dist <= sep_dist
961
+
937
962
else :
938
- sep_proceed = False
939
-
940
- elif 'sum_radii' in Eddy .SEPARATION_METHOD :
941
- sep_dist = Eddy .new_radii_tmp_e [new_ind ]
942
- sep_dist += Eddy .old_radii_e [old_ind ]
943
- sep_dist *= Eddy .sep_dist_fac
944
- sep_proceed = new_dist <= sep_dist
945
-
946
- else :
947
- Exception
963
+ Exception
948
964
949
965
# Pass only the eddies within ellipse or sep_dist
950
966
if sep_proceed :
@@ -994,7 +1010,8 @@ def track_eddies(Eddy, first_record):
994
1010
# corresponding new_eddy_inds set to False
995
1011
new_eddy_inds [np .nonzero (Eddy .new_lon_tmp ==
996
1012
Eddy .new_lon_tmp [new_ind ])] = False
997
- dist_mat [:, new_ind ] = 1e9 # km
1013
+ #print 'aa', new_eddy_inds
1014
+ dist_mat [:, new_ind ] = far_away # km
998
1015
999
1016
1000
1017
if Eddy .TRACK_EXTRA_VARIABLES :
@@ -1004,9 +1021,9 @@ def track_eddies(Eddy, first_record):
1004
1021
kwargs = {}
1005
1022
1006
1023
# Only one eddy within range
1007
- if dist_arr .size == 1 : # then update the eddy tracks only
1024
+ if dist_arr .size == 1 : # then update the eddy track only
1008
1025
1009
- # Use index 0 here because type is list, but we want the float
1026
+ # Use index 0 here because type is list and we want the scalar
1010
1027
args = (Eddy , old_ind , new_ln [0 ], new_lt [0 ], new_rd_s [0 ],
1011
1028
new_rd_e [0 ], new_am [0 ], new_Ua [0 ], new_ek [0 ], new_tm [0 ],
1012
1029
new_eddy , first_record )
@@ -1059,6 +1076,16 @@ def track_eddies(Eddy, first_record):
1059
1076
dx_unused = dx [1 :] # index/indices to the unused eddy/eddies
1060
1077
1061
1078
1079
+ if debug_dist :
1080
+ print 'delta_area' , delta_area
1081
+ print 'delta_amp' , delta_amp
1082
+ print 'dist_arr' , dist_arr
1083
+ print 'dx' , dx
1084
+ print 'dx0' , dx0
1085
+ print 'dx_unused' , dx_unused
1086
+
1087
+
1088
+
1062
1089
# Update eddy track dx0
1063
1090
if not Eddy .TRACK_EXTRA_VARIABLES :
1064
1091
new_cntr_e = new_cntr_s = new_uavg_prf = new_shp_err = None
@@ -1081,37 +1108,55 @@ def track_eddies(Eddy, first_record):
1081
1108
Eddy = accounting (* args , ** kwargs )
1082
1109
1083
1110
if debug_dist :
1084
- plt .subplot (132 )
1085
- plt .imshow (dist_mat .copy (), interpolation = 'none' ,
1086
- origin = 'lower' , cmap = plt .cm .Accent )
1087
- plt .clim (0 , 5e6 )
1111
+ debug_ax = fig .add_subplot (132 )
1112
+ im = plt .imshow (dist_mat , interpolation = 'none' ,
1113
+ origin = 'lower' , cmap = debug_cmap )
1114
+ im .cmap .set_over ('k' )
1115
+ im .set_clim (0 , debug_distmax )
1116
+ plt .axis ('image' )
1088
1117
plt .colorbar ()
1089
1118
plt .xlabel ('new' )
1090
1119
plt .ylabel ('old' )
1091
1120
plt .title ('before' )
1092
1121
1093
1122
# Use backup_ind to reinsert distances into dist_mat for the unused eddy/eddies
1094
- for i , bind in enumerate (backup_ind [dx_unused ]):
1123
+ for bind in backup_ind [dx_unused ]:
1124
+ #print dist_mat.shape
1125
+ #print dist_mat[:, bind]
1126
+ #print dist_mat_copy[:, bind]
1095
1127
dist_mat [:, bind ] = dist_mat_copy [:, bind ]
1096
-
1128
+ #print dist_mat[:, bind]
1129
+ #print '\n'
1130
+ #print 'B new_eddy_inds', new_eddy_inds
1131
+ new_eddy_inds [bind ] = True
1132
+ #print 'A new_eddy_inds', new_eddy_inds
1133
+ #print '\n'
1134
+
1135
+
1136
+
1097
1137
if debug_dist :
1098
- print 'backup_ind[dx_unused].shape' ,backup_ind [dx_unused ].shape
1099
- print 'backup_ind[dx_unused]' ,backup_ind [dx_unused ]
1100
- plt .subplot (133 )
1101
- plt .imshow (dist_mat .copy (), interpolation = 'none' ,
1102
- origin = 'lower' , cmap = plt .cm .Accent )
1103
- plt .clim (0 , 5e6 )
1138
+ print 'backup_ind' , backup_ind
1139
+ print 'backup_ind[dx_unused]' , backup_ind [dx_unused ]
1140
+ print 'backup_ind[dx_unused].shape' , backup_ind [dx_unused ].shape
1141
+ debug_ax = fig .add_subplot (133 )
1142
+ im = plt .imshow (dist_mat , interpolation = 'none' ,
1143
+ origin = 'lower' , cmap = debug_cmap )
1144
+ im .cmap .set_over ('k' )
1145
+ im .set_clim (0 , debug_distmax )
1146
+ plt .axis ('image' )
1104
1147
plt .colorbar ()
1105
1148
plt .xlabel ('new' )
1106
1149
plt .ylabel ('old' )
1107
1150
plt .title ('after' )
1108
1151
plt .tight_layout ()
1109
1152
plt .show ()
1153
+ plt .close (225 )
1110
1154
1111
1155
# Finished looping over old eddy tracks
1112
1156
1113
1157
# Now we need to add new eddies defined by new_eddy_inds
1114
1158
if np .any (new_eddy_inds ):
1159
+
1115
1160
if False :
1116
1161
print '------adding %s new eddies' % new_eddy_inds .sum ()
1117
1162
0 commit comments