pytroll / satpy

Python package for earth-observing satellite data processing
http://satpy.readthedocs.org/en/latest/
GNU General Public License v3.0
1.07k stars 295 forks source link

`Scene.start_time` computation fails for datasets/composites with `start_time=None` (and same for `end_time`) #2883

Open ameraner opened 2 months ago

ameraner commented 2 months ago

Describe the bug After https://github.com/pytroll/satpy/pull/2737, the start_time of a StaticImageCompositor dataset are set to None if not available in the filename. This is ok per-se, but this causes the Scene.start_time computation to fail for composites with static images, since the Scene tries to compute the min of all datasets here: https://github.com/pytroll/satpy/blob/89f09d3b3eedf2a27a14a5536d1cb9ad72c707a5/satpy/scene.py#L222 The same applies to end_time

To Reproduce


filenames = glob('/tcenas/fbf/mtg/RollingBuffer/OPE/idpfi/FCI-L1/*FDHSI*__C_0030*')
scn = Scene(filenames=filenames, reader='fci_l1c_fdhsi')
scn.load(['geo_color'], upper_right_corner='NE')
print(scn.start_time)

Expected behavior

We would propose to handle None when trying to compute the Scene.start_time, e.g. with

return min([x for x in start_times if x is not None])

and for the end_time

return max([x for x in start_times if x is not None])

to get a sensible time.

Actual results

  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/scene.py", line 219, in start_time
    return min(start_times)
           ^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'NoneType' and 'datetime.datetime'
djhoese commented 2 months ago

I think this was likely introduced recently when changes were made to the StaticImageCompositor and/or the generic_image reader where start_time was made optional (can be set to None). Looks like we missed a couple cases where start times are used.

PRs welcome!