From 73c9e35f5fee28c6a45b9890414a68c6e98e214e Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Wed, 9 Mar 2022 18:15:09 +0100 Subject: [PATCH] Fix sunlight coverage check to return 100% when the data is fully lit and checkpass is true --- trollflow2/plugins/__init__.py | 24 ++++++++++++------------ trollflow2/tests/test_trollflow2.py | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/trollflow2/plugins/__init__.py b/trollflow2/plugins/__init__.py index 66e2e4b7..c9f6a4bb 100644 --- a/trollflow2/plugins/__init__.py +++ b/trollflow2/plugins/__init__.py @@ -630,7 +630,7 @@ def check_sunlight_coverage(job): continue min_day = config.get('min') max_day = config.get('max') - use_pass = config.get('check_pass', False) + check_pass = config.get('check_pass', False) if min_day is None and max_day is None: LOG.debug("Sunlight coverage not configured for %s / %s", @@ -642,24 +642,24 @@ def check_sunlight_coverage(job): if area_def is None: continue - if use_pass and overpass is None: + if check_pass and overpass is None: overpass = Pass(platform_name, start_time, end_time, instrument=sensor) - if coverage[use_pass] is None: - coverage[use_pass] = _get_sunlight_coverage(area_def, - start_time, - overpass) + if coverage[check_pass] is None: + coverage[check_pass] = _get_sunlight_coverage(area_def, + start_time, + overpass) area_conf = product_list['product_list']['areas'][area] - area_conf['area_sunlight_coverage_percent'] = coverage[use_pass] * 100 - if min_day is not None and coverage[use_pass] < (min_day / 100.0): + area_conf['area_sunlight_coverage_percent'] = coverage[check_pass] * 100 + if min_day is not None and coverage[check_pass] < (min_day / 100.0): LOG.info("Not enough sunlight coverage for " f"product '{product!s}', removed. Needs at least " - f"{min_day:.1f}%, got {coverage[use_pass]:.1%}.") + f"{min_day:.1f}%, got {coverage[check_pass]:.1%}.") dpath.util.delete(product_list, prod_path) - if max_day is not None and coverage[use_pass] > (max_day / 100.0): + if max_day is not None and coverage[check_pass] > (max_day / 100.0): LOG.info("Too much sunlight coverage for " f"product '{product!s}', removed. Needs at most " - f"{max_day:.1f}%, got {coverage[use_pass]:.1%}.") + f"{max_day:.1f}%, got {coverage[check_pass]:.1%}.") dpath.util.delete(product_list, prod_path) @@ -693,7 +693,7 @@ def _get_sunlight_coverage(area_def, start_time, overpass=None): return 0.0 else: daylight_area = daylight.area() - total_area = adp.area() + total_area = cut_area_poly.area() return daylight_area / total_area diff --git a/trollflow2/tests/test_trollflow2.py b/trollflow2/tests/test_trollflow2.py index f695aa4b..428c2a42 100644 --- a/trollflow2/tests/test_trollflow2.py +++ b/trollflow2/tests/test_trollflow2.py @@ -1003,6 +1003,22 @@ def test_metadata_is_read_from_scene(self): ts_pass.assert_called_with(job["input_mda"]["platform_name"], scene.start_time, scene.end_time, instrument=list(scene.sensor_names)[0]) + def test_fully_sunlit_scene_returns_full_coverage(self): + """Test that a fully sunlit scene returns 100% coverage.""" + from trollflow2.plugins import check_sunlight_coverage + from pyresample.spherical import SphPolygon + import numpy as np + with mock.patch('trollflow2.plugins.Pass') as tst_pass,\ + mock.patch('trollflow2.plugins.get_twilight_poly') as twilight: + tst_pass.return_value.boundary.contour_poly = SphPolygon(np.array([(0, 0), (0, 90), (45, 0)])) + twilight.return_value = SphPolygon(np.array([(0, 0), (0, 90), (90, 0)])) + scene = _get_mocked_scene_with_properties() + job = {"scene": scene, "product_list": self.product_list.copy(), + "input_mda": {"platform_name": "platform"}} + job['product_list']['product_list']['sunlight_coverage'] = {'min': 10, 'max': 40, 'check_pass': True} + check_sunlight_coverage(job) + assert job['product_list']['product_list']['areas']['euron1']['area_sunlight_coverage_percent'] == 100 + def test_product_not_loaded(self): """Test that product isn't loaded when sunlight coverage is too low.""" from trollflow2.plugins import check_sunlight_coverage