Skip to content

Commit

Permalink
Fix tests after refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Aug 29, 2024
1 parent d4aab34 commit 52f95e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions pygac/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pygac/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 52f95e5

Please sign in to comment.