Skip to content

Commit 812e746

Browse files
author
C-PROOF
committed
MNT: more time changes - seconds to nano
1 parent eff60ad commit 812e746

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pyglider/ncprocess.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def extract_timeseries_profiles(inname, outdir, deploymentyaml):
117117

118118
# outname = outdir + '/' + utils.get_file_id(dss) + '.nc'
119119
_log.info('Writing %s', outname)
120-
timeunits = 'seconds since 1970-01-01T00:00:00Z'
120+
timeunits = 'nanoseconds since 1970-01-01T00:00:00Z'
121121
timecalendar = 'gregorian'
122122
dss.to_netcdf(outname, encoding={'time': {'units': timeunits,
123123
'calendar': timecalendar},
@@ -164,7 +164,7 @@ def make_gridfiles(inname, outdir, deploymentyaml, *, fnamesuffix='', dz=1):
164164
deployment = yaml.safe_load(fin)
165165
profile_meta = deployment['profile_variables']
166166

167-
ds = xr.open_dataset(inname)
167+
ds = xr.open_dataset(inname, decode_times=True)
168168
_log.info(f'Working on: {inname}')
169169
_log.debug(str(ds))
170170
_log.debug(str(ds.time[0]))
@@ -183,8 +183,9 @@ def make_gridfiles(inname, outdir, deploymentyaml, *, fnamesuffix='', dz=1):
183183
dsout = xr.Dataset(
184184
coords={'depth': ('depth', depths),
185185
'profile': ('time', profiles)})
186+
print('Booo', ds.time, ds.temperature)
186187
ds['time_1970'] = ds.temperature.copy()
187-
ds['time_1970'].values = ds.time.values.astype(np.float64)/1e9
188+
ds['time_1970'].values = ds.time.values.astype(np.float64)
188189
for td in ('time_1970', 'longitude', 'latitude'):
189190
good = np.where(~np.isnan(ds[td]) & (ds['profile_index'] % 1 == 0))[0]
190191
dat, xedges, binnumber = stats.binned_statistic(
@@ -193,7 +194,7 @@ def make_gridfiles(inname, outdir, deploymentyaml, *, fnamesuffix='', dz=1):
193194
bins=[profile_bins])
194195
if td == 'time_1970':
195196
td = 'time'
196-
dat = dat.astype('timedelta64[s]') + np.datetime64('1970-01-01T00:00:00')
197+
dat = dat.astype('timedelta64[ns]') + np.datetime64('1970-01-01T00:00:00')
197198
_log.info(f'{td} {len(dat)}')
198199
dsout[td] = (('time'), dat, ds[td].attrs)
199200
ds.drop('time_1970')
@@ -249,8 +250,8 @@ def make_gridfiles(inname, outdir, deploymentyaml, *, fnamesuffix='', dz=1):
249250

250251
outname = outdir + '/' + ds.attrs['deployment_name'] + '_grid' + fnamesuffix + '.nc'
251252
_log.info('Writing %s', outname)
252-
timeunits = 'seconds since 1970-01-01T00:00:00Z'
253-
dsout.to_netcdf(outname, encoding={'time': {'units': timeunits}})
253+
# timeunits = 'nanoseconds since 1970-01-01T00:00:00Z'
254+
dsout.to_netcdf(outname)
254255
_log.info('Done gridding')
255256

256257
return outname

pyglider/slocum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ def parse_logfiles(files):
10641064

10651065
# now parse them
10661066
out = xr.Dataset(
1067-
coords={'time': ('surfacing', np.zeros(ntimes, dtype='datetime64[s]'))})
1067+
coords={'time': ('surfacing', np.zeros(ntimes, dtype='datetime64[ns]'))})
10681068
out['ampH'] = ('surfacing', np.zeros(ntimes) * np.NaN)
10691069
out['lon'] = ('surfacing', np.zeros(ntimes) * np.NaN)
10701070
out['lat'] = ('surfacing', np.zeros(ntimes) * np.NaN)
@@ -1073,7 +1073,7 @@ def parse_logfiles(files):
10731073
timestring = times[i][11:-13]
10741074
try:
10751075
out['time'][i] = np.datetime64(
1076-
datetime.strptime(timestring, '%a %b %d %H:%M:%S %Y'))
1076+
datetime.strptime(timestring, '%a %b %d %H:%M:%S %Y'), 'ns')
10771077
st = amph[i].index('=')
10781078
en = amph[i][st:].index(' ') + st
10791079
out['ampH'][i] = float(amph[i][(st+1):en])

0 commit comments

Comments
 (0)