noaaplotter 1.0.0__tar.gz → 1.1.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.
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/PKG-INFO +78 -2
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/README.md +74 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/cli/__init__.py +187 -1
- noaaplotter-1.1.0/noaaplotter/figures/__init__.py +12 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/figures/plotly_daily.py +137 -17
- noaaplotter-1.1.0/noaaplotter/figures/plotly_heatmap.py +91 -0
- noaaplotter-1.1.0/noaaplotter/figures/plotly_stripes.py +107 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/noaaplotter.py +621 -14
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/sources/base.py +6 -0
- noaaplotter-1.1.0/noaaplotter/sources/cds.py +342 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/sources/open_meteo.py +43 -8
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/utils/dataset.py +8 -4
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter.egg-info/PKG-INFO +78 -2
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter.egg-info/SOURCES.txt +3 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter.egg-info/requires.txt +3 -1
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/pyproject.toml +7 -2
- noaaplotter-1.1.0/tests/test_cds_source.py +194 -0
- noaaplotter-1.1.0/tests/test_plotly_figures.py +565 -0
- noaaplotter-1.0.0/noaaplotter/figures/__init__.py +0 -5
- noaaplotter-1.0.0/noaaplotter/sources/cds.py +0 -168
- noaaplotter-1.0.0/tests/test_plotly_figures.py +0 -210
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/LICENSE +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/__init__.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/__main__.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/figures/plotly_monthly.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/scripts/download_data.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/scripts/plot_daily.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/scripts/plot_monthly.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/sources/__init__.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/utils/__init__.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/utils/config.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/utils/download_utils.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/utils/plot_utils.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter/utils/utils.py +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter.egg-info/dependency_links.txt +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter.egg-info/entry_points.txt +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/noaaplotter.egg-info/top_level.txt +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/setup.cfg +0 -0
- {noaaplotter-1.0.0 → noaaplotter-1.1.0}/tests/test_polars_parity.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: noaaplotter
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Package to plot fancy climate/weather data of NOAA
|
|
5
5
|
Author-email: Ingmar Nitze <ingmar.nitze@awi.de>
|
|
6
6
|
License: MIT
|
|
@@ -20,7 +20,7 @@ Requires-Python: >=3.11
|
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
21
|
License-File: LICENSE
|
|
22
22
|
Requires-Dist: pandas>=2.2
|
|
23
|
-
Requires-Dist: numpy<3,>=
|
|
23
|
+
Requires-Dist: numpy<3,>=1.26
|
|
24
24
|
Requires-Dist: matplotlib>=3.9
|
|
25
25
|
Requires-Dist: requests
|
|
26
26
|
Requires-Dist: joblib>=1.4
|
|
@@ -31,6 +31,8 @@ Requires-Dist: python-dotenv>=1.0.1
|
|
|
31
31
|
Requires-Dist: plotly>=5.18
|
|
32
32
|
Requires-Dist: narwhals>=1.20.1
|
|
33
33
|
Requires-Dist: cdsapi>=0.7
|
|
34
|
+
Requires-Dist: xarray>=2024.02
|
|
35
|
+
Requires-Dist: netCDF4>=1.6
|
|
34
36
|
Requires-Dist: typer>=0.9.0
|
|
35
37
|
Provides-Extra: docs
|
|
36
38
|
Requires-Dist: mkdocs>=1.6; extra == "docs"
|
|
@@ -41,6 +43,21 @@ Dynamic: license-file
|
|
|
41
43
|
# noaaplotter
|
|
42
44
|
A python package to create fancy plots with NOAA weather data (stations) and ERA5 reanalysis (by coordinates).
|
|
43
45
|
|
|
46
|
+
<p align="center">
|
|
47
|
+
<a href="https://pypi.org/project/noaaplotter/">
|
|
48
|
+
<img src="https://img.shields.io/badge/version-v1.1.0-31ad52" alt="version">
|
|
49
|
+
</a>
|
|
50
|
+
<a href="https://pypi.org/project/noaaplotter/">
|
|
51
|
+
<img src="https://img.shields.io/pypi/pyversions/noaaplotter" alt="Python versions">
|
|
52
|
+
</a>
|
|
53
|
+
<a href="https://github.com/initze/noaaplotter/actions/workflows/python-package.yml">
|
|
54
|
+
<img src="https://img.shields.io/github/actions/workflow/status/initze/noaaplotter/python-package.yml?label=tests" alt="CI status">
|
|
55
|
+
</a>
|
|
56
|
+
<a href="https://initze.github.io/noaaplotter/">
|
|
57
|
+
<img src="https://img.shields.io/badge/docs-site-2f80ed?logo=readthedocs&logoColor=white" alt="Documentation">
|
|
58
|
+
</a>
|
|
59
|
+
</p>
|
|
60
|
+
|
|
44
61
|
> 📚 **Docs & API reference:** [initze.github.io/noaaplotter](https://initze.github.io/noaaplotter)
|
|
45
62
|
>
|
|
46
63
|
> **Install:** `pip install noaaplotter`
|
|
@@ -108,6 +125,12 @@ noaaplotter download-data -o data/potsdam.parquet --source open_meteo -lat 52.4
|
|
|
108
125
|
|
|
109
126
|
Data files are cached: re-running only fetches the missing dates.
|
|
110
127
|
|
|
128
|
+
The ERA5-backed sources (`--source open_meteo` / `cds`) additionally return
|
|
129
|
+
daily **wind** columns: `WSPD` (daily mean 10 m wind speed, m/s) and
|
|
130
|
+
`WDIR` (daily dominant direction in degrees, meteorological convention —
|
|
131
|
+
the direction the wind blows FROM; 0 = north). NOAA station data has no
|
|
132
|
+
equivalent, so both stay null for `--source noaa`.
|
|
133
|
+
|
|
111
134
|
### `noaaplotter plot-daily`
|
|
112
135
|
Daily temperature (observed vs. climate mean ± 1σ, with anomaly fills) + precipitation (bars + 7-day rolling sum).
|
|
113
136
|
|
|
@@ -153,6 +176,39 @@ noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 20
|
|
|
153
176
|
| `-save_plot` | write the plot (`.png` / `.html`) |
|
|
154
177
|
| `--engine` | `matplotlib` (default) or `plotly` |
|
|
155
178
|
|
|
179
|
+
### `noaaplotter plot-stripes`
|
|
180
|
+
Warming stripes (Ed Hawkins style): one vertical bar per period, coloured by
|
|
181
|
+
temperature anomaly (cool-blue → white → warm-red).
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
noaaplotter plot-stripes -infile data/kotzebue.parquet -type Temperature -start 1980-01-01 -end 2018-12-31 -save_plot figures/kotzebue_stripes.png
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
| Option | Meaning |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `-infile` | input parquet/csv (required) |
|
|
190
|
+
| `-start`, `-end` | optional window, `YYYY-MM-DD` (default: full record in the file) |
|
|
191
|
+
| `-type` | `Temperature` (default) or `Precipitation` (case-insensitive) |
|
|
192
|
+
| `-resolution` | `year` (default, one bar per year) or `month` |
|
|
193
|
+
| `-save_plot` | write the plot (`.png` / `.html`) |
|
|
194
|
+
| `--engine` | `matplotlib` (default) or `plotly` |
|
|
195
|
+
|
|
196
|
+
### `noaaplotter plot-heatmap`
|
|
197
|
+
Activity heatmap (GitHub-style matrix): months on x, one row per year (latest on top).
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Temperature -scale anomaly -save_plot figures/kotzebue_heatmap_anomaly.png
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
| Option | Meaning |
|
|
204
|
+
|---|---|
|
|
205
|
+
| `-infile` | input parquet/csv (required) |
|
|
206
|
+
| `-type` | `Temperature` (default) or `Precipitation` (case-insensitive) |
|
|
207
|
+
| `-scale` | `anomaly` (default: deviation from climate mean, red↔white↔blue), `percentile` (month's rank 0–100 across the record), `absolute` (raw monthly value; precipitation uses the Blues palette) |
|
|
208
|
+
| `-start`, `-end` | optional window, `YYYY-MM-DD` |
|
|
209
|
+
| `-save_plot` | write the plot (`.png` / `.html`) |
|
|
210
|
+
| `--engine` | `matplotlib` (default) or `plotly` |
|
|
211
|
+
|
|
156
212
|
## Examples
|
|
157
213
|
|
|
158
214
|
### Download data
|
|
@@ -194,6 +250,26 @@ Precipitation, absolute (12-month trailing mean):
|
|
|
194
250
|
|
|
195
251
|

|
|
196
252
|
|
|
253
|
+
### Warming stripes
|
|
254
|
+
One bar per year, coloured by the monthly-mean temperature anomaly (ed Hawkins style):
|
|
255
|
+
|
|
256
|
+
`noaaplotter plot-stripes -infile data/kotzebue.parquet -type Temperature -start 1980-01-01 -end 2018-12-31 -save_plot figures/kotzebue_stripes.png`
|
|
257
|
+
|
|
258
|
+

|
|
259
|
+
|
|
260
|
+
### Activity heatmap (months × years)
|
|
261
|
+
Anomaly from the climate mean, red↔white↔blue (white in the centre):
|
|
262
|
+
|
|
263
|
+
`noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Temperature -scale anomaly -save_plot figures/kotzebue_heatmap_anomaly.png`
|
|
264
|
+
|
|
265
|
+

|
|
266
|
+
|
|
267
|
+
Precipitation (absolute, `Blues` palette — blue for wet months):
|
|
268
|
+
|
|
269
|
+
`noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Precipitation -scale absolute -save_plot figures/kotzebue_heatmap_precip.png`
|
|
270
|
+
|
|
271
|
+

|
|
272
|
+
|
|
197
273
|
## Advanced Usage
|
|
198
274
|
|
|
199
275
|
### Get help for any command
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# noaaplotter
|
|
2
2
|
A python package to create fancy plots with NOAA weather data (stations) and ERA5 reanalysis (by coordinates).
|
|
3
3
|
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://pypi.org/project/noaaplotter/">
|
|
6
|
+
<img src="https://img.shields.io/badge/version-v1.1.0-31ad52" alt="version">
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://pypi.org/project/noaaplotter/">
|
|
9
|
+
<img src="https://img.shields.io/pypi/pyversions/noaaplotter" alt="Python versions">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/initze/noaaplotter/actions/workflows/python-package.yml">
|
|
12
|
+
<img src="https://img.shields.io/github/actions/workflow/status/initze/noaaplotter/python-package.yml?label=tests" alt="CI status">
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://initze.github.io/noaaplotter/">
|
|
15
|
+
<img src="https://img.shields.io/badge/docs-site-2f80ed?logo=readthedocs&logoColor=white" alt="Documentation">
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
4
19
|
> 📚 **Docs & API reference:** [initze.github.io/noaaplotter](https://initze.github.io/noaaplotter)
|
|
5
20
|
>
|
|
6
21
|
> **Install:** `pip install noaaplotter`
|
|
@@ -68,6 +83,12 @@ noaaplotter download-data -o data/potsdam.parquet --source open_meteo -lat 52.4
|
|
|
68
83
|
|
|
69
84
|
Data files are cached: re-running only fetches the missing dates.
|
|
70
85
|
|
|
86
|
+
The ERA5-backed sources (`--source open_meteo` / `cds`) additionally return
|
|
87
|
+
daily **wind** columns: `WSPD` (daily mean 10 m wind speed, m/s) and
|
|
88
|
+
`WDIR` (daily dominant direction in degrees, meteorological convention —
|
|
89
|
+
the direction the wind blows FROM; 0 = north). NOAA station data has no
|
|
90
|
+
equivalent, so both stay null for `--source noaa`.
|
|
91
|
+
|
|
71
92
|
### `noaaplotter plot-daily`
|
|
72
93
|
Daily temperature (observed vs. climate mean ± 1σ, with anomaly fills) + precipitation (bars + 7-day rolling sum).
|
|
73
94
|
|
|
@@ -113,6 +134,39 @@ noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 20
|
|
|
113
134
|
| `-save_plot` | write the plot (`.png` / `.html`) |
|
|
114
135
|
| `--engine` | `matplotlib` (default) or `plotly` |
|
|
115
136
|
|
|
137
|
+
### `noaaplotter plot-stripes`
|
|
138
|
+
Warming stripes (Ed Hawkins style): one vertical bar per period, coloured by
|
|
139
|
+
temperature anomaly (cool-blue → white → warm-red).
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
noaaplotter plot-stripes -infile data/kotzebue.parquet -type Temperature -start 1980-01-01 -end 2018-12-31 -save_plot figures/kotzebue_stripes.png
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
| Option | Meaning |
|
|
146
|
+
|---|---|
|
|
147
|
+
| `-infile` | input parquet/csv (required) |
|
|
148
|
+
| `-start`, `-end` | optional window, `YYYY-MM-DD` (default: full record in the file) |
|
|
149
|
+
| `-type` | `Temperature` (default) or `Precipitation` (case-insensitive) |
|
|
150
|
+
| `-resolution` | `year` (default, one bar per year) or `month` |
|
|
151
|
+
| `-save_plot` | write the plot (`.png` / `.html`) |
|
|
152
|
+
| `--engine` | `matplotlib` (default) or `plotly` |
|
|
153
|
+
|
|
154
|
+
### `noaaplotter plot-heatmap`
|
|
155
|
+
Activity heatmap (GitHub-style matrix): months on x, one row per year (latest on top).
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Temperature -scale anomaly -save_plot figures/kotzebue_heatmap_anomaly.png
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
| Option | Meaning |
|
|
162
|
+
|---|---|
|
|
163
|
+
| `-infile` | input parquet/csv (required) |
|
|
164
|
+
| `-type` | `Temperature` (default) or `Precipitation` (case-insensitive) |
|
|
165
|
+
| `-scale` | `anomaly` (default: deviation from climate mean, red↔white↔blue), `percentile` (month's rank 0–100 across the record), `absolute` (raw monthly value; precipitation uses the Blues palette) |
|
|
166
|
+
| `-start`, `-end` | optional window, `YYYY-MM-DD` |
|
|
167
|
+
| `-save_plot` | write the plot (`.png` / `.html`) |
|
|
168
|
+
| `--engine` | `matplotlib` (default) or `plotly` |
|
|
169
|
+
|
|
116
170
|
## Examples
|
|
117
171
|
|
|
118
172
|
### Download data
|
|
@@ -154,6 +208,26 @@ Precipitation, absolute (12-month trailing mean):
|
|
|
154
208
|
|
|
155
209
|

|
|
156
210
|
|
|
211
|
+
### Warming stripes
|
|
212
|
+
One bar per year, coloured by the monthly-mean temperature anomaly (ed Hawkins style):
|
|
213
|
+
|
|
214
|
+
`noaaplotter plot-stripes -infile data/kotzebue.parquet -type Temperature -start 1980-01-01 -end 2018-12-31 -save_plot figures/kotzebue_stripes.png`
|
|
215
|
+
|
|
216
|
+

|
|
217
|
+
|
|
218
|
+
### Activity heatmap (months × years)
|
|
219
|
+
Anomaly from the climate mean, red↔white↔blue (white in the centre):
|
|
220
|
+
|
|
221
|
+
`noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Temperature -scale anomaly -save_plot figures/kotzebue_heatmap_anomaly.png`
|
|
222
|
+
|
|
223
|
+

|
|
224
|
+
|
|
225
|
+
Precipitation (absolute, `Blues` palette — blue for wet months):
|
|
226
|
+
|
|
227
|
+
`noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Precipitation -scale absolute -save_plot figures/kotzebue_heatmap_precip.png`
|
|
228
|
+
|
|
229
|
+

|
|
230
|
+
|
|
157
231
|
## Advanced Usage
|
|
158
232
|
|
|
159
233
|
### Get help for any command
|
|
@@ -162,7 +162,7 @@ def plot_monthly(
|
|
|
162
162
|
"""
|
|
163
163
|
if engine not in ("matplotlib", "plotly"):
|
|
164
164
|
raise typer.BadParameter("engine must be 'matplotlib' or 'plotly'")
|
|
165
|
-
if information not in ("
|
|
165
|
+
if information.lower() not in ("temperature", "precipitation"):
|
|
166
166
|
raise typer.BadParameter("-type must be 'Temperature' or 'Precipitation'")
|
|
167
167
|
if not infile:
|
|
168
168
|
raise typer.BadParameter("-infile is required")
|
|
@@ -184,3 +184,189 @@ def plot_monthly(
|
|
|
184
184
|
engine=engine,
|
|
185
185
|
)
|
|
186
186
|
_report(save_path, show_plot, engine)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@app.command("plot-stripes")
|
|
190
|
+
def plot_stripes(
|
|
191
|
+
infile: str = typer.Option(..., "-infile", "--input-file", help="Input file (parquet/csv) with climate data"),
|
|
192
|
+
start_date: Optional[str] = typer.Option(None, "-start", "--start-date", help="Start date (YYYY-MM-DD); default = min date in file"),
|
|
193
|
+
end_date: Optional[str] = typer.Option(None, "-end", "--end-date", help="End date (YYYY-MM-DD); default = max date in file"),
|
|
194
|
+
location: Optional[str] = typer.Option(None, "-loc", "--location", help="Location name"),
|
|
195
|
+
save_path: Optional[str] = typer.Option(None, "-save_plot", "--save-plot", help="File path for the plot (png, or html with --engine plotly)"),
|
|
196
|
+
information: str = typer.Option("Temperature", "-type", "--information", help="Attribute: Temperature or Precipitation"),
|
|
197
|
+
resolution: str = typer.Option("year", "-res", "--resolution", help="One stripe per: year or month"),
|
|
198
|
+
title: Optional[str] = typer.Option(None, "-title", help="Plot title (with --annotations)"),
|
|
199
|
+
annotations: bool = typer.Option(False, "--annotations", help="Show title, axes and colorbar. Default: bare band only"),
|
|
200
|
+
dpi: float = typer.Option(300.0, "--dpi", help="DPI for plot output"),
|
|
201
|
+
show_plot: bool = typer.Option(False, "--plot", "--show-plot", help="Open the plot in a browser/GUI"),
|
|
202
|
+
engine: str = typer.Option("matplotlib", "--engine", help="Rendering engine: matplotlib or plotly"),
|
|
203
|
+
):
|
|
204
|
+
"""Create warming stripes (anomaly from climate: cool-blue to warm-red).
|
|
205
|
+
|
|
206
|
+
The default output is the bare band only — no title, axes or colorbar.
|
|
207
|
+
Pass --annotations to add them. Optional dates: when omitted, the whole
|
|
208
|
+
record in the file is used.
|
|
209
|
+
|
|
210
|
+
Example: noaaplotter plot-stripes -infile data/kotzebue.parquet -type Temperature -res year -save_plot kotzebue_stripes.png
|
|
211
|
+
"""
|
|
212
|
+
if engine not in ("matplotlib", "plotly"):
|
|
213
|
+
raise typer.BadParameter("engine must be 'matplotlib' or 'plotly'")
|
|
214
|
+
if information.lower() not in ("temperature", "precipitation"):
|
|
215
|
+
raise typer.BadParameter("-type must be 'Temperature' or 'Precipitation'")
|
|
216
|
+
if resolution not in ("year", "month"):
|
|
217
|
+
raise typer.BadParameter("-res must be 'year' or 'month'")
|
|
218
|
+
if not infile:
|
|
219
|
+
raise typer.BadParameter("-infile is required")
|
|
220
|
+
|
|
221
|
+
n = NOAAPlotter(infile, location=location)
|
|
222
|
+
n.plot_warming_stripes(
|
|
223
|
+
start_date=start_date,
|
|
224
|
+
end_date=end_date,
|
|
225
|
+
information=information,
|
|
226
|
+
resolution=resolution,
|
|
227
|
+
title=title,
|
|
228
|
+
annotations=annotations,
|
|
229
|
+
show_plot=show_plot,
|
|
230
|
+
dpi=dpi,
|
|
231
|
+
save_path=save_path or False,
|
|
232
|
+
engine=engine,
|
|
233
|
+
)
|
|
234
|
+
_report(save_path, show_plot, engine)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
@app.command("plot-heatmap")
|
|
238
|
+
def plot_heatmap(
|
|
239
|
+
infile: str = typer.Option(..., "-infile", "--input-file", help="Input file (parquet/csv) with climate data"),
|
|
240
|
+
start_date: Optional[str] = typer.Option(None, "-start", "--start-date", help="Start date (YYYY-MM-DD); default = min date in file"),
|
|
241
|
+
end_date: Optional[str] = typer.Option(None, "-end", "--end-date", help="End date (YYYY-MM-DD); default = max date in file"),
|
|
242
|
+
location: Optional[str] = typer.Option(None, "-loc", "--location", help="Location name"),
|
|
243
|
+
save_path: Optional[str] = typer.Option(None, "-save_plot", "--save-plot", help="File path for the plot (png, or html with --engine plotly)"),
|
|
244
|
+
information: str = typer.Option("Temperature", "-type", "--information", help="Attribute: Temperature or Precipitation"),
|
|
245
|
+
scale: str = typer.Option("anomaly", "-scale", "--scale", help="Cell value: anomaly, percentile, or absolute (default anomaly)"),
|
|
246
|
+
title: Optional[str] = typer.Option(None, "-title", help="Plot title"),
|
|
247
|
+
dpi: float = typer.Option(300.0, "--dpi", help="DPI for plot output"),
|
|
248
|
+
show_plot: bool = typer.Option(False, "--plot", "--show-plot", help="Open the plot in a browser/GUI"),
|
|
249
|
+
engine: str = typer.Option("matplotlib", "--engine", help="Rendering engine: matplotlib or plotly"),
|
|
250
|
+
):
|
|
251
|
+
"""Create a months x years activity heatmap (square cells, latest year on top).
|
|
252
|
+
|
|
253
|
+
--scale chooses what each cell encodes:
|
|
254
|
+
anomaly — deviation from the climate mean (cool-blue / white / warm-red)
|
|
255
|
+
percentile — the month's rank 0-100 across the full record
|
|
256
|
+
absolute — the raw monthly mean (degrees C / mm)
|
|
257
|
+
|
|
258
|
+
Temperature: high = warm (red), low = cool (blue).
|
|
259
|
+
Precipitation: high = wet (blue), low = dry (red) — inverted.
|
|
260
|
+
|
|
261
|
+
Example: noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Temperature -save_plot kotzebue_heatmap.png
|
|
262
|
+
"""
|
|
263
|
+
if engine not in ("matplotlib", "plotly"):
|
|
264
|
+
raise typer.BadParameter("engine must be 'matplotlib' or 'plotly'")
|
|
265
|
+
if information.lower() not in ("temperature", "precipitation"):
|
|
266
|
+
raise typer.BadParameter("-type must be 'Temperature' or 'Precipitation'")
|
|
267
|
+
if scale not in ("anomaly", "percentile", "absolute"):
|
|
268
|
+
raise typer.BadParameter("-scale must be 'anomaly', 'percentile', or 'absolute'")
|
|
269
|
+
if not infile:
|
|
270
|
+
raise typer.BadParameter("-infile is required")
|
|
271
|
+
|
|
272
|
+
n = NOAAPlotter(infile, location=location)
|
|
273
|
+
n.plot_activity_heatmap(
|
|
274
|
+
start_date=start_date,
|
|
275
|
+
end_date=end_date,
|
|
276
|
+
information=information,
|
|
277
|
+
scale=scale,
|
|
278
|
+
title=title,
|
|
279
|
+
show_plot=show_plot,
|
|
280
|
+
dpi=dpi,
|
|
281
|
+
save_path=save_path or False,
|
|
282
|
+
engine=engine,
|
|
283
|
+
)
|
|
284
|
+
_report(save_path, show_plot, engine)
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
@app.command("inspect-data")
|
|
288
|
+
def inspect_data(
|
|
289
|
+
infile: str = typer.Option(..., "-infile", "--input-file", help="Input file (parquet/csv) to inspect"),
|
|
290
|
+
location: Optional[str] = typer.Option(None, "-loc", "--location", help="Location name to display (default: NAME column if present)"),
|
|
291
|
+
):
|
|
292
|
+
"""Inspect an input data file and print its details to the console.
|
|
293
|
+
|
|
294
|
+
Reports the file path, location (if provided, else the NAME column),
|
|
295
|
+
the observation period (earliest and latest dates), the types of
|
|
296
|
+
information available, and the row count.
|
|
297
|
+
|
|
298
|
+
Example: noaaplotter inspect-data -infile data/kotzebue.parquet -loc Kotzebue
|
|
299
|
+
"""
|
|
300
|
+
if not infile:
|
|
301
|
+
raise typer.BadParameter("-infile is required")
|
|
302
|
+
|
|
303
|
+
import os
|
|
304
|
+
import pandas as pd
|
|
305
|
+
|
|
306
|
+
if not os.path.isfile(infile):
|
|
307
|
+
raise typer.BadParameter(f"input file not found: {infile}")
|
|
308
|
+
|
|
309
|
+
df = _read_input(infile)
|
|
310
|
+
df.columns = [str(c) for c in df.columns]
|
|
311
|
+
|
|
312
|
+
# Location: prefer the user's -loc, else the file's NAME column
|
|
313
|
+
name = location
|
|
314
|
+
if name is None and "NAME" in df.columns:
|
|
315
|
+
vals = sorted({str(v) for v in df["NAME"].dropna().unique()})
|
|
316
|
+
name = ", ".join(vals) if vals else None
|
|
317
|
+
|
|
318
|
+
# Observation period
|
|
319
|
+
start = end = None
|
|
320
|
+
for col in ("DATE", "DT_start", "TIME"):
|
|
321
|
+
if col in df.columns:
|
|
322
|
+
s = pd.to_datetime(df[col], errors="coerce").dropna()
|
|
323
|
+
if len(s):
|
|
324
|
+
start, end = s.min(), s.max()
|
|
325
|
+
break
|
|
326
|
+
if start is None:
|
|
327
|
+
# no explicit date column: try to parse from DATE_YM / DATE_MD
|
|
328
|
+
for col in ("DATE_YM", "DATE_MD"):
|
|
329
|
+
if col in df.columns:
|
|
330
|
+
s = pd.to_datetime(df[col], errors="coerce").dropna()
|
|
331
|
+
if len(s):
|
|
332
|
+
start, end = s.min(), s.max()
|
|
333
|
+
break
|
|
334
|
+
|
|
335
|
+
# Types of information available
|
|
336
|
+
cols = set(df.columns)
|
|
337
|
+
info_types = []
|
|
338
|
+
if cols & {"TAVG", "TMAX", "TMIN"}:
|
|
339
|
+
info_types.append("Temperature ({})".format(
|
|
340
|
+
", ".join(sorted(c for c in cols if c in ("TAVG", "TMAX", "TMIN")))))
|
|
341
|
+
if "PRCP" in cols:
|
|
342
|
+
info_types.append("Precipitation (PRCP)")
|
|
343
|
+
if "SNOW" in cols:
|
|
344
|
+
info_types.append("Snow (SNOW)")
|
|
345
|
+
|
|
346
|
+
typer.secho("Data file inspection", bold=True)
|
|
347
|
+
typer.echo("-" * 40)
|
|
348
|
+
typer.echo(f" File : {os.path.abspath(infile)}")
|
|
349
|
+
typer.echo(f" Location : {name or '(not specified)'}")
|
|
350
|
+
if start is not None:
|
|
351
|
+
span = (end - start).days
|
|
352
|
+
typer.echo(
|
|
353
|
+
f" Observation period: {start:%Y-%m-%d} .. {end:%Y-%m-%d}"
|
|
354
|
+
f" ({span} days)"
|
|
355
|
+
)
|
|
356
|
+
else:
|
|
357
|
+
typer.echo(" Observation period: could not determine (no date column)")
|
|
358
|
+
if info_types:
|
|
359
|
+
typer.echo(" Information types : " + "; ".join(info_types))
|
|
360
|
+
else:
|
|
361
|
+
typer.echo(" Information types : (none of TAVG/TMAX/TMIN/PRCP/SNOW found)")
|
|
362
|
+
typer.echo(f" Rows : {len(df)}")
|
|
363
|
+
typer.echo(f" Columns ({len(df.columns)}) : " + ", ".join(str(c) for c in df.columns))
|
|
364
|
+
typer.echo("-" * 40)
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _read_input(path):
|
|
368
|
+
"""Read a parquet or csv file into a DataFrame (helper for inspect-data)."""
|
|
369
|
+
import pandas as _pd
|
|
370
|
+
if path.lower().endswith(".parquet"):
|
|
371
|
+
return _pd.read_parquet(path)
|
|
372
|
+
return _pd.read_csv(path)
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
from .plotly_stripes import make_stripes_figure
|
|
5
|
+
from .plotly_heatmap import make_heatmap_figure
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"make_daily_figure",
|
|
9
|
+
"make_monthly_figure",
|
|
10
|
+
"make_stripes_figure",
|
|
11
|
+
"make_heatmap_figure",
|
|
12
|
+
]
|