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
7 changes: 7 additions & 0 deletions bluemath_tk/additive/greensurge.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ def plot_GS_vs_dynamic_windsetup_swath(
Maximum value for the color scale. Default is None.
figsize : tuple, optional
Figure size. Default is (10, 8).
Returns
-------
fig : Figure
The figure object containing the plots.
axs : list of Axes
List of Axes objects for the two subplots.
"""

warnings.filterwarnings("ignore", message="All-NaN slice encountered")
Expand Down Expand Up @@ -477,6 +483,7 @@ def plot_GS_vs_dynamic_windsetup_swath(

for ax in axs:
ax.set_extent([lon_min, lon_max, lat_min, lat_max])
return fig, axs


def GS_windsetup_reconstruction_with_postprocess(
Expand Down
72 changes: 0 additions & 72 deletions bluemath_tk/topo_bathy/mesh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ def plot_mesh_vals(
The axes with the plot.
"""

# Copy coordinates to avoid modifying original mesh
crd = np.array(msh_t.vert2["coord"], copy=True)
cnn = msh_t.tria3["index"]
val = msh_t.value.flatten()

# Transform to geographic coordinates if needed
if to_geo is not None:
crd[:, 0], crd[:, 1] = to_geo(crd[:, 0], crd[:, 1])

Expand Down Expand Up @@ -426,17 +424,6 @@ def simply_polygon(base_shape: Polygon, simpl_UTM: float, project) -> Polygon:
-------
Polygon
The simplified polygon in geographic coordinates.

Examples
--------
>>> from shapely.geometry import Polygon
>>> from pyproj import Transformer
>>> from shapely.ops import transform
>>> base_shape = Polygon([(0, 0), (1, 1), (1, 0), (0, 0)])
>>> project = Transformer.from_crs("EPSG:4326", "EPSG:32630").transform
>>> simpl_UTM = 100.0 # Simplification tolerance in meters
>>> simplified_shape = simply_polygon(base_shape, simpl_UTM, project)
>>> print(simplified_shape)
"""

base_shape_utm = transform(project, base_shape)
Expand Down Expand Up @@ -471,17 +458,6 @@ def remove_islands(base_shape: Polygon, threshold_area: float, project) -> Polyg
-------
Polygon
The polygon with small interior rings removed, transformed back to geographic coordinates.

Examples
--------
>>> from shapely.geometry import Polygon
>>> from pyproj import Transformer
>>> from shapely.ops import transform
>>> base_shape = Polygon([(0, 0), (1, 1), (1, 0), (0, 0)])
>>> project = Transformer.from_crs("EPSG:4326", "EPSG:32630").transform
>>> threshold_area = 100.0 # Minimum area for interior rings in square meters
>>> simplified_shape = remove_islands(base_shape, threshold_area, project)
>>> print(simplified_shape)
"""

base_shape_utm = transform(project, base_shape)
Expand Down Expand Up @@ -552,17 +528,6 @@ def calculate_edges(Elmts: np.ndarray) -> np.ndarray:
np.ndarray
A 2D array of shape (n_edges, 2) containing the unique edges,
each represented by a pair of node indices.

Examples
--------
>>> Elmts = np.array([[0, 1, 2], [1, 2, 3], [2, 0, 3]])
>>> edges = calculate_edges(Elmts)
>>> print(edges)
[[0 1]
[0 2]
[1 2]
[1 3]
[2 3]]
"""

perc = 0
Expand Down Expand Up @@ -901,15 +866,6 @@ def compute_circumcenter(p0: np.ndarray, p1: np.ndarray, p2: np.ndarray) -> np.n
-------
np.ndarray
2D coordinates of the circumcenter.

Examples
--------
>>> p0 = np.array([0, 0])
>>> p1 = np.array([1, 0])
>>> p2 = np.array([0, 1])
>>> center = compute_circumcenter(p0, p1, p2)
>>> print(center)
[0.5 0.5]
"""

A = p1 - p0
Expand Down Expand Up @@ -943,13 +899,6 @@ def build_edge_to_cells(elements: np.ndarray) -> Dict[Tuple[int, int], List[int]
-------
edge_to_cells : Dict[Tuple[int, int], List[int]]
Dictionary mapping edges to the list of adjacent element indices.

Examples
--------
>>> elements = np.array([[0, 1, 2], [1, 2, 3], [2, 0, 3]])
>>> edge_to_cells = build_edge_to_cells(elements)
>>> print(edge_to_cells)
{(0, 1): [0], (0, 2): [0, 2], (1, 2): [0, 1], (1, 3): [1], (2, 3): [1]}
"""

edge_to_cells = defaultdict(list)
Expand Down Expand Up @@ -985,15 +934,6 @@ def detect_circumcenter_too_close(
-------
bad_elements_mask : np.ndarray
Boolean mask indicating which elements are problematic (True if bad).

Examples
--------
>>> X = np.array([0, 1, 0, 1])
>>> Y = np.array([0, 0, 1, 1])
>>> elements = np.array([[0, 1, 2], [1, 3, 2]])
>>> bad_elements = detect_circumcenter_too_close(X, Y, elements, aj_threshold=0.1)
>>> print(bad_elements)
[False False]
"""

nodes = np.column_stack((X, Y))
Expand Down Expand Up @@ -1155,15 +1095,3 @@ def get_raster_resolution_meters(lon_center, lat_center, raster_resolution, proj
]
)
return raster_resolution_meters


if __name__ == "__main__":
# Example usage
from pyproj import Transformer
from shapely.geometry import Polygon

base_shape = Polygon([(0, 0), (1, 1), (1, 0), (0, 0)])
project = Transformer.from_crs("EPSG:4326", "EPSG:32630").transform
simpl_UTM = 100.0 # Simplification tolerance in meters
simplified_shape = simply_polygon(base_shape, simpl_UTM, project)
print(simplified_shape)
27 changes: 14 additions & 13 deletions bluemath_tk/wrappers/delft3d/delft3d_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@
#SBATCH --mem=4gb # Memory per node in GB (see also --mem-per-cpu)
#SBATCH --time=24:00:00

source /home/grupos/geocean/faugeree/miniforge3/etc/profile.d/conda.sh
conda activate GreenSurge

case_dir=$(ls | awk "NR == $SLURM_ARRAY_TASK_ID")
launchDelft3d.sh --case-dir $case_dir

output_file="${case_dir}/dflowfmoutput/GreenSurge_GFDcase_map.nc"
output_file_compressed="${case_dir}/dflowfmoutput/GreenSurge_GFDcase_map_compressed.nc"
output_file_compressed_tmp="${case_dir}/dflowfmoutput/GreenSurge_GFDcase_map_compressed_tmp.nc"

ncap2 -s 'mesh2d_s1=float(mesh2d_s1)' -v -O "$output_file" "$output_file_compressed_tmp"
ncks -4 -L 4 "$output_file_compressed_tmp" "$output_file_compressed"

rm "$output_file_compressed_tmp"
if [[ "$SLURM_ARRAY_TASK_ID" -ne 1 ]]; then
rm "$output_file"
fi
ncap2 -s 'mesh2d_s1=float(mesh2d_s1)' -v -O "$output_file" "$output_file_compressed_tmp" && {
ncks -4 -L 4 "$output_file_compressed_tmp" "$output_file_compressed"
rm "$output_file_compressed_tmp"
[[ "$SLURM_ARRAY_TASK_ID" -ne 1 ]] && rm "$output_file"
}
"""


Expand Down Expand Up @@ -149,14 +150,14 @@ def monitor_cases(
)


def format_matrix(mat):
return "\n".join(
" ".join(f"{x:.1f}" if abs(x) > 0.01 else "0" for x in line) for line in mat
)
# def format_matrix(mat):
# return "\n".join(
# " ".join(f"{x:.1f}" if abs(x) > 0.01 else "0" for x in line) for line in mat
# )


def format_zeros(mat_shape):
return "\n".join("0 " * mat_shape[1] for _ in range(mat_shape[0]))
# def format_zeros(mat_shape):
# return "\n".join("0 " * mat_shape[1] for _ in range(mat_shape[0]))


def actualize_grid_info(
Expand Down
Loading