Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug that would add spurious nan lines in gradient search #643

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ jobs:
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: latest
mamba-version: "1.5.10"
python-version: ${{ matrix.python-version }}
environment-file: continuous_integration/environment.yaml
activate-environment: test-environment
channels: conda-forge
conda-remove-defaults: true
channel-priority: strict

- name: Install unstable dependencies
if: matrix.experimental == true
Expand Down
2 changes: 1 addition & 1 deletion pyresample/gradient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def gradient_resampler(data, source_area, target_area, method='bilinear'):
method=method)


def gradient_resampler_indices_block(block_info=None, **kwargs):
def gradient_resampler_indices_block(block_info, **kwargs):
"""Do the gradient search resampling using block_info for areas, returning the resulting indices."""
source_area = block_info[0]["area"]
target_area = block_info[None]["area"]
Expand Down
1 change: 1 addition & 0 deletions pyresample/gradient/_gradient_search.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ cdef void one_step_gradient_search_no_gil(const data_type[:, :, :] data,

for _ in range(x_size):
if isinf(dst_x[i, j]):
j += col_step
continue
cnt = 0
while True:
Expand Down
26 changes: 25 additions & 1 deletion pyresample/test/test_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@

from pyresample.area_config import create_area_def
from pyresample.geometry import AreaDefinition, SwathDefinition
from pyresample.gradient import ResampleBlocksGradientSearchResampler, create_gradient_search_resampler
from pyresample.gradient import (
ResampleBlocksGradientSearchResampler,
create_gradient_search_resampler,
gradient_resampler_indices,
)


class TestRBGradientSearchResamplerArea2Area:
Expand Down Expand Up @@ -624,3 +628,23 @@ def test_index_search_with_data_requested_outside_top_left_boundary(self):
self.dst_x, self.dst_y)
np.testing.assert_allclose(res_x, expected_x)
np.testing.assert_allclose(res_y, expected_y)


def test_resampling_geos_edge_to_mercator():
"""Test that projecting the edges of geos onto a mercator area does not produce unnecessary NaNs."""
source_area = AreaDefinition.from_extent(area_id="side",
projection={'ellps': 'WGS84', 'h': '35786400', 'lon_0': '0',
'no_defs': 'None', 'proj': 'geos', 'type': 'crs',
'units': 'm', 'x_0': '0', 'y_0': '0'},
area_extent=(-2483999.9974, 5121999.9947, -1739999.9982, 4809999.995),
shape=(156, 372))
dest_area = AreaDefinition.from_extent(area_id="dest",
projection={'a': '6378137', 'b': '6378137', 'k': '1', 'lat_ts': '0',
'lon_0': '0', 'nadgrids': '@null', 'no_defs': 'None',
'proj': 'merc', 'type': 'crs', 'units': 'm', 'wktext': 'None',
'x_0': '0', 'y_0': '0'},
area_extent=(-7800000.0, 8595618.56, -6073037.8378, 10321713.92),
shape=(512, 512))

res = gradient_resampler_indices(source_area, dest_area, fill_value=np.nan)
assert not np.any(np.isnan(res[:, :, -1]))
djhoese marked this conversation as resolved.
Show resolved Hide resolved
Loading