Skip to content
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
30 changes: 27 additions & 3 deletions bluemath_tk/additive/greensurge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path

from matplotlib.path import Path
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -40,6 +39,31 @@ def create_triangle_mask(

return mask

def create_triangle_mask_from_points(
lon: np.ndarray, lat: np.ndarray, triangle: np.ndarray
) -> np.ndarray:
"""
Create a mask indicating which scattered points are inside a triangle.

Parameters
----------
lon : np.ndarray
1D array of longitudes of the points.
lat : np.ndarray
1D array of latitudes of the points.
triangle : np.ndarray
(3, 2) array containing the triangle vertices as (lon, lat) pairs.

Returns
-------
np.ndarray
1D boolean array of same length as lon/lat indicating points inside the triangle.
"""
points = np.column_stack((lon, lat)) # Shape (N, 2)
triangle_path = Path(triangle)
mask = triangle_path.contains_points(points)
return mask


def GS_LinearWindDragCoef(Wspeed, CD_Wl_abc, Wl_abc):
Wla = Wl_abc[0]
Expand Down Expand Up @@ -448,4 +472,4 @@ def GS_wind_partition_tri(ds_GFD_info, xds_vortex):
},
)

return ds_wind_partition
return ds_wind_partition
Loading