Skip to content

Commit

Permalink
Merge pull request #140 from mraspaud/fix-check-sunlight-coverage
Browse files Browse the repository at this point in the history
Fix sunlight coverage check to return 100% when the data is fully lit
  • Loading branch information
pnuu authored Mar 10, 2022
2 parents 98e2c59 + 73c9e35 commit 97882c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
24 changes: 12 additions & 12 deletions trollflow2/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)


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


Expand Down
16 changes: 16 additions & 0 deletions trollflow2/tests/test_trollflow2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 97882c0

Please sign in to comment.