Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fd20d1d
use pyproject.toml
ssolson May 19, 2025
6e22f4c
black
ssolson May 19, 2025
6db1515
dynamic version
ssolson May 19, 2025
e086196
dynamic = ["version"]
ssolson May 19, 2025
09a78ac
install module specific dependencies
ssolson May 20, 2025
cff7366
pip install with all
ssolson May 28, 2025
f62ee78
example dependencies setup
ssolson May 28, 2025
8e794be
coverage, coveralls
ssolson May 28, 2025
82232d6
pylint to dev env
ssolson May 28, 2025
aabffba
".[all+dev]"
ssolson May 28, 2025
207c1d4
".[all+dev]"
ssolson May 28, 2025
946e527
[all,dev]
ssolson May 29, 2025
19745ab
try except request with retry
ssolson May 30, 2025
8827327
simplify optional dependencies
ssolson Jun 5, 2025
592d650
add a pip opt deps test for each module
ssolson Jun 5, 2025
28e0d51
fix pip deps needs field
ssolson Jun 5, 2025
68b95fd
adjust pip needs field
ssolson Jun 5, 2025
8c7423a
remove hindcast artifact downloads
ssolson Jun 5, 2025
63f69d9
add bottleneck and lxml
ssolson Jun 5, 2025
b8d05fd
add cartopy to river
ssolson Jun 5, 2025
2cad0aa
cartopy => loads, mooring
ssolson Jun 6, 2025
3814020
lazy import modules for optional pip dependecies
ssolson Jun 6, 2025
865d58f
remove cartopy from river, loads, mooring
ssolson Jun 6, 2025
02171f1
lazy load cartopy in dolfyn discharge
ssolson Jun 9, 2025
7b44d89
try increasing usgs time
ssolson Jun 9, 2025
70609a2
Merge branch 'develop' of https://github.com/MHKiT-Software/MHKiT-Pyt…
ssolson Jul 1, 2025
bbb789c
remove qc module from test bc no specific mhkit tests
ssolson Jul 1, 2025
eabed6f
improve the lazy load error message
ssolson Jul 2, 2025
0e03da5
clean up error message more
ssolson Jul 2, 2025
34030a6
remove fstring on non variable strings
ssolson Jul 2, 2025
509b403
delete the deps test script
ssolson Jul 2, 2025
6125357
minor change to logic in mhkit/__init__.py
akeeste Jul 15, 2025
614bc60
rework mhkit init error messages
akeeste Jul 15, 2025
11ac941
make pecos a core dependency
akeeste Jul 15, 2025
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
45 changes: 39 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
shell: bash -l {0}
run: |
conda activate mhkit-env
pip install -e . --no-deps
pip install -e ".[all,dev]" --no-deps

- name: Prepare non-hindcast API data
shell: bash -l {0}
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
shell: bash -l {0}
run: |
conda activate mhkit-env
pip install -e . --no-deps
pip install -e ".[all,dev]" --no-deps

- name: Prepare Wave Hindcast data
shell: bash -l {0}
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
shell: bash -l {0}
run: |
conda activate mhkit-env
pip install -e . --no-deps
pip install -e ".[all,dev]" --no-deps

- name: Prepare Wind Hindcast data
shell: bash -l {0}
Expand Down Expand Up @@ -286,7 +286,7 @@ jobs:
shell: bash -l {0}
run: |
python -m pip install --upgrade pip wheel
pip install coverage pytest coveralls .
pip install -e ".[all,dev]"

- name: Install setuptools for Python 3.12
if: matrix.python-version == '3.12'
Expand Down Expand Up @@ -354,7 +354,7 @@ jobs:
shell: bash -l {0}
run: |
conda activate mhkit-env
pip install -e . --no-deps
pip install -e ".[all,dev]" --no-deps

- name: Download Wave Hindcast data from artifact
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -390,6 +390,39 @@ jobs:
parallel: true
path-to-lcov: ./coverage.lcov

test-optional-pip-dependencies:
needs: [set-os, prepare-nonhindcast-cache]
runs-on: ubuntu-latest
strategy:
matrix:
module:
[wave, tidal, river, dolfyn, power, loads, mooring, acoustics, utils]
python-version: ['3.12']

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Download non-hindcast data
uses: actions/download-artifact@v4
with:
name: data
path: ~/.cache/mhkit

- name: Install MHKiT with optional dependency
run: |
python -m pip install --upgrade pip
pip install "mhkit[${{ matrix.module }}]"
pip install pytest

- name: Run tests for ${{ matrix.module }}
run: |
python -m pytest -c .github/workflows/pytest.ini mhkit/tests/${{ matrix.module }}/

notebook-matrix:
runs-on: ubuntu-latest
needs:
Expand Down Expand Up @@ -476,7 +509,7 @@ jobs:
shell: bash -l {0}
run: |
conda activate mhkit-env
pip install -e . --no-deps
pip install -e ".[all,dev]" --no-deps

- name: Download non-hindcast data
uses: actions/download-artifact@v4
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install pylint
pip install .
pip install ".[all,dev]"

- name: Run Pylint on mhkit/loads/
run: |
Expand Down
41 changes: 31 additions & 10 deletions mhkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import warnings as _warn
from mhkit import wave
from mhkit import river
from mhkit import tidal
from mhkit import qc
from mhkit import utils
from mhkit import power
from mhkit import loads
from mhkit import dolfyn
from mhkit import mooring
from mhkit import acoustics
import importlib

# Register datetime converter for a matplotlib plotting methods
from pandas.plotting import register_matplotlib_converters as _rmc
Expand All @@ -28,3 +19,33 @@
retains certain rights in this software."""

__license__ = "Revised BSD License"


def __getattr__(name):
"""Lazy import modules to handle pip optional dependencies."""
known_modules = [
"wave",
"river",
"tidal",
"qc",
"utils",
"power",
"loads",
"dolfyn",
"mooring",
"acoustics",
]

if name in known_modules:
try:
return importlib.import_module(f"mhkit.{name}")
except ModuleNotFoundError:
error_msg = "Module dependencies not found.\n"
error_msg += f"To install the {name} module, run:\n"
error_msg += f" pip install mhkit[{name}]\n\n"
error_msg += "Or install all modules with:\n"
error_msg += " pip install mhkit[all]"
else:
error_msg = f"module 'mhkit' has no attribute '{name}'"

raise AttributeError(error_msg)
6 changes: 3 additions & 3 deletions mhkit/acoustics/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def plot_spectrogram(
fmax: int = 100000,
fig: plt.figure = None,
ax: plt.Axes = None,
**kwargs
**kwargs,
) -> Tuple[plt.figure, plt.Axes]:
"""
Plots the spectrogram of the sound pressure spectral density level.
Expand Down Expand Up @@ -86,7 +86,7 @@ def plot_spectrogram(
spsdl[freq].values,
spsdl.transpose(freq, time),
shading="nearest",
**kwargs
**kwargs,
)
fig.colorbar(h, ax=ax, label=getattr(spsdl, "units", None))
ax.set(ylim=(fmin, fmax), xlabel="Time", ylabel="Frequency [Hz]")
Expand All @@ -100,7 +100,7 @@ def plot_spectra(
fmax: int = 100000,
fig: plt.figure = None,
ax: plt.Axes = None,
**kwargs
**kwargs,
) -> Tuple[plt.figure, plt.Axes]:
"""
Plots spectral density. X axis is log-transformed.
Expand Down
4 changes: 3 additions & 1 deletion mhkit/dolfyn/adp/discharge.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import xarray as xr
import cartopy.crs as ccrs


def discharge(ds, water_depth, rho, mu=None, surface_offset=0, utm_zone=10):
Expand Down Expand Up @@ -54,6 +53,9 @@ def discharge(ds, water_depth, rho, mu=None, surface_offset=0, utm_zone=10):
- `reynolds_number`: (1) Reynolds number, unitless
"""

# Lazy import cartopy
import cartopy.crs as ccrs

def _extrapolate_to_bottom(vel, bottom, rng):
"""
Linearly extrapolate velocity values from the deepest valid bin down to zero at the seafloor.
Expand Down
19 changes: 17 additions & 2 deletions mhkit/river/io/usgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,23 @@ def request_usgs_data(

print("Data request URL: ", data_url + api_query)

response = requests.get(url=data_url + api_query, proxies=proxy, timeout=timeout)
text = json.loads(response.text)
max_retries = 3
retry_count = 0
while retry_count < max_retries:
try:
response = requests.get(
url=data_url + api_query, proxies=proxy, timeout=timeout, verify=True
)
text = json.loads(response.text)
break
except requests.exceptions.SSLError as e:
retry_count += 1
if retry_count == max_retries:
raise e
print(
f"SSL Error occurred, retrying... (Attempt {retry_count}/{max_retries})"
)
continue

# handle_caching is only set-up for pandas, so force this data to output as pandas for now
data = _read_usgs_json(text, True)
Expand Down
135 changes: 135 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "mhkit"
# `version` is read from `[tools.setuptools.dynamic] version` during build: https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata
dynamic = ["version"]
description = "Marine and Hydrokinetic Toolkit"
readme = "README.md"
authors = [
{name = "MHKiT developers"}
]
license = {text = "Revised BSD"}
classifiers = [
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
]
requires-python = ">=3.10"
dependencies = [
"numpy>=2.0.0",
"pandas>=2.2.2",
"scipy>=1.14.0",
"xarray>=2024.6.0",
"matplotlib>=3.9.1",
"pecos>=0.3.0",
]

[project.optional-dependencies]
# Core dependencies for each module
wave = [
"scikit-learn>=1.5.1",
"statsmodels>=0.14.2",
"netCDF4>=1.7.1.post1",
"pytz",
"NREL-rex>=0.2.63",
"beautifulsoup4",
"requests",
"bottleneck",
"lxml"
]

tidal = [
"netCDF4>=1.7.1.post1",
"requests",
"bottleneck"
]

river = [
"netCDF4>=1.7.1.post1",
"requests",
"bottleneck",
]

dolfyn = [
"h5py>=3.11.0",
"h5pyd>=0.18.0",
"netCDF4>=1.7.1.post1",
"cartopy",
]

power = [
]

loads = [
"fatpack"
]

mooring = [
]

acoustics = [

]

qc = [

]

utils = [

]

# Development dependencies
dev = [
"pytest",
"pylint",
"pytest-cov",
"pre-commit",
"coverage",
"coveralls"
]



# Install all optional dependencies
all = [
"mhkit[wave]",
"mhkit[tidal]",
"mhkit[river]",
"mhkit[dolfyn]",
"mhkit[power]",
"mhkit[loads]",
"mhkit[mooring]",
"mhkit[acoustics]",
"mhkit[qc]",
"mhkit[utils]",
]

# Examples dependencies
examples = [
"jupyter",
"notebook",
"ipykernel",
"nbval",
"utm",
"folium",
"mhkit[all]",

]

[project.urls]
Homepage = "https://github.com/MHKiT-Software/mhkit-python"
Documentation = "https://mhkit-software.github.io/MHKiT"

[tool.setuptools]
packages = ["mhkit"]
zip-safe = false
include-package-data = true

[tool.setuptools.dynamic]
version = {attr = "mhkit.__version__"}
20 changes: 0 additions & 20 deletions requirements.txt

This file was deleted.

Loading
Loading