Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Sep 16, 2020
1 parent 75d3e86 commit 1571c9d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 17 deletions.
6 changes: 3 additions & 3 deletions satpy/readers/eps_l1b.py
Expand Up @@ -188,7 +188,7 @@ def keys(self):
return keys

def get_full_lonlats(self):
"""Get the interpolated lons_like/lats_like."""
"""Get the interpolated longitudes and latitudes."""
if self.lons is not None and self.lats is not None:
return self.lons, self.lats

Expand All @@ -212,7 +212,7 @@ def _interpolate(self, lons_like, lats_like):
shape=(self.scanlines, self.pixels))
return lons_like_1km, lats_like_1km
else:
raise NotImplementedError("Lon/lat expansion not implemented for " +
raise NotImplementedError("Lon/lat and angle expansion not implemented for " +
"sample rate = " + str(nav_sample_rate) +
" and earth views = " +
str(self.pixels))
Expand Down Expand Up @@ -241,7 +241,7 @@ def _get_full_angles(self, solar_zenith, sat_zenith, solar_azimuth, sat_azimuth)
str(self.pixels))

def get_full_angles(self):
"""Get the interpolated lons_like/lats_like."""
"""Get the interpolated angles."""
if (self.sun_azi is not None and self.sun_zen is not None and
self.sat_azi is not None and self.sat_zen is not None):
return self.sun_azi, self.sun_zen, self.sat_azi, self.sat_zen
Expand Down
73 changes: 59 additions & 14 deletions satpy/tests/reader_tests/test_eps_l1b.py
Expand Up @@ -59,21 +59,29 @@ def create_sections(structure):
return sections


class TestEPSL1B(TestCase):
class BaseTestCaseEPSL1B(TestCase):
"""Base class for EPS l1b test case."""

def _create_structure(self):
structure = [(1, ('mphr', 0)), (1, ('sphr', 0)), (11, ('ipr', 0)),
(1, ('geadr', 1)), (1, ('geadr', 2)), (1, ('geadr', 3)),
(1, ('geadr', 4)), (1, ('geadr', 5)), (1, ('geadr', 6)),
(1, ('geadr', 7)), (1, ('giadr', 1)), (1, ('giadr', 2)),
(1, ('veadr', 1)), (self.scan_lines, ('mdr', 2))]
sections = create_sections(structure)
return sections


class TestEPSL1B(BaseTestCaseEPSL1B):
"""Test the filehandler."""

def setUp(self):
"""Set up the tests."""
# ipr is not present in the xml format ?
self.scan_lines = 1080
self.earth_views = 2048
structure = [(1, ('mphr', 0)), (1, ('sphr', 0)), (11, ('ipr', 0)),
(1, ('geadr', 1)), (1, ('geadr', 2)), (1, ('geadr', 3)),
(1, ('geadr', 4)), (1, ('geadr', 5)), (1, ('geadr', 6)),
(1, ('geadr', 7)), (1, ('giadr', 1)), (1, ('giadr', 2)),
(1, ('veadr', 1)), (self.scan_lines, ('mdr', 2))]

sections = create_sections(structure)
sections = self._create_structure()
sections[('mphr', 0)]['TOTAL_MDR'] = (b'TOTAL_MDR = ' +
bytes(str(self.scan_lines), encoding='ascii') +
b'\n')
Expand Down Expand Up @@ -170,7 +178,7 @@ def mock_getitem(key):
assert np.allclose(sun_zen_np1, sun_zen_np2)


class TestWrongEPSL1B(TestCase):
class TestWrongScanlinesEPSL1B(BaseTestCaseEPSL1B):
"""Test the filehandler on a corrupt file."""

@pytest.fixture(autouse=True)
Expand All @@ -183,13 +191,8 @@ def setUp(self):
# ipr is not present in the xml format ?
self.scan_lines = 1080
self.earth_views = 2048
structure = [(1, ('mphr', 0)), (1, ('sphr', 0)), (11, ('ipr', 0)),
(1, ('geadr', 1)), (1, ('geadr', 2)), (1, ('geadr', 3)),
(1, ('geadr', 4)), (1, ('geadr', 5)), (1, ('geadr', 6)),
(1, ('geadr', 7)), (1, ('giadr', 1)), (1, ('giadr', 2)),
(1, ('veadr', 1)), (self.scan_lines, ('mdr', 2))]

sections = create_sections(structure)
sections = self._create_structure()
sections[('mphr', 0)]['TOTAL_MDR'] = (b'TOTAL_MDR = ' +
bytes(str(self.scan_lines - 2), encoding='ascii') +
b'\n')
Expand Down Expand Up @@ -235,3 +238,45 @@ def tearDown(self):
"""Tear down the tests."""
with suppress(OSError):
os.remove(self.filename)


class TestWrongSamplingEPSL1B(BaseTestCaseEPSL1B):
"""Test the filehandler on a corrupt file."""

@pytest.fixture(autouse=True)
def inject_fixtures(self, caplog):
"""Inject caplog."""
self._caplog = caplog

def setUp(self):
"""Set up the tests."""
self.scan_lines = 1080
self.earth_views = 2048
self.sample_rate = 23
sections = self._create_structure()
sections[('mphr', 0)]['TOTAL_MDR'] = (b'TOTAL_MDR = ' +
bytes(str(self.scan_lines), encoding='ascii') +
b'\n')
sections[('mphr', 0)]['SPACECRAFT_ID'] = b'SPACECRAFT_ID = M03\n'
sections[('mphr', 0)]['INSTRUMENT_ID'] = b'INSTRUMENT_ID = AVHR\n'
sections[('sphr', 0)]['EARTH_VIEWS_PER_SCANLINE'] = (b'EARTH_VIEWS_PER_SCANLINE = ' +
bytes(str(self.earth_views), encoding='ascii') +
b'\n')
sections[('sphr', 0)]['NAV_SAMPLE_RATE'] = (b'NAV_SAMPLE_RATE = ' +
bytes(str(self.sample_rate), encoding='ascii') +
b'\n')
_fd, fname = mkstemp()
fd = open(_fd)

self.filename = fname
for _, arr in sections.items():
arr.tofile(fd)
fd.close()
self.fh = eps.EPSAVHRRFile(self.filename, {'start_time': 'now',
'end_time': 'later'}, {})

def test_get_dataset_fails_because_of_wrong_sample_rate(self):
"""Test that lons fail to be interpolate."""
key = make_dataid(name="longitude")
with pytest.raises(NotImplementedError):
self.fh.get_dataset(key, dict())

0 comments on commit 1571c9d

Please sign in to comment.