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
73 changes: 73 additions & 0 deletions bluemath_tk/core/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
import pandas as pd
import pyproj
import xarray as xr
from sklearn.preprocessing import StandardScaler

Expand Down Expand Up @@ -378,3 +379,75 @@ def get_degrees_from_uv(xu: np.ndarray, xv: np.ndarray) -> np.ndarray:

# Return the degrees
return x_deg


def convert_utm_to_lonlat(
utm_x: np.ndarray,
utm_y: np.ndarray,
projection: Union[int, str, dict, pyproj.CRS],
) -> Tuple[np.ndarray, np.ndarray]:
"""
This method converts UTM coordinates to Longitude and Latitude.

Parameters
----------
utm_x : np.ndarray
The x values in UTM.
utm_y : np.ndarray
The y values in UTM.
projection : int, str, dict, pyproj.CRS
The projection to use for the transformation.

Returns
-------
Tuple[np.ndarray, np.ndarray]
The longitude and latitude values.
"""

available_projections = {
"SPAIN": pyproj.Proj(proj="utm", zone=30, ellps="WGS84"),
}
if isinstance(projection, str):
projection = available_projections.get(projection, projection)

# Create the UTM to LonLat transformer
lon, lat = projection(utm_x, utm_y, inverse=True)

# Return the LonLat coordinates
return lon, lat


def convert_lonlat_to_utm(
lon: np.ndarray,
lat: np.ndarray,
projection: Union[int, str, dict, pyproj.CRS],
) -> Tuple[np.ndarray, np.ndarray]:
"""
This method converts Longitude and Latitude to UTM coordinates.

Parameters
----------
lon : np.ndarray
The longitude values.
lat : np.ndarray
The latitude values.
projection : int, str, dict, pyproj.CRS
The projection to use for the transformation.

Returns
-------
Tuple[np.ndarray, np.ndarray]
The x and y coordinates in UTM.
"""

available_projections = {
"SPAIN": pyproj.Proj(proj="utm", zone=30, ellps="WGS84"),
}
if isinstance(projection, str):
projection = available_projections.get(projection, projection)

# Create the LonLat to UTM transformer
utm_x, utm_y = projection(lon, lat)

# Return the UTM coordinates
return utm_x, utm_y
18 changes: 9 additions & 9 deletions bluemath_tk/wrappers/swan/swan_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,13 @@ def build_case(self, case_dir: str, case_context: dict):
input_spectrum = construct_partition(
freq_name="jonswap",
freq_kwargs={
"freq": example_frequencies,
"freq": laura_frequencies,
"fp": 1.0 / case_context.get("tp"),
"hs": case_context.get("hs"),
},
dir_name="cartwright",
dir_kwargs={
"dir": example_directions,
"dir": laura_directions,
"dm": case_context.get("dir"),
"dspr": case_context.get("spr"),
},
Expand Down Expand Up @@ -335,7 +335,7 @@ def build_cases(self, mode="one_by_one"):
"/home/tausiaj/GitHub-GeoOcean/BlueMath/bluemath_tk/wrappers/swan/templates/"
)
templates_name = ["input.swn", "depth_main_cantabria.dat", "buoys.loc"]
output_dir = "/home/tausiaj/GitHub-GeoOcean/BlueMath/test_cases/swan/CAN_mono/"
output_dir = "/home/tausiaj/GitHub-GeoOcean/BlueMath/test_cases/swan/CAN_part/"
# Generate swan model parameters
model_parameters = (
generate_swan_cases(
Expand All @@ -355,17 +355,17 @@ def build_cases(self, mode="one_by_one"):
output_dir=output_dir,
)
# Build the input files
# swan_wrapper.build_cases(mode="one_by_one")
swan_wrapper.build_cases(mode="one_by_one")
# Set the cases directories from the output directory
swan_wrapper.set_cases_dirs_from_output_dir()
# List available launchers
# print(swan_wrapper.list_available_launchers())
print(swan_wrapper.list_available_launchers())
# Run the model
# swan_wrapper.run_cases(launcher="docker", parallel=True)
swan_wrapper.run_cases(launcher="docker", parallel=True)
# Post-process the output files
# postprocessed_ds = swan_wrapper.postprocess_cases()
# postprocessed_ds.to_netcdf(op.join(swan_wrapper.output_dir, "waves_part.nc"))
# print(postprocessed_ds)
postprocessed_ds = swan_wrapper.postprocess_cases()
postprocessed_ds.to_netcdf(op.join(swan_wrapper.output_dir, "waves_part.nc"))
print(postprocessed_ds)
# Get input and ouput spectra files from self.cases_dirs
input_files = [op.join(d, "input_spectra.bnd") for d in swan_wrapper.cases_dirs]
output_files = [op.join(d, "output.spec") for d in swan_wrapper.cases_dirs]
Expand Down
24 changes: 23 additions & 1 deletion bluemath_tk/wrappers/swan/templates/buoys.loc
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
462805.45 4815333.56
428845.10 4815606.89
428845.10 4815606.89
486188.03 4829324.3
465203.88 4824779.32
451388.03 4832783.55
425791.5 4832079.32
409288.03 4826042.32
486188.03 4825863.79
459188.03 4822656.97
436319.44 4834779.32
407988.03 4825027.76
404188.03 4817791.13
471657.81 4820179.32
443351.32 4826879.32
414488.03 4815685.36
466288.03 4821379.1
447858.9 4831079.32
486188.03 4805133.7
455615.99 4820279.32
424888.03 4816866.29
486188.03 4802065.55
455588.03 4818313.6
430588.03 4817238.8
431888.03 4818251.37
9 changes: 4 additions & 5 deletions bluemath_tk/wrappers/swan/templates/input.swn
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ $
INPGRID BOTTOM REGULAR 409888.026 4802179.317 0 702 359 100.0 100.0
READINP BOTTOM 1 'depth_main_cantabria.dat' 1 0 FREE
$
{% if dir < 45 %}BOU SIDE N CON FILE 'input_spectra.bnd'
{% elif dir < 135 %}BOU SIDE E CON FILE 'input_spectra.bnd'
{% elif dir < 225 %}BOU SIDE S CON FILE 'input_spectra.bnd'
{% elif dir < 315 %}BOU SIDE W CON FILE 'input_spectra.bnd'
{% else %}BOU SIDE N CON FILE 'input_spectra.bnd'{% endif %}
BOUndspec SIDE N CONstant PAR {{ hs }} {{ tp }} {{ dir }} {{ spr }}
BOUndspec SIDE E CONstant PAR {{ hs }} {{ tp }} {{ dir }} {{ spr }}
BOUndspec SIDE W CONstant PAR {{ hs }} {{ tp }} {{ dir }} {{ spr }}
BOUndspec SIDE S CONstant PAR {{ hs }} {{ tp }} {{ dir }} {{ spr }}
$
FRICTION JONSWAP
BREAKING
Expand Down