@@ -94,9 +94,9 @@ def do_basemap(M, ax):
9494 else :
9595 stride = 2
9696 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 )
9898 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 )
100100 M .fillcontinents ('k' , ax = ax )
101101 M .drawcoastlines (linewidth = 0.5 , ax = ax )
102102 return
@@ -170,8 +170,8 @@ def get_cax(subplot, dx=0, width=.015, position='r'):
170170
171171def oceantime2ymd (ocean_time , integer = False ):
172172 """
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.
175175 """
176176 if np .isscalar (ocean_time ):
177177 ocean_time = np .array ([ocean_time ])
@@ -184,12 +184,12 @@ def oceantime2ymd(ocean_time, integer=False):
184184 day = (day .astype (np .int16 ) + 1 )[0 ]
185185 if not integer :
186186 year = str (year )
187- month = str (month )
188- day = str (day )
189187 if len (year ) < 2 :
190188 year = year .zfill (2 )
189+ month = str (month )
191190 if len (month ) < 2 :
192191 month = month .zfill (2 )
192+ day = str (day )
193193 if len (day ) < 2 :
194194 day = day .zfill (2 )
195195 return year , month , day
@@ -243,21 +243,21 @@ def vort(u, v, dx, dy):
243243 mn_p = np .zeros ((M , L ))
244244 uom = np .zeros ((M , Lp ))
245245 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 ])
250250 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 ],
252252 mn [1 :Mp ,1 :Lp ], mn [1 :Mp , :L ])
253253 # Sigma_T
254254 ST = mn * psi2rho (von [:,1 :Lp ] - von [:,:L ] + uom [1 :Mp ,:] - uom [:M ,:])
255255 # Sigma_N
256256 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 ])
261261 # Relative vorticity
262262 xi = vorticity (u , v , pm , pn )
263263 # Okubo
@@ -828,9 +828,7 @@ def track_eddies(Eddy, first_record):
828828 """
829829 Track the eddies. First a distance matrix is calculated between
830830 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.
834832 """
835833 DIST0 = Eddy .DIST0
836834 AMP0 = Eddy .AMP0
@@ -841,7 +839,10 @@ def track_eddies(Eddy, first_record):
841839 # True to debug
842840 debug_dist = False
843841
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
845846 old_x , old_y = Eddy .M (np .array (Eddy .old_lon ), np .array (Eddy .old_lat ))
846847 new_x , new_y = Eddy .M (np .array (Eddy .new_lon_tmp ),
847848 np .array (Eddy .new_lat_tmp ))
@@ -868,7 +869,12 @@ def track_eddies(Eddy, first_record):
868869
869870 dist_mat_copy = dist_mat .copy ()
870871
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 )
872878 new_eddy = False
873879
874880 old_area = np .empty (1 )
@@ -906,14 +912,20 @@ def track_eddies(Eddy, first_record):
906912 np .unique (dist_mat [old_ind ],
907913 return_index = True )[1 ])
908914 # 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
910916
911917 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 )
917929 plt .colorbar ()
918930 plt .xlabel ('new' )
919931 plt .ylabel ('old' )
@@ -929,22 +941,26 @@ def track_eddies(Eddy, first_record):
929941
930942 # Loop over separation distances between old and new
931943 for new_ind , new_dist in enumerate (dist_mat [old_ind ]):
944+
945+ sep_proceed = False
932946
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+
937962 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
948964
949965 # Pass only the eddies within ellipse or sep_dist
950966 if sep_proceed :
@@ -994,7 +1010,8 @@ def track_eddies(Eddy, first_record):
9941010 # corresponding new_eddy_inds set to False
9951011 new_eddy_inds [np .nonzero (Eddy .new_lon_tmp ==
9961012 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
9981015
9991016
10001017 if Eddy .TRACK_EXTRA_VARIABLES :
@@ -1004,9 +1021,9 @@ def track_eddies(Eddy, first_record):
10041021 kwargs = {}
10051022
10061023 # 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
10081025
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
10101027 args = (Eddy , old_ind , new_ln [0 ], new_lt [0 ], new_rd_s [0 ],
10111028 new_rd_e [0 ], new_am [0 ], new_Ua [0 ], new_ek [0 ], new_tm [0 ],
10121029 new_eddy , first_record )
@@ -1059,6 +1076,16 @@ def track_eddies(Eddy, first_record):
10591076 dx_unused = dx [1 :] # index/indices to the unused eddy/eddies
10601077
10611078
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+
10621089 # Update eddy track dx0
10631090 if not Eddy .TRACK_EXTRA_VARIABLES :
10641091 new_cntr_e = new_cntr_s = new_uavg_prf = new_shp_err = None
@@ -1081,37 +1108,55 @@ def track_eddies(Eddy, first_record):
10811108 Eddy = accounting (* args , ** kwargs )
10821109
10831110 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' )
10881117 plt .colorbar ()
10891118 plt .xlabel ('new' )
10901119 plt .ylabel ('old' )
10911120 plt .title ('before' )
10921121
10931122 # 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]
10951127 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+
10971137 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' )
11041147 plt .colorbar ()
11051148 plt .xlabel ('new' )
11061149 plt .ylabel ('old' )
11071150 plt .title ('after' )
11081151 plt .tight_layout ()
11091152 plt .show ()
1153+ plt .close (225 )
11101154
11111155 # Finished looping over old eddy tracks
11121156
11131157 # Now we need to add new eddies defined by new_eddy_inds
11141158 if np .any (new_eddy_inds ):
1159+
11151160 if False :
11161161 print '------adding %s new eddies' % new_eddy_inds .sum ()
11171162
0 commit comments