SalishSeaNowcast Package Development

Continuous Integration

Pytest with Coverage Status Codecov Testing Coverage Report CodeQL analysis

Documentation

Documentation Status Sphinx linkcheck

Package

Releases Python Version from PEP 621 TOML Issue Tracker

Meta

Licensed under the Apache License, Version 2.0 Git on GitHub pre-commit The uncompromising Python code formatter Hatch project

The SalishSeaNowcast package is a collection of Python modules associated with running the SalishSeaCast ocean models in a daily nowcast/forecast mode. The package uses the NEMO_Nowcast framework to implement the SalishSeaCast Ocean Model Automation System.

Python Version

Python Version from PEP 621 TOML

The SalishSeaNowcast package is developed and tested using Python 3.12.

Getting the Code

Git on GitHub

Clone the code and documentation repository from GitHub with:

$ git clone git@github.com:SalishSeaCast/SalishSeaNowcast.git

Development Environment

Setting up an isolated development environment using Conda is recommended. Assuming that you have Miniconda installed, you can create and activate an environment called salishsea-nowcast that will have all of the Python packages necessary for development, testing, and building the documentation with the commands below.

SalishSeaNowcast depends on a collection of other Python packages developed by the SalishSeaCast project and friends:

If you have not done so already, you can clone those repos with:

$ cd SalishSeaNowcast/..
$ git clone git@github.com:43ravens/NEMO_Nowcast.git
$ git clone git@github.com:UBC-MOAD/moad_tools.git
$ git clone git@github.com:UBC-MOAD/Reshapr.git
$ git clone git@github.com:SalishSeaCast/tools.git
$ git clone git@gitlab.com:douglatornell/OPPTools.git
$ git clone git@github.com:SalishSeaCast/NEMO-Cmd.git
$ git clone git@github.com:SalishSeaCast/SalishSeaCmd.git
$ git clone git@github.com:SalishSeaCast/FVCOM-Cmd.git

If you already have clones of those repos, please ensure that they are up to date.

Assuming that those repos are cloned beside your SalishSeaNowcast clone, the commands below install the packages into your salishsea-nowcast development environment.

$ cd SalishSeaNowcast
$ conda env create -f envs/environment-dev.yaml
$ conda activate salishsea-nowcast
(salishsea-nowcast)$ python3 -m pip install --editable ../NEMO_Nowcast
(salishsea-nowcast)$ python3 -m pip install --editable ../moad_tools
(salishsea-nowcast)$ python3 -m pip install --editable ../Reshapr
(salishsea-nowcast)$ python3 -m pip install --editable ../tools/SalishSeaTools
(salishsea-nowcast)$ cd ../OPPTools
(salishsea-nowcast)$ git switch SalishSeaCast-prod
(salishsea-nowcast)$ cd ../SalishSeaNowcast
(salishsea-nowcast)$ python3 -m pip install --editable OPPTools
(salishsea-nowcast)$ python3 -m pip install --editable ../NEMO-Cmd
(salishsea-nowcast)$ python3 -m pip install --editable ../SalishSeaCmd
(salishsea-nowcast)$ python3 -m pip install --editable ../FVCOM-Cmd
(salishsea-nowcast)$ python3 -m pip install --editable .

The --editable option in the pip install command above installs the packages from the cloned repos via symlinks so that the installed packages will be automatically updated as the repos evolve.

To deactivate the environment use:

(salishsea-nowcast)$ conda deactivate

Coding Style

pre-commit The uncompromising Python code formatter

The SalishSeaNowcast package uses Git pre-commit hooks managed by pre-commit to maintain consistent code style and and other aspects of code, docs, and repo QA.

To install the pre-commit hooks in a newly cloned repo, activate the conda development environment, and run pre-commit install:

$ cd SalishSeaNowcast
$ conda activate salishsea-nowcast
(salishsea-nowcast)$ pre-commit install

Note

You only need to install the hooks once immediately after you make a new clone of the SalishSeaNowcast repository and build your Development Environment.

Building the Documentation

Documentation Status

The documentation for the SalishSeaNowcast package is written in reStructuredText and converted to HTML using Sphinx. Creating a Development Environment as described above includes the installation of Sphinx. Building the documentation is driven by the docs/Makefile. With your salishsea-nowcast development environment activated, use:

(salishsea-nowcast)$ (cd docs && make clean html)

to do a clean build of the documentation. The output looks something like:

Removing everything under '_build'...
Running Sphinx v3.3.1
making output directory... done
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
loading intersphinx inventory from https://nemo-nowcast.readthedocs.io/en/latest/objects.inv...
loading intersphinx inventory from https://salishsea-meopar-docs.readthedocs.io/en/latest/objects.inv...
loading intersphinx inventory from https://salishsea-meopar-tools.readthedocs.io/en/latest/objects.inv...
loading intersphinx inventory from https://salishsea-site.readthedocs.io/en/latest/objects.inv...
loading intersphinx inventory from https://salishseacmd.readthedocs.io/en/latest/objects.inv...
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 20 source files that are out of date
updating environment: [new config] 20 added, 0 changed, 0 removed
reading sources... [100%] workers
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] workers
generating indices... genindex py-modindex done
highlighting module code... [100%] nowcast.workers.watch_ww3
writing additional pages... search done
copying images... [100%] ProcessFlow.png
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded.

The HTML pages are in _build/html.

The HTML rendering of the docs ends up in docs/_build/html/. You can open the index.html file in that directory tree in your browser to preview the results of the build.

If you have write access to the repository on GitHub, whenever you push changes to GitHub the documentation is automatically re-built and rendered at https://salishsea-nowcast.readthedocs.io/en/latest/.

Running the Unit Tests

The test suite for the SalishSeaNowcast package is in SalishSeaNowcast/tests/. The pytest tool is used for test parametrization and as the test runner for the suite.

With your salishsea-nowcast development environment activated, use:

(salishsea-nowcast)$ cd SalishSeaNowcast/
(salishsea-nowcast)$ pytest

to run the test suite. The output looks something like:

============================ test session starts ============================
platform linux -- Python 3.9.2, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
Using --randomly-seed=1204534893
rootdir: /media/doug/warehouse/MEOPAR/SalishSeaNowcast
plugins: randomly-3.7.0, xdist-2.2.1, forked-1.3.0
collected 2063 items

tests/workers/test_make_fvcom_atmos_forcing.py .....................................
tests/workers/test_upload_fvcom_atmos_forcing.py ..............................
tests/workers/test_get_onc_ctd.py ...........
tests/test_residuals.py ...
tests/workers/test_upload_forcing.py ...............................................
..........................
tests/workers/test_make_surface_current_tiles.py .............................
tests/workers/test_ping_erddap.py .................................
tests/workers/test_run_NEMO_hindcast.py ............................................
....................................................................................
................
tests/workers/test_collect_river_data.py ............
tests/workers/test_watch_NEMO.py ...................................................
.............................................
tests/workers/test_run_NEMO_agrif.py .................
tests/workers/test_get_onc_ferry.py .............
tests/workers/test_split_results.py .............
tests/workers/test_run_NEMO.py .....................................................
....................................................................................
.................
tests/workers/test_grib_to_netcdf.py ..................
tests/workers/test_make_fvcom_rivers_forcing.py ....................................
tests/workers/test_run_fvcom.py ....................................................
................
tests/workers/test_download_live_ocean.py ..........
tests/workers/test_download_results.py .............................................
.............................
tests/workers/test_make_runoff_file.py ...........
tests/workers/test_make_turbidity_file.py ......
tests/workers/test_make_ssh_file.py .................
tests/test_config.py .............
tests/workers/test_update_forecast_datasets.py .....................................
..............................
tests/workers/test_make_CHS_currents_file.py .............................
tests/workers/test_make_forcing_links.py ...........................................
..............................
tests/workers/test_download_wwatch3_results.py ............
tests/workers/test_watch_fvcom.py ...............................
tests/test_next_workers.py .........................................................
....................................................................................
....................................................................................
....................................................................................
..........................................
tests/release_mgmt/test_tag_release.py .........
tests/workers/test_run_ww3.py ......................................................
..............
tests/workers/test_download_weather.py .............................................
.....................
tests/workers/test_make_feeds.py .....................
tests/test_analyze.py .................
tests/workers/test_make_fvcom_boundary.py .....................................
tests/workers/test_watch_NEMO_hindcast.py ..........................................
.....................
tests/workers/test_collect_weather.py ..............................................
.......
tests/workers/test_download_fvcom_results.py .............................
tests/workers/test_collect_NeahBay_ssh.py ...................
tests/workers/test_make_live_ocean_files.py ...........
tests/workers/test_watch_ww3.py ................
tests/workers/test_make_ww3_current_file.py .................................
tests/workers/test_make_plots.py ...................................................
.............
tests/workers/test_get_vfpa_hadcp.py ...............
tests/workers/test_watch_NEMO_agrif.py ....................
tests/workers/test_launch_remote_worker.py ...............
tests/workers/test_make_ww3_wind_file.py ..........................

===================== 2063 passed in 95.74s (0:01:35) ======================

You can monitor what lines of code the test suite exercises using the coverage.py and pytest-cov tools with the command:

(salishsea-nowcast)$ cd SalishSeaNowcast/
(salishsea-nowcast)$ pytest --cov=./

The test coverage report will be displayed below the test suite run output.

Alternatively, you can use

(salishsea-nowcast)$ pytest --cov=./ --cov-report html

to produce an HTML report that you can view in your browser by opening SalishSeaNowcast/htmlcov/index.html.

Continuous Integration

GitHub Workflow Status

The SalishSeaNowcast package unit test suite is run and a coverage report is generated whenever changes are pushed to GitHub. The results are visible on the repo actions page, from the green checkmarks beside commits on the repo commits page, or from the green checkmark to the left of the “Latest commit” message on the repo code overview page . The testing coverage report is uploaded to codecov.io

The GitHub Actions workflow configuration that defines the continuous integration tasks is in the .github/workflows/pytest-coverage.yaml file.

Version Control Repository

Git on GitHub

The SalishSeaNowcast package code and documentation source files are available as a Git repository at https://github.com/SalishSeaCast/SalishSeaNowcast.

Issue Tracker

Issue Tracker

Development tasks, bug reports, and enhancement ideas are recorded and managed in the issue tracker at https://github.com/SalishSeaCast/SalishSeaNowcast/issues.

License

Licensed under the Apache License, Version 2.0

The SalishSeaCast NEMO model nowcast system code and documentation are copyright 2013 – present by the SalishSeaCast Project Contributors and The University of British Columbia.

They are licensed under the Apache License, Version 2.0. https://www.apache.org/licenses/LICENSE-2.0 Please see the LICENSE file for details of the license.

Release Process

Releases Hatch project

Releases are done at Doug’s discretion when significant pieces of development work have been completed.

The release process steps are:

  1. Use hatch version release to bump the version from .devn to the next release version identifier

  2. Commit the version bump

  3. Create an annotated tag for the release with Git -> New Tag… in PyCharm or git tag -e -a vyy.n

  4. Push the version bump commit and tag to GitHub

  5. Use the GitHub web interface to create a release, editing the auto-generated release notes as necessary

  6. Use the GitHub Issues -> Milestones web interface to edit the release milestone:

    • Change the Due date to the release date

    • Delete the “when it’s ready” comment in the Description

  7. Use the GitHub Issues -> Milestones web interface to create a milestone for the next release:

    • Set the Title to the next release version, prepended with a v; e.g. v23.1

    • Set the Due date to the end of the year of the next release

    • Set the Description to something like v23.1 release - when it's ready :-)

    • Create the next release milestone

  8. Review the open issues, especially any that are associated with the milestone for the just released version, and update their milestone.

  9. Close the milestone for the just released version.

  10. Use hatch version minor,dev to bump the version for the next development cycle, or use hatch version major,minor,dev for a year rollover version bump

  11. Commit the version bump

  12. Push the version bump commit to GitHub