noaaplotter 1.1.2__tar.gz → 1.1.3__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.1.2 → noaaplotter-1.1.3}/PKG-INFO +30 -9
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/README.md +29 -8
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/figures/plotly_daily.py +52 -85
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/noaaplotter.py +40 -56
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter.egg-info/PKG-INFO +30 -9
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/pyproject.toml +1 -1
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/tests/test_plotly_figures.py +53 -33
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/LICENSE +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/__init__.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/__main__.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/cli/__init__.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/figures/__init__.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/figures/plotly_heatmap.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/figures/plotly_monthly.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/figures/plotly_stripes.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/scripts/download_data.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/scripts/plot_daily.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/scripts/plot_monthly.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/sources/__init__.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/sources/base.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/sources/cds.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/sources/open_meteo.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/utils/__init__.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/utils/config.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/utils/dataset.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/utils/download_utils.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/utils/plot_utils.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter/utils/utils.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter.egg-info/SOURCES.txt +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter.egg-info/dependency_links.txt +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter.egg-info/entry_points.txt +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter.egg-info/requires.txt +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/noaaplotter.egg-info/top_level.txt +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/setup.cfg +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/tests/test_cds_source.py +0 -0
- {noaaplotter-1.1.2 → noaaplotter-1.1.3}/tests/test_polars_parity.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: noaaplotter
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.3
|
|
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
|
|
@@ -45,7 +45,7 @@ A python package to create fancy plots with NOAA weather data (stations) and ERA
|
|
|
45
45
|
|
|
46
46
|
<p align="center">
|
|
47
47
|
<a href="https://pypi.org/project/noaaplotter/">
|
|
48
|
-
<img src="https://img.shields.io/badge/version-v1.1.
|
|
48
|
+
<img src="https://img.shields.io/badge/version-v1.1.3-31ad52" alt="version">
|
|
49
49
|
</a>
|
|
50
50
|
<a href="https://pypi.org/project/noaaplotter/">
|
|
51
51
|
<img src="https://img.shields.io/pypi/pyversions/noaaplotter" alt="Python versions">
|
|
@@ -89,10 +89,10 @@ python-dotenv, typer (all listed in `pyproject.toml` and installed automatically
|
|
|
89
89
|
noaaplotter download-data -o data/kotzebue.parquet -sid USW00026616 -start 1970-01-01 -end 2021-12-31
|
|
90
90
|
|
|
91
91
|
# 2. Create a daily plot (temperature vs. climate + precipitation, incl. 7-day rolling sum)
|
|
92
|
-
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/
|
|
92
|
+
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
|
|
93
93
|
|
|
94
94
|
# 3. ...or an interactive HTML plot
|
|
95
|
-
noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 --engine plotly -save_plot figures/
|
|
95
|
+
noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 --engine plotly -save_plot figures/kotzebue_daily_1992.html
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
## Command Line Interface (CLI)
|
|
@@ -133,10 +133,15 @@ equivalent, so both stay null for `--source noaa`.
|
|
|
133
133
|
|
|
134
134
|
### `noaaplotter plot-daily`
|
|
135
135
|
Daily temperature (observed vs. climate mean ± 1σ, with anomaly fills) + precipitation (bars + 7-day rolling sum).
|
|
136
|
+
When the input file has `WSPD`/`WDIR` (ERA5 sources only — NOAA station data has no wind), a third row is added automatically: one dot per day coloured/positioned by wind direction plus a wind-speed line on a right-hand axis; the plotly hover also shows the 16-point compass name (N, NNE, NE, ...).
|
|
136
137
|
|
|
137
138
|
```bash
|
|
138
|
-
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/
|
|
139
|
-
noaaplotter plot-daily -infile data/kotzebue.parquet -start 2017-07-01 -end 2018-06-30 --snow_acc --engine plotly -save_plot figures/
|
|
139
|
+
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
|
|
140
|
+
noaaplotter plot-daily -infile data/kotzebue.parquet -start 2017-07-01 -end 2018-06-30 --snow_acc --engine plotly -save_plot figures/kotzebue_daily_winter.html
|
|
141
|
+
|
|
142
|
+
# ERA5 input with wind columns -> daily plot gains the wind row (dots + speed line)
|
|
143
|
+
noaaplotter plot-daily -infile data/NTaymyr_ERA5_75.6_98.7.parquet -start 2020-01-01 -end 2020-12-31 -save_plot figures/NTaymyr_ERA5_75.6_98.7_daily.png
|
|
144
|
+
noaaplotter plot-daily -infile data/NTaymyr_ERA5_75.6_98.7.parquet --engine plotly -start 2020-01-01 -end 2020-12-31 -save_plot figures/NTaymyr_ERA5_75.6_98.7_daily.html
|
|
140
145
|
```
|
|
141
146
|
|
|
142
147
|
| Option | Meaning |
|
|
@@ -160,10 +165,10 @@ Monthly bar chart of temperature or precipitation, with anomaly and trailing mea
|
|
|
160
165
|
|
|
161
166
|
```bash
|
|
162
167
|
# Absolute values
|
|
163
|
-
noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Temperature -trail 12 -save_plot figures/
|
|
168
|
+
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
|
|
164
169
|
|
|
165
170
|
# Anomaly from climate (1981-2010)
|
|
166
|
-
noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Precipitation -trail 12 -
|
|
171
|
+
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
|
|
167
172
|
```
|
|
168
173
|
|
|
169
174
|
| Option | Meaning |
|
|
@@ -231,6 +236,22 @@ Entire year 1 January until 31 December (e.g. 1992):
|
|
|
231
236
|
|
|
232
237
|

|
|
233
238
|
|
|
239
|
+
### Daily plot with wind (ERA5 sources)
|
|
240
|
+
|
|
241
|
+
NOAA station data has no wind columns, so the wind row only appears for
|
|
242
|
+
ERA5-backed inputs (`--source open_meteo` / `cds`), which also deliver
|
|
243
|
+
`WSPD`/`WDIR`. The wind row draws one dot per day placed by wind direction
|
|
244
|
+
(hover shows the 16-point compass name, e.g. `247° (WSW)`) plus a wind-speed
|
|
245
|
+
line on a right-hand axis:
|
|
246
|
+
|
|
247
|
+
`noaaplotter plot-daily --input-file data/NTaymyr_ERA5_75.6_98.7.parquet --start-date 2020-01-01 --end-date 2020-12-31 --save-plot figures/NTaymyr_ERA5_75.6_98.7_daily.png`
|
|
248
|
+
|
|
249
|
+

|
|
250
|
+
|
|
251
|
+
Interactive (plotly) version of the same figure:
|
|
252
|
+
|
|
253
|
+
`noaaplotter plot-daily --input-file data/NTaymyr_ERA5_75.6_98.7.parquet --engine plotly --start-date 2020-01-01 --end-date 2020-12-31 --save-plot figures/NTaymyr_ERA5_75.6_98.7_daily.html`
|
|
254
|
+
|
|
234
255
|
### Monthly aggregates
|
|
235
256
|
Temperature, absolute (12-month trailing mean):
|
|
236
257
|
|
|
@@ -292,5 +313,5 @@ from noaaplotter import NOAAPlotter
|
|
|
292
313
|
n = NOAAPlotter("data/kotzebue.parquet", location="Kotzebue", climate_filtersize=7)
|
|
293
314
|
fig = n.plot_weather_series(start_date="1992-01-01", end_date="1992-12-31",
|
|
294
315
|
show_plot=False, return_plot=True, engine="plotly")
|
|
295
|
-
fig.write_html("figures/
|
|
316
|
+
fig.write_html("figures/kotzebue_daily_1992.html")
|
|
296
317
|
```
|
|
@@ -3,7 +3,7 @@ A python package to create fancy plots with NOAA weather data (stations) and ERA
|
|
|
3
3
|
|
|
4
4
|
<p align="center">
|
|
5
5
|
<a href="https://pypi.org/project/noaaplotter/">
|
|
6
|
-
<img src="https://img.shields.io/badge/version-v1.1.
|
|
6
|
+
<img src="https://img.shields.io/badge/version-v1.1.3-31ad52" alt="version">
|
|
7
7
|
</a>
|
|
8
8
|
<a href="https://pypi.org/project/noaaplotter/">
|
|
9
9
|
<img src="https://img.shields.io/pypi/pyversions/noaaplotter" alt="Python versions">
|
|
@@ -47,10 +47,10 @@ python-dotenv, typer (all listed in `pyproject.toml` and installed automatically
|
|
|
47
47
|
noaaplotter download-data -o data/kotzebue.parquet -sid USW00026616 -start 1970-01-01 -end 2021-12-31
|
|
48
48
|
|
|
49
49
|
# 2. Create a daily plot (temperature vs. climate + precipitation, incl. 7-day rolling sum)
|
|
50
|
-
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/
|
|
50
|
+
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
|
|
51
51
|
|
|
52
52
|
# 3. ...or an interactive HTML plot
|
|
53
|
-
noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 --engine plotly -save_plot figures/
|
|
53
|
+
noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 --engine plotly -save_plot figures/kotzebue_daily_1992.html
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
## Command Line Interface (CLI)
|
|
@@ -91,10 +91,15 @@ equivalent, so both stay null for `--source noaa`.
|
|
|
91
91
|
|
|
92
92
|
### `noaaplotter plot-daily`
|
|
93
93
|
Daily temperature (observed vs. climate mean ± 1σ, with anomaly fills) + precipitation (bars + 7-day rolling sum).
|
|
94
|
+
When the input file has `WSPD`/`WDIR` (ERA5 sources only — NOAA station data has no wind), a third row is added automatically: one dot per day coloured/positioned by wind direction plus a wind-speed line on a right-hand axis; the plotly hover also shows the 16-point compass name (N, NNE, NE, ...).
|
|
94
95
|
|
|
95
96
|
```bash
|
|
96
|
-
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/
|
|
97
|
-
noaaplotter plot-daily -infile data/kotzebue.parquet -start 2017-07-01 -end 2018-06-30 --snow_acc --engine plotly -save_plot figures/
|
|
97
|
+
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
|
|
98
|
+
noaaplotter plot-daily -infile data/kotzebue.parquet -start 2017-07-01 -end 2018-06-30 --snow_acc --engine plotly -save_plot figures/kotzebue_daily_winter.html
|
|
99
|
+
|
|
100
|
+
# ERA5 input with wind columns -> daily plot gains the wind row (dots + speed line)
|
|
101
|
+
noaaplotter plot-daily -infile data/NTaymyr_ERA5_75.6_98.7.parquet -start 2020-01-01 -end 2020-12-31 -save_plot figures/NTaymyr_ERA5_75.6_98.7_daily.png
|
|
102
|
+
noaaplotter plot-daily -infile data/NTaymyr_ERA5_75.6_98.7.parquet --engine plotly -start 2020-01-01 -end 2020-12-31 -save_plot figures/NTaymyr_ERA5_75.6_98.7_daily.html
|
|
98
103
|
```
|
|
99
104
|
|
|
100
105
|
| Option | Meaning |
|
|
@@ -118,10 +123,10 @@ Monthly bar chart of temperature or precipitation, with anomaly and trailing mea
|
|
|
118
123
|
|
|
119
124
|
```bash
|
|
120
125
|
# Absolute values
|
|
121
|
-
noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Temperature -trail 12 -save_plot figures/
|
|
126
|
+
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
|
|
122
127
|
|
|
123
128
|
# Anomaly from climate (1981-2010)
|
|
124
|
-
noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Precipitation -trail 12 -
|
|
129
|
+
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
|
|
125
130
|
```
|
|
126
131
|
|
|
127
132
|
| Option | Meaning |
|
|
@@ -189,6 +194,22 @@ Entire year 1 January until 31 December (e.g. 1992):
|
|
|
189
194
|
|
|
190
195
|

|
|
191
196
|
|
|
197
|
+
### Daily plot with wind (ERA5 sources)
|
|
198
|
+
|
|
199
|
+
NOAA station data has no wind columns, so the wind row only appears for
|
|
200
|
+
ERA5-backed inputs (`--source open_meteo` / `cds`), which also deliver
|
|
201
|
+
`WSPD`/`WDIR`. The wind row draws one dot per day placed by wind direction
|
|
202
|
+
(hover shows the 16-point compass name, e.g. `247° (WSW)`) plus a wind-speed
|
|
203
|
+
line on a right-hand axis:
|
|
204
|
+
|
|
205
|
+
`noaaplotter plot-daily --input-file data/NTaymyr_ERA5_75.6_98.7.parquet --start-date 2020-01-01 --end-date 2020-12-31 --save-plot figures/NTaymyr_ERA5_75.6_98.7_daily.png`
|
|
206
|
+
|
|
207
|
+

|
|
208
|
+
|
|
209
|
+
Interactive (plotly) version of the same figure:
|
|
210
|
+
|
|
211
|
+
`noaaplotter plot-daily --input-file data/NTaymyr_ERA5_75.6_98.7.parquet --engine plotly --start-date 2020-01-01 --end-date 2020-12-31 --save-plot figures/NTaymyr_ERA5_75.6_98.7_daily.html`
|
|
212
|
+
|
|
192
213
|
### Monthly aggregates
|
|
193
214
|
Temperature, absolute (12-month trailing mean):
|
|
194
215
|
|
|
@@ -250,5 +271,5 @@ from noaaplotter import NOAAPlotter
|
|
|
250
271
|
n = NOAAPlotter("data/kotzebue.parquet", location="Kotzebue", climate_filtersize=7)
|
|
251
272
|
fig = n.plot_weather_series(start_date="1992-01-01", end_date="1992-12-31",
|
|
252
273
|
show_plot=False, return_plot=True, engine="plotly")
|
|
253
|
-
fig.write_html("figures/
|
|
274
|
+
fig.write_html("figures/kotzebue_daily_1992.html")
|
|
254
275
|
```
|
|
@@ -5,10 +5,11 @@ climatological mean +/- std with red/blue fill, no-data shading, record
|
|
|
5
5
|
markers) plus precipitation panel (bars, 7-day rolling sum, no-data shading,
|
|
6
6
|
optional cumulative snowfall on a secondary axis).
|
|
7
7
|
|
|
8
|
-
When the data carries non-empty WSPD/WDIR columns a third "wind
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
colorbar anywhere — the hover shows
|
|
8
|
+
When the data carries non-empty WSPD/WDIR columns a third "wind" row is
|
|
9
|
+
added with two channels on two axes: wind DIRECTION as plain dots (vertical
|
|
10
|
+
position = 0-360 deg, N at top) and wind SPEED as a red line on an overlaid
|
|
11
|
+
right axis. No legend and no colorbar anywhere — the hover shows
|
|
12
|
+
"Direction: x° (NAME)" (16-point compass names) and "Speed: y m/s".
|
|
12
13
|
The wind row is NOT drawn when snow accumulation is active (the secondary
|
|
13
14
|
snow axis and the wind row would both own yaxis3).
|
|
14
15
|
|
|
@@ -27,53 +28,12 @@ C_HIGH = "#d6604d"
|
|
|
27
28
|
C_LOW = "#4393c3"
|
|
28
29
|
YEAR_BAND = "rgba(0,0,0,0.025)" # light grey per calendar year (even years white)
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
WIND_MAX_PAD = 1.25 # colour-bar cap = data max * this (rounded up to 1 m/s)
|
|
32
|
-
WIND_ROWS_HEIGHTS = {"2 rows": (0.6, 0.4), "3 rows": (0.5, 0.3, 0.2)}
|
|
33
|
-
DARKEN = 0.68 # per-dot outline: marker colour * DARKEN (same hue, ~32% darker)
|
|
31
|
+
WIND_ROWS_HEIGHTS = {"2 rows": (0.6, 0.4), "3 rows": (0.41, 0.27, 0.21)}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Low speed -> green (calm), high speed -> red (gusty). Sampled from
|
|
40
|
-
matplotlib's RdYlGn colormap reversed (at 1-t) so t=0 is green and
|
|
41
|
-
t=1 is red. The stops drive the per-dot fill color AND its darkened
|
|
42
|
-
outline (same fill * DARKEN) — the speed value reaches the marker as
|
|
43
|
-
rgb strings so the trace carries NO colorscale and therefore no colorbar.
|
|
44
|
-
"""
|
|
45
|
-
import matplotlib
|
|
46
|
-
cmap = matplotlib.colormaps["RdYlGn"]
|
|
47
|
-
scale = []
|
|
48
|
-
for i in range(10):
|
|
49
|
-
t = i / 9.0
|
|
50
|
-
r, g, b = (int(c * 255) for c in cmap(1.0 - t)[:3])
|
|
51
|
-
scale.append([t, f"rgb({r},{g},{b})"])
|
|
52
|
-
return scale
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def _scale_color(scale, t):
|
|
56
|
-
"""Interpolated 'rgb(r,g,b)' for scale position t (0..1)."""
|
|
57
|
-
t = min(max(float(t), 0.0), 1.0)
|
|
58
|
-
pos = t * (len(scale) - 1)
|
|
59
|
-
i0 = int(pos)
|
|
60
|
-
i1 = min(i0 + 1, len(scale) - 1)
|
|
61
|
-
w = pos - i0
|
|
62
|
-
def _rgb(s):
|
|
63
|
-
import re
|
|
64
|
-
return tuple(int(x) for x in re.match(
|
|
65
|
-
r"rgb\((\d+),(\d+),(\d+)\)", s).groups())
|
|
66
|
-
c0, c1 = _rgb(scale[i0][1]), _rgb(scale[i1][1])
|
|
67
|
-
r, g, b = (round(c0[k] * (1 - w) + c1[k] * w) for k in range(3))
|
|
68
|
-
return f"rgb({r},{g},{b})"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def _dark_rgb(rgb_str):
|
|
72
|
-
"""Same colour, DARKEN factor darker (per-dot outline)."""
|
|
73
|
-
import re
|
|
74
|
-
r, g, b = (int(x) for x in re.match(
|
|
75
|
-
r"rgb\((\d+),(\d+),(\d+)\)", rgb_str).groups())
|
|
76
|
-
return f"rgb({int(r * DARKEN)},{int(g * DARKEN)},{int(b * DARKEN)})"
|
|
33
|
+
# 16-point compass rose (deg -> name via 22.5-degree bins centred on each card
|
|
34
|
+
# in the list); index i covers the sector centred on i*22.5 from north CW.
|
|
35
|
+
COMPASS16 = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
|
|
36
|
+
"S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]
|
|
77
37
|
|
|
78
38
|
|
|
79
39
|
def _clean(v):
|
|
@@ -317,50 +277,50 @@ def make_daily_figure(df_obs, x_dates, x_dates_short, y_clim, y_clim_hi, y_clim_
|
|
|
317
277
|
line=dict(color="black", width=1, dash="dash"),
|
|
318
278
|
showlegend=False, yaxis="y3"))
|
|
319
279
|
|
|
320
|
-
# --- wind
|
|
321
|
-
#
|
|
322
|
-
#
|
|
323
|
-
#
|
|
324
|
-
#
|
|
325
|
-
#
|
|
280
|
+
# --- wind row (row 3): TWO channels on two axes, one panel -------------
|
|
281
|
+
# DIRECTION = plain dots (no connector line); vertical position =
|
|
282
|
+
# 0-360 deg, N at top (inverted left axis).
|
|
283
|
+
# SPEED = a red line on its own overlaid right axis.
|
|
284
|
+
# No legend, no colorbar; hover carries "x° (NAME)" and "y m/s" (16-point
|
|
285
|
+
# compass names: N, NNE, NE, ...).
|
|
326
286
|
if add_wind_row:
|
|
327
287
|
wspd = np.asarray(df_obs["WSPD"], dtype=float)
|
|
328
288
|
wdir = np.asarray(df_obs["WDIR"], dtype=float)
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
289
|
+
names = [COMPASS16[int(round(float(d) / 22.5) % 16)]
|
|
290
|
+
if np.isfinite(d) else "" for d in wdir]
|
|
291
|
+
deg_str = [f"{v:.0f}\u00b0" if np.isfinite(v) else "" for v in wdir]
|
|
292
|
+
custom = list(zip(deg_str, names))
|
|
293
|
+
spd_top = (
|
|
294
|
+
max(float(np.nanmax(wspd)) * 1.15, 1.0)
|
|
295
|
+
if np.isfinite(np.nanmax(wspd)) else 1.0
|
|
335
296
|
)
|
|
336
|
-
custom = list(zip(np.round(wdir, 0), np.round(wspd, 1)))
|
|
337
|
-
# per-dot rgb fill (no colorscale on the trace -> NO colorbar).
|
|
338
|
-
# plotly rejects None elements in a marker.color LIST ("Invalid
|
|
339
|
-
# element(s) received for the 'color' property of scatter.marker"),
|
|
340
|
-
# so missing-speed dots use a fully transparent colour instead.
|
|
341
|
-
fill = [
|
|
342
|
-
"rgba(0,0,0,0)" if not np.isfinite(v) else _scale_color(scale, v / vmax)
|
|
343
|
-
for v in wspd
|
|
344
|
-
]
|
|
345
|
-
outline = [
|
|
346
|
-
"rgba(0,0,0,0)" if c == "rgba(0,0,0,0)" else _dark_rgb(c)
|
|
347
|
-
for c in fill
|
|
348
|
-
]
|
|
349
297
|
fig.add_trace(go.Scatter(
|
|
350
298
|
x=dates, y=list(pd.Series(wdir).where(pd.notna(wdir))),
|
|
351
|
-
mode="
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
299
|
+
mode="markers", name="Wind direction",
|
|
300
|
+
marker=dict(size=4, color="rgba(30,45,70,0.55)"),
|
|
301
|
+
customdata=custom,
|
|
302
|
+
hovertemplate="Direction: %{customdata[0]} (%{customdata[1]})"
|
|
303
|
+
"<extra></extra>",
|
|
304
|
+
showlegend=False),
|
|
356
305
|
3, 1)
|
|
306
|
+
fig.add_trace(go.Scatter(
|
|
307
|
+
x=dates, y=list(pd.Series(wspd).where(pd.notna(wspd))),
|
|
308
|
+
mode="lines", name="Wind speed",
|
|
309
|
+
line=dict(width=1, color="rgba(214,96,77,0.85)"),
|
|
310
|
+
yaxis="y4", xaxis="x3",
|
|
311
|
+
hovertemplate="Speed: %{y:.1f} m/s<extra></extra>",
|
|
312
|
+
showlegend=False))
|
|
357
313
|
# headroom above N / below S (mirror of the static render) so extreme
|
|
358
314
|
# direction dots are not glued to the axis edge
|
|
359
315
|
fig.update_yaxes(range=[375, -15], title="Direction", row=3, col=1,
|
|
360
316
|
tickmode="array",
|
|
361
|
-
tickvals=[0,
|
|
362
|
-
ticktext=["N", "
|
|
363
|
-
|
|
317
|
+
tickvals=[0, 90, 180, 270],
|
|
318
|
+
ticktext=["N", "E", "S", "W"])
|
|
319
|
+
fig.update_layout(yaxis4=dict(range=[0, spd_top],
|
|
320
|
+
title="Wind speed in m/s", side="right",
|
|
321
|
+
overlaying="y3", anchor="free",
|
|
322
|
+
position=1.0))
|
|
323
|
+
for a in (0, 90, 180, 270):
|
|
364
324
|
fig.add_hline(y=a, line=dict(color="rgba(0,0,0,0.10)", dash="dot"),
|
|
365
325
|
row=3, col=1)
|
|
366
326
|
|
|
@@ -370,8 +330,11 @@ def make_daily_figure(df_obs, x_dates, x_dates_short, y_clim, y_clim_hi, y_clim_
|
|
|
370
330
|
showlegend=False,
|
|
371
331
|
margin=dict(l=40, r=40, t=50 if title else 40, b=30),
|
|
372
332
|
title=dict(text=title, y=0.98) if title else None,
|
|
373
|
-
xaxis_rangeslider_visible=False
|
|
374
|
-
|
|
333
|
+
xaxis_rangeslider_visible=False)
|
|
334
|
+
# the "Date" title belongs on the BOTTOMMOST (visible) x-axis only —
|
|
335
|
+
# matching where the date tick labels are drawn (shared x-axes: the
|
|
336
|
+
# upper rows' x-axes are hidden masters)
|
|
337
|
+
layout[f"xaxis{n_rows}_title"] = "Date"
|
|
375
338
|
# --- initial x-view (window = user-selected period).
|
|
376
339
|
# NOTE: with shared_xaxes the visible master axis is x2 (xaxis "matches"
|
|
377
340
|
# it and is hidden), so the initial range must be applied to BOTH.
|
|
@@ -381,4 +344,8 @@ def make_daily_figure(df_obs, x_dates, x_dates_short, y_clim, y_clim_hi, y_clim_
|
|
|
381
344
|
layout["xaxis_range"] = [d0, d1]
|
|
382
345
|
layout["xaxis2_range"] = [d0, d1]
|
|
383
346
|
fig.update_layout(**layout)
|
|
347
|
+
# consistent, compact font sizes across every axis (titles + ticks),
|
|
348
|
+
# mirroring the static render's "small"/"x-small" pair
|
|
349
|
+
fig.update_xaxes(tickfont=dict(size=9), title_font=dict(size=11))
|
|
350
|
+
fig.update_yaxes(tickfont=dict(size=9), title_font=dict(size=11))
|
|
384
351
|
return fig
|
|
@@ -372,14 +372,21 @@ class NOAAPlotter(object):
|
|
|
372
372
|
# the exact same width and every y-label sits at the same global x.
|
|
373
373
|
# (tight_layout would re-derive margins per-label; legend/titles sit
|
|
374
374
|
# outside the axes, so the margins are pinned explicitly instead.)
|
|
375
|
-
|
|
375
|
+
# the wind layout adds a RIGHT-side speed axis whose label + tick
|
|
376
|
+
# labels must fit: pin a wider right margin for it (the plain layout
|
|
377
|
+
# keeps the old tight one)
|
|
376
378
|
if has_wind_mpl:
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
379
|
+
fig.subplots_adjust(
|
|
380
|
+
left=0.09, right=0.90, top=0.90, bottom=0.18)
|
|
381
|
+
else:
|
|
382
|
+
fig.subplots_adjust(
|
|
383
|
+
left=0.09, right=0.985, top=0.90, bottom=0.18)
|
|
384
|
+
if has_wind_mpl:
|
|
385
|
+
# explicit vertical bands: temp, gap, precip, gap, wind
|
|
386
|
+
# (hspace 0 — every gap comes a spacer row)
|
|
380
387
|
gs = fig.add_gridspec(
|
|
381
388
|
5, 1,
|
|
382
|
-
height_ratios=[0.
|
|
389
|
+
height_ratios=[0.41, 0.05, 0.27, 0.05, 0.21],
|
|
383
390
|
hspace=0.0,
|
|
384
391
|
)
|
|
385
392
|
ax_t = fig.add_subplot(gs[0, 0])
|
|
@@ -628,71 +635,48 @@ class NOAAPlotter(object):
|
|
|
628
635
|
)
|
|
629
636
|
ax_p.set_xlabel("Date", fontsize=label_fontsize)
|
|
630
637
|
|
|
631
|
-
# --- wind
|
|
632
|
-
#
|
|
633
|
-
#
|
|
634
|
-
#
|
|
635
|
-
#
|
|
636
|
-
#
|
|
638
|
+
# --- wind row (third row, when source carries WSPD + WDIR) --------
|
|
639
|
+
# Two visual channels on two axes, one panel:
|
|
640
|
+
# DIRECTION = plain dots (no connector line, no colour encoding);
|
|
641
|
+
# vertical position = 0-360 deg, N at top (inverted axis).
|
|
642
|
+
# SPEED = a red line on its own (secondary) axis below it.
|
|
643
|
+
# Static figure: no hover, so no compass-name labels here (the plotly
|
|
644
|
+
# engine adds those to its hover).
|
|
637
645
|
if has_wind_mpl:
|
|
638
|
-
import matplotlib
|
|
639
|
-
from matplotlib.colors import Normalize
|
|
640
|
-
from matplotlib.lines import Line2D
|
|
641
646
|
wspd_w = np.asarray(df_obs["WSPD"], dtype=float)
|
|
642
647
|
wdir_w = np.asarray(df_obs["WDIR"], dtype=float)
|
|
643
|
-
|
|
644
|
-
vmax_w = (
|
|
645
|
-
max(float(np.nanmax(wspd_w)) * 1.25, 1.0)
|
|
646
|
-
if np.isfinite(np.nanmax(wspd_w)) else 1.0
|
|
647
|
-
)
|
|
648
|
-
norm_w = Normalize(vmin=0.0, vmax=vmax_w)
|
|
649
|
-
sc = ax_w.scatter(
|
|
650
|
-
x_dates_short["DATE"].values,
|
|
651
|
-
wdir_w,
|
|
652
|
-
s=12, c=wspd_w, cmap=cmap_w, norm=norm_w,
|
|
653
|
-
edgecolors="none",
|
|
654
|
-
)
|
|
655
|
-
# faint connector line (thin, grey) under the dots
|
|
656
|
-
ax_w.plot(
|
|
648
|
+
ax_w.scatter(
|
|
657
649
|
x_dates_short["DATE"].values, wdir_w,
|
|
658
|
-
color=(30/255, 45/255, 70/255, 0.
|
|
650
|
+
s=8, color=(30 / 255, 45 / 255, 70 / 255, 0.55),
|
|
651
|
+
linewidths=0,
|
|
652
|
+
)
|
|
653
|
+
ax_ws = ax_w.twinx()
|
|
654
|
+
ax_ws.plot(
|
|
655
|
+
x_dates_short["DATE"].values, wspd_w,
|
|
656
|
+
color="#d6604d", linewidth=0.9, alpha=0.85,
|
|
659
657
|
)
|
|
660
658
|
# headroom above N and below S so extreme dots are not glued to
|
|
661
659
|
# the axis edge
|
|
662
660
|
ax_w.set_ylim(375, -15)
|
|
663
|
-
# 4 cardinal ticks only: the wind row is short, 8 compass ticks
|
|
664
|
-
# would collide vertically
|
|
665
661
|
ax_w.set_yticks([0, 90, 180, 270])
|
|
666
662
|
ax_w.set_yticklabels(["N", "E", "S", "W"])
|
|
667
663
|
plt.setp(ax_w.get_yticklabels(), fontsize=tick_fontsize)
|
|
668
664
|
ax_w.set_ylabel("Direction", fontsize=label_fontsize)
|
|
665
|
+
spd_top = (
|
|
666
|
+
max(float(np.nanmax(wspd_w)) * 1.15, 1.0)
|
|
667
|
+
if np.isfinite(np.nanmax(wspd_w)) else 1.0
|
|
668
|
+
)
|
|
669
|
+
ax_ws.set_ylim(0, spd_top)
|
|
670
|
+
ax_ws.set_ylabel("Wind speed in m/s", fontsize=label_fontsize,
|
|
671
|
+
color="#d6604d")
|
|
672
|
+
plt.setp(ax_ws.get_yticklabels(), fontsize=tick_fontsize,
|
|
673
|
+
color="#d6604d")
|
|
669
674
|
ax_w.yaxis.grid(True, linestyle=":", alpha=0.5)
|
|
670
675
|
ax_w.xaxis.set_major_locator(locator)
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
)
|
|
675
|
-
ax_w.set_xlabel("Date")
|
|
676
|
-
# speed scale as 4 discrete bins; landscape legend placed ABOVE the
|
|
677
|
-
# wind panel (in the gap below the precipitation panel), mirroring
|
|
678
|
-
# the temperature legend style
|
|
679
|
-
n_bins = 4
|
|
680
|
-
speed_handles, speed_labels = [], []
|
|
681
|
-
for i in range(n_bins):
|
|
682
|
-
lo_b, hi_b = vmax_w * i / n_bins, vmax_w * (i + 1) / n_bins
|
|
683
|
-
speed_handles.append(Line2D(
|
|
684
|
-
[], [], marker="o", ls="none", markersize=5,
|
|
685
|
-
color=cmap_w((i + 0.5) / n_bins),
|
|
686
|
-
))
|
|
687
|
-
speed_labels.append(f"{lo_b:.0f}-{hi_b:.0f}")
|
|
688
|
-
leg_w = ax_w.legend(
|
|
689
|
-
speed_handles, speed_labels,
|
|
690
|
-
loc="lower center", ncol=n_bins, fontsize=legend_fontsize,
|
|
691
|
-
title="Wind speed (m/s)",
|
|
692
|
-
bbox_to_anchor=(0.5, 1.02),
|
|
693
|
-
)
|
|
694
|
-
# match the legend text font of the temperature/precipitation panels
|
|
695
|
-
leg_w.get_title().set_fontsize(legend_fontsize)
|
|
676
|
+
# the twin shares the x-axis; keep its date tick labels hidden so
|
|
677
|
+
# only the bottommost (direction) panel shows dates
|
|
678
|
+
plt.setp(ax_ws.get_xticklabels(), visible=False)
|
|
679
|
+
plt.setp(ax_ws.get_yticklabels(), fontsize=tick_fontsize)
|
|
696
680
|
|
|
697
681
|
# Save Figure
|
|
698
682
|
if save_path:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: noaaplotter
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.3
|
|
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
|
|
@@ -45,7 +45,7 @@ A python package to create fancy plots with NOAA weather data (stations) and ERA
|
|
|
45
45
|
|
|
46
46
|
<p align="center">
|
|
47
47
|
<a href="https://pypi.org/project/noaaplotter/">
|
|
48
|
-
<img src="https://img.shields.io/badge/version-v1.1.
|
|
48
|
+
<img src="https://img.shields.io/badge/version-v1.1.3-31ad52" alt="version">
|
|
49
49
|
</a>
|
|
50
50
|
<a href="https://pypi.org/project/noaaplotter/">
|
|
51
51
|
<img src="https://img.shields.io/pypi/pyversions/noaaplotter" alt="Python versions">
|
|
@@ -89,10 +89,10 @@ python-dotenv, typer (all listed in `pyproject.toml` and installed automatically
|
|
|
89
89
|
noaaplotter download-data -o data/kotzebue.parquet -sid USW00026616 -start 1970-01-01 -end 2021-12-31
|
|
90
90
|
|
|
91
91
|
# 2. Create a daily plot (temperature vs. climate + precipitation, incl. 7-day rolling sum)
|
|
92
|
-
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/
|
|
92
|
+
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
|
|
93
93
|
|
|
94
94
|
# 3. ...or an interactive HTML plot
|
|
95
|
-
noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 --engine plotly -save_plot figures/
|
|
95
|
+
noaaplotter plot-daily -infile data/kotzebue.parquet -start 1992-01-01 -end 1992-12-31 --engine plotly -save_plot figures/kotzebue_daily_1992.html
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
## Command Line Interface (CLI)
|
|
@@ -133,10 +133,15 @@ equivalent, so both stay null for `--source noaa`.
|
|
|
133
133
|
|
|
134
134
|
### `noaaplotter plot-daily`
|
|
135
135
|
Daily temperature (observed vs. climate mean ± 1σ, with anomaly fills) + precipitation (bars + 7-day rolling sum).
|
|
136
|
+
When the input file has `WSPD`/`WDIR` (ERA5 sources only — NOAA station data has no wind), a third row is added automatically: one dot per day coloured/positioned by wind direction plus a wind-speed line on a right-hand axis; the plotly hover also shows the 16-point compass name (N, NNE, NE, ...).
|
|
136
137
|
|
|
137
138
|
```bash
|
|
138
|
-
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/
|
|
139
|
-
noaaplotter plot-daily -infile data/kotzebue.parquet -start 2017-07-01 -end 2018-06-30 --snow_acc --engine plotly -save_plot figures/
|
|
139
|
+
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
|
|
140
|
+
noaaplotter plot-daily -infile data/kotzebue.parquet -start 2017-07-01 -end 2018-06-30 --snow_acc --engine plotly -save_plot figures/kotzebue_daily_winter.html
|
|
141
|
+
|
|
142
|
+
# ERA5 input with wind columns -> daily plot gains the wind row (dots + speed line)
|
|
143
|
+
noaaplotter plot-daily -infile data/NTaymyr_ERA5_75.6_98.7.parquet -start 2020-01-01 -end 2020-12-31 -save_plot figures/NTaymyr_ERA5_75.6_98.7_daily.png
|
|
144
|
+
noaaplotter plot-daily -infile data/NTaymyr_ERA5_75.6_98.7.parquet --engine plotly -start 2020-01-01 -end 2020-12-31 -save_plot figures/NTaymyr_ERA5_75.6_98.7_daily.html
|
|
140
145
|
```
|
|
141
146
|
|
|
142
147
|
| Option | Meaning |
|
|
@@ -160,10 +165,10 @@ Monthly bar chart of temperature or precipitation, with anomaly and trailing mea
|
|
|
160
165
|
|
|
161
166
|
```bash
|
|
162
167
|
# Absolute values
|
|
163
|
-
noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Temperature -trail 12 -save_plot figures/
|
|
168
|
+
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
|
|
164
169
|
|
|
165
170
|
# Anomaly from climate (1981-2010)
|
|
166
|
-
noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 2021-08-31 -type Precipitation -trail 12 -
|
|
171
|
+
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
|
|
167
172
|
```
|
|
168
173
|
|
|
169
174
|
| Option | Meaning |
|
|
@@ -231,6 +236,22 @@ Entire year 1 January until 31 December (e.g. 1992):
|
|
|
231
236
|
|
|
232
237
|

|
|
233
238
|
|
|
239
|
+
### Daily plot with wind (ERA5 sources)
|
|
240
|
+
|
|
241
|
+
NOAA station data has no wind columns, so the wind row only appears for
|
|
242
|
+
ERA5-backed inputs (`--source open_meteo` / `cds`), which also deliver
|
|
243
|
+
`WSPD`/`WDIR`. The wind row draws one dot per day placed by wind direction
|
|
244
|
+
(hover shows the 16-point compass name, e.g. `247° (WSW)`) plus a wind-speed
|
|
245
|
+
line on a right-hand axis:
|
|
246
|
+
|
|
247
|
+
`noaaplotter plot-daily --input-file data/NTaymyr_ERA5_75.6_98.7.parquet --start-date 2020-01-01 --end-date 2020-12-31 --save-plot figures/NTaymyr_ERA5_75.6_98.7_daily.png`
|
|
248
|
+
|
|
249
|
+

|
|
250
|
+
|
|
251
|
+
Interactive (plotly) version of the same figure:
|
|
252
|
+
|
|
253
|
+
`noaaplotter plot-daily --input-file data/NTaymyr_ERA5_75.6_98.7.parquet --engine plotly --start-date 2020-01-01 --end-date 2020-12-31 --save-plot figures/NTaymyr_ERA5_75.6_98.7_daily.html`
|
|
254
|
+
|
|
234
255
|
### Monthly aggregates
|
|
235
256
|
Temperature, absolute (12-month trailing mean):
|
|
236
257
|
|
|
@@ -292,5 +313,5 @@ from noaaplotter import NOAAPlotter
|
|
|
292
313
|
n = NOAAPlotter("data/kotzebue.parquet", location="Kotzebue", climate_filtersize=7)
|
|
293
314
|
fig = n.plot_weather_series(start_date="1992-01-01", end_date="1992-12-31",
|
|
294
315
|
show_plot=False, return_plot=True, engine="plotly")
|
|
295
|
-
fig.write_html("figures/
|
|
316
|
+
fig.write_html("figures/kotzebue_daily_1992.html")
|
|
296
317
|
```
|
|
@@ -185,23 +185,29 @@ def test_wind_row_present_when_wspd_wdir_exist_matplotlib(tmp_path):
|
|
|
185
185
|
engine="matplotlib", show_plot=False, plot_extrema=False,
|
|
186
186
|
return_plot=True, show_snow_accumulation=False,
|
|
187
187
|
)
|
|
188
|
-
#
|
|
189
|
-
# (
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
# find the wind axis by its "Direction" ylabel (not just "last")
|
|
188
|
+
# 4 axes in the wind layout: temperature, precipitation, wind direction
|
|
189
|
+
# (primary), wind speed (twinned secondary axis). No colorbar axis.
|
|
190
|
+
assert len(fig.axes) == 4, f"expected 4 axes, got {len(fig.axes)}"
|
|
191
|
+
# find the wind direction axis by its "Direction" ylabel
|
|
193
192
|
wind_ax = next(
|
|
194
193
|
ax for ax in fig.axes if ax.get_ylabel() == "Direction"
|
|
195
194
|
)
|
|
196
195
|
ticks = {t.get_text() for t in wind_ax.get_yticklabels()}
|
|
197
196
|
assert {"N", "S", "E", "W"} <= ticks
|
|
198
|
-
# speed
|
|
199
|
-
|
|
200
|
-
assert
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
assert
|
|
197
|
+
# speed twin axis carries the m/s ylabel
|
|
198
|
+
spd_ax = next(ax for ax in fig.axes if ax.get_ylabel() == "Wind speed in m/s")
|
|
199
|
+
assert spd_ax is not wind_ax
|
|
200
|
+
# direction dots: scatter collection with offsets, no line segments and
|
|
201
|
+
# no per-dot colour encoding (single flat colour)
|
|
202
|
+
coll = wind_ax.collections
|
|
203
|
+
assert coll, "direction dots missing"
|
|
204
|
+
assert not wind_ax.get_lines(), "direction must be dots WITHOUT a line"
|
|
205
|
+
# speed line exists on the twin axis
|
|
206
|
+
assert spd_ax.get_lines(), "wind speed line missing"
|
|
207
|
+
# the twin axis must NOT draw its own date labels (shared x: only the
|
|
208
|
+
# bottommost panel shows dates)
|
|
209
|
+
assert all(not t.get_visible() for t in spd_ax.get_xticklabels()), \
|
|
210
|
+
"speed twin must not draw duplicate date labels"
|
|
205
211
|
# headroom: (inverted) ylim spans beyond the compass range so extreme dots
|
|
206
212
|
# clear the axis edge
|
|
207
213
|
lo, hi = wind_ax.get_ylim()
|
|
@@ -242,28 +248,42 @@ def test_wind_row_present_when_wspd_wdir_exist(tmp_path):
|
|
|
242
248
|
engine="plotly", show_plot=False, plot_extrema=True,
|
|
243
249
|
)
|
|
244
250
|
names = [t.name for t in fig.data]
|
|
245
|
-
assert "
|
|
246
|
-
|
|
251
|
+
assert "Wind direction" in names, f"missing wind trace, got {names}"
|
|
252
|
+
assert "Wind speed" in names, f"missing speed trace, got {names}"
|
|
253
|
+
# legend removed entirely; no colorscale anywhere on the wind traces
|
|
247
254
|
assert fig.layout.showlegend is False
|
|
248
|
-
wind = next(t for t in fig.data if t.name == "
|
|
255
|
+
wind = next(t for t in fig.data if t.name == "Wind direction")
|
|
256
|
+
spd = next(t for t in fig.data if t.name == "Wind speed")
|
|
249
257
|
assert getattr(wind.marker, "colorscale", None) in (None, False, "")
|
|
250
|
-
# direction
|
|
251
|
-
# ylim headroom beyond the compass range
|
|
258
|
+
# direction dots: on yaxis3 (row 3 primary) with compass tick text and
|
|
259
|
+
# ylim headroom beyond the compass range; markers-only (no line)
|
|
260
|
+
assert wind.mode == "markers"
|
|
252
261
|
assert getattr(wind, "yaxis", "") == "y3"
|
|
262
|
+
# regression: the speed line MUST pin the wind row's x-axis explicitly
|
|
263
|
+
# (xaxis=x3). Without it plotly anchors the free-positioned y4 to its own
|
|
264
|
+
# default x-axis and the line renders in a phantom axis (blank panel).
|
|
265
|
+
assert getattr(spd, "xaxis", "") == "x3"
|
|
253
266
|
compass_axis = fig.layout.yaxis3
|
|
254
267
|
ticks = list(getattr(compass_axis, "ticktext", []) or [])
|
|
255
268
|
assert "N" in ticks and "S" in ticks and "E" in ticks
|
|
256
269
|
rng = [float(v) for v in (getattr(compass_axis, "range", []) or [])]
|
|
257
270
|
assert rng and max(rng) > 360 and min(rng) < 0, f"no wind ylim headroom: {rng}"
|
|
258
|
-
#
|
|
259
|
-
assert
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
271
|
+
# speed line overlays on its own axis (y4), single colour
|
|
272
|
+
assert spd.mode == "lines"
|
|
273
|
+
assert getattr(spd, "yaxis", "") == "y4"
|
|
274
|
+
assert str(spd.line.color).startswith("rgba(")
|
|
275
|
+
# hover carries degrees AND the 16-point compass name
|
|
276
|
+
assert "customdata" in wind.hovertemplate
|
|
277
|
+
assert all(isinstance(c, (list, tuple)) for c in wind.customdata[:5])
|
|
278
|
+
assert list(wind.customdata[0])[1] in (
|
|
279
|
+
"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
|
|
280
|
+
"S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW")
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def test_wind_gap_days_render_as_missing(tmp_path):
|
|
284
|
+
# Regression guard for the dots+line design: days without WSPD/WDIR must
|
|
285
|
+
# stay null (no dot / no line segment fabricated for them) — and the flat
|
|
286
|
+
# single-colour markers make the old None-in-color-list failure impossible.
|
|
267
287
|
import numpy as np
|
|
268
288
|
import pandas as pd
|
|
269
289
|
|
|
@@ -290,16 +310,16 @@ def test_wind_gap_days_use_transparent_color(tmp_path):
|
|
|
290
310
|
df.to_parquet(path)
|
|
291
311
|
|
|
292
312
|
n = NOAAPlotter(str(path), location="Synthetic")
|
|
293
|
-
# before the fix this raised a plotly ValidationError on None colours
|
|
294
313
|
fig = n.plot_weather_series(
|
|
295
314
|
start_date="2009-01-01", end_date="2010-12-31",
|
|
296
315
|
engine="plotly", show_plot=False, plot_extrema=True,
|
|
297
316
|
)
|
|
298
|
-
wind = next(t for t in fig.data if t.name == "
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
assert
|
|
317
|
+
wind = next(t for t in fig.data if t.name == "Wind direction")
|
|
318
|
+
spd = next(t for t in fig.data if t.name == "Wind speed")
|
|
319
|
+
# null days stay NaN (no fabricated values, no interpolation)
|
|
320
|
+
import numpy as _np
|
|
321
|
+
assert _np.isnan(spd.y).sum() >= 9, "speed nulls must stay null"
|
|
322
|
+
assert _np.isnan(wind.y).any(), "direction nulls must stay null"
|
|
303
323
|
|
|
304
324
|
|
|
305
325
|
def test_no_wind_row_when_source_lacks_wind(tmp_path):
|
|
@@ -327,7 +347,7 @@ def test_no_wind_row_when_source_lacks_wind(tmp_path):
|
|
|
327
347
|
engine="plotly", show_plot=False, plot_extrema=True,
|
|
328
348
|
)
|
|
329
349
|
names = [t.name for t in fig.data]
|
|
330
|
-
assert "
|
|
350
|
+
assert "Wind direction" not in names and "Wind speed" not in names
|
|
331
351
|
|
|
332
352
|
|
|
333
353
|
def test_download_cli_runs_without_token(tmp_path, monkeypatch):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|