Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinkens committed Nov 25, 2019
1 parent e568e68 commit b02bbdb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions satpy/tests/writer_tests/test_cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,23 @@ def test_bounds(self):
end_time=end_time))
with TempFile() as filename:
scn.save_datasets(filename=filename, writer='cf')
# Check decoded time coordinates & bounds
with xr.open_dataset(filename, decode_cf=True) as f:
bounds_exp = np.array([[start_time, end_time]], dtype='datetime64[m]')
np.testing.assert_array_equal(f['time_bnds'], bounds_exp)
self.assertEqual(f['time'].attrs['bounds'], 'time_bnds')

# Check that time coordinates and bounds have the same units
# Check raw time coordinates & bounds
with xr.open_dataset(filename, decode_cf=False) as f:
self.assertEqual(f['time_bnds'].attrs['units'], f['time'].attrs['units'])
self.assertEqual(f['time_bnds'].attrs['calendar'], f['time'].attrs['calendar'])
np.testing.assert_almost_equal(f['time_bnds'], [[-0.0034722, 0.0069444]])

# User-specified time encoding should have preference
with TempFile() as filename:
time_units = 'seconds since 2018-01-01'
scn.save_datasets(filename=filename, encoding={'time': {'units': time_units}},
writer='cf')
with xr.open_dataset(filename, decode_cf=False) as f:
self.assertEqual(f['time'].attrs['units'], time_units)
self.assertEqual(f['time_bnds'].attrs['units'], time_units)
np.testing.assert_array_equal(f['time_bnds'], [[12909600, 12910500]])

def test_bounds_minimum(self):
"""Test minimum bounds."""
Expand Down
2 changes: 1 addition & 1 deletion satpy/writers/cf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def update_encoding(self, dataset, to_netcdf_kwargs):
'calendar': time_enc['calendar'],
'_FillValue': None}
encoding['time'] = time_enc
encoding['time_bnds'] = bounds_enc
encoding['time_bnds'] = bounds_enc # FUTURE: Not required anymore with xarray-0.14+

return encoding, other_to_netcdf_kwargs

Expand Down

0 comments on commit b02bbdb

Please sign in to comment.