Skip to content

Commit

Permalink
Merge branch 'MHKiT-Software:master' into acoustics_module
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcvey3 authored Aug 27, 2024
2 parents d330162 + 948c6b9 commit dffc74c
Show file tree
Hide file tree
Showing 66 changed files with 445,085 additions and 443,369 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/generate_notebook_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Dynamically creates a matrix for the GitHub Actions workflow that
runs the notebooks in the examples directory.
"""

import os
import json

# Dictionary to store custom timeouts for each notebook
notebook_timeouts = {
"ADCP_Delft3D_TRTS_example.ipynb": 1200,
"adcp_example.ipynb": 240,
"adv_example.ipynb": 180,
"cdip_example.ipynb": 180,
"Delft3D_example.ipynb": 180,
"directional_waves.ipynb": 180,
"environmental_contours_example.ipynb": 360,
"extreme_response_contour_example.ipynb": 360,
"extreme_response_full_sea_state_example.ipynb": 360,
"extreme_response_MLER_example.ipynb": 360,
"loads_example.ipynb": 180,
"metocean_example.ipynb": 180,
"mooring_example.ipynb": 240,
"PacWave_resource_characterization_example.ipynb": 780,
"power_example.ipynb": 180,
"qc_example.ipynb": 180,
"river_example.ipynb": 180,
"short_term_extremes_example.ipynb": 180,
"SWAN_example.ipynb": 180,
"tidal_example.ipynb": 180,
"tidal_performance_example.ipynb": 180,
"upcrossing_example.ipynb": 180,
"wave_example.ipynb": 180,
"wecsim_example.ipynb": 180,
"WPTO_hindcast_example.ipynb": 180,
"default": 60, # Default timeout for other notebooks
}
notebooks = []
for root, dirs, files in os.walk("examples"):
for file in files:
if file.endswith(".ipynb"):
notebooks.append(os.path.join(root, file))

# Generate the matrix configuration
matrix = {"include": []}
for notebook in notebooks:
timeout = notebook_timeouts.get(
os.path.basename(notebook), notebook_timeouts["default"]
)

matrix["include"].append({"notebook": notebook, "timeout": timeout})


# Print the matrix as a properly formatted JSON string
matrix_json = json.dumps(matrix)
print(f"matrix={matrix_json}")
161 changes: 139 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Py 3.8, 3.9, 3.10, 3.11 | Windows Mac Linux
name: Py 3.10, 3.11 | Windows Mac Linux

on:
push:
Expand All @@ -9,6 +9,7 @@ on:
branches:
- master
- develop

jobs:
set-os:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -52,7 +53,7 @@ jobs:
prepare-nonhindcast-cache:
runs-on: ubuntu-latest
env:
PYTHON_VER: 3.9
PYTHON_VER: 3.11
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -95,7 +96,7 @@ jobs:
needs: [check-changes]
runs-on: ubuntu-latest
env:
PYTHON_VER: 3.9
PYTHON_VER: 3.11
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
steps:
- name: Checkout code
Expand Down Expand Up @@ -137,7 +138,7 @@ jobs:
needs: [check-changes, prepare-wave-hindcast-cache]
runs-on: ubuntu-latest
env:
PYTHON_VER: 3.9
PYTHON_VER: 3.11
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
steps:
- name: Checkout code
Expand Down Expand Up @@ -183,7 +184,7 @@ jobs:
fail-fast: false
matrix:
os: ${{fromJson(needs.set-os.outputs.matrix_os)}}
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']
env:
PYTHON_VER: ${{ matrix.python-version }}

Expand Down Expand Up @@ -234,7 +235,7 @@ jobs:
fail-fast: false
matrix:
os: ${{fromJson(needs.set-os.outputs.matrix_os)}}
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']

steps:
- uses: conda-incubator/setup-miniconda@v3
Expand All @@ -244,21 +245,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install HDF5 (macOS with Python 3.8)
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8'
run: brew install hdf5

- name: Install NetCDF (macOS with Python 3.8)
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8'
run: brew install netcdf

- name: Set environment variables (macOS with Python 3.8)
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8'
run: |
echo "HDF5_DIR=$(brew --prefix hdf5)" >> $GITHUB_ENV
echo "NETCDF4_DIR=$(brew --prefix netcdf)" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$(brew --prefix hdf5)/lib/pkgconfig:$(brew --prefix netcdf)/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV

- name: Set up Git repository
uses: actions/checkout@v4

Expand Down Expand Up @@ -305,7 +291,7 @@ jobs:
fail-fast: false
matrix:
os: ${{fromJson(needs.set-os.outputs.matrix_os)}}
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -359,6 +345,137 @@ jobs:
parallel: true
path-to-lcov: ./coverage.lcov

notebook-matrix:
runs-on: ubuntu-latest
needs:
[
check-changes,
prepare-nonhindcast-cache,
prepare-wave-hindcast-cache,
prepare-wind-hindcast-cache,
]
if: |
always() &&
(
(
needs.prepare-nonhindcast-cache.result == 'success' &&
needs.prepare-wave-hindcast-cache.result == 'skipped' &&
needs.prepare-wind-hindcast-cache.result == 'skipped' &&
needs.check-changes.outputs.should-run-hindcast == 'false'
) ||
(
needs.prepare-nonhindcast-cache.result == 'success' &&
needs.prepare-wave-hindcast-cache.result == 'success' &&
needs.prepare-wind-hindcast-cache.result == 'success' &&
needs.check-changes.outputs.should-run-hindcast == 'true'
)
)
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'

- name: Generate matrix
id: set-matrix
run: |
matrix_json=$(python .github/workflows/generate_notebook_matrix.py)
echo "$matrix_json" >> $GITHUB_OUTPUT

test-notebooks:
needs:
[
notebook-matrix,
check-changes,
prepare-nonhindcast-cache,
prepare-wave-hindcast-cache,
prepare-wind-hindcast-cache,
]
strategy:
matrix: ${{ fromJson(needs.notebook-matrix.outputs.matrix) }}
if: |
always()
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: 'latest'
auto-update-conda: true
python-version: '3.11'
activate-environment: TESTconda
use-only-tar-bz2: true

- name: Install dependencies
shell: bash -l {0}
run: |
conda install numpy cython pip hdf5 libnetcdf cftime netcdf4 --strict-channel-priority
pip install -e . --force-reinstall
python -m pip install --upgrade pip wheel
pip install nbval jupyter
pip install utm folium

- name: Ensure Conda environment is activated
shell: bash -l {0}
run: |
echo "source ~/miniconda3/etc/profile.d/conda.sh" >> ~/.bashrc
echo "conda activate TESTconda" >> ~/.bashrc
source ~/.bashrc

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

- name: Download Wave Hindcast data (if available)
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
uses: actions/download-artifact@v4
with:
name: wave-hindcast-data
path: ~/.cache/mhkit/wave-hindcast

- name: Download Wind Hindcast data (if available)
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
uses: actions/download-artifact@v4
with:
name: wind-hindcast-data
path: ~/.cache/mhkit/wind-hindcast

- name: Consolidate hindcast data
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
run: |
mkdir -p ~/.cache/mhkit/hindcast
mv ~/.cache/mhkit/wave-hindcast/hindcast/* ~/.cache/mhkit/hindcast/
mv ~/.cache/mhkit/wind-hindcast/hindcast/* ~/.cache/mhkit/hindcast/
shell: bash

- name: Copy .hscfg file to examples directory
shell: bash -l {0}
run: |
cp .hscfg examples/

- name: Run notebook
shell: bash -l {0}
run: |
if [[ "${{ matrix.notebook }}" == "examples/metocean_example.ipynb" || "${{ matrix.notebook }}" == "examples/WPTO_hindcast_example.ipynb" ]]; then
if [[ "${{ needs.check-changes.outputs.should-run-hindcast }}" == 'true' ]]; then
jupyter nbconvert --to notebook --execute --inplace --ExecutePreprocessor.timeout=${{ matrix.timeout }} "${{ matrix.notebook }}"
else
echo "Skipping ${{ matrix.notebook }}"
fi
else
jupyter nbconvert --to notebook --execute --inplace --ExecutePreprocessor.timeout=${{ matrix.timeout }} "${{ matrix.notebook }}"
fi

coveralls:
name: Indicate completion to coveralls.io
needs:
Expand Down
12 changes: 7 additions & 5 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ channels:
- conda-forge
- defaults
dependencies:
- python>=3.8
- python>=3.8,<3.12
- pip
- pandas>=1.0.0
- numpy>=1.21.0
- scipy
- matplotlib
- numpy>=1.21.0, <2.0.0
- scipy<=1.13.1
- matplotlib>=3.8.0
- requests
- lxml
- scikit-learn
Expand All @@ -16,10 +17,11 @@ dependencies:
- beautifulsoup4
- xarray
- h5py>=3.6.0
- netcdf4>=1.5.8
- netcdf4>=1.5.8, <=1.6.5
- pip:
- pecos>=0.3.0
- fatpack
- NREL-rex>=0.2.63
- h5pyd>=0.7.0
- six>=1.13.0
- notebook
Loading

0 comments on commit dffc74c

Please sign in to comment.