From 9006e5eb4efe441f93fa4ee72ef3fb490c1d785e Mon Sep 17 00:00:00 2001 From: C-PROOF Date: Tue, 8 Nov 2022 13:57:32 -0800 Subject: [PATCH] Add attributes to the time variable in netcdf files Changed two lines in slocum.py to make sure that the attributes for the time variable are not getting lost or being specified twice. Attributes are from the metadata yaml file. --- pyglider/slocum.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyglider/slocum.py b/pyglider/slocum.py index 323699e..a3761da 100644 --- a/pyglider/slocum.py +++ b/pyglider/slocum.py @@ -845,7 +845,7 @@ def binary_to_timeseries(indir, cachedir, outdir, deploymentyaml, *, attr = {} name = 'time' for atts in ncvar[name].keys(): - if atts != 'coordinates': + if (atts != 'coordinates') & (atts != 'units') & (atts != 'calendar'): attr[atts] = ncvar[name][atts] if 'sci_m_present_time' in dbd.parameterNames['sci']: time_base = 'sci_m_present_time' @@ -902,8 +902,8 @@ def binary_to_timeseries(indir, cachedir, outdir, deploymentyaml, *, ds = ds.assign_coords(latitude=ds.latitude) ds = ds.assign_coords(depth=ds.depth) - ds['time'] = (ds.time.values.astype('timedelta64[s]') + - np.datetime64('1970-01-01T00:00:00')) + ds['time'] = (('time'), ds.time.values.astype('timedelta64[s]') + + np.datetime64('1970-01-01T00:00:00'), attr) ds = utils.fill_metadata(ds, deployment['metadata'], device_data) start = ds['time'].values[0] end = ds['time'].values[-1] @@ -1069,4 +1069,4 @@ def parse_logfiles(files): __all__ = ['binary_to_rawnc', 'merge_rawnc', 'raw_to_timeseries', - 'parse_gliderState', 'parse_logfiles'] \ No newline at end of file + 'parse_gliderState', 'parse_logfiles']