pytroll / pytroll/pyresample

Bilinear resampling across dateline gives ValueError

Open
#199 23 comments 0 reactions 1 assignee View on GitHub

@pnuu is already working on this.

Since Jul 22, 2019.

Dominant language
Python
Stars
385
Forks
102
Avg merge
4d 2h
Merged PRs (30d)
9

Description

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

Sample data file to use with this code sample:
test_data.pickle.zip

import numpy
import pyresample
import pickle

if __name__ == "__main__":
    # Load data from pickled file
    with open('test_data.pickle', 'rb') as f:
        data = pickle.load(f)

    # All source longitudes should be in range -180 to +180
    assert(not numpy.any(data['longitude'] > 180))
    assert(not numpy.any(data['longitude'] < -180))

    source_def=pyresample.geometry.SwathDefinition(lons=data['longitude'],
                                                   lats=data['latitude'])

    area_extent = (-190.0, 40.0, -170.0, 60.0)
    proj_dict = {'proj': 'longlat', 'over': True}    
    target_def = pyresample.create_area_def("Binned", proj_dict, area_extent=area_extent,
                                            shape=(10, 10))

    # Bilinear resample
    t_params, s_params, input_idxs, idx_ref = pyresample.bilinear.get_bil_info(source_def, target_def)
    binned_data = pyresample.bilinear.get_sample_from_bil_info(data['so2'],
                                                               t_params, s_params, input_idxs, idx_ref,
                                                               output_shape=target_def.shape)

    print(binned_data)

Problem description

When running the above code, with an area definition that crosses the dateline, the get_bil_info function throws a ValueError exception rather than properly binning the data. Attempting other methods of specifying the area extent produce incorrect latitude/longitude bins.

Expected Output

The data should be binned across the dateline properly

Actual Result, Traceback if applicable

ValueError:

Traceback (most recent call last):
  File "test_bin.py", line 31, in <module>
    t_params, s_params, input_idxs, idx_ref = pyresample.bilinear.get_bil_info(source_def, target_def)
  File "/Users/israel/Development/TROPOMI/lib/python3.7/site-packages/pyresample/bilinear/__init__.py", line 248, in get_bil_info
    _get_bounding_corners(in_x, in_y, out_x, out_y, neighbours, idx_ref)
  File "/Users/israel/Development/TROPOMI/lib/python3.7/site-packages/pyresample/bilinear/__init__.py", line 445, in _get_bounding_corners
    x_diff = out_x_tile - in_x
ValueError: operands could not be broadcast together with shapes (100,32) (50,32) 
Versions of Python, package at hand and relevant dependencies

Using python 3.7 in my testing, with the only dependancies being numpy and pyresample.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.