Skip to content

Commit

Permalink
Update test_mersi_l1b.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yukaribbba committed Jun 4, 2024
1 parent f48d740 commit d04bd36
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions satpy/tests/reader_tests/test_mersi_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def _geo_prefix_for_file_type(self):
return ""


def _test_helper(res, band_list, exp_result):
def _assert_bands_mda_as_exp(res, band_list, exp_result):
"""Remove test code duplication."""
exp_cal = exp_result[0]
exp_unit = exp_result[1]
Expand Down Expand Up @@ -521,17 +521,17 @@ def test_all_resolutions(self):
res.__getitem__(band)

if resolution in ["all", "250"]:
_test_helper(res, self.vis_250_bands, ("reflectance", "%", (2 * 40, 2048 * 2)))
_test_helper(res, self.ir_250_bands, ("brightness_temperature", "K", (2 * 40, 2048 * 2)))
_assert_bands_mda_as_exp(res, self.vis_250_bands, ("reflectance", "%", (2 * 40, 2048 * 2)))
_assert_bands_mda_as_exp(res, self.ir_250_bands, ("brightness_temperature", "K", (2 * 40, 2048 * 2)))

if resolution == "all":
_test_helper(res, self.vis_1000_bands, ("reflectance", "%", (2 * 10, 2048)))
_test_helper(res, self.ir_1000_bands, ("brightness_temperature", "K", (2 * 10, 2048)))
_assert_bands_mda_as_exp(res, self.vis_1000_bands, ("reflectance", "%", (2 * 10, 2048)))
_assert_bands_mda_as_exp(res, self.ir_1000_bands, ("brightness_temperature", "K", (2 * 10, 2048)))
else:
_test_helper(res, self.vis_250_bands, ("reflectance", "%", (2 * 10, 2048)))
_test_helper(res, self.vis_1000_bands, ("reflectance", "%", (2 * 10, 2048)))
_test_helper(res, self.ir_250_bands, ("brightness_temperature", "K", (2 * 10, 2048)))
_test_helper(res, self.ir_1000_bands, ("brightness_temperature", "K", (2 * 10, 2048)))
_assert_bands_mda_as_exp(res, self.vis_250_bands, ("reflectance", "%", (2 * 10, 2048)))
_assert_bands_mda_as_exp(res, self.vis_1000_bands, ("reflectance", "%", (2 * 10, 2048)))
_assert_bands_mda_as_exp(res, self.ir_250_bands, ("brightness_temperature", "K", (2 * 10, 2048)))
_assert_bands_mda_as_exp(res, self.ir_1000_bands, ("brightness_temperature", "K", (2 * 10, 2048)))

Check warning on line 534 in satpy/tests/reader_tests/test_mersi_l1b.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

MERSI12llL1BTester.test_all_resolutions has 3 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

def test_counts_calib(self):
"""Test loading data at counts calibration."""
Expand All @@ -545,8 +545,8 @@ def test_counts_calib(self):
ds_ids.append(make_dataid(name="satellite_zenith_angle"))
res = reader.load(ds_ids)
assert len(res) == len(self.bands_1000) + len(self.bands_250) + 1
_test_helper(res, self.bands_250, ("counts", "1", (2 * 40, 2048 * 2)))
_test_helper(res, self.bands_1000, ("counts", "1", (2 * 10, 2048)))
_assert_bands_mda_as_exp(res, self.bands_250, ("counts", "1", (2 * 40, 2048 * 2)))
_assert_bands_mda_as_exp(res, self.bands_1000, ("counts", "1", (2 * 10, 2048)))

def test_rad_calib(self):
"""Test loading data at radiance calibration. For MERSI-2/LL VIS/IR and MERSI-1 IR."""
Expand All @@ -563,11 +563,11 @@ def test_rad_calib(self):
res = reader.load(ds_ids)
assert len(res) == len(test_bands)
if self.yaml_file in ["mersi2_l1b.yaml", "mersi_ll_l1b.yaml"]:
_test_helper(res, self.bands_250, ("radiance", "mW/ (m2 cm-1 sr)", (2 * 40, 2048 * 2)))
_test_helper(res, self.bands_1000, ("radiance", "mW/ (m2 cm-1 sr)", (2 * 10, 2048)))
_assert_bands_mda_as_exp(res, self.bands_250, ("radiance", "mW/ (m2 cm-1 sr)", (2 * 40, 2048 * 2)))
_assert_bands_mda_as_exp(res, self.bands_1000, ("radiance", "mW/ (m2 cm-1 sr)", (2 * 10, 2048)))
else:
_test_helper(res, self.ir_250_bands, ("radiance", "mW/ (m2 cm-1 sr)", (2 * 40, 2048 * 2)))
_test_helper(res, self.ir_1000_bands, ("radiance", "mW/ (m2 cm-1 sr)", (2 * 10, 2048)))
_assert_bands_mda_as_exp(res, self.ir_250_bands, ("radiance", "mW/ (m2 cm-1 sr)", (2 * 40, 2048 * 2)))
_assert_bands_mda_as_exp(res, self.ir_1000_bands, ("radiance", "mW/ (m2 cm-1 sr)", (2 * 10, 2048)))


class TestFY3AMERSI1L1B(MERSI12llL1BTester):
Expand Down

0 comments on commit d04bd36

Please sign in to comment.