Skip to content

Commit 53c47e4

Browse files
committed
Fixed bilinear to catch values outside dual mesh
1 parent aa4f6c1 commit 53c47e4

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

uxarray/remap/bilinear.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def _bilinear(
122122
dual=dual,
123123
source_data=source_data,
124124
data_size=data_size,
125+
source_grid=source_grid,
125126
)
126127

127128
return values
@@ -157,6 +158,7 @@ def _bilinear_uxda(
157158

158159
# perform remapping
159160
destination_data = _bilinear(source_uxda, destination_grid, remap_to)
161+
160162
# construct a data array for remapping variable
161163
uxda_remap = uxarray.core.dataarray.UxDataArray(
162164
data=destination_data,
@@ -194,7 +196,7 @@ def _bilinear_uxds(
194196
return destination_uxds
195197

196198

197-
def _get_values(point_xyz, point_lonlat, dual, source_data, data_size):
199+
def _get_values(point_xyz, point_lonlat, dual, source_data, data_size, source_grid):
198200
"""Get the values for each point being remapped to by calculating and applying the weights"""
199201
values = np.zeros(data_size)
200202

@@ -207,7 +209,15 @@ def _get_values(point_xyz, point_lonlat, dual, source_data, data_size):
207209
number_of_faces = len(face_ind)
208210

209211
if number_of_faces == 0:
210-
values[i] = 0
212+
# Check to see if the point lies within the source grid instead
213+
face_ind = source_grid.get_faces_containing_point(
214+
point_xyz=point_xyz[i], point_lonlat=point_lonlat[i]
215+
)
216+
217+
if len(face_ind) == 0:
218+
values[i] = 0
219+
else:
220+
values[i] = source_data[face_ind[0]]
211221
else:
212222
# Get the index of the face that holds the point
213223
node_ind = dual.uxgrid.face_node_connectivity[face_ind[0]].values

0 commit comments

Comments
 (0)