-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix swath builtin coordinates not being used #1541
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,14 @@ | |
# satpy. If not, see <http://www.gnu.org/licenses/>. | ||
"""Tests for the CF reader.""" | ||
|
||
import unittest | ||
import os | ||
import unittest | ||
from contextlib import suppress | ||
from datetime import datetime | ||
import xarray as xr | ||
|
||
import numpy as np | ||
import xarray as xr | ||
|
||
from satpy import Scene | ||
from satpy.readers.satpy_cf_nc import SatpyCFFileHandler | ||
|
||
|
@@ -85,25 +88,24 @@ def setUp(self): | |
|
||
def test_write_and_read(self): | ||
"""Save a file with cf_writer and read the data again.""" | ||
# '{testin}-{sensor}-{start_time:%Y%m%d%H%M%S}-{end_time:%Y%m%d%H%M%S}.nc' | ||
filename = 'testingcfwriter{:s}-viirs-mband-20201007075915-20201007080744.nc'.format( | ||
datetime.utcnow().strftime('%Y%j%H%M%S')) | ||
self.scene.save_datasets(writer='cf', | ||
filename=filename, | ||
header_attrs={'instrument': 'avhrr'}, | ||
engine='h5netcdf', | ||
flatten_attrs=True, | ||
pretty=True) | ||
scn_ = Scene(reader='satpy_cf_nc', | ||
filenames=[filename]) | ||
scn_.load(['image0', 'image1', 'lat']) | ||
self.assertTrue(np.all(scn_['image0'].data == self.scene['image0'].data)) | ||
self.assertTrue(np.all(scn_['lat'].data == self.scene['lat'].data)) # lat loaded as dataset | ||
self.assertTrue(np.all(scn_['image0'].coords['lon'] == self.scene['lon'].data)) # lon loded as coord | ||
try: | ||
os.remove(filename) | ||
except PermissionError: | ||
pass | ||
self.scene.save_datasets(writer='cf', | ||
filename=filename, | ||
header_attrs={'instrument': 'avhrr'}, | ||
engine='h5netcdf', | ||
flatten_attrs=True, | ||
pretty=True) | ||
scn_ = Scene(reader='satpy_cf_nc', | ||
filenames=[filename]) | ||
scn_.load(['image0', 'image1', 'lat']) | ||
self.assertTrue(np.all(scn_['image0'].data == self.scene['image0'].data)) | ||
self.assertTrue(np.all(scn_['lat'].data == self.scene['lat'].data)) # lat loaded as dataset | ||
self.assertTrue(np.all(scn_['image0'].coords['lon'] == self.scene['lon'].data)) # lon loded as coord | ||
finally: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, never seen a try without an except. So any exceptions raise before
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the exception isn't ignored, but 'finally' ensures its part of the code is executed before raising the exception. |
||
with suppress(PermissionError): | ||
os.remove(filename) | ||
|
||
def test_fix_modifier_attr(self): | ||
"""Check that fix modifier can handle empty list as modifier attribute.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, the return value is the opposite of the method name. Prefer lon, lats I think.