noaaplotter 1.0.0__tar.gz → 1.0.1__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 (36) hide show
  1. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/PKG-INFO +70 -2
  2. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/README.md +68 -0
  3. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/cli/__init__.py +187 -1
  4. noaaplotter-1.0.1/noaaplotter/figures/__init__.py +12 -0
  5. noaaplotter-1.0.1/noaaplotter/figures/plotly_heatmap.py +91 -0
  6. noaaplotter-1.0.1/noaaplotter/figures/plotly_stripes.py +107 -0
  7. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/noaaplotter.py +492 -0
  8. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/utils/dataset.py +5 -1
  9. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter.egg-info/PKG-INFO +70 -2
  10. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter.egg-info/SOURCES.txt +2 -0
  11. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter.egg-info/requires.txt +1 -1
  12. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/pyproject.toml +2 -2
  13. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/tests/test_plotly_figures.py +195 -0
  14. noaaplotter-1.0.0/noaaplotter/figures/__init__.py +0 -5
  15. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/LICENSE +0 -0
  16. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/__init__.py +0 -0
  17. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/__main__.py +0 -0
  18. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/figures/plotly_daily.py +0 -0
  19. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/figures/plotly_monthly.py +0 -0
  20. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/scripts/download_data.py +0 -0
  21. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/scripts/plot_daily.py +0 -0
  22. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/scripts/plot_monthly.py +0 -0
  23. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/sources/__init__.py +0 -0
  24. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/sources/base.py +0 -0
  25. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/sources/cds.py +0 -0
  26. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/sources/open_meteo.py +0 -0
  27. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/utils/__init__.py +0 -0
  28. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/utils/config.py +0 -0
  29. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/utils/download_utils.py +0 -0
  30. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/utils/plot_utils.py +0 -0
  31. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter/utils/utils.py +0 -0
  32. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter.egg-info/dependency_links.txt +0 -0
  33. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter.egg-info/entry_points.txt +0 -0
  34. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/noaaplotter.egg-info/top_level.txt +0 -0
  35. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/setup.cfg +0 -0
  36. {noaaplotter-1.0.0 → noaaplotter-1.0.1}/tests/test_polars_parity.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: noaaplotter
3
- Version: 1.0.0
3
+ Version: 1.0.1
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,>=2
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
@@ -41,6 +41,21 @@ Dynamic: license-file
41
41
  # noaaplotter
42
42
  A python package to create fancy plots with NOAA weather data (stations) and ERA5 reanalysis (by coordinates).
43
43
 
44
+ <p align="center">
45
+ <a href="https://pypi.org/project/noaaplotter/">
46
+ <img src="https://img.shields.io/pypi/v/noaaplotter?label=version" alt="PyPI version">
47
+ </a>
48
+ <a href="https://pypi.org/project/noaaplotter/">
49
+ <img src="https://img.shields.io/pypi/pyversions/noaaplotter" alt="Python versions">
50
+ </a>
51
+ <a href="https://github.com/initze/noaaplotter/actions/workflows/python-package.yml">
52
+ <img src="https://img.shields.io/github/actions/workflow/status/initze/noaaplotter/python-package.yml?label=tests" alt="CI status">
53
+ </a>
54
+ <a href="https://initze.github.io/noaaplotter/">
55
+ <img src="https://img.shields.io/badge/docs-site-2f80ed?logo=readthedocs&logoColor=white" alt="Documentation">
56
+ </a>
57
+ </p>
58
+
44
59
  > 📚 **Docs & API reference:** [initze.github.io/noaaplotter](https://initze.github.io/noaaplotter)
45
60
  >
46
61
  > **Install:** `pip install noaaplotter`
@@ -153,6 +168,39 @@ noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 20
153
168
  | `-save_plot` | write the plot (`.png` / `.html`) |
154
169
  | `--engine` | `matplotlib` (default) or `plotly` |
155
170
 
171
+ ### `noaaplotter plot-stripes`
172
+ Warming stripes (Ed Hawkins style): one vertical bar per period, coloured by
173
+ temperature anomaly (cool-blue → white → warm-red).
174
+
175
+ ```bash
176
+ noaaplotter plot-stripes -infile data/kotzebue.parquet -type Temperature -start 1980-01-01 -end 2018-12-31 -save_plot figures/kotzebue_stripes.png
177
+ ```
178
+
179
+ | Option | Meaning |
180
+ |---|---|
181
+ | `-infile` | input parquet/csv (required) |
182
+ | `-start`, `-end` | optional window, `YYYY-MM-DD` (default: full record in the file) |
183
+ | `-type` | `Temperature` (default) or `Precipitation` (case-insensitive) |
184
+ | `-resolution` | `year` (default, one bar per year) or `month` |
185
+ | `-save_plot` | write the plot (`.png` / `.html`) |
186
+ | `--engine` | `matplotlib` (default) or `plotly` |
187
+
188
+ ### `noaaplotter plot-heatmap`
189
+ Activity heatmap (GitHub-style matrix): months on x, one row per year (latest on top).
190
+
191
+ ```bash
192
+ noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Temperature -scale anomaly -save_plot figures/kotzebue_heatmap_anomaly.png
193
+ ```
194
+
195
+ | Option | Meaning |
196
+ |---|---|
197
+ | `-infile` | input parquet/csv (required) |
198
+ | `-type` | `Temperature` (default) or `Precipitation` (case-insensitive) |
199
+ | `-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) |
200
+ | `-start`, `-end` | optional window, `YYYY-MM-DD` |
201
+ | `-save_plot` | write the plot (`.png` / `.html`) |
202
+ | `--engine` | `matplotlib` (default) or `plotly` |
203
+
156
204
  ## Examples
157
205
 
158
206
  ### Download data
@@ -194,6 +242,26 @@ Precipitation, absolute (12-month trailing mean):
194
242
 
195
243
  ![Kotzebue monthly precipitation](figures/kotzebue_monthly_p.png)
196
244
 
245
+ ### Warming stripes
246
+ One bar per year, coloured by the monthly-mean temperature anomaly (ed Hawkins style):
247
+
248
+ `noaaplotter plot-stripes -infile data/kotzebue.parquet -type Temperature -start 1980-01-01 -end 2018-12-31 -save_plot figures/kotzebue_stripes.png`
249
+
250
+ ![Kotzebue warming stripes 1980-2018](figures/kotzebue_stripes.png)
251
+
252
+ ### Activity heatmap (months × years)
253
+ Anomaly from the climate mean, red↔white↔blue (white in the centre):
254
+
255
+ `noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Temperature -scale anomaly -save_plot figures/kotzebue_heatmap_anomaly.png`
256
+
257
+ ![Kotzebue activity heatmap — temperature anomaly](figures/kotzebue_heatmap_anomaly.png)
258
+
259
+ Precipitation (absolute, `Blues` palette — blue for wet months):
260
+
261
+ `noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Precipitation -scale absolute -save_plot figures/kotzebue_heatmap_precip.png`
262
+
263
+ ![Kotzebue activity heatmap — precipitation (Blues)](figures/kotzebue_heatmap_precip.png)
264
+
197
265
  ## Advanced Usage
198
266
 
199
267
  ### 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/pypi/v/noaaplotter?label=version" alt="PyPI 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`
@@ -113,6 +128,39 @@ noaaplotter plot-monthly -infile data/kotzebue.parquet -start 1980-01-01 -end 20
113
128
  | `-save_plot` | write the plot (`.png` / `.html`) |
114
129
  | `--engine` | `matplotlib` (default) or `plotly` |
115
130
 
131
+ ### `noaaplotter plot-stripes`
132
+ Warming stripes (Ed Hawkins style): one vertical bar per period, coloured by
133
+ temperature anomaly (cool-blue → white → warm-red).
134
+
135
+ ```bash
136
+ noaaplotter plot-stripes -infile data/kotzebue.parquet -type Temperature -start 1980-01-01 -end 2018-12-31 -save_plot figures/kotzebue_stripes.png
137
+ ```
138
+
139
+ | Option | Meaning |
140
+ |---|---|
141
+ | `-infile` | input parquet/csv (required) |
142
+ | `-start`, `-end` | optional window, `YYYY-MM-DD` (default: full record in the file) |
143
+ | `-type` | `Temperature` (default) or `Precipitation` (case-insensitive) |
144
+ | `-resolution` | `year` (default, one bar per year) or `month` |
145
+ | `-save_plot` | write the plot (`.png` / `.html`) |
146
+ | `--engine` | `matplotlib` (default) or `plotly` |
147
+
148
+ ### `noaaplotter plot-heatmap`
149
+ Activity heatmap (GitHub-style matrix): months on x, one row per year (latest on top).
150
+
151
+ ```bash
152
+ noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Temperature -scale anomaly -save_plot figures/kotzebue_heatmap_anomaly.png
153
+ ```
154
+
155
+ | Option | Meaning |
156
+ |---|---|
157
+ | `-infile` | input parquet/csv (required) |
158
+ | `-type` | `Temperature` (default) or `Precipitation` (case-insensitive) |
159
+ | `-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) |
160
+ | `-start`, `-end` | optional window, `YYYY-MM-DD` |
161
+ | `-save_plot` | write the plot (`.png` / `.html`) |
162
+ | `--engine` | `matplotlib` (default) or `plotly` |
163
+
116
164
  ## Examples
117
165
 
118
166
  ### Download data
@@ -154,6 +202,26 @@ Precipitation, absolute (12-month trailing mean):
154
202
 
155
203
  ![Kotzebue monthly precipitation](figures/kotzebue_monthly_p.png)
156
204
 
205
+ ### Warming stripes
206
+ One bar per year, coloured by the monthly-mean temperature anomaly (ed Hawkins style):
207
+
208
+ `noaaplotter plot-stripes -infile data/kotzebue.parquet -type Temperature -start 1980-01-01 -end 2018-12-31 -save_plot figures/kotzebue_stripes.png`
209
+
210
+ ![Kotzebue warming stripes 1980-2018](figures/kotzebue_stripes.png)
211
+
212
+ ### Activity heatmap (months × years)
213
+ Anomaly from the climate mean, red↔white↔blue (white in the centre):
214
+
215
+ `noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Temperature -scale anomaly -save_plot figures/kotzebue_heatmap_anomaly.png`
216
+
217
+ ![Kotzebue activity heatmap — temperature anomaly](figures/kotzebue_heatmap_anomaly.png)
218
+
219
+ Precipitation (absolute, `Blues` palette — blue for wet months):
220
+
221
+ `noaaplotter plot-heatmap -infile data/kotzebue.parquet -type Precipitation -scale absolute -save_plot figures/kotzebue_heatmap_precip.png`
222
+
223
+ ![Kotzebue activity heatmap — precipitation (Blues)](figures/kotzebue_heatmap_precip.png)
224
+
157
225
  ## Advanced Usage
158
226
 
159
227
  ### 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 ("Temperature", "Precipitation"):
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
+ ]
@@ -0,0 +1,91 @@
1
+ """Interactive (plotly) months x years activity heatmap.
2
+
3
+ GitHub-style matrix: months on x (J–D), years on y (most recent on top).
4
+ Square cells: the layout's width and height are computed from ``cell_px``
5
+ so every cell is exactly ``cell_px`` on both axes.
6
+ """
7
+ import math
8
+
9
+ import plotly.graph_objects as go
10
+
11
+ # House palette (matches the static heatmap)
12
+ C_HIGH = "#d6604d"
13
+ C_LOW = "#4393c3"
14
+ MONTHS = ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"]
15
+
16
+
17
+ def _not_nan(v):
18
+ return v is not None and not (isinstance(v, float) and math.isnan(v))
19
+
20
+
21
+ def make_heatmap_figure(
22
+ matrix,
23
+ years,
24
+ title,
25
+ month_labels=None,
26
+ colorscale=None,
27
+ zmin=0.0,
28
+ zmax=1.0,
29
+ colorbar_title="",
30
+ format_spec=".1f",
31
+ hover_ctx="°C vs climate",
32
+ cell_px=None,
33
+ ):
34
+ """Build the interactive months × years heatmap.
35
+
36
+ matrix : (n_years x 12) of display values; None / NaN for missing.
37
+ years : year ints aligned to the rows (row 0 = top / most recent).
38
+ title : figure title.
39
+ month_labels : override for the x labels (default: "J","F",…,"D").
40
+ colorscale : plotly colorscale; default = diverging cool-blue/white/warm-red.
41
+ zmin / zmax : color-scale bounds in the *display value* units.
42
+ colorbar_title : label for the colorbar ("" -> no colorbar).
43
+ format_spec : printf-style numeric format in the hover text.
44
+ hover_ctx : text after the hover number (e.g. "°C", "th percentile").
45
+ cell_px : square cell size in px. Default None = auto: cells scale so the
46
+ whole figure fits ~700px tall (a standard 720p screen) whether
47
+ the record spans 40 or 200+ years (clamped to 4..20 px).
48
+ """
49
+ if colorscale is None:
50
+ colorscale = [[0.0, C_LOW], [0.5, "#ffffff"], [1.0, C_HIGH]]
51
+ months = month_labels or MONTHS
52
+
53
+ n_years = len(years)
54
+ z = [[None if not _not_nan(v) else float(v) for v in row] for row in matrix]
55
+ ylabels = [str(int(y)) for y in years]
56
+ show_colorbar = bool(colorbar_title)
57
+
58
+ hm = dict(
59
+ z=z,
60
+ y=ylabels,
61
+ x=months,
62
+ colorscale=colorscale,
63
+ zmin=zmin,
64
+ zmax=zmax,
65
+ showscale=show_colorbar,
66
+ hovertemplate=(
67
+ "%{{y}}-%{{x}}: %{{z:{0}}} {1}".format(format_spec, hover_ctx)
68
+ ),
69
+ )
70
+ if show_colorbar:
71
+ hm["colorbar"] = dict(title=colorbar_title, lenmode="fraction", len=0.8)
72
+ fig = go.Figure(go.Heatmap(**hm))
73
+
74
+ # Square cells: auto-scale so the whole figure fits ~700px tall
75
+ # (a standard 720p screen) unless the caller fixes cell_px.
76
+ if cell_px is None:
77
+ cell_px = int(max(4, min(16, 700 / max(n_years, 1))))
78
+ plot_w = 12 * cell_px
79
+ plot_h = n_years * cell_px
80
+ fig.update_layout(
81
+ template="plotly_white",
82
+ height=plot_h + 70, # +70 for title + x labels + margin
83
+ width=plot_w + 110, # +110 for y labels + colorbar
84
+ xaxis=dict(tickfont=dict(size=13)),
85
+ yaxis=dict(autorange="reversed", tickfont=dict(size=11)),
86
+ margin=dict(l=55, r=(90 if show_colorbar else 30), t=55, b=50),
87
+ title=dict(text=title, x=0),
88
+ hovermode="closest",
89
+ dragmode=False,
90
+ )
91
+ return fig
@@ -0,0 +1,107 @@
1
+ """Interactive (plotly) warming-stripes figure.
2
+
3
+ One horizontal band of one cell per year or month. The caller supplies the
4
+ display values and the colorscale/bounds (so the builder stays mode-agnostic).
5
+ """
6
+ import math
7
+
8
+ import plotly.graph_objects as go
9
+
10
+ # House palette (matches the static stripes: cool-blue low, warm-red high)
11
+ C_HIGH = "#d6604d"
12
+ C_LOW = "#4393c3"
13
+
14
+
15
+ def _not_nan(v):
16
+ return v is not None and not (isinstance(v, float) and math.isnan(v))
17
+
18
+
19
+ def make_stripes_figure(
20
+ values,
21
+ labels,
22
+ title,
23
+ height=220,
24
+ colorscale=None,
25
+ zmin=0.0,
26
+ zmax=1.0,
27
+ colorbar_title="",
28
+ format_spec=".1f",
29
+ hover_ctx="°C vs climate",
30
+ annotations=False,
31
+ ):
32
+ """Build the interactive warming-stripes figure.
33
+
34
+ Parameters
35
+ ----------
36
+ values : list of float (or None / NaN)
37
+ One value per stripe — already in the units the caller wants to show.
38
+ labels : list of str
39
+ Aligned x labels ("1980", "1981", … or "Jan-1980", "Feb-1980", …).
40
+ title : str
41
+ Figure title, shown only when ``annotations=True``.
42
+ height : int
43
+ Figure height in px.
44
+ colorscale : list of [t, hex]
45
+ Plotly colorscale. When None, the default diverging cool-warm
46
+ palette is used.
47
+ zmin / zmax : float
48
+ Color-scale bounds in the *display value* units.
49
+ colorbar_title : str
50
+ Label for the colorbar ("", or None, to hide the colorbar).
51
+ format_spec : str
52
+ printf-style numeric format in the hover text.
53
+ hover_ctx : str
54
+ Text following the hover number (e.g. "°C vs climate").
55
+ annotations : bool
56
+ When True, show the title, x-ticks and colorbar. When False (default)
57
+ the figure is the bare band — no chrome at all.
58
+ """
59
+ if colorscale is None:
60
+ colorscale = [[0.0, C_LOW], [0.5, "#ffffff"], [1.0, C_HIGH]]
61
+
62
+ n = len(values)
63
+ z = [[None if not _not_nan(v) else float(v) for v in values]]
64
+ show_colorbar = bool(colorbar_title) and annotations
65
+ hm = dict(
66
+ z=z,
67
+ x=[str(x) for x in labels],
68
+ y=[""],
69
+ colorscale=colorscale,
70
+ zmin=zmin,
71
+ zmax=zmax,
72
+ showscale=show_colorbar,
73
+ hovertemplate=(
74
+ "%{{x}}: %{{z:{0}}} {1}<extra>Warming stripes</extra>".format(
75
+ format_spec, hover_ctx
76
+ )
77
+ ),
78
+ )
79
+ if show_colorbar:
80
+ hm["colorbar"] = dict(title=colorbar_title, lenmode="fraction", len=0.55)
81
+ fig = go.Figure(go.Heatmap(**hm))
82
+
83
+ # With N cells and height H, we want the *cell width* to be about 1/N of
84
+ # the figure width — so the band fills the figure edge-to-edge with no
85
+ # gaps. The overall band is kept wide-and-short: width : height = 8 : 1.
86
+ fig_width = int(height * 8) + (90 if annotations else 25)
87
+ fig.update_layout(
88
+ template="plotly_white",
89
+ height=height,
90
+ width=fig_width,
91
+ xaxis=dict(
92
+ visible=annotations, # hide the entire axis (line + ticks) when bare
93
+ showticklabels=annotations,
94
+ tickangle=-45,
95
+ ),
96
+ yaxis=dict(showticklabels=False, zeroline=False, showgrid=False),
97
+ margin=dict(
98
+ l=15,
99
+ r=(70 if annotations else 20),
100
+ t=(45 if annotations else 15),
101
+ b=(45 if annotations else 15),
102
+ ),
103
+ title=dict(text=title if annotations else "", x=0),
104
+ hovermode="x",
105
+ dragmode=False,
106
+ )
107
+ return fig