Skip to content

Commit

Permalink
Fix issue for relative=True for structured cases. Add relative 1d str…
Browse files Browse the repository at this point in the history
…uctured test
  • Loading branch information
HendrikKok committed Jul 18, 2023
1 parent 529f6d1 commit 2a9be03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions tests/test_regrid/test_structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ def test_overlap_1d(
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, 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

0 comments on commit 2a9be03

Please sign in to comment.