Skip to content

Commit 5563a20

Browse files
committed
[EJP] OCSmesh cleaned and optimized
1 parent ce7f72f commit 5563a20

File tree

3 files changed

+366
-314
lines changed

3 files changed

+366
-314
lines changed

bluemath_tk/additive/greensurge.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from pathlib import Path
2-
1+
from matplotlib.path import Path
32
import cartopy.crs as ccrs
43
import matplotlib.pyplot as plt
54
import numpy as np
@@ -40,6 +39,31 @@ def create_triangle_mask(
4039

4140
return mask
4241

42+
def create_triangle_mask_from_points(
43+
lon: np.ndarray, lat: np.ndarray, triangle: np.ndarray
44+
) -> np.ndarray:
45+
"""
46+
Create a mask indicating which scattered points are inside a triangle.
47+
48+
Parameters
49+
----------
50+
lon : np.ndarray
51+
1D array of longitudes of the points.
52+
lat : np.ndarray
53+
1D array of latitudes of the points.
54+
triangle : np.ndarray
55+
(3, 2) array containing the triangle vertices as (lon, lat) pairs.
56+
57+
Returns
58+
-------
59+
np.ndarray
60+
1D boolean array of same length as lon/lat indicating points inside the triangle.
61+
"""
62+
points = np.column_stack((lon, lat)) # Shape (N, 2)
63+
triangle_path = Path(triangle)
64+
mask = triangle_path.contains_points(points)
65+
return mask
66+
4367

4468
def GS_LinearWindDragCoef(Wspeed, CD_Wl_abc, Wl_abc):
4569
Wla = Wl_abc[0]
@@ -448,4 +472,4 @@ def GS_wind_partition_tri(ds_GFD_info, xds_vortex):
448472
},
449473
)
450474

451-
return ds_wind_partition
475+
return ds_wind_partition

0 commit comments

Comments
 (0)