Skip to content

Commit 14fe2e0

Browse files
authored
Merge pull request #128 from jhamman/fix/precision
default to f4 and don't override encoding
2 parents b6426b9 + 82dd7d7 commit 14fe2e0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

metsim/metsim.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class MetSim(object):
119119
"time_step": -1,
120120
"calendar": 'standard',
121121
"out_fmt": '',
122-
"out_precision": 'f8',
122+
"out_precision": 'f4',
123123
"verbose": 0,
124124
"sw_prec_thresh": 0.0,
125125
"time_grouper": None,
@@ -409,13 +409,14 @@ def setup_output(self, prototype: xr.Dataset=None):
409409
v = ', '.join(v)
410410
attrs['_global'][k] = v
411411
self.output.attrs = attrs['_global']
412+
413+
dtype = self.params['out_precision']
414+
412415
for varname in self.params['out_vars']:
413416
self.output[varname] = xr.DataArray(
414-
data=np.full(shape, np.nan),
417+
data=np.full(shape, np.nan, dtype=dtype),
415418
coords=coords, dims=dims,
416-
name=varname, attrs=attrs.get(varname, {}),
417-
encoding={'dtype': self.params['out_precision'],
418-
'_FillValue': cnst.FILL_VALUES['f8']})
419+
name=varname, attrs=attrs.get(varname, {}))
419420
self.output['time'].attrs.update(attrs['time'])
420421

421422
def _aggregate_state(self):
@@ -551,8 +552,10 @@ def write_netcdf(self, suffix: str):
551552
logger.info(output_filename)
552553
out_encoding = {'time': {'dtype': 'f8',
553554
'calendar': self.params['calendar']}}
555+
dtype = self.params['out_precision']
554556
for v in self.output.data_vars:
555-
out_encoding[v] = {'dtype': 'f8'}
557+
out_encoding[v] = {'dtype': dtype,
558+
'_FillValue': cnst.FILL_VALUES[dtype]}
556559
self.output.to_netcdf(output_filename,
557560
unlimited_dims=['time'],
558561
encoding=out_encoding)

0 commit comments

Comments
 (0)