Open danschef opened 3 years ago
Hi, and sorry for the late reply.
This is an unfortunate side-effect of how the algorithm we use for bilinear interpolation works. For the bilinear interpolation we need to find four closest data points from the source data that surround the requested target location. The distance the algorithm uses is in the target area's projection coordinates. Swath data doesn't have a valid projection, thus the target area's projection coordinates can't be calculated.
I think it could be possible to adapt the resampler to use 3D geocentric cartesian (X, Y, Z) coordinates. But at the least this shortcoming should be indicated in the documentation until we can address the issue.
Thanks for the reply. I agree, if there is a limitation of the current bilinear algorithm, this should be mentioned in the docs. Additionally, I would also return a meaningful exception in case NumpyBilinearResampler is called to resample grid data to swath data.
Honestly, I don´t really get why you need a valid projection for the swath data. I mean with swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
you have a clear mapping between cartesian image coordinates and longitude/latitude coordinates. If needed, you can also easily transform these lon/lat coordinates to the projection of the grid data to have both in the same projection. What makes it difficult to determine the 4 closest pixels within the grid data array for a given lon/lat coordinate?
@pnuu So far, I worked around this issue by pinning pyresample to <1.17. This now increasingly causes trouble and blocks me from building a subsequent package for Python 3.10.
What do you think is the effort to adapt the bilinear resampler to use cartesian coordinates instead of target area's projection coordinates when resampling grid data to swath data? Or is there any workaround I could use for now to make this work?
Code Sample, a minimal, complete, and verifiable piece of code
Problem description
I am using pyresample for transforming swath data to grid data and vice versa. Using gauss resampling or nearest neighbor resampling, everything works fine in both directions. The code example for bilinear resampling in the docs is also working without any issues. However, it only contains the case of resampling a swath array into a grid array and not vice versa. But I also need the other direction.
When I swap the source and target geometry definition which are passed to NumpyBilinearResampler (as in the code sample above), pyresample raises the AttributError below. I used the example code snippet from the docs, I just added the resampling in the other direction (last line, which fails).
Am I doing something wrong here? If yes, could someone show me how to use NumpyBilinearResampler to resample grid data to swath data?
Expected Output
I would expect that the bilinear resampling produces a similar result like the gauss resampling where it is easiliy possible to resample from swath to grid data and vice versa (code is taken from the docs, only variable names are changed):
When plotted, the arrays look like this: Note, that swath_data_resamp has nearly the same values like the original swath_data array within the extent given to geometry.AreaDefinition. This is exactly how the result should look like.
Actual Result, Traceback if applicable
NumpyBilinearResampler.resample() raises
AttributeError: 'SwathDefinition' object has no attribute 'get_proj_coords'
:Arrays look like this (swath_data_resamp is missing):
Versions of Python, package at hand and relevant dependencies
pyyresample 1.17.0, installed via
conda install -c conda-forge pyresample
; Python 3.9