Skip to content

EWA resampler fails (with METimage/VII data) with non-contiguous lonlat arrays #723

Description

@ameraner

The EWA resampler currently fails when trying to resample a METimage/VII swath.
To reproduce:

scn = Scene(filenames=filenames, reader='vii_l1b_nc')
scn.load(["vii_10690"])
scn_r = scn.resample("EPSG_4326_720x360", resampler='ewa', rows_per_scan=24)
scn_r.save_datasets(writer='simple_image')

results in

Traceback (most recent call last):
  File "/tcenas/home/andream/anaconda3/envs/devenv/lib/python3.11/site-packages/dask/base.py", line 662, in compute
    results = schedule(dsk, keys, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tcenas/home/andream/code/satpy_latest/pyresample/pyresample/ewa/dask_ewa.py", line 60, in _call_ll2cr
    swath_points_in_grid, cols, rows = ll2cr(new_src, target_geo_def)
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tcenas/home/andream/code/satpy_latest/pyresample/pyresample/ewa/ewa.py", line 78, in ll2cr
    swath_points_in_grid = _ll2cr.ll2cr_static(lons, lats, fill,
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pyresample/ewa/_ll2cr.pyx", line 242, in pyresample.ewa._ll2cr.ll2cr_static
  File "<stringsource>", line 664, in View.MemoryView.memoryview_cwrapper
  File "<stringsource>", line 352, in View.MemoryView.memoryview.__cinit__
ValueError: ndarray is not C-contiguous

A simple fix seems to be adding the following lines after this block (where the lonlats are already computed ndarrays)

lons, lats = swath_def.get_lonlats()
# ll2cr requires 64-bit floats due to pyproj limitations
# also need a copy of lons, lats since they are written to in-place
try:
lons = lons.astype(np.float64, copy=copy)
lats = lats.astype(np.float64, copy=copy)
except TypeError:
lons = lons.astype(np.float64)
lats = lats.astype(np.float64)

    lons = np.ascontiguousarray(lons)
    lats = np.ascontiguousarray(lats)

Is this a good idea? Or is there a better way?

Fixing it at the source without breaking lazyness is probably not trivial, due to the lon-lats of METimage being computed with rather complex geotiepoints interpolations and coordinate transforms...

cc @cesclc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions