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

TypeError calculating sunlight coverage when no pytroll-schedule installed #132

Closed gerritholl closed 1 week ago

gerritholl commented 2 years ago

Describe the bug

When I try to calculate sunlight coverage while pytroll-schedule is not installed, I get a TypeError.

To Reproduce

from pyresample import create_area_def
from pyproj import CRS
from trollflow2.plugins import _get_sunlight_coverage
from datetime import datetime
euro4326 = create_area_def(
        "epsg4326europa",
        CRS.from_epsg(4326),
        resolution=1/128,
        area_extent=(-10, 40, 20, 60),
        proj_id="EQC_PLAT")
print(_get_sunlight_coverage(euro4326, datetime(2021, 12, 29, 12)))

Expected behavior

Some number between 0 and 1.

Actual results

Traceback (most recent call last):
  File "/data/gholl/checkouts/protocode/mwe/trollflow2-sunlight-typerror.py", line 11, in <module>
    print(_get_sunlight_coverage(euro4326, datetime(2021, 12, 29, 12)))
  File "/data/gholl/checkouts/trollflow2/trollflow2/plugins/__init__.py", line 666, in _get_sunlight_coverage
    poly = get_twilight_poly(start_time)
TypeError: 'NoneType' object is not callable

Environment Info:

Additional context

Found this when calling _get_sunlight_coverage directly to find out why it gives 0 for me in the middle of the day. Perhaps there will be a new issue soon...

pnuu commented 1 week ago

The parent function check_sunlight_coverage() has these log messages printed when pytroll-schedule is not installed

    if get_twilight_poly is None:
        logger.error("Trollsched import failed, sunlight coverage calculation not possible")
        logger.info("Keeping all products")
        return

so I'd say this is not an issue (do not call private functions directly).

Out of the two other plugin that use the pytroll-schedule package, covers(), has the same check, but check_valid_data_fraction() does not. These are also using a public get_scene_coverage() function.

I'll create a PR for these plugins and close this issue.