Skip to content

Commit 0fad647

Browse files
committed
Allow to add field on a dataset
1 parent 48ed689 commit 0fad647

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/py_eddy_tracker/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,19 @@ def parse_args(self, *args, **kwargs):
432432
longname='effective contour error',
433433
)
434434
),
435+
score=dict(
436+
attr_name=None,
437+
nc_name='score',
438+
nc_type='f2',
439+
output_type='u1',
440+
scale_factor=0.4,
441+
nc_dims=('obs',),
442+
nc_attr=dict(
443+
units='%',
444+
description='score',
445+
longname='score',
446+
)
447+
),
435448
shape_error_s=dict(
436449
attr_name=None,
437450
nc_name='speed_contour_shape_error',

src/py_eddy_tracker/observations/observation.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
array,
4242
empty,
4343
absolute,
44+
concatenate,
4445
)
4546
from netCDF4 import Dataset
4647
from ..generic import distance_grid, distance
@@ -219,6 +220,25 @@ def obs_dimension(cls, handler):
219220
if candidate in handler.dimensions.keys():
220221
return candidate
221222

223+
def add_fields(self, fields):
224+
"""
225+
Add a new field
226+
"""
227+
nb_obs = self.obs.shape[0]
228+
new = self.__class__(
229+
size=nb_obs,
230+
track_extra_variables=list(concatenate((self.track_extra_variables, fields))),
231+
track_array_variables=self.track_array_variables,
232+
array_variables=self.array_variables,
233+
raw_data=self.raw_data
234+
)
235+
new.sign_type = self.sign_type
236+
for field in self.obs.dtype.descr:
237+
logging.debug('Copy of field %s ...', field)
238+
var = field[0]
239+
new.obs[var] = self.obs[var]
240+
return new
241+
222242
@property
223243
def dtype(self):
224244
"""Return dtype to build numpy array
@@ -368,8 +388,6 @@ def load_from_netcdf(cls, filename, raw_data=False, remove_vars=None):
368388
with Dataset(filename) as h_nc:
369389
var_list = list(h_nc.variables.keys())
370390
if remove_vars is not None:
371-
print(var_list)
372-
print(remove_vars)
373391
var_list = [i for i in var_list if i not in remove_vars]
374392

375393
nb_obs = len(h_nc.dimensions[cls.obs_dimension(h_nc)])

0 commit comments

Comments
 (0)