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 issue when using relative overlap regridder for structured grids #123

Merged
merged 2 commits into from
Jul 24, 2023
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
14 changes: 14 additions & 0 deletions tests/test_regrid/test_structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ def test_overlap_1d(
assert np.array_equal(target[sorter], np.array([0, 1, 1, 2]))
assert np.array_equal(weights[sorter], np.array([17.5, 32.5, 17.5, 25.0]))

# relative
# --------
# source targets weight
# node 0 0, 1 17.5 m, 32.5 m
# node 1 1, 2 17.5 m, 25.0 m
# --------
source, target, weights = grid_data_a_1d.overlap(grid_data_e_1d, relative=True)
sorter = np.argsort(source)
assert np.array_equal(source[sorter], np.array([0, 0, 1, 1]))
assert np.array_equal(target[sorter], np.array([0, 1, 1, 2]))
assert np.array_equal(
weights[sorter], np.array([17.5 / 50.0, 32.5 / 50.0, 17.5 / 50.0, 25.0 / 50.0])
)


def test_overlap_2d(grid_data_a_2d, grid_data_b_2d):
# --------
Expand Down
4 changes: 2 additions & 2 deletions xugrid/regrid/structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def size(self) -> int:

@property
def length(self) -> FloatArray:
return abs(np.diff(self.bounds, axis=1))
return np.squeeze(abs(np.diff(self.bounds, axis=1)))

def flip_if_needed(self, index: IntArray) -> IntArray:
if self.flipped:
Expand Down Expand Up @@ -339,7 +339,7 @@ def overlap(
"""
source_index, target_index, weights = self.overlap_1d_structured(other)
if relative:
weights /= self.length()[source_index]
weights /= self.length[source_index]
return self.sorted_output(source_index, target_index, weights)

def locate_centroids(
Expand Down