From 52f95e5cdfcf7ad0de9a2b1f225b961d17149052 Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Thu, 29 Aug 2024 10:42:22 +0200 Subject: [PATCH] Fix tests after refactoring --- pygac/reader.py | 13 +++++++++---- pygac/tests/test_reader.py | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pygac/reader.py b/pygac/reader.py index 9cf7bf5..2203a16 100644 --- a/pygac/reader.py +++ b/pygac/reader.py @@ -89,6 +89,10 @@ class DecodingError(ValueError): """Raised when decoding of some value fails.""" +class TimestampMismatch(IndexError): + """Raise when matching timestamps doesn't work.""" + + class Reader(ABC): """Reader for GAC and LAC format, POD and KLM platforms.""" @@ -457,7 +461,10 @@ def get_times(self): year, jday, msec = self.correct_times_median(year=year, jday=jday, msec=msec) self._utcs = self.to_datetime64(year=year, jday=jday, msec=msec) - self._utcs = self.correct_times_thresh() + try: + self._utcs = self.correct_times_thresh() + except TimestampMismatch as err: + LOG.error(str(err)) return self._utcs @@ -550,7 +557,6 @@ def create_counts_dataset(self): ir_channel_names = ["3b", "4", "5"] columns = np.arange(scan_size) - channels = xr.DataArray(counts, dims=["scan_line_index", "columns", "channel_name"], coords=dict(scan_line_index=line_numbers, channel_name=channel_names, @@ -1123,9 +1129,8 @@ def correct_times_thresh(self, max_diff_from_t0_head=6*60*1000, if near_t0_head.size / float(nums.size) >= min_frac_near_t0_head: t0 = np.median(offsets[near_t0_head]) else: - LOG.error("Timestamp mismatch. Cannot perform correction.") results['fail_reason'] = "Timestamp mismatch" - return results + raise TimestampMismatch("Timestamp mismatch. Cannot perform correction.") # Add estimated offset to the ideal timestamps tn += t0 diff --git a/pygac/tests/test_reader.py b/pygac/tests/test_reader.py index 2869445..aec2af7 100644 --- a/pygac/tests/test_reader.py +++ b/pygac/tests/test_reader.py @@ -272,7 +272,7 @@ def test_lineno2msec(self): self.assertEqual(self.reader.lineno2msec(12345), 6172000) @mock.patch('pygac.reader.Reader.update_meta_data') - @mock.patch('pygac.gac_reader.GACReader._get_lonlat') + @mock.patch('pygac.gac_reader.GACReader._get_lonlat_from_file') @mock.patch('pygac.gac_reader.GACReader._get_corrupt_mask') @mock.patch('pygac.gac_reader.GACReader._adjust_clock_drift') def test_get_lonlat(self, adjust_clockdrift, @@ -333,7 +333,7 @@ def test_get_lonlat(self, adjust_clockdrift, @mock.patch('pygac.reader.Reader.update_meta_data') @mock.patch('pygac.gac_reader.GACReader._get_corrupt_mask') @mock.patch('pygac.gac_reader.GACReader._adjust_clock_drift') - @mock.patch('pygac.gac_reader.GACReader._get_lonlat') + @mock.patch('pygac.gac_reader.GACReader._get_lonlat_from_file') def test_interpolate(self, _get_lonlat, _adjust_clock_drift, _get_corrupt_mask, update_meta_data): """Test interpolate method in get_lonlat."""