Skip to content

Commit 63640f0

Browse files
committed
Check if h units is coherent with (step, always in m)
1 parent 0b2a630 commit 63640f0

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/py_eddy_tracker/dataset/grid.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,21 @@ def bounds(self):
438438

439439
def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape_error=55,
440440
array_sampling=50, pixel_limit=None):
441+
"""
442+
443+
Args:
444+
grid_height:
445+
uname:
446+
vname:
447+
date:
448+
step: must be in meter (m)
449+
shape_error: must be in percent (%)
450+
array_sampling:
451+
pixel_limit:
452+
453+
Returns:
454+
455+
"""
441456
if not isinstance(date, datetime):
442457
raise Exception('Date argument be a datetime object')
443458
# The inf limit must be in pixel and sup limit in surface
@@ -447,6 +462,14 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
447462
# Compute an interpolator for eke
448463
self.init_speed_coef(uname, vname)
449464

465+
# Get unit of h grid
466+
h_units = self.units(grid_height)
467+
units = UnitRegistry()
468+
in_h_unit = units.parse_expression(h_units)
469+
if in_h_unit is not None:
470+
factor, _ = in_h_unit.to('m').to_tuple()
471+
step /= factor
472+
450473
# Get h grid
451474
data = self.grid(grid_height)
452475

@@ -614,13 +637,11 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
614637
eddies_collection.obs['contour_lon_s'] = ((eddies_collection.obs['contour_lon_s'].T - ref) % 360 + ref).T
615638

616639
a_and_c.append(eddies_collection)
617-
h_units = self.units(grid_height)
618-
units = UnitRegistry()
619-
in_unit = units.parse_expression(h_units)
620-
if in_unit is not None:
640+
641+
if in_h_unit is not None:
621642
for name in ['amplitude', 'height_max_speed_contour', 'height_external_contour', 'height_inner_contour']:
622643
out_unit = units.parse_expression(VAR_DESCR[name]['nc_attr']['units'])
623-
factor, _ = in_unit.to(out_unit).to_tuple()
644+
factor, _ = in_h_unit.to(out_unit).to_tuple()
624645
a_and_c[0].obs[name] *= factor
625646
a_and_c[1].obs[name] *= factor
626647
return a_and_c

0 commit comments

Comments
 (0)