rsplot 0.3.2.dev4__py3-none-any.whl → 0.4.0__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 (67) hide show
  1. rsplot/atomic.py +36 -0
  2. rsplot/cli.py +272 -497
  3. rsplot/commands/common.py +52 -3
  4. rsplot/commands/fnr.py +389 -104
  5. rsplot/commands/forecast.py +0 -2
  6. rsplot/commands/meteo.py +499 -186
  7. rsplot/commands/overlay.py +284 -326
  8. rsplot/commands/radius.py +526 -0
  9. rsplot/commands/raster.py +418 -293
  10. rsplot/commands/reconstruct.py +0 -1
  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 +43 -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 +212 -9
  19. rsplot/geo/footprints.py +3 -0
  20. rsplot/geo/processing.py +2 -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 +84 -6
  25. rsplot/plotting/meteo.py +10 -3
  26. rsplot/plotting/overlay.py +31 -40
  27. rsplot/plotting/raster.py +10 -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 +52 -4
  33. rsplot/readers/_tropomi.py +121 -3
  34. rsplot/readers/era5.py +110 -10
  35. rsplot/readers/era5_wind.py +3 -2
  36. rsplot/readers/gems.py +11 -8
  37. rsplot/readers/guokong.py +125 -39
  38. rsplot/readers/netcdf.py +32 -0
  39. rsplot/readers/tropomi_hcho.py +1 -1
  40. rsplot/readers/tropomi_no2.py +1 -1
  41. rsplot/readers/tropomi_nrti.py +116 -0
  42. rsplot/readers/tropomi_o3.py +1 -1
  43. rsplot/readers/tropomi_o3pr.py +1 -1
  44. rsplot/result_builders/__init__.py +0 -14
  45. rsplot/result_builders/common.py +4 -1
  46. rsplot/result_builders/envelope.py +236 -0
  47. rsplot/result_builders/fnr.py +47 -131
  48. rsplot/result_builders/provenance.py +59 -0
  49. rsplot/result_builders/satellite.py +240 -0
  50. rsplot/result_builders/series_layer.py +289 -0
  51. rsplot/result_builders/station.py +23 -0
  52. rsplot/result_builders/station_layer.py +326 -0
  53. rsplot/results.py +0 -12
  54. rsplot/schemas/result.schema.json +566 -0
  55. rsplot/temporal.py +7 -0
  56. {rsplot-0.3.2.dev4.dist-info → rsplot-0.4.0.dist-info}/METADATA +426 -121
  57. rsplot-0.4.0.dist-info/RECORD +76 -0
  58. {rsplot-0.3.2.dev4.dist-info → rsplot-0.4.0.dist-info}/WHEEL +1 -1
  59. rsplot/commands/recent.py +0 -186
  60. rsplot/recent.py +0 -447
  61. rsplot/result_builders/meteo.py +0 -171
  62. rsplot/result_builders/overlay.py +0 -105
  63. rsplot/result_builders/raster.py +0 -104
  64. rsplot/result_builders/station_trend.py +0 -229
  65. rsplot-0.3.2.dev4.dist-info/RECORD +0 -66
  66. {rsplot-0.3.2.dev4.dist-info → rsplot-0.4.0.dist-info}/entry_points.txt +0 -0
  67. {rsplot-0.3.2.dev4.dist-info → rsplot-0.4.0.dist-info}/licenses/LICENSE +0 -0
rsplot/commands/common.py CHANGED
@@ -3,11 +3,14 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import math
6
+ import re
6
7
  from collections.abc import Callable
7
8
  from typing import TYPE_CHECKING, ParamSpec, TypeVar
8
9
 
9
10
  import typer
10
11
 
12
+ from rsplot.errors import RsplotError
13
+
11
14
  if TYPE_CHECKING:
12
15
  import geopandas as gpd
13
16
  from rich.console import Console
@@ -39,6 +42,50 @@ def parse_basemap(value: str | None) -> bool | None:
39
42
  raise ValueError("--basemap 仅支持 satellite / none。")
40
43
 
41
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
+
42
89
  def validate_positive(value: float, option: str) -> None:
43
90
  """Require a finite value greater than zero."""
44
91
  if not math.isfinite(value) or value <= 0:
@@ -123,12 +170,13 @@ def resolve_satellite(
123
170
  qa: float | None,
124
171
  cfg: AppConfig,
125
172
  console: Console,
173
+ processing: str | None = None,
126
174
  ) -> tuple[ProductInfo, float]:
127
175
  """Resolve source and QA policy before opening regional/data files."""
128
176
  from rsplot.readers import get_product_info
129
177
 
130
178
  try:
131
- info = get_product_info(product, sensor=sensor)
179
+ info = get_product_info(product, sensor=sensor, processing=processing)
132
180
  if info.sensor == "gems" and qa is not None:
133
181
  raise ValueError(
134
182
  "--qa 仅用于 TROPOMI;GEMS 使用最终质量标记 = 0 "
@@ -142,9 +190,10 @@ def resolve_satellite(
142
190
  else cfg.qa_threshold
143
191
  )
144
192
  validate_unit_interval(threshold, "--qa")
193
+ except RsplotError:
194
+ raise
145
195
  except ValueError as error:
146
- console.print(f"[red]{error}[/red]")
147
- raise typer.Exit(1) from error
196
+ raise RsplotError("invalid_argument", str(error)) from error
148
197
  return info, threshold
149
198
 
150
199