Skip to content
12 changes: 6 additions & 6 deletions bluemath_tk/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from abc import ABC, abstractmethod
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor, as_completed
from typing import Any, Callable, List, Tuple, TypeVar, Union
from typing import Any, Callable, Dict, List, Tuple, Union

import numpy as np
import pandas as pd
Expand All @@ -29,8 +29,6 @@
standarize,
)

T = TypeVar("T")


class BlueMathModel(ABC):
"""
Expand Down Expand Up @@ -525,7 +523,7 @@ def parallel_execute(
num_workers: int,
cpu_intensive: bool = False,
**kwargs,
) -> List[T]:
) -> Dict[int, Any]:
"""
Execute a function in parallel using concurrent.futures.

Expand All @@ -544,8 +542,10 @@ def parallel_execute(

Returns
-------
List[T]
List of results from each function call
Dict[int, Any]
Dictionary with the results of the function execution.
The keys are the indices of the items in the original list.
The values are the results of the function execution.

Warnings
--------
Expand Down
46 changes: 46 additions & 0 deletions bluemath_tk/core/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,49 @@ def spatial_gradient(data: xr.DataArray) -> xr.DataArray:
var_grad.attrs["name"] = "Gradient"

return var_grad


def nautical_to_mathematical(nautical_degrees: np.ndarray) -> np.ndarray:
"""
Convert nautical degrees (0° at North, clockwise) to
mathematical degrees (0° at East, counterclockwise)

Parameters
----------
nautical_degrees : np.ndarray
Directional angle in nautical convention

Returns
-------
np.ndarray
Directional angle in mathematical convention
"""

# Convert nautical degrees to mathematical degrees
return (90 - nautical_degrees) % 360


def mathematical_to_nautical(math_degrees: np.ndarray) -> np.ndarray:
"""
Convert mathematical degrees (0° at East, counterclockwise) to
nautical degrees (0° at North, clockwise)

Parameters
----------
math_degrees : float or array-like
Directional angle in mathematical convention

Returns
-------
np.ndarray
Directional angle in nautical convention
"""

# Rotate the angle by 360 degrees
if math_degrees == 0:
reversed_angle = 0
else:
reversed_angle = 360 - math_degrees

# Convert mathematical degrees to nautical degrees
return (reversed_angle + 90) % 360
36 changes: 36 additions & 0 deletions bluemath_tk/setup/ocsmesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import subprocess
import sys


def post_install():
"""
Post-installation script to set up OCSMesh dependencies.
This installs jigsawpy via conda and ocsmesh via pip.
"""
print("Setting up OCSMesh and dependencies...")

try:
# Install jigsawpy from conda-forge
print("Installing jigsawpy from conda-forge...")
subprocess.check_call(
["conda", "install", "-y", "-c", "conda-forge", "jigsawpy"]
)

# Install ocsmesh via pip
print("Installing ocsmesh via pip...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "ocsmesh"])

print("Successfully set up OCSMesh and dependencies!")
except subprocess.CalledProcessError as e:
print(f"Error during installation: {e}", file=sys.stderr)
print("Command output:", e.output, file=sys.stderr)
return 1
except Exception as e:
print(f"Unexpected error setting up OCSMesh: {e}", file=sys.stderr)
return 1

return 0


if __name__ == "__main__":
sys.exit(post_install())
Loading