Commit 8d2d06bb authored by PIOLLE's avatar PIOLLE
Browse files

fix for default time units when saving

parent 2e18ae1e
...@@ -73,7 +73,7 @@ def set_masked_values(data, fill_value): ...@@ -73,7 +73,7 @@ def set_masked_values(data, fill_value):
'float16', 'float32', 'float64', 'complex64', 'complex128', 'float16', 'float32', 'float64', 'complex64', 'complex128',
' datetime64'] ' datetime64']
and not numpy.issubdtype(data.dtype, numpy.datetime64)): and not numpy.issubdtype(data.dtype, numpy.datetime64)):
if isinstance(data, (numpy.ma.core.MaskedArray, numpy.ndarray)): if isinstance(data, numpy.ma.core.MaskedArray):
# mask fill values for int types # mask fill values for int types
return data.filled(fill_value) return data.filled(fill_value)
return data return data
......
...@@ -833,12 +833,12 @@ class Dataset(ABC): ...@@ -833,12 +833,12 @@ class Dataset(ABC):
def _make_lat_coord(self, values): def _make_lat_coord(self, values):
return self._make_coord( return self._make_coord(
'lat', values, 'degrees_north', 'latitude', 'latitude' 'lat', values, 'degree_north', 'latitude', 'latitude'
) )
def _make_lon_coord(self, values): def _make_lon_coord(self, values):
return self._make_coord( return self._make_coord(
'lon', values, 'degrees_east', 'longitude', 'longitude' 'lon', values, 'degree_east', 'longitude', 'longitude'
) )
def _make_time_coord(self, values): def _make_time_coord(self, values):
...@@ -2087,7 +2087,8 @@ class Dataset(ABC): ...@@ -2087,7 +2087,8 @@ class Dataset(ABC):
def add_field_encoding( def add_field_encoding(
cls, cls,
dataset: 'xr.Dataset', dataset: 'xr.Dataset',
attrs: Mapping[str, Any]) -> None: attrs: Mapping[str, Any],
force_profile: bool = False) -> None:
"""Add field encoding to the dataset from a attribute definition """Add field encoding to the dataset from a attribute definition
file. file.
...@@ -2105,8 +2106,11 @@ class Dataset(ABC): ...@@ -2105,8 +2106,11 @@ class Dataset(ABC):
) )
continue continue
for att in attrs[v]: for att in attrs[v]:
dataset.variables[v].encoding[att] = attrs[v][att] if att not in dataset.variables[v].encoding or force_profile:
value = attrs[v][att]
if value is None:
continue
dataset.variables[v].encoding[att] = value
def _convert_format(self, profile=None, force_profile=False, **kwargs): def _convert_format(self, profile=None, force_profile=False, **kwargs):
"""Implement specific formatting rules to a dataset. """Implement specific formatting rules to a dataset.
......
...@@ -73,6 +73,30 @@ attributes: ...@@ -73,6 +73,30 @@ attributes:
fields: fields:
lat:
standard_name: latitude
units: degree_north
valid_range: [-90, 90]
lon:
standard_name: longitude
units: degree_east
valid_range: [-180., 180]
time:
long_name: measurement time
standard_name: time
encoding: encoding:
lat:
dtype: float32
least_significant_digit: 3
lon:
dtype: float32
least_significant_digit: 3
time:
dtype: int32
units: 'seconds since 1981-01-01 00:00:00'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment