Skip to content

Commit

Permalink
Bugfix in the case time subsetting is not specified and time exists i…
Browse files Browse the repository at this point in the history
…n the input file.
  • Loading branch information
pagecp committed Feb 12, 2021
1 parent 9e5bdef commit 7c5e0e1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions subsetnc.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
except:
dset = xr.open_dataset(f, mask_and_scale=False, decode_coords=True, decode_times=True, use_cftime=True)
if 'time' in dset.keys():
tunits = dset.time.encoding['units']
year_startf = dset.time.dt.year[0]
month_startf = dset.time.dt.month[0]
day_startf = dset.time.dt.day[0]
Expand Down Expand Up @@ -108,8 +107,8 @@
fend_year = dset.time.dt.strftime("%Y")[-1].values
fend_month = dset.time.dt.strftime("%m")[-1].values
fend_day = dset.time.dt.strftime("%d")[-1].values
fbs = fb.strip('.nc')
outf = fbs + "_subset_" + fstart_year + fstart_month + fstart_day + "-" + fend_year + fend_month + fend_day + ".nc"
fbs = fb.strip('.nc')
outf = fbs + "_subset_" + fstart_year + fstart_month + fstart_day + "-" + fend_year + fend_month + fend_day + ".nc"
else:
period_start_time = -1
fbs = fb.strip('.nc')
Expand Down Expand Up @@ -162,6 +161,7 @@
enc = dict.fromkeys(enc, {'_FillValue': None})
tdimsf = {k: v for k, v in dims.items() if k == 'time'}
if len(tdimsf) > 0:
tunits = dset.time.encoding['units']
tenc = dict(tdimsf)
tenc = dict.fromkeys(tenc, {'_FillValue': None, 'units': tunits})
enc.update(tenc)
Expand Down

0 comments on commit 7c5e0e1

Please sign in to comment.