Skip to content

Commit

Permalink
Assert computed results are of right type
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Oct 17, 2024
1 parent 41bd4ee commit eceedf9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions satpy/tests/reader_tests/test_sar_c_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def test_read_calibrated_natural(self, measurement_filehandler):
expected = np.array([[np.nan, 0.02707529], [2.55858416, 3.27611055]], dtype=np.float32)
np.testing.assert_allclose(xarr.values[:2, :2], expected, rtol=2e-7)
assert xarr.dtype == np.float32
assert xarr.compute().dtype == np.float32

def test_read_calibrated_dB(self, measurement_filehandler):
"""Test the calibration routines."""
Expand All @@ -301,6 +302,7 @@ def test_read_calibrated_dB(self, measurement_filehandler):
expected = np.array([[np.nan, -15.674268], [4.079997, 5.153585]], dtype=np.float32)
np.testing.assert_allclose(xarr.values[:2, :2], expected, rtol=1e-6)
assert xarr.dtype == np.float32
assert xarr.compute().dtype == np.float32

def test_read_lon_lats(self, measurement_filehandler):
"""Test reading lons and lats."""
Expand All @@ -309,6 +311,7 @@ def test_read_lon_lats(self, measurement_filehandler):
expected = expected_longitudes
np.testing.assert_allclose(xarr.values, expected[:10, :10], atol=1e-3)
assert xarr.dtype == np.float64
assert xarr.compute().dtype == np.float64


annotation_xml = b"""<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -781,6 +784,7 @@ def test_get_noise_dataset(self, noise_filehandler):
res = noise_filehandler.get_dataset(query, {})
np.testing.assert_allclose(res, self.expected_azimuth_noise * self.expected_range_noise)
assert res.dtype == np.float32
assert res.compute().dtype == np.float32

def test_get_noise_dataset_has_right_chunk_size(self, noise_filehandler):
"""Test using get_dataset for the noise has right chunk size in result."""
Expand All @@ -804,13 +808,15 @@ def test_dn_calibration_array(self, calibration_filehandler):
res = calibration_filehandler.get_calibration(Calibration.dn, chunks=5)
np.testing.assert_allclose(res, expected_dn)
assert res.dtype == np.float32
assert res.compute().dtype == np.float32

def test_beta_calibration_array(self, calibration_filehandler):
"""Test reading the beta calibration array."""
expected_beta = np.ones((10, 10)) * 1087
res = calibration_filehandler.get_calibration(Calibration.beta_nought, chunks=5)
np.testing.assert_allclose(res, expected_beta)
assert res.dtype == np.float32
assert res.compute().dtype == np.float32

def test_sigma_calibration_array(self, calibration_filehandler):
"""Test reading the sigma calibration array."""
Expand All @@ -819,19 +825,22 @@ def test_sigma_calibration_array(self, calibration_filehandler):
res = calibration_filehandler.get_calibration(Calibration.sigma_nought, chunks=5)
np.testing.assert_allclose(res, expected_sigma)
assert res.dtype == np.float32
assert res.compute().dtype == np.float32

def test_gamma_calibration_array(self, calibration_filehandler):
"""Test reading the gamma calibration array."""
res = calibration_filehandler.get_calibration(Calibration.gamma, chunks=5)
np.testing.assert_allclose(res, self.expected_gamma)
assert res.dtype == np.float32
assert res.compute().dtype == np.float32

def test_get_calibration_dataset(self, calibration_filehandler):
"""Test using get_dataset for the calibration."""
query = DataQuery(name="gamma", polarization="vv")
res = calibration_filehandler.get_dataset(query, {})
np.testing.assert_allclose(res, self.expected_gamma)
assert res.dtype == np.float32
assert res.compute().dtype == np.float32

def test_get_calibration_dataset_has_right_chunk_size(self, calibration_filehandler):
"""Test using get_dataset for the calibration yields array with right chunksize."""
Expand All @@ -854,6 +863,7 @@ def test_incidence_angle(annotation_filehandler):
res = annotation_filehandler.get_dataset(query, {})
np.testing.assert_allclose(res, 19.18318046)
assert res.dtype == np.float32
assert res.compute().dtype == np.float32


def test_reading_from_reader(measurement_file, calibration_file, noise_file, annotation_file):
Expand All @@ -874,6 +884,7 @@ def test_reading_from_reader(measurement_file, calibration_file, noise_file, ann
expected_db = np.array([[np.nan, -15.674268], [4.079997, 5.153585]])
np.testing.assert_allclose(array.values[:2, :2], expected_db, rtol=1e-6)
assert array.dtype == np.float32
assert array.compute().dtype == np.float32


def test_filename_filtering_from_reader(measurement_file, calibration_file, noise_file, annotation_file, tmp_path):
Expand Down

0 comments on commit eceedf9

Please sign in to comment.