noaaplotter 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. noaaplotter-1.0.0/LICENSE +21 -0
  2. noaaplotter-1.0.0/PKG-INFO +220 -0
  3. noaaplotter-1.0.0/README.md +180 -0
  4. noaaplotter-1.0.0/noaaplotter/__init__.py +20 -0
  5. noaaplotter-1.0.0/noaaplotter/__main__.py +8 -0
  6. noaaplotter-1.0.0/noaaplotter/cli/__init__.py +186 -0
  7. noaaplotter-1.0.0/noaaplotter/figures/__init__.py +5 -0
  8. noaaplotter-1.0.0/noaaplotter/figures/plotly_daily.py +258 -0
  9. noaaplotter-1.0.0/noaaplotter/figures/plotly_monthly.py +51 -0
  10. noaaplotter-1.0.0/noaaplotter/noaaplotter.py +726 -0
  11. noaaplotter-1.0.0/noaaplotter/scripts/download_data.py +150 -0
  12. noaaplotter-1.0.0/noaaplotter/scripts/plot_daily.py +108 -0
  13. noaaplotter-1.0.0/noaaplotter/scripts/plot_monthly.py +72 -0
  14. noaaplotter-1.0.0/noaaplotter/sources/__init__.py +17 -0
  15. noaaplotter-1.0.0/noaaplotter/sources/base.py +97 -0
  16. noaaplotter-1.0.0/noaaplotter/sources/cds.py +168 -0
  17. noaaplotter-1.0.0/noaaplotter/sources/open_meteo.py +108 -0
  18. noaaplotter-1.0.0/noaaplotter/utils/__init__.py +0 -0
  19. noaaplotter-1.0.0/noaaplotter/utils/config.py +30 -0
  20. noaaplotter-1.0.0/noaaplotter/utils/dataset.py +418 -0
  21. noaaplotter-1.0.0/noaaplotter/utils/download_utils.py +232 -0
  22. noaaplotter-1.0.0/noaaplotter/utils/plot_utils.py +49 -0
  23. noaaplotter-1.0.0/noaaplotter/utils/utils.py +110 -0
  24. noaaplotter-1.0.0/noaaplotter.egg-info/PKG-INFO +220 -0
  25. noaaplotter-1.0.0/noaaplotter.egg-info/SOURCES.txt +31 -0
  26. noaaplotter-1.0.0/noaaplotter.egg-info/dependency_links.txt +1 -0
  27. noaaplotter-1.0.0/noaaplotter.egg-info/entry_points.txt +5 -0
  28. noaaplotter-1.0.0/noaaplotter.egg-info/requires.txt +18 -0
  29. noaaplotter-1.0.0/noaaplotter.egg-info/top_level.txt +1 -0
  30. noaaplotter-1.0.0/pyproject.toml +61 -0
  31. noaaplotter-1.0.0/setup.cfg +4 -0
  32. noaaplotter-1.0.0/tests/test_plotly_figures.py +210 -0
  33. noaaplotter-1.0.0/tests/test_polars_parity.py +107 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ingmar Nitze
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,220 @@
1
+ Metadata-Version: 2.4
2
+ Name: noaaplotter
3
+ Version: 1.0.0
4
+ Summary: Package to plot fancy climate/weather data of NOAA
5
+ Author-email: Ingmar Nitze <ingmar.nitze@awi.de>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/initze/noaaplotter
8
+ Project-URL: Repository, https://github.com/initze/noaaplotter
9
+ Project-URL: Issues, https://github.com/initze/noaaplotter/issues
10
+ Project-URL: Documentation, https://initze.github.io/noaaplotter
11
+ Keywords: climate,weather,NOAA,plotting
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
18
+ Classifier: Intended Audience :: Science/Research
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: pandas>=2.2
23
+ Requires-Dist: numpy<3,>=2
24
+ Requires-Dist: matplotlib>=3.9
25
+ Requires-Dist: requests
26
+ Requires-Dist: joblib>=1.4
27
+ Requires-Dist: tqdm>=4.67
28
+ Requires-Dist: polars>=1.18.0
29
+ Requires-Dist: pyarrow>=18.1.0
30
+ Requires-Dist: python-dotenv>=1.0.1
31
+ Requires-Dist: plotly>=5.18
32
+ Requires-Dist: narwhals>=1.20.1
33
+ Requires-Dist: cdsapi>=0.7
34
+ Requires-Dist: typer>=0.9.0
35
+ Provides-Extra: docs
36
+ Requires-Dist: mkdocs>=1.6; extra == "docs"
37
+ Requires-Dist: mkdocs-material>=9.5; extra == "docs"
38
+ Requires-Dist: mkdocstrings[python]>=1.0; extra == "docs"
39
+ Dynamic: license-file
40
+
41
+ # noaaplotter
42
+ A python package to create fancy plots with NOAA weather data (stations) and ERA5 reanalysis (by coordinates).
43
+
44
+ > 📚 **Docs & API reference:** [initze.github.io/noaaplotter](https://initze.github.io/noaaplotter)
45
+ >
46
+ > **Install:** `pip install noaaplotter`
47
+
48
+ ## Install
49
+
50
+ ### PyPI (recommended for end users)
51
+ ```bash
52
+ pip install noaaplotter
53
+ ```
54
+
55
+ ### From source (development)
56
+ ```bash
57
+ uv venv
58
+ uv pip install -e . # install this package + all dependencies
59
+ # or from GitHub:
60
+ uv pip install git+https://github.com/initze/noaaplotter.git
61
+ ```
62
+
63
+ ### Requirements
64
+ matplotlib, numpy, pandas, requests, joblib, tqdm, polars, pyarrow, plotly,
65
+ python-dotenv, typer (all listed in `pyproject.toml` and installed automatically).
66
+
67
+ ## Quick start (3 steps)
68
+
69
+ ```bash
70
+ # 1. Download data (no token needed — NOAA data comes from the public
71
+ # NCEI Access Data Service)
72
+ noaaplotter download-data -o data/kotzebue.parquet -sid USW00026616 -start 1970-01-01 -end 2021-12-31
73
+
74
+ # 2. Create a daily plot (temperature vs. climate + precipitation, incl. 7-day rolling sum)
75
+ noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 -t_range -45 25 -p_range 50 -save_plot figures/kotzebue_1992.png
76
+
77
+ # 3. ...or an interactive HTML plot
78
+ noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 --engine plotly -save_plot figures/kotzebue_1992.html
79
+ ```
80
+
81
+ ## Command Line Interface (CLI)
82
+
83
+ Unified command line interface: `noaaplotter <command> [OPTIONS]`.
84
+ Every command supports `-h` / `--help` for detailed usage.
85
+
86
+ ### `noaaplotter download-data`
87
+ Download weather data to a parquet file.
88
+
89
+ ```bash
90
+ # NOAA station (no token needed — public NCEI service)
91
+ noaaplotter download-data -o data/kotzebue.parquet -sid USW00026616 -start 1970-01-01 -end 2021-12-31
92
+
93
+ # ERA5 reanalysis by coordinates (open_meteo, no token needed)
94
+ noaaplotter download-data -o data/potsdam.parquet --source open_meteo -lat 52.4 -lon 13.05 -start 1980-01-01 -end 2021-12-31
95
+ ```
96
+
97
+ | Option | Meaning |
98
+ |---|---|
99
+ | `-o` / `--output-file` | output parquet file (required) |
100
+ | `-sid` / `--station-id` | NOAA station id, e.g. `USW00026616` (Kotzebue) |
101
+ | `-lat`, `-lon` | coordinates for `--source open_meteo` / `cds` |
102
+ | `-start`, `-end` | start / end date, `YYYY-MM-DD` |
103
+ | `-t` / `--token` | NOAA token (optional; the public endpoint needs none). Defaults to `NOAA_API_TOKEN` env / `.env` if set |
104
+ | `--source` | `noaa` (default), `open_meteo`, `cds` |
105
+ | `--datatypes` | `TMIN,TMAX,PRCP,SNOW` (NOAA only) |
106
+ | `-n_jobs` | parallel processes (NOAA only) |
107
+ | `-loc` | location name for the output file |
108
+
109
+ Data files are cached: re-running only fetches the missing dates.
110
+
111
+ ### `noaaplotter plot-daily`
112
+ Daily temperature (observed vs. climate mean ± 1σ, with anomaly fills) + precipitation (bars + 7-day rolling sum).
113
+
114
+ ```bash
115
+ noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 -t_range -45 25 -p_range 50 -save_plot figures/kotzebue_1992.png
116
+ noaaplotter plot-daily -infile data/kotzebue.parquet -start 2017-07-01 -end 2018-06-30 --snow_acc --engine plotly -save_plot figures/kotzebue_winter.html
117
+ ```
118
+
119
+ | Option | Meaning |
120
+ |---|---|
121
+ | `-infile` | input parquet/csv (required) |
122
+ | `-start`, `-end` | plot window, `YYYY-MM-DD` (end date may be in the future; the plot just stops at the last available data) |
123
+ | `-t_range` | temperature range `min max`, e.g. `-45 25` |
124
+ | `-p_range` | max precipitation value (mm) |
125
+ | `-s_range` | max snow accumulation (cm) |
126
+ | `--snow_acc` | show cumulative snowfall (winter season) |
127
+ | `-filtersize` | climate smoothing window in days (default 7) |
128
+ | `-figsize` | figure size in inches `width height` |
129
+ | `-title` | plot title |
130
+ | `-save_plot` | write the plot (`.png` for matplotlib, `.html` for plotly) |
131
+ | `--plot` | open in a browser/GUI |
132
+ | `--engine` | `matplotlib` (default) or `plotly` |
133
+ | `--full-series` | plotly only: include the entire observed record in the HTML plot — the view still opens on the selected period (default: plot only the selected period, smaller file) |
134
+
135
+ ### `noaaplotter plot-monthly`
136
+ Monthly bar chart of temperature or precipitation, with anomaly and trailing mean.
137
+
138
+ ```bash
139
+ # Absolute values
140
+ noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Temperature -trail 12 -save_plot figures/kotzebue_t.png
141
+
142
+ # Anomaly from climate (1981-2010)
143
+ noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Precipitation -trail 12 -anomaly -save_plot figures/kotzebue_p_anomaly.png
144
+ ```
145
+
146
+ | Option | Meaning |
147
+ |---|---|
148
+ | `-infile` | input parquet/csv (required) |
149
+ | `-start`, `-end` | plot window, `YYYY-MM-DD` |
150
+ | `-type` | `Temperature` (default) or `Precipitation` |
151
+ | `-trail` | trailing/rolling mean in months, e.g. `12` |
152
+ | `-anomaly` | show anomaly from the climate baseline |
153
+ | `-save_plot` | write the plot (`.png` / `.html`) |
154
+ | `--engine` | `matplotlib` (default) or `plotly` |
155
+
156
+ ## Examples
157
+
158
+ ### Download data
159
+ **Option 1 — NOAA Daily Summaries via CLI** (Kotzebue, 1970-2021)
160
+ * No token required — served by the public NCEI Access Data Service.
161
+
162
+ `noaaplotter download-data -o data/kotzebue.parquet -sid USW00026616 -start 1970-01-01 -end 2021-12-31`
163
+
164
+ **Option 2 — NOAA Daily Summaries via browser**
165
+ CSV files of "daily summaries" (https://www.ncdc.noaa.gov/cdo-web/search),
166
+ values: metric, file type: csv.
167
+
168
+ **Option 3 — ERA5 via CLI** (Potsdam, 13.05°E / 52.4°N, 1980-2021 — no token)
169
+ `noaaplotter download-data -o data/potsdam.parquet --source open_meteo -lat 52.4 -lon 13.05 -start 1980-01-01 -end 2021-12-31`
170
+
171
+ ### Daily Mean Temperature and Precipitation vs. Climate
172
+ Entire year 1 January until 31 December (e.g. 1992):
173
+
174
+ `noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 -t_range -45 25 -p_range 50 -save_plot figures/kotzebue_daily_1992.png`
175
+
176
+ ![Kotzebue daily 1992 — temperature (top) vs. climate ±1σ, precipitation (bottom) with 7-day rolling sum](figures/kotzebue_daily_1992.png)
177
+
178
+ ### Monthly aggregates
179
+ Temperature, absolute (12-month trailing mean):
180
+
181
+ `noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Temperature -trail 12 -save_plot figures/kotzebue_monthly_t.png`
182
+
183
+ ![Kotzebue monthly temperature](figures/kotzebue_monthly_t.png)
184
+
185
+ Temperature, anomaly from climate (1981-2010):
186
+
187
+ `noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Temperature -trail 12 -anomaly -save_plot figures/kotzebue_monthly_t_anomaly.png`
188
+
189
+ ![Kotzebue monthly temperature anomaly](figures/kotzebue_monthly_t_anomaly.png)
190
+
191
+ Precipitation, absolute (12-month trailing mean):
192
+
193
+ `noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Precipitation -trail 12 -save_plot figures/kotzebue_monthly_p.png`
194
+
195
+ ![Kotzebue monthly precipitation](figures/kotzebue_monthly_p.png)
196
+
197
+ ## Advanced Usage
198
+
199
+ ### Get help for any command
200
+ ```bash
201
+ noaaplotter --help
202
+ noaaplotter download-data --help
203
+ noaaplotter plot-daily --help
204
+ noaaplotter plot-monthly --help
205
+ ```
206
+
207
+ ### Interactive (plotly) plots
208
+ Use `--engine plotly` and save to `.html` to get interactive plots
209
+ (zoom, hover, range slider). Daily plots also show a 7-day rolling sum of precipitation.
210
+
211
+ ### Python API
212
+ The package is a normal Python library as well:
213
+ ```python
214
+ from noaaplotter import NOAAPlotter
215
+
216
+ n = NOAAPlotter("data/kotzebue.parquet", location="Kotzebue", climate_filtersize=7)
217
+ fig = n.plot_weather_series(start_date="1992-01-01", end_date="1992-12-31",
218
+ show_plot=False, return_plot=True, engine="plotly")
219
+ fig.write_html("figures/kotzebue_1992.html")
220
+ ```
@@ -0,0 +1,180 @@
1
+ # noaaplotter
2
+ A python package to create fancy plots with NOAA weather data (stations) and ERA5 reanalysis (by coordinates).
3
+
4
+ > 📚 **Docs & API reference:** [initze.github.io/noaaplotter](https://initze.github.io/noaaplotter)
5
+ >
6
+ > **Install:** `pip install noaaplotter`
7
+
8
+ ## Install
9
+
10
+ ### PyPI (recommended for end users)
11
+ ```bash
12
+ pip install noaaplotter
13
+ ```
14
+
15
+ ### From source (development)
16
+ ```bash
17
+ uv venv
18
+ uv pip install -e . # install this package + all dependencies
19
+ # or from GitHub:
20
+ uv pip install git+https://github.com/initze/noaaplotter.git
21
+ ```
22
+
23
+ ### Requirements
24
+ matplotlib, numpy, pandas, requests, joblib, tqdm, polars, pyarrow, plotly,
25
+ python-dotenv, typer (all listed in `pyproject.toml` and installed automatically).
26
+
27
+ ## Quick start (3 steps)
28
+
29
+ ```bash
30
+ # 1. Download data (no token needed — NOAA data comes from the public
31
+ # NCEI Access Data Service)
32
+ noaaplotter download-data -o data/kotzebue.parquet -sid USW00026616 -start 1970-01-01 -end 2021-12-31
33
+
34
+ # 2. Create a daily plot (temperature vs. climate + precipitation, incl. 7-day rolling sum)
35
+ noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 -t_range -45 25 -p_range 50 -save_plot figures/kotzebue_1992.png
36
+
37
+ # 3. ...or an interactive HTML plot
38
+ noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 --engine plotly -save_plot figures/kotzebue_1992.html
39
+ ```
40
+
41
+ ## Command Line Interface (CLI)
42
+
43
+ Unified command line interface: `noaaplotter <command> [OPTIONS]`.
44
+ Every command supports `-h` / `--help` for detailed usage.
45
+
46
+ ### `noaaplotter download-data`
47
+ Download weather data to a parquet file.
48
+
49
+ ```bash
50
+ # NOAA station (no token needed — public NCEI service)
51
+ noaaplotter download-data -o data/kotzebue.parquet -sid USW00026616 -start 1970-01-01 -end 2021-12-31
52
+
53
+ # ERA5 reanalysis by coordinates (open_meteo, no token needed)
54
+ noaaplotter download-data -o data/potsdam.parquet --source open_meteo -lat 52.4 -lon 13.05 -start 1980-01-01 -end 2021-12-31
55
+ ```
56
+
57
+ | Option | Meaning |
58
+ |---|---|
59
+ | `-o` / `--output-file` | output parquet file (required) |
60
+ | `-sid` / `--station-id` | NOAA station id, e.g. `USW00026616` (Kotzebue) |
61
+ | `-lat`, `-lon` | coordinates for `--source open_meteo` / `cds` |
62
+ | `-start`, `-end` | start / end date, `YYYY-MM-DD` |
63
+ | `-t` / `--token` | NOAA token (optional; the public endpoint needs none). Defaults to `NOAA_API_TOKEN` env / `.env` if set |
64
+ | `--source` | `noaa` (default), `open_meteo`, `cds` |
65
+ | `--datatypes` | `TMIN,TMAX,PRCP,SNOW` (NOAA only) |
66
+ | `-n_jobs` | parallel processes (NOAA only) |
67
+ | `-loc` | location name for the output file |
68
+
69
+ Data files are cached: re-running only fetches the missing dates.
70
+
71
+ ### `noaaplotter plot-daily`
72
+ Daily temperature (observed vs. climate mean ± 1σ, with anomaly fills) + precipitation (bars + 7-day rolling sum).
73
+
74
+ ```bash
75
+ noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 -t_range -45 25 -p_range 50 -save_plot figures/kotzebue_1992.png
76
+ noaaplotter plot-daily -infile data/kotzebue.parquet -start 2017-07-01 -end 2018-06-30 --snow_acc --engine plotly -save_plot figures/kotzebue_winter.html
77
+ ```
78
+
79
+ | Option | Meaning |
80
+ |---|---|
81
+ | `-infile` | input parquet/csv (required) |
82
+ | `-start`, `-end` | plot window, `YYYY-MM-DD` (end date may be in the future; the plot just stops at the last available data) |
83
+ | `-t_range` | temperature range `min max`, e.g. `-45 25` |
84
+ | `-p_range` | max precipitation value (mm) |
85
+ | `-s_range` | max snow accumulation (cm) |
86
+ | `--snow_acc` | show cumulative snowfall (winter season) |
87
+ | `-filtersize` | climate smoothing window in days (default 7) |
88
+ | `-figsize` | figure size in inches `width height` |
89
+ | `-title` | plot title |
90
+ | `-save_plot` | write the plot (`.png` for matplotlib, `.html` for plotly) |
91
+ | `--plot` | open in a browser/GUI |
92
+ | `--engine` | `matplotlib` (default) or `plotly` |
93
+ | `--full-series` | plotly only: include the entire observed record in the HTML plot — the view still opens on the selected period (default: plot only the selected period, smaller file) |
94
+
95
+ ### `noaaplotter plot-monthly`
96
+ Monthly bar chart of temperature or precipitation, with anomaly and trailing mean.
97
+
98
+ ```bash
99
+ # Absolute values
100
+ noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Temperature -trail 12 -save_plot figures/kotzebue_t.png
101
+
102
+ # Anomaly from climate (1981-2010)
103
+ noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Precipitation -trail 12 -anomaly -save_plot figures/kotzebue_p_anomaly.png
104
+ ```
105
+
106
+ | Option | Meaning |
107
+ |---|---|
108
+ | `-infile` | input parquet/csv (required) |
109
+ | `-start`, `-end` | plot window, `YYYY-MM-DD` |
110
+ | `-type` | `Temperature` (default) or `Precipitation` |
111
+ | `-trail` | trailing/rolling mean in months, e.g. `12` |
112
+ | `-anomaly` | show anomaly from the climate baseline |
113
+ | `-save_plot` | write the plot (`.png` / `.html`) |
114
+ | `--engine` | `matplotlib` (default) or `plotly` |
115
+
116
+ ## Examples
117
+
118
+ ### Download data
119
+ **Option 1 — NOAA Daily Summaries via CLI** (Kotzebue, 1970-2021)
120
+ * No token required — served by the public NCEI Access Data Service.
121
+
122
+ `noaaplotter download-data -o data/kotzebue.parquet -sid USW00026616 -start 1970-01-01 -end 2021-12-31`
123
+
124
+ **Option 2 — NOAA Daily Summaries via browser**
125
+ CSV files of "daily summaries" (https://www.ncdc.noaa.gov/cdo-web/search),
126
+ values: metric, file type: csv.
127
+
128
+ **Option 3 — ERA5 via CLI** (Potsdam, 13.05°E / 52.4°N, 1980-2021 — no token)
129
+ `noaaplotter download-data -o data/potsdam.parquet --source open_meteo -lat 52.4 -lon 13.05 -start 1980-01-01 -end 2021-12-31`
130
+
131
+ ### Daily Mean Temperature and Precipitation vs. Climate
132
+ Entire year 1 January until 31 December (e.g. 1992):
133
+
134
+ `noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 -t_range -45 25 -p_range 50 -save_plot figures/kotzebue_daily_1992.png`
135
+
136
+ ![Kotzebue daily 1992 — temperature (top) vs. climate ±1σ, precipitation (bottom) with 7-day rolling sum](figures/kotzebue_daily_1992.png)
137
+
138
+ ### Monthly aggregates
139
+ Temperature, absolute (12-month trailing mean):
140
+
141
+ `noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Temperature -trail 12 -save_plot figures/kotzebue_monthly_t.png`
142
+
143
+ ![Kotzebue monthly temperature](figures/kotzebue_monthly_t.png)
144
+
145
+ Temperature, anomaly from climate (1981-2010):
146
+
147
+ `noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Temperature -trail 12 -anomaly -save_plot figures/kotzebue_monthly_t_anomaly.png`
148
+
149
+ ![Kotzebue monthly temperature anomaly](figures/kotzebue_monthly_t_anomaly.png)
150
+
151
+ Precipitation, absolute (12-month trailing mean):
152
+
153
+ `noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Precipitation -trail 12 -save_plot figures/kotzebue_monthly_p.png`
154
+
155
+ ![Kotzebue monthly precipitation](figures/kotzebue_monthly_p.png)
156
+
157
+ ## Advanced Usage
158
+
159
+ ### Get help for any command
160
+ ```bash
161
+ noaaplotter --help
162
+ noaaplotter download-data --help
163
+ noaaplotter plot-daily --help
164
+ noaaplotter plot-monthly --help
165
+ ```
166
+
167
+ ### Interactive (plotly) plots
168
+ Use `--engine plotly` and save to `.html` to get interactive plots
169
+ (zoom, hover, range slider). Daily plots also show a 7-day rolling sum of precipitation.
170
+
171
+ ### Python API
172
+ The package is a normal Python library as well:
173
+ ```python
174
+ from noaaplotter import NOAAPlotter
175
+
176
+ n = NOAAPlotter("data/kotzebue.parquet", location="Kotzebue", climate_filtersize=7)
177
+ fig = n.plot_weather_series(start_date="1992-01-01", end_date="1992-12-31",
178
+ show_plot=False, return_plot=True, engine="plotly")
179
+ fig.write_html("figures/kotzebue_1992.html")
180
+ ```
@@ -0,0 +1,20 @@
1
+ """noaaplotter — plot NOAA / reanalysis weather data.
2
+
3
+ Public API:
4
+ from noaaplotter import NOAAPlotter
5
+
6
+ See the documentation for the full API reference and CLI reference.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from importlib.metadata import PackageNotFoundError, version
12
+
13
+ from noaaplotter.noaaplotter import NOAAPlotter
14
+
15
+ __all__ = ["NOAAPlotter", "__version__"]
16
+
17
+ try:
18
+ __version__ = version("noaaplotter")
19
+ except PackageNotFoundError: # installed without metadata (e.g. source checkout)
20
+ __version__ = "unknown"
@@ -0,0 +1,8 @@
1
+ """
2
+ Main module to make noaaplotter directly executable.
3
+ """
4
+
5
+ from noaaplotter.cli import app
6
+
7
+ if __name__ == "__main__":
8
+ app()
@@ -0,0 +1,186 @@
1
+ """
2
+ CLI Commands for noaaplotter
3
+ """
4
+
5
+ import typer
6
+ from typing import Optional, Tuple
7
+
8
+ # Import the core functionality
9
+ from noaaplotter.utils.config import get_noaa_token
10
+ from noaaplotter.utils.download_utils import download_from_noaa
11
+ from noaaplotter.noaaplotter import NOAAPlotter
12
+ from noaaplotter.sources import get_source
13
+ from noaaplotter.sources.open_meteo import save_to_parquet
14
+
15
+ # Create Typer app instance for commands
16
+ app = typer.Typer(no_args_is_help=True)
17
+
18
+
19
+ @app.command("download-data")
20
+ def download_data(
21
+ output_file: str = typer.Option(..., "-o", "--output-file", help="Output file path (parquet)"),
22
+ station_id: Optional[str] = typer.Option(None, "-sid", "--station-id", help='NOAA station id, e.g. "USW00026616" (Kotzebue)'),
23
+ latitude: Optional[float] = typer.Option(None, "-lat", "--latitude", help="Latitude for coordinate-based sources (required for open_meteo/cds)"),
24
+ longitude: Optional[float] = typer.Option(None, "-lon", "--longitude", help="Longitude for coordinate-based sources (required for open_meteo/cds)"),
25
+ start_date: str = typer.Option(..., "-start", "--start-date", help="Start date (YYYY-MM-DD)"),
26
+ end_date: str = typer.Option(..., "-end", "--end-date", help="End date (YYYY-MM-DD)"),
27
+ token: Optional[str] = typer.Option(None, "-t", "--token", help="NOAA token (optional; the public NCEI endpoint needs none). Defaults to NOAA_API_TOKEN from environment or .env if set"),
28
+ source: str = typer.Option("noaa", "--source", help="Data source: noaa, open_meteo, or cds"),
29
+ datatypes: str = typer.Option("TMIN,TMAX,PRCP,SNOW", "--datatypes", help="Comma-separated datatypes (NOAA only)"),
30
+ n_jobs: int = typer.Option(1, "-n_jobs", "--n-jobs", help="Number of parallel processes (NOAA only)"),
31
+ loc_name: Optional[str] = typer.Option(None, "-loc", "--location-name", help="Location name for the output"),
32
+ ):
33
+ """Download weather data (NOAA station or reanalysis by coordinates).
34
+
35
+ NOAA station: noaaplotter download-data -o data/kotzebue.parquet -sid USW00026616 -start 1970-01-01 -end 2021-12-31
36
+ ERA5 (open_meteo): noaaplotter download-data -o data/potsdam.parquet --source open_meteo -lat 52.4 -lon 13.05 -start 1980-01-01 -end 2021-12-31
37
+ """
38
+ src = source.lower()
39
+
40
+ if src in ("open_meteo", "cds"):
41
+ if latitude is None or longitude is None:
42
+ raise typer.BadParameter(f"--source {src} requires both -lat and -lon")
43
+ name = loc_name or f"{latitude:.2f},{longitude:.2f}"
44
+ df = get_source(src)(
45
+ latitude=latitude,
46
+ longitude=longitude,
47
+ start=start_date,
48
+ end=end_date,
49
+ name=name,
50
+ )
51
+ save_to_parquet(df, output_file)
52
+ typer.echo(f"Saved {df.shape[0]} rows ({name}) to {output_file}")
53
+ return
54
+
55
+ # NOAA path (default)
56
+ if not station_id:
57
+ raise typer.BadParameter("NOAA data requires -sid (station id)")
58
+
59
+ # token is optional: the NCEI service endpoint this hits is public. It is
60
+ # only forwarded if the user has one set (legacy/defensive), and a
61
+ # DeprecationWarning is raised if so.
62
+ api_token = get_noaa_token(token)
63
+
64
+ datatypes_list = [dt.strip() for dt in datatypes.split(",") if dt.strip()]
65
+
66
+ download_from_noaa(
67
+ output_file=output_file,
68
+ start_date=start_date,
69
+ end_date=end_date,
70
+ datatypes=datatypes_list,
71
+ noaa_api_token=api_token,
72
+ loc_name=loc_name,
73
+ station_id=station_id,
74
+ n_jobs=n_jobs,
75
+ )
76
+ typer.echo(f"Downloaded data for {station_id} ({start_date} .. {end_date}) to {output_file}")
77
+
78
+
79
+ def _report(save_path, show_plot, engine):
80
+ if save_path:
81
+ typer.echo(f"Plot written to {save_path}")
82
+ elif show_plot:
83
+ typer.echo("Plot displayed (in-browser / GUI)")
84
+ else:
85
+ if engine == "plotly":
86
+ typer.echo("Figure created in memory - add -save_plot <x.html> to write it out")
87
+ else:
88
+ typer.echo("Figure created in memory - add -save_plot <x.png> to write it out")
89
+
90
+
91
+ @app.command("plot-daily")
92
+ def plot_daily(
93
+ infile: str = typer.Option(..., "-infile", "--input-file", help="Input file (parquet/csv) with climate data"),
94
+ start_date: str = typer.Option(..., "-start", "--start-date", help="Start date of plot (YYYY-MM-DD)"),
95
+ end_date: str = typer.Option(..., "-end", "--end-date", help="End date of plot (YYYY-MM-DD)"),
96
+ location: Optional[str] = typer.Option(None, "-loc", "--location", help="Location name, must be in data file"),
97
+ save_path: Optional[str] = typer.Option(None, "-save_plot", "--save-plot", help="File path for the plot (png, or html with --engine plotly)"),
98
+ t_range: Optional[Tuple[float, float]] = typer.Option(None, "-t_range", "--temperature-range", help="Temperature range (min, max), e.g. -45 25"),
99
+ p_range: Optional[float] = typer.Option(None, "-p_range", "--precipitation-range", help="Maximum precipitation value in the plot"),
100
+ s_range: Optional[float] = typer.Option(None, "-s_range", "--snow-range", help="Maximum snow accumulation value in the plot"),
101
+ snow_acc: bool = typer.Option(False, "--snow_acc", "--snow-accumulation", help="Show snow accumulation (useful for the winter season, e.g. July to June)"),
102
+ filtersize: int = typer.Option(7, "-filtersize", help="Smooth the climate temperature series by n days (default 7)"),
103
+ dpi: float = typer.Option(300.0, "--dpi", help="DPI for plot output (print quality; matches the Python API default)"),
104
+ show_plot: bool = typer.Option(False, "--plot", "--show-plot", help="Open the plot in a browser/GUI"),
105
+ figsize: Optional[Tuple[float, float]] = typer.Option(None, "-figsize", help="Figure size in inches, width height (e.g. 15 10 for 2 years)"),
106
+ title: Optional[str] = typer.Option(None, "-title", help="Plot title"),
107
+ engine: str = typer.Option("matplotlib", "--engine", help="Rendering engine: matplotlib (static) or plotly (interactive HTML)"),
108
+ full_series: bool = typer.Option(False, "--full-series", help="plotly only: include the ENTIRE observed record in the interactive plot; the initial view is still limited to the requested period (default: plot only the requested period, lightweight)"),
109
+ ):
110
+ """Create a daily temperature/precipitation plot vs. climate.
111
+
112
+ Example: noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 -t_range -45 25 -p_range 50 -save_plot figures/kotzebue_1992.png
113
+ """
114
+ tmin, tmax = ("auto", "auto") if t_range is None else t_range
115
+ fsize = figsize if figsize is not None else (9, 6)
116
+
117
+ if engine not in ("matplotlib", "plotly"):
118
+ raise typer.BadParameter("engine must be 'matplotlib' or 'plotly'")
119
+ if not infile:
120
+ raise typer.BadParameter("-infile is required")
121
+
122
+ n = NOAAPlotter(infile, location=location, climate_filtersize=filtersize)
123
+
124
+ n.plot_weather_series(
125
+ start_date=start_date,
126
+ end_date=end_date,
127
+ show_snow_accumulation=snow_acc,
128
+ plot_extrema=True,
129
+ show_plot=show_plot,
130
+ save_path=save_path or False,
131
+ plot_tmin=tmin,
132
+ plot_tmax=tmax,
133
+ plot_pmax=p_range,
134
+ plot_snowmax=s_range,
135
+ dpi=dpi,
136
+ figsize=fsize,
137
+ title=title,
138
+ engine=engine,
139
+ full_series=full_series,
140
+ )
141
+ _report(save_path, show_plot, engine)
142
+
143
+
144
+ @app.command("plot-monthly")
145
+ def plot_monthly(
146
+ infile: str = typer.Option(..., "-infile", "--input-file", help="Input file (parquet/csv) with climate data"),
147
+ start_date: str = typer.Option(..., "-start", "--start-date", help="Start date of plot (YYYY-MM-DD)"),
148
+ end_date: str = typer.Option(..., "-end", "--end-date", help="End date of plot (YYYY-MM-DD)"),
149
+ location: Optional[str] = typer.Option(None, "-loc", "--location", help="Location name, must be in data file"),
150
+ save_path: Optional[str] = typer.Option(None, "-save_plot", "--save-plot", help="File path for the plot (png, or html with --engine plotly)"),
151
+ information: str = typer.Option("Temperature", "-type", "--information", help="Attribute type: Temperature or Precipitation"),
152
+ trailing_mean: Optional[int] = typer.Option(None, "-trail", "--trailing-mean", help="Trailing/rolling mean in months (e.g. 12)"),
153
+ anomaly: bool = typer.Option(False, "-anomaly", help="Show anomaly from climate baseline"),
154
+ dpi: float = typer.Option(300.0, "--dpi", help="DPI for plot output (print quality; matches the Python API default)"),
155
+ show_plot: bool = typer.Option(False, "--plot", "--show-plot", help="Open the plot in a browser/GUI"),
156
+ figsize: Optional[Tuple[float, float]] = typer.Option(None, "-figsize", help="Figure size in inches, width height"),
157
+ engine: str = typer.Option("matplotlib", "--engine", help="Rendering engine: matplotlib (static) or plotly (interactive HTML)"),
158
+ ):
159
+ """Create a monthly temperature/precipitation bar chart.
160
+
161
+ Example: noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-12-31 -type Temperature -trail 12 -anomaly -save_plot figures/kotzebue_t_anomaly.png
162
+ """
163
+ if engine not in ("matplotlib", "plotly"):
164
+ raise typer.BadParameter("engine must be 'matplotlib' or 'plotly'")
165
+ if information not in ("Temperature", "Precipitation"):
166
+ raise typer.BadParameter("-type must be 'Temperature' or 'Precipitation'")
167
+ if not infile:
168
+ raise typer.BadParameter("-infile is required")
169
+
170
+ fsize = figsize if figsize is not None else (9, 4)
171
+
172
+ n = NOAAPlotter(infile, location=location)
173
+
174
+ n.plot_monthly_barchart(
175
+ start_date=start_date,
176
+ end_date=end_date,
177
+ information=information,
178
+ anomaly=anomaly,
179
+ trailing_mean=trailing_mean,
180
+ show_plot=show_plot,
181
+ dpi=dpi,
182
+ figsize=fsize,
183
+ save_path=save_path or False,
184
+ engine=engine,
185
+ )
186
+ _report(save_path, show_plot, engine)
@@ -0,0 +1,5 @@
1
+ """Plotly figure builders — interactive versions of the matplotlib plots."""
2
+ from .plotly_daily import make_daily_figure
3
+ from .plotly_monthly import make_monthly_figure
4
+
5
+ __all__ = ["make_daily_figure", "make_monthly_figure"]