Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Oct 18, 2024
1 parent 91c42ff commit a421bae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pygac/calibration/noaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ def calibrate_thermal(counts, prt, ict, space, line_numbers, channel, cal):
nonzeros = np.logical_not(zeros)

space[zeros] = np.interp((zeros).nonzero()[0],
(nonzeros).nonzero()[0],
space[nonzeros])
(nonzeros).nonzero()[0],
space[nonzeros])

# convolving and smoothing PRT, ICT and SPACE values
if lines > 51:
Expand Down
8 changes: 5 additions & 3 deletions pygac/tests/test_klm.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ def test_get_ch3_switch(self):

def test_calibrate_channels(self):
"""Test channel calibration."""
# Switch on 3b
self.reader.scans["scan_line_bit_field"] = 0
# ICT
self.reader.scans["back_scan"] = 400
self.reader.scans["back_scan"][0::5, :] = 0
self.reader.scans["back_scan"][50, :, :] = 0
# Space
self.reader.scans["space_data"] = 400
self.reader.scans["space_data"][0::5, :] = 0

self.reader.scans["space_data"][50, :, :] = 0
self.reader.get_calibrated_channels()
assert np.any(np.isfinite(self.reader.get_calibrated_channels()))

def test_calibrate_inactive_3b(self):
Expand Down
31 changes: 23 additions & 8 deletions pygac/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,25 @@ def get_header_timestamp(self):

def get_telemetry(self):
"""Get the telemetry."""
prt = 51 * np.ones(self.along_track) # prt threshold is 50
prt[::5] = 0
ict = 101 * np.ones((self.along_track, 3)) # ict threshold is 100
space = 101 * np.ones((self.along_track, 3)) # space threshold is 100
return prt, ict, space
prt = 51 * np.ones((self.along_track, 3)) # prt threshold is 50
prt[::5, :] = 0
ict = 101 * np.ones((self.along_track, 10, 3)) # ict threshold is 100
space = 101 * np.ones((self.along_track, 10, 5)) # space threshold is 100

prt_counts = xr.DataArray(prt,
dims=["scan_line_index", "PRT_measurement"])

# getting ICT counts
ict_counts = xr.DataArray(ict,
dims=["scan_line_index", "back_scan", "channel_name"],
coords=dict(channel_name=["3", "4", "5"]))

# getting space counts
space_counts = xr.DataArray(self.split_array_along_channel_3(space),
dims=["scan_line_index", "back_scan", "channel_name"],
coords=dict(channel_name=["1", "2", "3", "4", "5"]))

return xr.Dataset(dict(PRT=prt_counts, ICT=ict_counts, space_counts=space_counts))

def _adjust_clock_drift(self):
pass
Expand Down Expand Up @@ -835,9 +849,10 @@ def test_read_to_dataset_is_a_dataset_including_channels_and_telemetry(pod_file_
assert "times" in dataset.coords
assert "scan_line_index" in dataset.coords
assert "channel_name" in dataset.coords
assert dataset["prt_counts"].shape == (3,)
assert dataset["ict_counts"].shape == (3, 3)
assert dataset["space_counts"].shape == (3, 3)
assert dataset["PRT"].shape == (3, 3)
assert dataset["ICT"].shape == (3, 10, 5)
np.testing.assert_array_equal(dataset["ICT"].sel(channel_name=["1", "2"]), np.nan)
assert dataset["space_counts"].shape == (3, 10, 5)


def test_read_to_dataset_without_interpolation(pod_file_with_tbm_header, pod_tle):
Expand Down

0 comments on commit a421bae

Please sign in to comment.