@@ -353,6 +353,9 @@ def is_circular(self):
353
353
return False
354
354
355
355
def units (self , varname ):
356
+ stored_units = self .variables_description [varname ]['attrs' ].get ('units' , None )
357
+ if stored_units is not None :
358
+ return stored_units
356
359
with Dataset (self .filename ) as h :
357
360
var = h .variables [varname ]
358
361
if hasattr (var , 'units' ):
@@ -437,7 +440,7 @@ def bounds(self):
437
440
return self .x_bounds .min (), self .x_bounds .max (), self .y_bounds .min (), self .y_bounds .max ()
438
441
439
442
def eddy_identification (self , grid_height , uname , vname , date , step = 0.005 , shape_error = 55 ,
440
- array_sampling = 50 , pixel_limit = None ):
443
+ array_sampling = 50 , pixel_limit = None , precision = None ):
441
444
"""
442
445
443
446
Args:
@@ -449,6 +452,7 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
449
452
shape_error: must be in percent (%)
450
453
array_sampling:
451
454
pixel_limit:
455
+ precision: must be in meter(m)
452
456
453
457
Returns:
454
458
@@ -468,11 +472,15 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
468
472
in_h_unit = units .parse_expression (h_units )
469
473
if in_h_unit is not None :
470
474
factor , _ = in_h_unit .to ('m' ).to_tuple ()
475
+ logging .info ('We will apply on step a factor to be coherent with grid : %f' , 1 / factor )
471
476
step /= factor
477
+ if precision is not None :
478
+ precision /= factor
472
479
473
480
# Get h grid
474
- data = self .grid (grid_height )
475
-
481
+ data = self .grid (grid_height ).astype ('f8' )
482
+ if precision is not None :
483
+ data = (data / precision ).round () * precision
476
484
# Compute levels for ssh
477
485
z_min , z_max = data .min (), data .max ()
478
486
d_z = z_max - z_min
@@ -599,10 +607,10 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
599
607
if speed_array .shape [0 ] == 1 :
600
608
properties .obs ['uavg_profile' ][:] = speed_array [0 ]
601
609
else :
602
- properties .obs ['uavg_profile' ] = raw_resample (speed_array , array_sampling ) * .01
610
+ properties .obs ['uavg_profile' ] = raw_resample (speed_array , array_sampling )
603
611
properties .obs ['amplitude' ] = amp .amplitude
604
612
properties .obs ['radius_s' ] = eddy_radius_s
605
- properties .obs ['speed_radius' ] = max_average_speed * .01
613
+ properties .obs ['speed_radius' ] = max_average_speed
606
614
properties .obs ['radius_e' ] = eddy_radius_e
607
615
properties .obs ['shape_error_e' ] = aerr
608
616
properties .obs ['shape_error_s' ] = aerr_s
@@ -644,6 +652,13 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
644
652
factor , _ = in_h_unit .to (out_unit ).to_tuple ()
645
653
a_and_c [0 ].obs [name ] *= factor
646
654
a_and_c [1 ].obs [name ] *= factor
655
+ in_u_units = units .parse_expression (self .units (uname ))
656
+ if in_u_units is not None :
657
+ for name in ['speed_radius' , 'uavg_profile' ]:
658
+ out_unit = units .parse_expression (VAR_DESCR [name ]['nc_attr' ]['units' ])
659
+ factor , _ = in_u_units .to (out_unit ).to_tuple ()
660
+ a_and_c [0 ].obs [name ] *= factor
661
+ a_and_c [1 ].obs [name ] *= factor
647
662
return a_and_c
648
663
649
664
def get_uavg (self , all_contours , centlon_e , centlat_e , original_contour , anticyclonic_search , level_start ,
@@ -652,6 +667,7 @@ def get_uavg(self, all_contours, centlon_e, centlat_e, original_contour, anticyc
652
667
Calculate geostrophic speed around successive contours
653
668
Returns the average
654
669
"""
670
+ # Init max speed to search maximum
655
671
max_average_speed = self .speed_coef_mean (original_contour )
656
672
speed_array = [max_average_speed ]
657
673
0 commit comments