Skip to content

Commit

Permalink
Merge d9c8079 into 52dba91
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinkens committed Oct 29, 2020
2 parents 52dba91 + d9c8079 commit f33df00
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
6 changes: 4 additions & 2 deletions pygac_fdr/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ class QualityFlags(IntEnum):
},
{
"name": "equator_crossing_longitude",
"long_name": "Longitude where ascending node crosses the equator (can happen twice per file)",
"long_name": "Longitude where ascending node crosses the equator",
"comment": "Can happen twice per file",
"units": "degrees_east",
"dtype": np.float64,
"fill_value": FILL_VALUE_FLOAT,
},
{
"name": "equator_crossing_time",
"long_name": "UTC time when ascending node crosses the equator (can happen twice per file)",
"long_name": "UTC time when ascending node crosses the equator",
"comment": "Can happen twice per file",
"units": "seconds since 1970-01-01 00:00:00",
"calendar": "standard",
"dtype": np.float64,
Expand Down
18 changes: 14 additions & 4 deletions pygac_fdr/tests/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,24 @@ def _assert_numerical_attrs_close(self, attrs_a, attrs_b):
val_b = attrs_b.pop(attr)
np.testing.assert_allclose(val_a, val_b, rtol=self.rtol, atol=self.atol)

def assert_attrs_close(self, a, b):
attrs_a = a.attrs.copy()
attrs_b = b.attrs.copy()
def assert_global_attrs_close(self, attrs_a, attrs_b):
attrs_a = attrs_a.copy()
attrs_b = attrs_b.copy()
self._assert_time_attrs_close(attrs_a, attrs_b)
self._assert_numerical_attrs_close(attrs_a, attrs_b)
assert dict_equiv(attrs_a, attrs_b), diff_attrs_repr(
attrs_a, attrs_b, "identical"
)

def assert_variable_attrs_equal(self, ds_a, ds_b):
# Does not test whether ds_a and ds_b have the same set of variables
for var_name in ds_a.variables.keys():
attrs_a = ds_a[var_name].attrs
attrs_b = ds_b[var_name].attrs
assert dict_equiv(attrs_a, attrs_b), diff_attrs_repr(
attrs_a, attrs_b, "identical"
)

@classmethod
def setUpClass(cls):
logging_on(logging.DEBUG, for_all=True)
Expand Down Expand Up @@ -238,7 +247,8 @@ def _tst_regression(self, nc_files, nc_files_ref):
ds.attrs["geospatial_lat_min"] = 9999.0

# Compare datasets
self.assert_attrs_close(ds, ds_ref)
self.assert_global_attrs_close(ds.attrs, ds_ref.attrs)
self.assert_variable_attrs_equal(ds, ds_ref)
try:
xr.testing.assert_allclose(
ds, ds_ref, atol=self.atol, rtol=self.rtol
Expand Down
9 changes: 7 additions & 2 deletions pygac_fdr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,13 @@ def _update_coordinates(self, scene):
"""
for ds_name in scene.keys():
if scene[ds_name].dims == ("y", "x"):
scene[ds_name].coords["longitude"] = (("y", "x"), scene["longitude"])
scene[ds_name].coords["latitude"] = (("y", "x"), scene["latitude"])
for coord_name in ("latitude", "longitude"):
scene[ds_name].coords[coord_name] = (("y", "x"), scene[coord_name])
scene[ds_name].coords[coord_name].attrs = dict(
(key, val)
for key, val in scene[coord_name].attrs.copy().items()
if not key.startswith("_satpy")
)

def _fix_global_attrs(self, filename, global_attrs):
LOG.info("Fixing global attributes")
Expand Down

0 comments on commit f33df00

Please sign in to comment.