rsplot 0.3.1.dev3__py3-none-any.whl → 0.3.2.dev37__py3-none-any.whl

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 (71) hide show
  1. rsplot/atomic.py +36 -0
  2. rsplot/cli.py +282 -469
  3. rsplot/commands/common.py +113 -1
  4. rsplot/commands/fnr.py +389 -104
  5. rsplot/commands/forecast.py +24 -7
  6. rsplot/commands/meteo.py +499 -186
  7. rsplot/commands/overlay.py +292 -205
  8. rsplot/commands/radius.py +526 -0
  9. rsplot/commands/raster.py +479 -230
  10. rsplot/commands/reconstruct.py +27 -6
  11. rsplot/commands/sidecar.py +106 -0
  12. rsplot/commands/station.py +154 -42
  13. rsplot/commands/station_trend.py +259 -174
  14. rsplot/config.py +46 -16
  15. rsplot/data_files.py +253 -0
  16. rsplot/errors.py +43 -0
  17. rsplot/fnr.py +38 -46
  18. rsplot/geo/boundaries.py +317 -11
  19. rsplot/geo/footprints.py +205 -0
  20. rsplot/geo/processing.py +84 -5
  21. rsplot/geo/radius.py +205 -0
  22. rsplot/plotting/colormap_22.txt +256 -0
  23. rsplot/plotting/colormaps.py +24 -29
  24. rsplot/plotting/map_frame.py +203 -9
  25. rsplot/plotting/meteo.py +10 -3
  26. rsplot/plotting/overlay.py +36 -40
  27. rsplot/plotting/raster.py +15 -3
  28. rsplot/plotting/station.py +86 -33
  29. rsplot/plotting/station_focus.py +84 -0
  30. rsplot/plotting/station_trend.py +60 -47
  31. rsplot/plotting/styles.py +3 -5
  32. rsplot/readers/__init__.py +89 -7
  33. rsplot/readers/_tropomi.py +121 -3
  34. rsplot/readers/base.py +16 -1
  35. rsplot/readers/era5.py +110 -10
  36. rsplot/readers/era5_wind.py +3 -2
  37. rsplot/readers/gems.py +429 -0
  38. rsplot/readers/guokong.py +125 -39
  39. rsplot/readers/netcdf.py +32 -0
  40. rsplot/readers/tropomi_hcho.py +1 -1
  41. rsplot/readers/tropomi_no2.py +1 -1
  42. rsplot/readers/tropomi_nrti.py +116 -0
  43. rsplot/readers/tropomi_o3.py +1 -1
  44. rsplot/readers/tropomi_o3pr.py +1 -1
  45. rsplot/result_builders/__init__.py +0 -14
  46. rsplot/result_builders/common.py +84 -0
  47. rsplot/result_builders/envelope.py +236 -0
  48. rsplot/result_builders/fnr.py +47 -131
  49. rsplot/result_builders/forecast.py +7 -0
  50. rsplot/result_builders/provenance.py +59 -0
  51. rsplot/result_builders/reconstruct.py +7 -0
  52. rsplot/result_builders/satellite.py +240 -0
  53. rsplot/result_builders/series_layer.py +289 -0
  54. rsplot/result_builders/station.py +23 -0
  55. rsplot/result_builders/station_layer.py +326 -0
  56. rsplot/results.py +0 -12
  57. rsplot/schemas/result.schema.json +566 -0
  58. rsplot/temporal.py +146 -16
  59. rsplot-0.3.2.dev37.dist-info/METADATA +996 -0
  60. rsplot-0.3.2.dev37.dist-info/RECORD +76 -0
  61. {rsplot-0.3.1.dev3.dist-info → rsplot-0.3.2.dev37.dist-info}/WHEEL +1 -1
  62. rsplot/commands/recent.py +0 -164
  63. rsplot/recent.py +0 -404
  64. rsplot/result_builders/meteo.py +0 -171
  65. rsplot/result_builders/overlay.py +0 -75
  66. rsplot/result_builders/raster.py +0 -72
  67. rsplot/result_builders/station_trend.py +0 -229
  68. rsplot-0.3.1.dev3.dist-info/METADATA +0 -477
  69. rsplot-0.3.1.dev3.dist-info/RECORD +0 -64
  70. {rsplot-0.3.1.dev3.dist-info → rsplot-0.3.2.dev37.dist-info}/entry_points.txt +0 -0
  71. {rsplot-0.3.1.dev3.dist-info → rsplot-0.3.2.dev37.dist-info}/licenses/LICENSE +0 -0
rsplot/commands/common.py CHANGED
@@ -3,13 +3,21 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import math
6
- from typing import TYPE_CHECKING
6
+ import re
7
+ from collections.abc import Callable
8
+ from typing import TYPE_CHECKING, ParamSpec, TypeVar
9
+
10
+ import typer
11
+
12
+ from rsplot.errors import RsplotError
7
13
 
8
14
  if TYPE_CHECKING:
9
15
  import geopandas as gpd
10
16
  from rich.console import Console
11
17
 
18
+ from rsplot.config import AppConfig
12
19
  from rsplot.geo.boundaries import RegionInfo
20
+ from rsplot.readers import ProductInfo
13
21
 
14
22
 
15
23
  FORECAST_STATION_PAIR: dict[str, str] = {
@@ -34,6 +42,50 @@ def parse_basemap(value: str | None) -> bool | None:
34
42
  raise ValueError("--basemap 仅支持 satellite / none。")
35
43
 
36
44
 
45
+ def parse_explicit_window(date_arg: str, days: int | None) -> list[str]:
46
+ """Return the dates of a window whose length is stated explicitly.
47
+
48
+ The window is either a ``YYYYMMDD-YYYYMMDD`` range or an end date
49
+ ``YYYYMMDD`` with ``--days``; a single date alone is rejected.
50
+ """
51
+ from rsplot.temporal import parse_date_window
52
+
53
+ if days is not None and days < 1:
54
+ raise RsplotError(
55
+ "invalid_argument", "--days 必须 >= 1。", option="--days"
56
+ )
57
+ if "-" in date_arg and days is not None:
58
+ raise RsplotError(
59
+ "invalid_argument",
60
+ "日期区间不能与 --days 同时使用;"
61
+ "请选择 YYYYMMDD-YYYYMMDD 或结束日期 YYYYMMDD 配合 --days N。",
62
+ option="--days",
63
+ )
64
+ if "-" not in date_arg and days is None:
65
+ raise RsplotError(
66
+ "invalid_argument",
67
+ "单日 DATE 需要 --days N 指定窗口长度,"
68
+ "或使用日期区间 YYYYMMDD-YYYYMMDD。",
69
+ option="--days",
70
+ )
71
+ try:
72
+ return parse_date_window(date_arg, default_days=days or 0)
73
+ except ValueError as error:
74
+ raise RsplotError("invalid_time", str(error)) from error
75
+
76
+
77
+ def require_single_region(region: str) -> None:
78
+ """Reject a comma list where a merged regional mean would be implicit."""
79
+ names = [name.strip() for name in re.split("[,,]", region)]
80
+ if len(names) > 1:
81
+ raise RsplotError(
82
+ "invalid_argument",
83
+ f"'{region}' 列出了多个区域。时间序列一次只汇总一个区域,"
84
+ "合并多个区域会隐式加权;请对每个区域分别运行。",
85
+ details={"regions": [name for name in names if name]},
86
+ )
87
+
88
+
37
89
  def validate_positive(value: float, option: str) -> None:
38
90
  """Require a finite value greater than zero."""
39
91
  if not math.isfinite(value) or value <= 0:
@@ -110,3 +162,63 @@ def print_failed_dates(
110
162
  console.print(f" - {date}: {message}")
111
163
  if len(items) > max_items:
112
164
  console.print(f" ... 另有 {len(items) - max_items} 天")
165
+
166
+
167
+ def resolve_satellite(
168
+ product: str,
169
+ sensor: str,
170
+ qa: float | None,
171
+ cfg: AppConfig,
172
+ console: Console,
173
+ processing: str | None = None,
174
+ ) -> tuple[ProductInfo, float]:
175
+ """Resolve source and QA policy before opening regional/data files."""
176
+ from rsplot.readers import get_product_info
177
+
178
+ try:
179
+ info = get_product_info(product, sensor=sensor, processing=processing)
180
+ if info.sensor == "gems" and qa is not None:
181
+ raise ValueError(
182
+ "--qa 仅用于 TROPOMI;GEMS 使用最终质量标记 = 0 "
183
+ "及 SZA/VZA < 70°,云量可通过 --cf 设置。"
184
+ )
185
+ threshold = (
186
+ 0.5
187
+ if info.sensor == "gems"
188
+ else qa
189
+ if qa is not None
190
+ else cfg.qa_threshold
191
+ )
192
+ validate_unit_interval(threshold, "--qa")
193
+ except RsplotError:
194
+ raise
195
+ except ValueError as error:
196
+ raise RsplotError("invalid_argument", str(error)) from error
197
+ return info, threshold
198
+
199
+
200
+ def satellite_filter_label(sensor: str, qa: float, cf: float) -> str:
201
+ """Describe the actual filter rather than a synthetic GEMS QA value."""
202
+ quality = (
203
+ "最终质量标记 = 0, SZA/VZA < 70°" if sensor == "gems" else f"QA > {qa}"
204
+ )
205
+ return f"{quality}, 云量 <= {cf}"
206
+
207
+
208
+ _P = ParamSpec("_P")
209
+ _R = TypeVar("_R")
210
+
211
+
212
+ def satellite_errors(function: Callable[_P, _R]) -> Callable[_P, _R]:
213
+ """Render expected satellite input/data errors in the CLI's style."""
214
+ from functools import wraps
215
+
216
+ @wraps(function)
217
+ def wrapped(*args: _P.args, **kwargs: _P.kwargs) -> _R:
218
+ try:
219
+ return function(*args, **kwargs)
220
+ except (ValueError, FileNotFoundError, OSError) as error:
221
+ kwargs["console"].print(f"[red]{error}[/red]")
222
+ raise typer.Exit(1) from error
223
+
224
+ return wrapped