@@ -194,6 +194,7 @@ class GridDataset(object):
194
194
'vars' ,
195
195
'interpolators' ,
196
196
'speed_coef' ,
197
+ 'contours' ,
197
198
)
198
199
199
200
GRAVITY = 9.807
@@ -211,6 +212,7 @@ def __init__(self, filename, x_name, y_name, centered=None):
211
212
self .x_dim = None
212
213
self .y_dim = None
213
214
self .centered = centered
215
+ self .contours = None
214
216
self .xinterp = None
215
217
self .yinterp = None
216
218
self .filename = filename
@@ -413,16 +415,18 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
413
415
x , y = self .x_c , self .y_c
414
416
415
417
# Compute ssh contour
416
- contours = Contours (x , y , data , levels , bbox_surface_min_degree = bbox_surface_min_degree , wrap_x = self .is_circular ())
418
+ self . contours = Contours (x , y , data , levels , bbox_surface_min_degree = bbox_surface_min_degree , wrap_x = self .is_circular ())
417
419
420
+ track_extra_variables = ['height_max_speed_contour' , 'height_external_contour' , 'height_inner_contour' ]
421
+ array_variables = ['contour_lon_e' , 'contour_lat_e' , 'contour_lon_s' , 'contour_lat_s' , 'uavg_profile' ]
418
422
# Compute cyclonic and anticylonic research:
419
423
a_and_c = list ()
420
424
for anticyclonic_search in [True , False ]:
421
425
eddies = list ()
422
426
iterator = 1 if anticyclonic_search else - 1
423
427
424
428
# Loop over each collection
425
- for coll_ind , coll in enumerate (contours .iter (step = iterator )):
429
+ for coll_ind , coll in enumerate (self . contours .iter (step = iterator )):
426
430
corrected_coll_index = coll_ind
427
431
if iterator == - 1 :
428
432
corrected_coll_index = - coll_ind - 1
@@ -431,7 +435,7 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
431
435
nb_paths = len (contour_paths )
432
436
if nb_paths == 0 :
433
437
continue
434
- cvalues = contours .cvalues [corrected_coll_index ]
438
+ cvalues = self . contours .cvalues [corrected_coll_index ]
435
439
logging .debug ('doing collection %s, contour value %.4f, %d paths' ,
436
440
corrected_coll_index , cvalues , nb_paths )
437
441
@@ -440,6 +444,7 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
440
444
if current_contour .used :
441
445
continue
442
446
centlon_e , centlat_e , eddy_radius_e , aerr = current_contour .fit_circle ()
447
+
443
448
# Filter for shape
444
449
if aerr < 0 or aerr > shape_error :
445
450
continue
@@ -465,13 +470,14 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
465
470
# Compute amplitude
466
471
reset_centroid , amp = self .get_amplitude (current_contour , cvalues , data ,
467
472
anticyclonic_search = anticyclonic_search ,
468
- level = contours .levels [corrected_coll_index ], step = step )
469
-
473
+ level = self . contours .levels [corrected_coll_index ], step = step )
474
+ print ( reset_centroid , amp . amplitude )
470
475
# If we have a valid amplitude
471
476
if (not amp .within_amplitude_limits ()) or (amp .amplitude == 0 ):
472
477
continue
473
478
474
479
if reset_centroid :
480
+
475
481
if self .is_circular ():
476
482
centi = self .normalize_x_indice (reset_centroid [0 ])
477
483
else :
@@ -487,7 +493,8 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
487
493
488
494
# centlat_e and centlon_e must be index of maximum, we will loose some inner contour, if it's not
489
495
max_average_speed , speed_contour , inner_contour , speed_array , i_max_speed , i_inner = \
490
- self .get_uavg (contours , centlon_e , centlat_e , current_contour , anticyclonic_search , corrected_coll_index )
496
+ self .get_uavg (self .contours , centlon_e , centlat_e , current_contour , anticyclonic_search ,
497
+ corrected_coll_index )
491
498
492
499
# Use azimuth equal projection for radius
493
500
proj = Proj ('+proj=aeqd +ellps=WGS84 +lat_0={1} +lon_0={0}' .format (* inner_contour .mean_coordinates ))
@@ -502,16 +509,13 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
502
509
_ , _ , eddy_radius_s , aerr_s = fit_circle_c (c_x , c_y )
503
510
504
511
# Instantiate new EddyObservation object
505
- properties = EddiesObservations (
506
- size = 1 ,
507
- track_extra_variables = [ 'height_max_speed_contour' , 'height_external_contour' , 'height_inner_contour' ],
508
- track_array_variables = array_sampling ,
509
- array_variables = ['contour_lon_e' , 'contour_lat_e' , 'contour_lon_s' , 'contour_lat_s' , 'uavg_profile' ]
510
- )
511
-
512
- properties .obs ['height_max_speed_contour' ] = contours .cvalues [i_max_speed ]
512
+ properties = EddiesObservations (size = 1 , track_extra_variables = track_extra_variables ,
513
+ track_array_variables = array_sampling ,
514
+ array_variables = array_variables )
515
+
516
+ properties .obs ['height_max_speed_contour' ] = self .contours .cvalues [i_max_speed ]
513
517
properties .obs ['height_external_contour' ] = cvalues
514
- properties .obs ['height_inner_contour' ] = contours .cvalues [i_inner ]
518
+ properties .obs ['height_inner_contour' ] = self . contours .cvalues [i_inner ]
515
519
array_size = speed_array .shape [0 ]
516
520
properties .obs ['nb_contour_selected' ] = array_size
517
521
if speed_array .shape [0 ] == 1 :
@@ -537,7 +541,9 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
537
541
# To reserve definitively the area
538
542
data .mask [i_x_in , i_y_in ] = True
539
543
if len (eddies ) == 0 :
540
- eddies_collection = EddiesObservations ()
544
+ eddies_collection = EddiesObservations (track_extra_variables = track_extra_variables ,
545
+ track_array_variables = array_sampling ,
546
+ array_variables = array_variables )
541
547
else :
542
548
eddies_collection = EddiesObservations .concatenate (eddies )
543
549
eddies_collection .sign_type = 1 if anticyclonic_search else - 1
@@ -1168,6 +1174,11 @@ def init_speed_coef(self, uname='u', vname='v'):
1168
1174
speed [speed .mask ] = 0
1169
1175
self ._speed_ev = RectBivariateSpline (self .x_c , self .y_c , speed , kx = 1 , ky = 1 ).ev
1170
1176
1177
+ def display (self , ax , name , ** kwargs ):
1178
+ if 'cmap' not in kwargs :
1179
+ kwargs ['cmap' ] = 'coolwarm'
1180
+ return ax .pcolormesh (self .x_bounds , self .y_bounds , self .grid (name ).T , ** kwargs )
1181
+
1171
1182
def interp (self , grid_name , lons , lats ):
1172
1183
"""
1173
1184
Compute z over lons, lats
0 commit comments