pytroll / pyresample

Geospatial image resampling in Python
http://pyresample.readthedocs.org
GNU Lesser General Public License v3.0
346 stars 94 forks source link

Infinite values in geostationary bounding box crash intersection function #492

Closed mraspaud closed 1 year ago

mraspaud commented 1 year ago

Code Sample, a minimal, complete, and verifiable piece of code

from pyresample.geometry import AreaDefinition

projection = {'a': '6378169', 'h': '35785831', 'lon_0': '9.5', 'no_defs': 'None', 'proj': 'geos', 'rf': '295.488065897014', 'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'}
area_extent = (5567248.0742, 5570248.4773, -5570248.4773, 1393687.2705)
width = 3712
height = 1392
source_def = AreaDefinition('msg_rss', "msg_rss", "msg_rss", projection, width, height, area_extent)

from satpy.resample import get_area_def

target_def = get_area_def("eurol")
source_def.get_area_slices(target_def)

Problem description

This crashes (as reported in https://github.com/pytroll/satpy/issues/2368) because the lons and lats of the bounding box computed by pyresample for the geostationary area contain np.inf values.

Expected Output

I expect this not to crash

Actual Result, Traceback if applicable

Traceback (most recent call last):
  File "/home/a001673/usr/src/spy-test/test_pyresample_inf.py", line 13, in <module>
    source_def.get_area_slices(target_def)
  File "/home/a001673/usr/src/pyresample/pyresample/geometry.py", line 2616, in get_area_slices
    intersection = data_boundary.contour_poly.intersection(
  File "/home/a001673/usr/src/pyresample/pyresample/spherical.py", line 713, in intersection
    return self._bool_oper(other, -1)
  File "/home/a001673/usr/src/pyresample/pyresample/spherical.py", line 649, in _bool_oper
    arcs1 = [edge for edge in self.aedges()]
  File "/home/a001673/usr/src/pyresample/pyresample/spherical.py", line 649, in <listcomp>
    arcs1 = [edge for edge in self.aedges()]
  File "/home/a001673/usr/src/pyresample/pyresample/spherical.py", line 571, in aedges
    yield Arc(SCoordinate(lon_start, lat_start),
  File "/home/a001673/usr/src/pyresample/pyresample/spherical.py", line 131, in __init__
    lon, lat = _check_lon_lat(lon, lat)
  File "/home/a001673/usr/src/pyresample/pyresample/spherical.py", line 119, in _check_lon_lat
    _check_lat_validity(lat)
  File "/home/a001673/usr/src/pyresample/pyresample/spherical.py", line 109, in _check_lat_validity
    raise ValueError("Latitude values can not contain inf values.")
ValueError: Latitude values can not contain inf values.

Versions of Python, package at hand and relevant dependencies

Crashes in pyresample >1.25.0

gerritholl commented 1 year ago

Related: #393

gerritholl commented 1 year ago

NB: this gets triggered from Satpy if you use pad_data=False for geostationary data:

import hdf5plugin
import pathlib
import os
from satpy import Scene
from glob import glob
bd = pathlib.Path("/media/nas/x21308/MTG_test_data/2022_05_MTG_Testdata/RC0040/")
sc = Scene(filenames=[os.fspath(f) for f in bd.glob("*BODY*003[789].nc")],reader="fci_l1c_nc")
sc.load(["vis_04"], pad_data=False)
ls = sc.resample("nqeuro1km")
ls.save_datasets()