Skip to content

Commit a2c35b8

Browse files
create a top-level plotting interface to replace the plots lib; clean up API refs for plotting
1 parent 4a237fd commit a2c35b8

6 files changed

Lines changed: 62 additions & 10 deletions

File tree

cdippy/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# import plots library
2-
from . import plots
3-
41
# import public top-level modules
5-
from . import cdipnc, nchashes, ncstats, ndbc, spectra, stndata
2+
from . import cdipnc, nchashes, ncstats, ndbc, plotting, spectra, stndata
63

74
# public API (i.e. "from cdippy import *")
8-
__all__ = ["plots", "cdipnc", "nchashes", "ncstats", "ndbc", "spectra", "stndata"]
5+
__all__ = ["cdipnc", "nchashes", "ncstats", "ndbc", "plotting", "spectra", "stndata"]

cdippy/plots/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
from . import annual_hs_boxplot, compendium, sst_climatology
2-
3-
__all__ = ["annual_hs_boxplot", "compendium", "sst_climatology"]

cdippy/plots/compendium.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
def make_plot(
18-
stns: str, start: datetime, end: datetime, params: str, x_inch: int
18+
stns: str, start: datetime, end: datetime, params: str, x_inch: int = None
1919
) -> tuple:
2020
"""CDIP's classic compendium plot for multiple stations and parameters.
2121

cdippy/plots/sst_climatology.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import matplotlib.pyplot as plt # noqa: E402
1515

1616

17-
def make_plot(stn: str, x_inch: int = None, y_inch: int = None):
17+
def make_plot(stn: str, x_inch: int = None, y_inch: int = None) -> tuple:
1818
"""
1919
Year-long Climatology of Sea Surface Temperature across all years of available data for a station.
2020

cdippy/plotting.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import plots.annual_hs_boxplot as hs
2+
import plots.compendium as comp
3+
import plots.sst_climatology as sst
4+
5+
from matplotlib.pyplot import Figure
6+
7+
8+
def make_annual_hs_boxplot(stn: str, year: int) -> Figure:
9+
"""
10+
Create a boxplot of annual significant wave heights for a station.
11+
12+
Args:
13+
stn (str): A 5-char station identifier, e.g. '100p1'.
14+
year (int): The year to plot.
15+
16+
Returns:
17+
fig (Figure): A matplotlib.pyplot.Figure object for the created plot.
18+
"""
19+
20+
return hs.make_plot(stn, year)
21+
22+
23+
def make_compendium_plot(
24+
stns: str, start: str, end: str, params: str, x_inch: int
25+
) -> Figure:
26+
"""CDIP's classic compendium plot for multiple stations and parameters.
27+
28+
Args:
29+
stns (str): A comma-delimited list of 5-char station identifiers, e.g. '100p1,201p1'.
30+
start (str): Start time of data series formatted as 'yyyymm[ddHHMMss]' where 'ddHHMMss' are optional components.
31+
end (str): End time of data series ('yyyymm[ddHHMMss]') If 'None' is provided, defaults to the current date and time.
32+
params (str): A comma-delimited string of parameter names, e.g. 'waveHs,waveTp'.
33+
34+
Returns:
35+
fig (Figure): A matplotlib.pyplot.Figure object for the created plot.
36+
37+
"""
38+
39+
return comp.make_plot(stns, start, end, params, x_inch)
40+
41+
42+
def make_sst_climatology_plot(
43+
stn: str, x_inch: int = None, y_inch: int = None
44+
) -> Figure:
45+
"""
46+
Create a plot of yearly climatology of sea surface temperature at a station for all years of available data.
47+
48+
Args:
49+
stn (str): A 5-char station identifier, e.g. '100p1'.
50+
51+
Returns:
52+
fig (Figure): A matplotlib.pyplot.Figure object for the created plot.
53+
"""
54+
55+
return sst.make_plot(stn, x_inch, y_inch)

docs/api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
::: cdippy.ndbc
1313

1414

15+
::: cdippy.plotting
16+
17+
1518
::: cdippy.spectra
1619

1720

0 commit comments

Comments
 (0)