bluemath_tk.additive package
Submodules
bluemath_tk.additive.greensurge module
- bluemath_tk.additive.greensurge.GS_LinearWindDragCoef(Wspeed: ndarray, CD_Wl_abc: ndarray, Wl_abc: ndarray) ndarray[source]
Calculate the linear drag coefficient based on wind speed and specified thresholds.
- Parameters:
Wspeed (np.ndarray) – Wind speed values (1D array).
CD_Wl_abc (np.ndarray) – Coefficients for the drag coefficient calculation, should be a 1D array of length 3.
Wl_abc (np.ndarray) – Wind speed thresholds for the drag coefficient calculation, should be a 1D array of length 3.
- Returns:
Calculated drag coefficient values based on the input wind speed.
- Return type:
np.ndarray
- bluemath_tk.additive.greensurge.GS_LinearWindDragCoef_mat(Wspeed: ndarray, CD_Wl_abc: ndarray, Wl_abc: ndarray) ndarray[source]
Calculate the linear drag coefficient based on wind speed and specified thresholds.
- Parameters:
Wspeed (np.ndarray) – Wind speed values (1D array).
CD_Wl_abc (np.ndarray) – Coefficients for the drag coefficient calculation, should be a 1D array of length 3.
Wl_abc (np.ndarray) – Wind speed thresholds for the drag coefficient calculation, should be a 1D array of length 3.
- Returns:
Calculated drag coefficient values based on the input wind speed.
- Return type:
np.ndarray
- bluemath_tk.additive.greensurge.GS_windsetup_reconstruction_with_postprocess(greensurge_dataset: Dataset, ds_gfd_metadata: Dataset, wind_direction_input: Dataset, velocity_thresholds: ndarray = array([0, 100, 100]), drag_coefficients: ndarray = array([0.00063, 0.00723, 0.00723])) Dataset[source]
Reconstructs the GreenSurge wind setup using the provided wind direction input and metadata.
- Parameters:
greensurge_dataset (xr.Dataset) – xarray Dataset containing the GreenSurge mesh and forcing data.
ds_gfd_metadata (xr.Dataset) – xarray Dataset containing metadata for the GFD mesh.
wind_direction_input (xr.Dataset) – xarray Dataset containing wind direction and speed data.
velocity_thresholds (np.ndarray) – Array of velocity thresholds for drag coefficient calculation.
drag_coefficients (np.ndarray) – Array of drag coefficients corresponding to the velocity thresholds.
- Returns:
xarray Dataset containing the reconstructed wind setup.
- Return type:
xr.Dataset
- bluemath_tk.additive.greensurge.GS_windsetup_reconstruction_with_postprocess_parallel(greensurge_dataset: Dataset, ds_gfd_metadata: Dataset, wind_direction_input: Dataset, num_workers: int = None, velocity_thresholds: ndarray = array([0, 100, 100]), drag_coefficients: ndarray = array([0.00063, 0.00723, 0.00723])) Dataset[source]
Reconstructs the GreenSurge wind setup using the provided wind direction input and metadata in parallel.
- Parameters:
greensurge_dataset (xr.Dataset) – xarray Dataset containing the GreenSurge mesh and forcing data.
ds_gfd_metadata (xr.Dataset) – xarray Dataset containing metadata for the GFD mesh.
wind_direction_input (xr.Dataset) – xarray Dataset containing wind direction and speed data.
velocity_thresholds (np.ndarray) – Array of velocity thresholds for drag coefficient calculation.
drag_coefficients (np.ndarray) – Array of drag coefficients corresponding to the velocity thresholds.
- Returns:
xarray Dataset containing the reconstructed wind setup.
- Return type:
xr.Dataset
- bluemath_tk.additive.greensurge.adcirc2DFlowFM(Path_grd: str, netcdf_path: str) None[source]
Converts ADCIRC grid data to a NetCDF Delft3DFM format.
- Parameters:
Path_grd (str) – Path to the ADCIRC grid file.
netcdf_path (str) – Path where the resulting NetCDF file will be saved.
Examples
>>> adcirc2DFlowFM("path/to/grid.grd", "path/to/output.nc") >>> print("NetCDF file created successfully.")
- bluemath_tk.additive.greensurge.build_greensurge_infos_dataset(path_grd_calc: str, path_grd_forz: str, site: str, wind_speed: float, direction_step: float, simulation_duration_hours: float, simulation_time_step_hours: float, forcing_time_step: float, reference_date_dt: datetime, Eddy: float, Chezy: float) Dataset[source]
Build a structured dataset containing simulation parameters for hybrid modeling.
- Parameters:
path_grd_calc (str) – Path to the computational grid file.
path_grd_forz (str) – Path to the forcing grid file.
site (str) – Name of the case study location.
wind_speed (float) – Wind speed for each discretized direction.
direction_step (float) – Step size for wind direction discretization in degrees.
simulation_duration_hours (float) – Total duration of the simulation in hours.
simulation_time_step_hours (float) – Time step used in the simulation in hours.
forcing_time_step (float) – Time step used for applying external forcing data in hours.
reference_date_dt (datetime) – Reference start date of the simulation.
Eddy (float) – Eddy viscosity used in the simulation in m²/s.
Chezy (float) – Chezy coefficient used for bottom friction.
- Returns:
A structured dataset containing simulation parameters for hybrid modeling.
- Return type:
xr.Dataset
- bluemath_tk.additive.greensurge.calculate_edges(Elmts: ndarray) ndarray[source]
Calculates the unique edges from the given triangle elements.
- Parameters:
Elmts (np.ndarray) – A 2D array of shape (nelmts, 3) containing the node indices for each triangle element.
- Returns:
A 2D array of shape (n_edges, 2) containing the unique edges, each represented by a pair of node indices.
- Return type:
np.ndarray
- bluemath_tk.additive.greensurge.compute_water_level_for_time(time_index: int, direction_data: ndarray, wind_speed_data: ndarray, direction_bins: ndarray, forcing_cell_indices: ndarray, greensurge_dataset: Dataset, wind_speed_reference: float, base_drag_coeff: float, drag_coefficients: ndarray, velocity_thresholds: ndarray, duration_in_steps: int, num_output_times: int) ndarray[source]
Compute the water level for a specific time index based on wind direction and speed.
- Parameters:
time_index (int) – The index of the time step to compute the water level for.
direction_data (np.ndarray) – 2D array of wind direction data with shape (n_cells, n_times).
wind_speed_data (np.ndarray) – 2D array of wind speed data with shape (n_cells, n_times).
direction_bins (np.ndarray) – 1D array of wind direction bins.
forcing_cell_indices (np.ndarray) – 1D array of indices for the forcing cells.
greensurge_dataset (xr.Dataset) – xarray Dataset containing the GreenSurge mesh and forcing data.
wind_speed_reference (float) – Reference wind speed value for scaling.
base_drag_coeff (float) – Base drag coefficient value for scaling.
drag_coefficients (np.ndarray) – 1D array of drag coefficients corresponding to the velocity thresholds.
velocity_thresholds (np.ndarray) – 1D array of velocity thresholds for drag coefficient calculation.
duration_in_steps (int) – Total duration of the simulation in steps.
num_output_times (int) – Total number of output time steps.
- Returns:
2D array of computed water levels for the specified time index.
- Return type:
np.ndarray
- bluemath_tk.additive.greensurge.create_triangle_mask(lon_grid: ndarray, lat_grid: ndarray, triangle: ndarray) ndarray[source]
Create a mask for a triangle defined by its vertices.
- Parameters:
lon_grid (np.ndarray) – The longitude grid.
lat_grid (np.ndarray) – The latitude grid.
triangle (np.ndarray) – The triangle vertices.
- Returns:
The mask for the triangle.
- Return type:
np.ndarray
- bluemath_tk.additive.greensurge.create_triangle_mask_from_points(lon: ndarray, lat: ndarray, triangle: ndarray) ndarray[source]
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:
mask – 1D boolean array of same length as lon/lat indicating points inside the triangle.
- Return type:
np.ndarray
- bluemath_tk.additive.greensurge.extract_pos_nearest_points(ds_mesh_info: Dataset, lon_points: ndarray, lat_points: ndarray) Tuple[ndarray, ndarray][source]
Extract the nearest point indices for given longitude and latitude points in a mesh dataset.
- Parameters:
ds_mesh_info (xr.Dataset) – Dataset containing mesh information with longitude and latitude coordinates.
lon_points (np.ndarray) – Array of longitudes for which to find the nearest point indices.
lat_points (np.ndarray) – Array of latitudes for which to find the nearest point indices.
- Returns:
pos_lon_points_mesh (np.ndarray) – Array of longitude indices corresponding to the input longitude points in the mesh.
pos_lat_points_mesh (np.ndarray) – Array of latitude indices corresponding to the input latitude points in the mesh.
- bluemath_tk.additive.greensurge.extract_pos_nearest_points_tri(ds_mesh_info: Dataset, lon_points: ndarray, lat_points: ndarray) ndarray[source]
Extract the nearest triangle index for given longitude and latitude points.
- Parameters:
ds_mesh_info (xr.Dataset) – Dataset containing mesh information with longitude and latitude coordinates.
lon_points (np.ndarray) – Array of longitudes for which to find the nearest triangle index.
lat_points (np.ndarray) – Array of latitudes for which to find the nearest triangle index.
- Returns:
Array of nearest triangle indices corresponding to the input longitude and latitude points.
- Return type:
np.ndarray
- bluemath_tk.additive.greensurge.generate_structured_points(triangle_connectivity: ndarray, node_lon: ndarray, node_lat: ndarray) Tuple[ndarray, ndarray][source]
Generate structured points for each triangle in the mesh. Each triangle will have 10 points: vertices, centroid, midpoints of edges, and midpoints of vertex-centroid segments.
- Parameters:
triangle_connectivity (np.ndarray) – Array of shape (n_triangles, 3) containing indices of the vertices for each triangle.
node_lon (np.ndarray) – Array of shape (n_nodes,) containing the longitudes of the nodes.
node_lat (np.ndarray) – Array of shape (n_nodes,) containing the latitudes of the nodes.
- Returns:
lon_all (np.ndarray) – Array of shape (n_triangles, 10) containing the longitudes of the structured points for each triangle.
lat_all (np.ndarray) – Array of shape (n_triangles, 10) containing the latitudes of the structured points for each triangle.
- bluemath_tk.additive.greensurge.get_regular_grid(node_computation_longitude: ndarray, node_computation_latitude: ndarray, node_computation_elements: ndarray, factor: float = 10) tuple[source]
Generate a regular grid based on the node computation longitude and latitude. The grid is defined by the minimum and maximum longitude and latitude values, and the minimum distance between nodes in both dimensions. The grid is generated with a specified factor to adjust the resolution. Parameters: - node_computation_longitude: 1D array of longitudes for the nodes. - node_computation_latitude: 1D array of latitudes for the nodes. - node_computation_elements: 2D array of indices defining the elements (triangles). - factor: A scaling factor to adjust the resolution of the grid. Returns: - lon_grid: 1D array of longitudes defining the grid. - lat_grid: 1D array of latitudes defining the grid.
- bluemath_tk.additive.greensurge.interp_vortex_to_triangles(xds_vortex_GS: Dataset, lon_all: ndarray, lat_all: ndarray, type: str = 'tri_mean') Dataset[source]
Interpolates the vortex model data to the triangle points. :param xds_vortex_GS: Dataset containing the vortex model data. :type xds_vortex_GS: xr.Dataset :param lon_all: Longitudes of the triangle points. :type lon_all: np.ndarray :param lat_all: Latitudes of the triangle points. :type lat_all: np.ndarray
- Returns:
xds_vortex_interp (xr.Dataset) – Dataset containing the interpolated vortex model data at the triangle points.
———–
This function interpolates the vortex model data (wind speed, direction, and pressure)
to the triangle points defined by lon_all and lat_all. It reshapes the data
to match the number of triangles and points, and computes the mean values for each triangle.
- bluemath_tk.additive.greensurge.load_GS_database(xds_vortex_interp: Dataset, ds_GFD_info: Dataset, p_GFD_libdir: str) Dataset[source]
Load the Green Surge database based on the interpolated vortex data. :param xds_vortex_interp: Interpolated vortex data on the structured grid. :type xds_vortex_interp: xarray.Dataset :param ds_GFD_info: Dataset containing information about the Green Surge database. :type ds_GFD_info: xarray.Dataset :param p_GFD_libdir: Path to the Green Surge database directory. :type p_GFD_libdir: str
- Returns:
Dataset containing the Green Surge data for the specified wind directions.
- Return type:
xarray.Dataset
- bluemath_tk.additive.greensurge.plot_GS_TG_validation_timeseries(ds_WL_GS_WindSetUp: Dataset, ds_WL_GS_IB: Dataset, ds_WL_dynamic_WindSetUp: Dataset, tide_gauge: Dataset, ds_GFD_info: Dataset, figsize: tuple = (20, 7), WLmin: float = None, WLmax: float = None) None[source]
Plot a time series comparison of GreenSurge, dynamic wind setup, and tide gauge data with a bathymetry map.
- Parameters:
ds_WL_GS_WindSetUp (xr.Dataset) – Dataset containing GreenSurge wind setup data with dimensions (nface, time).
ds_WL_GS_IB (xr.Dataset) – Dataset containing inverse barometer data with dimensions (lat, lon, time).
ds_WL_dynamic_WindSetUp (xr.Dataset) – Dataset containing dynamic wind setup data with dimensions (mesh2d_nFaces, time).
tide_gauge (xr.Dataset) – Dataset containing tide gauge data with dimensions (time).
ds_GFD_info (xr.Dataset) – Dataset containing grid information with longitude and latitude coordinates.
figsize (tuple, optional) – Size of the figure for the plot. Default is (15, 7).
WLmin (float, optional) – Minimum water level for the plot. Default is None.
WLmax (float, optional) – Maximum water level for the plot. Default is None.
- bluemath_tk.additive.greensurge.plot_GS_input_wind_partition(xds_vortex_GS: Dataset, xds_vortex_interp: Dataset, ds_GFD_info: Dataset, i_time: int = 0, SWATH: bool = False, figsize=(10, 8)) None[source]
Plot the wind partition for GreenSurge input data.
- Parameters:
xds_vortex_GS (xr.Dataset) – Dataset containing the vortex model data for GreenSurge.
xds_vortex_interp (xr.Dataset) – Dataset containing the interpolated vortex model data.
ds_GFD_info (xr.Dataset) – Dataset containing the GreenSurge forcing information.
i_time (int, optional) – Index of the time step to plot. Default is 0.
figsize (tuple, optional) – Figure size. Default is (10, 8).
- bluemath_tk.additive.greensurge.plot_GS_validation_timeseries(ds_WL_GS_WindSetUp: Dataset, ds_WL_GS_IB: Dataset, ds_WL_dynamic_WindSetUp: Dataset, ds_GFD_info: Dataset, lon_obs: float = [184.8], lat_obs: float = [-21.14], figsize: tuple = (20, 7), WLmin: float = None, WLmax: float = None) None[source]
Plot a time series comparison of GreenSurge, dynamic wind setup, and tide gauge data with a bathymetry map.
- Parameters:
ds_WL_GS_WindSetUp (xr.Dataset) – Dataset containing GreenSurge wind setup data with dimensions (nface, time).
ds_WL_GS_IB (xr.Dataset) – Dataset containing inverse barometer data with dimensions (lat, lon, time).
ds_WL_dynamic_WindSetUp (xr.Dataset) – Dataset containing dynamic wind setup data with dimensions (mesh2d_nFaces, time).
ds_GFD_info (xr.Dataset) – Dataset containing grid information with longitude and latitude coordinates.
figsize (tuple, optional) – Size of the figure for the plot. Default is (15, 7).
WLmin (float, optional) – Minimum water level for the plot. Default is None.
WLmax (float, optional) – Maximum water level for the plot. Default is None.
- bluemath_tk.additive.greensurge.plot_GS_vs_dynamic_windsetup(ds_WL_GS_WindSetUp: Dataset, ds_WL_dynamic_WindSetUp: Dataset, ds_gfd_metadata: Dataset, time: datetime, vmin: float = None, vmax: float = None, figsize: tuple = (10, 8)) None[source]
Plot the GreenSurge and dynamic wind setup from the provided datasets.
- Parameters:
ds_WL_GS_WindSetUp (xr.Dataset) – xarray Dataset containing the GreenSurge wind setup data.
ds_WL_dynamic_WindSetUp (xr.Dataset) – xarray Dataset containing the dynamic wind setup data.
ds_gfd_metadata (xr.Dataset) – xarray Dataset containing the metadata for the GFD mesh.
time (datetime.datetime) – The time point at which to plot the data.
vmin (float, optional) – Minimum value for the color scale. Default is None.
vmax (float, optional) – Maximum value for the color scale. Default is None.
figsize (tuple, optional) – Tuple specifying the figure size. Default is (10, 8).
- bluemath_tk.additive.greensurge.plot_GS_vs_dynamic_windsetup_swath(ds_WL_GS_WindSetUp: Dataset, ds_WL_dynamic_WindSetUp: Dataset, ds_gfd_metadata: Dataset, vmin: float = None, vmax: float = None, figsize: tuple = (10, 8)) None[source]
Plot the GreenSurge and dynamic wind setup from the provided datasets.
- Parameters:
ds_WL_GS_WindSetUp (xr.Dataset) – Dataset containing the GreenSurge wind setup data.
ds_WL_dynamic_WindSetUp (xr.Dataset) – Dataset containing the dynamic wind setup data.
ds_gfd_metadata (xr.Dataset) – Dataset containing the metadata for the GFD mesh.
vmin (float, optional) – Minimum value for the color scale. Default is None.
vmax (float, optional) – 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.
- bluemath_tk.additive.greensurge.plot_greensurge_setup(info_ds: Dataset, figsize: tuple = (10, 10), fig: Figure = None, ax: Axes = None) Tuple[Figure, Axes][source]
Plot the GreenSurge mesh setup from the provided dataset.
- Parameters:
info_ds (xr.Dataset) – Dataset containing the mesh information.
figsize (tuple, optional) – Figure size. Default is (10, 10).
fig (Figure, optional) – Figure object to plot on. If None, a new figure will be created.
ax (Axes, optional) – Axes object to plot on. If None, a new axes will be created.
- Returns:
fig (Figure) – Figure object.
ax (Axes) – Axes object.
- bluemath_tk.additive.greensurge.plot_greensurge_setup_with_raster(simulation_dataset, path_grd_calc, figsize=(7, 7)) None[source]
Plot the GreenSurge setup with raster bathymetry.
- Parameters:
simulation_dataset (xr.Dataset) – Dataset containing simulation information.
path_grd_calc (str) – Path to the ADCIRC grid file for calculation.
figsize (tuple, optional) – Size of the figure, by default (7, 7)
- Returns:
None
———–
This function plots the GreenSurge setup using raster bathymetry
and the ADCIRC grid for calculation. It uses Cartopy for geographic
projections and matplotlib for plotting.
- bluemath_tk.additive.greensurge.plot_triangle_points(lon_all: ndarray, lat_all: ndarray, i: int, ds_GFD_info: Dataset, figsize: tuple = (7, 7)) None[source]
Plot a triangle and points selection for GreenSurge. :param lon_all: Longitudes of the points. :type lon_all: array-like :param lat_all: Latitudes of the points. :type lat_all: array-like :param i: Index of the triangle to plot. :type i: int :param ds_GFD_info: Dataset containing GreenSurge information. :type ds_GFD_info: xarray.Dataset :param figsize: Size of the figure, by default (7, 7). :type figsize: tuple, optional
- bluemath_tk.additive.greensurge.pressure_to_IB(xds_presure: Dataset) Dataset[source]
Convert pressure data in a dataset to inverse barometer (IB) values.
- Parameters:
xds_presure (xr.Dataset) – Dataset containing pressure data with dimensions (lat, lon, time).
- Returns:
Dataset with an additional variable ‘IB’ representing the inverse barometer values.
- Return type:
xr.Dataset
- bluemath_tk.additive.greensurge.read_adcirc_grd(grd_file: str) Tuple[ndarray, ndarray, List[str]][source]
Reads the ADCIRC grid file and returns the node and element data.
- Parameters:
grd_file (str) – Path to the ADCIRC grid file.
- Returns:
A tuple containing: - Nodes (np.ndarray): An array of shape (nnodes, 3) containing the coordinates of each node. - Elmts (np.ndarray): An array of shape (nelmts, 3) containing the element connectivity,
with node indices adjusted (decremented by 1).
lines (List[str]): The remaining lines in the file after reading the nodes and elements.
- Return type:
Tuple[np.ndarray, np.ndarray, List[str]]
Examples
>>> nodes, elmts, lines = read_adcirc_grd("path/to/grid.grd") >>> print(nodes.shape, elmts.shape, len(lines)) (1000, 3) (500, 3) 10
Module contents
Project: BlueMath_tk Sub-Module: additive Author: GeoOcean Research Group, Universidad de Cantabria Repository: https://github.com/GeoOcean/BlueMath_tk.git Status: Under development (Working)