@@ -145,6 +145,7 @@ def cutout_mask(
145
145
global_lats ,
146
146
global_lons ,
147
147
cropping_distance = 2.0 ,
148
+ neighbours = 5 ,
148
149
min_distance_km = None ,
149
150
plot = None ,
150
151
):
@@ -191,7 +192,8 @@ def cutout_mask(
191
192
192
193
# Use a KDTree to find the nearest points
193
194
kdtree = KDTree (lam_points )
194
- distances , indices = kdtree .query (global_points , k = 4 )
195
+
196
+ distances , indices = kdtree .query (global_points , k = neighbours )
195
197
196
198
if min_distance_km is not None :
197
199
min_distance = min_distance_km / 6371.0
@@ -213,25 +215,18 @@ def cutout_mask(
213
215
# We check more than one triangle in case te global point
214
216
# is near the edge of triangle, (the lam point and global points are colinear)
215
217
216
- t1 = Triangle3D (lam_points [index [0 ]], lam_points [index [1 ]], lam_points [index [2 ]])
217
- t2 = Triangle3D (lam_points [index [1 ]], lam_points [index [2 ]], lam_points [index [3 ]])
218
- t3 = Triangle3D (lam_points [index [2 ]], lam_points [index [3 ]], lam_points [index [0 ]])
219
- t4 = Triangle3D (lam_points [index [3 ]], lam_points [index [0 ]], lam_points [index [1 ]])
220
-
221
- # The point is inside the triangle if the intersection with the ray
222
- # from the point to the centre of the Earth is not None
223
- # (the direction of the ray is not important)
224
-
225
- intersect = (
226
- t1 .intersect (zero , global_point )
227
- or t2 .intersect (zero , global_point )
228
- or t3 .intersect (zero , global_point )
229
- or t4 .intersect (zero , global_point )
230
- )
218
+ inside = False
219
+ for j in range (neighbours ):
220
+ t = Triangle3D (
221
+ lam_points [index [j ]], lam_points [index [(j + 1 ) % neighbours ]], lam_points [index [(j + 2 ) % neighbours ]]
222
+ )
223
+ inside = t .intersect (zero , global_point )
224
+ if inside :
225
+ break
231
226
232
227
close = np .min (distance ) <= min_distance
233
228
234
- inside_lam .append (intersect or close )
229
+ inside_lam .append (inside or close )
235
230
236
231
j = 0
237
232
inside_lam = np .array (inside_lam )
0 commit comments