Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation and better error reporting #8

Merged
merged 28 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8844160
add installation instructions
mcflugen Jun 4, 2022
c456428
Merge branch 'main' into mcflugen/add-documentation
mcflugen Jun 7, 2022
bafc438
add minimal authors and changes files
mcflugen Jun 7, 2022
551b380
better error reporting
mcflugen Jun 7, 2022
3835a40
add tests for cli errors
mcflugen Jun 7, 2022
6442a9e
require toml for testing "ww3 info" command
mcflugen Jun 7, 2022
19442a1
add documentation for the WaveWatch3 class
mcflugen Jun 7, 2022
8bb1056
set data to None after changing date
mcflugen Jun 7, 2022
42abe50
remove lint
mcflugen Jun 7, 2022
1dcd139
fix ww3 info test
mcflugen Jun 7, 2022
ec18f54
add requirements for docs
mcflugen Jun 7, 2022
f3add39
add workflow for building docs
mcflugen Jun 7, 2022
8e034a6
add docs folder
mcflugen Jun 7, 2022
5565bd1
remove broken badge
mcflugen Jun 7, 2022
e72f0de
fix code block formatting
mcflugen Jun 8, 2022
b13d93c
add sidebar to docs
mcflugen Jun 8, 2022
61ad840
add outro to sidebar is csdms logo
mcflugen Jun 8, 2022
fec25d9
add table of contents to main page
mcflugen Jun 8, 2022
74dcf76
remove singlegrid cache files
mcflugen Jun 8, 2022
8eaba54
better error reporting for download errors
mcflugen Jun 8, 2022
eda30ac
use "grid", not "region" add "source" to config file
mcflugen Jun 8, 2022
2f0de00
add an example
mcflugen Jun 8, 2022
d51598e
add an example image
mcflugen Jun 8, 2022
68acecd
update example and image
mcflugen Jun 8, 2022
5816389
add step attribute, include hours in date
mcflugen Jun 8, 2022
652ab25
set the date after setting the step
mcflugen Jun 9, 2022
a627ea6
store source dates as datetimes
mcflugen Jun 9, 2022
23b6178
add news fragments
mcflugen Jun 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Documentation

on:
push:
paths:
- "docs/**"
- "AUTHORS.rst"
- "CHANGES.rst"
- "CONTRIBUTING.rst"
- "LICENSE.rst"
- "README.rst"
pull_request:
paths:
- "docs/**"
- "AUTHORS.rst"
- "CHANGES.rst"
- "CONTRIBUTING.rst"
- "LICENSE.rst"
- "README.rst"

jobs:
build:
# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. Without this if check, checks are duplicated since
# internal PRs match both the push and pull_request events.
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository

runs-on: ubuntu-latest

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: 3.9
channels: conda-forge
channel-priority: true

- name: Show conda installation info
run: conda info

- name: Install dependencies
run: |
pip install -e ".[doc]"

- name: Build documentation
run: make -C docs clean html
12 changes: 12 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Credits
=======

Development Lead
----------------

* Eric Hutton (@mcflugen)

Contributors
------------

None yet. Why not be the first?
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Release Notes
=============

.. towncrier release notes start
158 changes: 156 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,156 @@
# bmi-wavewatch3
Fetch WaveWatch3 data
wavewatch3: Python interface to WAVEWATCH III
=============================================

.. image:: https://github.com/csdms/bmi-wavewatch3/actions/workflows/test.yml/badge.svg
:target: https://github.com/csdms/bmi-wavewatch3/actions/workflows/test.yml
:alt: Test status

.. image:: https://github.com/csdms/bmi-wavewatch3/workflows/Flake8/badge.svg

.. image:: https://github.com/csdms/bmi-wavewatch3/workflows/Black/badge.svg


About
-----

The *wavewatch3* Python package provides both a command line interface and a programming interface
for downloading and working with `WAVEWATCH III`_ data.

*wavewatch3* provides access to the following raster data sources,

* 30 year wave hindcast `Phase 1`_
* 30 year wave hindcast `Phase 2`_
* Production hindcast Singlegrid_
* Production hindcast Multigrid_

All data sources provide both global and regional grids.

Installation
------------

*wavewatch3* can be installed by running ``pip install wavewatch3``. It requires Python >= 3.8 to run.

If you simply can't wait for the latest release, you can install *wavewatch3*
directly from GitHub,

.. code-block:: bash

$ pip install git+https://github.com/csdms/bmi-wavewatch3

*wavewatch3* is also available through *conda*, ``conda install wavewatch3 -c conda-forge``.


Usage
-----

To get started, you can download *WAVEWATCH III* data by date with the *ww3* command
(use `ww3 --help` to print a brief message),

.. code-block:: bash

$ ww3 fetch "2010-05-22"

You can also do this through Python,

.. code-block:: python

>>> from wavewatch3 import WaveWatch3
>>> WaveWatch3.fetch("2010-05-22")

The *wavewatch3* package provides the ``WaveWatch3`` class for downloading data and
presenting it as an *xarray* *Dataset*.

.. code-block:: python

>>> from wavewatch3 import WaveWatch3
>>> ww3 = WaveWatch3("2010-05-22")
>>> ww3.data
<xarray.Dataset>
...

Use the ``inc`` method to advance in time month-by-month,

.. code-block:: python

>>> ww3.date
'2010-05-22'
>>> ww3.inc()
'2010-06-22'
>>> ww3.data.time
<xarray.DataArray 'time' ()>
array('2010-06-01T00:00:00.000000000', dtype='datetime64[ns]')
...

This will download new datasets as necessary and load the new data into the ``data`` attribute.

.. note::

If the new data are not cached on you computer, you will notice a delay while the new
data are download. If the ``lazy`` flag is set, the download will only occur once you
try to access the data (i.e. ``ww3.data``), otherwise the data are downloaded
as soon as the date is set.

Example
-------


.. code:: python

>>> from wavewatch3 import WaveWatch3
>>> ww3 = WaveWatch3("2009-11-08")

The data can be accessed as an *xarray* *Dataset* through the ``data`` attribute.

.. code:: python

>>> ww3.data
<xarray.Dataset>
Dimensions: (step: 241, latitude: 311, longitude: 720)
Coordinates:
time datetime64[ns] 2009-11-01
* step (step) timedelta64[ns] 0 days 00:00:00 ... 30 days 00:00:00
surface float64 1.0
* latitude (latitude) float64 77.5 77.0 76.5 76.0 ... -76.5 -77.0 -77.5
* longitude (longitude) float64 0.0 0.5 1.0 1.5 ... 358.0 358.5 359.0 359.5
valid_time (step) datetime64[ns] dask.array<chunksize=(241,), meta=np.ndarray>
Data variables:
dirpw (step, latitude, longitude) float32 dask.array<chunksize=(241, 311, 720), meta=np.ndarray>
perpw (step, latitude, longitude) float32 dask.array<chunksize=(241, 311, 720), meta=np.ndarray>
swh (step, latitude, longitude) float32 dask.array<chunksize=(241, 311, 720), meta=np.ndarray>
u (step, latitude, longitude) float32 dask.array<chunksize=(241, 311, 720), meta=np.ndarray>
v (step, latitude, longitude) float32 dask.array<chunksize=(241, 311, 720), meta=np.ndarray>
Attributes:
GRIB_edition: 2
GRIB_centre: kwbc
GRIB_centreDescription: US National Weather Service - NCEP
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP
history: 2022-06-08T16:08 GRIB to CDM+CF via cfgrib-0.9.1...

The ``step`` attribute points to the current time slice into the data (i.e number of three hour increments
since the start of the month),

.. code:: python

>>> ww3.step
56
>>> ww3.data.swh[ww3.step, :, :].plot()

.. image:: https://raw.githubusercontent.com/csdms/bmi-wavewatch3/main/docs/source/_static/ww3_global_swh.png
:width: 100%
:alt: Significant wave height

.. _WAVEWATCH III: https://polar.ncep.noaa.gov/waves
.. _Phase 1: https://polar.ncep.noaa.gov/waves/hindcasts/nopp-phase1.php
.. _Phase 2: https://polar.ncep.noaa.gov/waves/hindcasts/nopp-phase2.php
.. _Multigrid: https://polar.ncep.noaa.gov/waves/hindcasts/prod-multi_1.php
.. _Singlegrid: https://polar.ncep.noaa.gov/waves/hindcasts/prod-nww3.php
.. _WAVEWATCH III description: https://polar.ncep.noaa.gov/waves/wavewatch/
.. _WAVEWATCH III hindcasts: http://polar.ncep.noaa.gov/waves/hindcasts/
.. _WAVEWATCH III thredds: https://www.ncei.noaa.gov/thredds-ocean/catalog/ncep/nww3/catalog.html
.. _Singlegrid data: https://polar.ncep.noaa.gov/waves/hindcasts/nww3/
.. _Multigrid data: https://polar.ncep.noaa.gov/waves/hindcasts/multi_1/



20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
Binary file added docs/source/_static/powered-by-logo-header.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/wavewatch3_logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/ww3_global_swh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/source/_templates/sidebaroutro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="https://csdms.colorado.edu">
<img src="_static/powered-by-logo-header.png" alt="Powered by CSDMS"/>
</a>
1 change: 1 addition & 0 deletions docs/source/authors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../../AUTHORS.rst
1 change: 1 addition & 0 deletions docs/source/changes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../../CHANGES.rst
73 changes: 73 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = "wavewatch3"
copyright = "2022, Eric Hutton"
author = "Eric Hutton"

# The full version, including alpha/beta/rc tags
release = "0.1"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = []

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

html_static_path = ["_static", "images"]

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "alabaster"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]

html_theme_options = {
"description": "WAVEWATCH III datasets in Python.",
"logo": "wavewatch3_logo.png",
"logo_name": False,
"github_user": "csdms",
"github_repo": "wavewatch3",
"extra_nav_links": {
"WAVEWATCH III": "https://polar.ncep.noaa.gov/waves",
"wavewatch3 @ GitHub": "https://github.com/csdms/wavewatch3/",
"Contact Us": "https://github.com/csdms/wavewatch3/issues",
},
}

html_sidebars = {
"**": ["about.html", "searchbox.html", "navigation.html", "sidebaroutro.html"]
}
16 changes: 16 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. include:: ../../README.rst

.. toctree::
:maxdepth: 2
:caption: Contents:

Release Notes <changes>
Contributors <authors>
License <license>

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
1 change: 1 addition & 0 deletions docs/source/license.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../../LICENSE.rst
4 changes: 4 additions & 0 deletions news/8.docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Added package description, installation, usage, and an example to the
documentation.


5 changes: 5 additions & 0 deletions news/8.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added a ``step`` property to ``WaveWatch3`` to track the current time slice
of the data cube. This property is also settable so that a user can use it to
advance throught the data (additional data are downloaded in the background as
needed).