pytroll / trollflow2

Next generation Trollflow. Trollflow is for batch-processing satellite data using Satpy
https://trollflow2.readthedocs.org/
GNU General Public License v3.0
10 stars 15 forks source link

For newer Satpy, check_sunlight_coverage fails if posttroll message has no end time #136

Closed gerritholl closed 2 years ago

gerritholl commented 2 years ago

Describe the bug

The trollflow2 plugin check_sunlight_coverage tries to combine information from the scene metadata with information from the posttroll message. Since https://github.com/pytroll/satpy/pull/1797 (specifically https://github.com/pytroll/satpy/pull/1797/commits/e05256994f7ef74b812ade158abc1a15c0f32018), scene metadata is no longer stored in a .attrs attribute such as trollflow2 expects, but rather in properties that calculate this information on-the-fly. Processing messages that do not explicitly contain an end_time fails.

To Reproduce

import datetime
from trollflow2.plugins import create_scene, check_sunlight_coverage
from glob import glob
filenames = glob("/media/nas/x21308/scratch/SEVIRI/IODC/202202021300/H-*")
job = {
        "input_filenames": filenames,
        "input_mda": {
            "platform_name": "Meteosat-8",
            "start_time": datetime.datetime(1900, 1, 1)},
        "product_list": {
            "product_list": {
                "reader": ["seviri_l1b_hrit"],
                "areas": {}}}}
create_scene(job)
check_sunlight_coverage(job)

Expected behavior

I expect check_sunlight_coverage to be successful.

Actual results

The plugin check_sunlight_coverage fails with KeyError:

Traceback (most recent call last):
  File "/data/gholl/checkouts/protocode/mwe/trollflow2-keyerror-end-time.py", line 14, in <module>
    check_sunlight_coverage(job)
  File "/data/gholl/mambaforge/envs/py310/lib/python3.10/site-packages/trollflow2/plugins/__init__.py", line 597, in check_sunlight_coverage
    end_time = scn_mda['end_time']
KeyError: 'end_time'

Environment Info:

Additional context

It works with Satpy v0.31.1, before https://github.com/pytroll/satpy/pull/1797 was merged. At the time, the scene attrs attribute for this case would have been {'sensor': {'seviri'}, 'start_time': datetime.datetime(2022, 2, 2, 13, 0), 'end_time': datetime.datetime(2022, 2, 2, 13, 15)}. With newer versions of Satpy, the scene attrs attribute is empty ({}).