Skip to content

Commit 4aac4d5

Browse files
committed
Add option to foce field unit
1 parent 9094d22 commit 4aac4d5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/py_eddy_tracker/dataset/grid.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ def bounds(self):
440440
return self.x_bounds.min(), self.x_bounds.max(), self.y_bounds.min(), self.y_bounds.max()
441441

442442
def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape_error=55,
443-
array_sampling=50, pixel_limit=None, precision=None):
443+
array_sampling=50, pixel_limit=None, precision=None, force_height_unit=None,
444+
force_speed_unit=None):
444445
"""
445446
446447
Args:
@@ -467,7 +468,8 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
467468
self.init_speed_coef(uname, vname)
468469

469470
# Get unit of h grid
470-
h_units = self.units(grid_height)
471+
472+
h_units = self.units(grid_height) if force_height_unit is None else force_height_unit
471473
units = UnitRegistry()
472474
in_h_unit = units.parse_expression(h_units)
473475
if in_h_unit is not None:
@@ -653,7 +655,8 @@ def eddy_identification(self, grid_height, uname, vname, date, step=0.005, shape
653655
factor, _ = in_h_unit.to(out_unit).to_tuple()
654656
a_and_c[0].obs[name] *= factor
655657
a_and_c[1].obs[name] *= factor
656-
in_u_units = units.parse_expression(self.units(uname))
658+
u_units = self.units(uname) if force_speed_unit is None else force_speed_unit
659+
in_u_units = units.parse_expression(u_units)
657660
if in_u_units is not None:
658661
for name in ['speed_average', 'uavg_profile']:
659662
out_unit = units.parse_expression(VAR_DESCR[name]['nc_attr']['units'])

src/scripts/EddyId

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def id_parser():
2626
help='Step between 2 isoline in m')
2727
parser.add_argument('--fir_errmax', default=55, type=float,
2828
help='Error max accepted to fit circle in percent')
29+
parser.add_argument('--height_unit', default=None, type=str,
30+
help='Force height unit')
31+
parser.add_argument('--speed_unit', default=None, type=str,
32+
help='Force speed unit')
2933
return parser
3034

3135

@@ -42,7 +46,8 @@ if __name__ == '__main__':
4246
if args.cut_wavelength != 0:
4347
h.bessel_high_filter(args.h, args.cut_wavelength, order=args.filter_order)
4448
a, c = h.eddy_identification(args.h, u, v, date, args.isoline_step, pixel_limit=(5, 2000),
45-
shape_error=args.fir_errmax)
49+
shape_error=args.fir_errmax, force_height_unit=args.height_unit,
50+
force_speed_unit=args.speed_unit)
4651
with Dataset(args.path_out + date.strftime('/Anticyclonic_%Y%m%d.nc'), 'w') as h:
4752
a.to_netcdf(h)
4853
with Dataset(args.path_out + date.strftime('/Cyclonic_%Y%m%d.nc'), 'w') as h:

0 commit comments

Comments
 (0)