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
@@ -2,43 +2,106 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import TYPE_CHECKING
5
+ from pathlib import Path
6
+ from typing import TYPE_CHECKING, Any
6
7
 
7
8
  import numpy as np
8
- import typer
9
9
 
10
10
  from rsplot.commands.common import (
11
11
  load_fallback_city_boundaries,
12
- parse_basemap,
13
- validate_color_range,
14
- validate_non_negative,
15
- validate_positive,
16
- validate_unit_interval,
17
- warn_missing_tianditu_key,
12
+ resolve_satellite,
18
13
  )
14
+ from rsplot.commands.raster import parse_raster_dates, prepare_raster
19
15
  from rsplot.config import AppConfig
16
+ from rsplot.errors import RsplotError
20
17
 
21
18
  if TYPE_CHECKING:
22
19
  from rich.console import Console
23
20
 
24
21
 
25
- PRODUCT_STATION_PAIR = {
26
- "no2": "NO2",
27
- "o3": "O3",
28
- "o3pr": "O3",
29
- }
22
+ def resolve_station_hour(
23
+ date_arg: str,
24
+ sensor: str,
25
+ days: int | None,
26
+ station_datetime: str | None,
27
+ ) -> tuple[str, dict[str, Any], list[str], bool]:
28
+ """Resolve satellite dates and one station hour; never pick the latest.
30
29
 
30
+ Returns the station hour, the ``time_matching`` relation, the satellite
31
+ dates and whether they form a window.
32
+ """
33
+ from rsplot.readers.gems import match_station_hour, parse_gems_time
34
+ from rsplot.temporal import adapt_hourly_time
31
35
 
32
- def run_overlay(
36
+ scan_mode = sensor == "gems" and len(date_arg) == 12
37
+ if scan_mode:
38
+ try:
39
+ parse_gems_time(date_arg)
40
+ except ValueError as error:
41
+ raise RsplotError("invalid_time", str(error)) from error
42
+ if days is not None:
43
+ raise RsplotError(
44
+ "invalid_argument",
45
+ "GEMS 单次扫描不能同时使用 --days。",
46
+ option="--days",
47
+ )
48
+ dates, window_mode = [date_arg[:8]], False
49
+ else:
50
+ dates, window_mode = parse_raster_dates(date_arg, days)
51
+ if station_datetime is not None:
52
+ try:
53
+ adapt_hourly_time(station_datetime, label="--station-datetime ")
54
+ except ValueError as error:
55
+ raise RsplotError(
56
+ "invalid_time", str(error), option="--station-datetime"
57
+ ) from error
58
+ if not scan_mode and station_datetime is None:
59
+ raise RsplotError(
60
+ "invalid_argument",
61
+ "卫星日均或窗口均值叠加站点时,必须通过 --station-datetime "
62
+ "YYYYMMDDHH 指定一个站点小时;不会自动选择。",
63
+ option="--station-datetime",
64
+ )
65
+ if scan_mode or (sensor == "gems" and not window_mode):
66
+ hour, pairing = match_station_hour(date_arg, station_datetime)
67
+ else:
68
+ hour = station_datetime
69
+ pairing = {
70
+ "reference": "period_mean_with_explicit_station_hour",
71
+ "difference_minutes": None,
72
+ "manual_override": True,
73
+ }
74
+ matching = {
75
+ "layers": ["satellite", "station"],
76
+ "reference": pairing["reference"],
77
+ "difference_minutes": pairing["difference_minutes"],
78
+ "manual_override": pairing["manual_override"],
79
+ }
80
+ return hour, matching, dates, window_mode
81
+
82
+
83
+ def run_overlay(**kwargs: Any) -> None:
84
+ """Overlay one station hour on a satellite layer."""
85
+ from rsplot.commands.sidecar import run_with_sidecar
86
+
87
+ run_with_sidecar(
88
+ kwargs=kwargs,
89
+ emit=lambda created: _emit_overlay(created, **kwargs),
90
+ )
91
+
92
+
93
+ def _emit_overlay(
94
+ created: list[Path],
33
95
  *,
34
96
  region: str,
35
- datetime_str: str,
97
+ date_arg: str,
36
98
  product: str,
37
- var: str | None,
38
- level: str | None,
39
- raster_dir: str | None,
40
- station_dir: str | None,
41
- output: str | None,
99
+ sensor: str = "tropomi",
100
+ processing: str | None = None,
101
+ days: int | None = None,
102
+ station_datetime: str | None = None,
103
+ station_var: str,
104
+ output: str,
42
105
  dpi: int | None,
43
106
  res: float | None,
44
107
  basemap: str | None,
@@ -51,217 +114,241 @@ def run_overlay(
51
114
  title: str | None,
52
115
  console: Console,
53
116
  ) -> None:
54
- """Execute satellite/station overlay orchestration."""
117
+ """Read one station hour, reuse raster preparation, write the sidecar."""
55
118
  from rsplot.config import STATION_VAR_META, get_exceedance_threshold
56
- from rsplot.geo.boundaries import resolve_region
57
- from rsplot.geo.processing import buffered_extent, prepare_swath_grid
119
+ from rsplot.data_files import data_path, write_grid_netcdf, write_table_csv
120
+ from rsplot.geo.boundaries import resolve_regions
121
+ from rsplot.geo.processing import buffered_extent
58
122
  from rsplot.plotting.overlay import plot_overlay
59
- from rsplot.plotting.styles import setup_fonts
60
- from rsplot.readers import auto_vrange, get_product_info
61
- from rsplot.readers.guokong import mask_stations_to_region, read_stations
62
- from rsplot.results import build_overlay_result, emit_result
63
-
64
- cfg = AppConfig.load()
65
- setup_fonts(cfg.font_dir)
66
-
67
- if var is None:
68
- var = PRODUCT_STATION_PAIR.get(product.lower(), "AQI")
69
- if var not in STATION_VAR_META:
70
- available = ", ".join(STATION_VAR_META)
71
- console.print(f"[red]未知站点变量 '{var}'[/red]。可用: {available}")
72
- raise typer.Exit(1)
73
-
74
- if not datetime_str.isdigit() or len(datetime_str) not in (8, 10):
75
- console.print(
76
- f"[red]datetime 参数 '{datetime_str}' 格式不正确[/red],"
77
- "请使用 YYYYMMDD 或 YYYYMMDDHH。"
78
- )
79
- raise typer.Exit(1)
80
- date = datetime_str[:8]
81
-
82
- console.print(f"[bold]解析区域:[/bold] {region}")
83
- info = resolve_region(region, cfg, level_override=level)
84
- console.print(f" → [green]{info.name}[/green] (级别: {info.level})")
85
- console.print(
86
- f" → 范围: {info.extent[0]:.2f}°~{info.extent[1]:.2f}°E, "
87
- f"{info.extent[2]:.2f}°~{info.extent[3]:.2f}°N"
88
- )
89
-
90
- params = info.params
91
- use_dpi = dpi if dpi is not None else cfg.dpi
92
- prod_info = get_product_info(product)
93
- product_defaults = prod_info.defaults_for_level(info.level)
94
- use_res = (
95
- res
96
- if res is not None
97
- else product_defaults.res
98
- if product_defaults.res is not None
99
- else params.res
123
+ from rsplot.readers.guokong import read_stations
124
+ from rsplot.result_builders.envelope import (
125
+ command_line,
126
+ sidecar_path,
127
+ success_envelope,
128
+ write_sidecar,
100
129
  )
101
- use_cmap = cmap if cmap is not None else prod_info.cmap
102
- use_qa = qa if qa is not None else cfg.qa_threshold
103
- use_smooth = (
104
- smooth
105
- if smooth is not None
106
- else product_defaults.smooth_sigma
107
- if product_defaults.smooth_sigma is not None
108
- else params.smooth_sigma
109
- )
110
- try:
111
- use_basemap = parse_basemap(basemap)
112
- validate_positive(use_dpi, "--dpi")
113
- validate_positive(use_res, "--res")
114
- validate_unit_interval(use_qa, "--qa")
115
- validate_unit_interval(cf, "--cf")
116
- validate_color_range(vmin, vmax)
117
- if use_smooth is not None:
118
- validate_non_negative(use_smooth, "--smooth")
119
- except ValueError as e:
120
- console.print(f"[red]{e}[/red]")
121
- raise typer.Exit(1) from e
122
- if use_smooth == 0:
123
- use_smooth = None
124
- warn_missing_tianditu_key(
125
- basemap=use_basemap,
126
- default_basemap=params.basemap,
127
- tianditu_key=cfg.tianditu_key,
128
- console=console,
130
+ from rsplot.result_builders.satellite import build_satellite_layer
131
+ from rsplot.result_builders.station import build_station_display
132
+ from rsplot.result_builders.station_layer import (
133
+ TABLE_COLUMNS,
134
+ StationInputs,
135
+ build_station_layer,
136
+ colocation_block,
137
+ satellite_at_stations,
129
138
  )
130
139
 
131
- use_raster_dir = (
132
- raster_dir if raster_dir is not None else cfg.get_data_dir(product)
133
- )
134
- reader = prod_info.reader_cls()
135
- reader.cloud_fraction_max = cf
136
- read_extent = buffered_extent(info.extent, 1.0)
137
- console.print(
138
- f"\n[bold]读取卫星数据:[/bold] {use_raster_dir} (产品: {product})"
139
- )
140
- console.print(f" 日期: {date}, QA > {use_qa}, CF <= {cf}")
141
- swath = reader.read(
142
- use_raster_dir,
143
- date,
144
- read_extent,
145
- qa_threshold=use_qa,
140
+ cfg = AppConfig.load()
141
+ prod_info, _ = resolve_satellite(
142
+ product, sensor, qa, cfg, console, processing
146
143
  )
147
- console.print(
148
- f" → [green]{swath.n_pixels}[/green] 有效像元 "
149
- f"({swath.n_files} 文件, {swath.n_broken} 损坏)"
144
+ sensor = prod_info.sensor
145
+ processing = prod_info.processing
146
+ station_hour, matching, dates, window_mode = resolve_station_hour(
147
+ date_arg, sensor, days, station_datetime
150
148
  )
151
149
 
152
- console.print(f"\n[bold]网格化:[/bold] {use_res}° 分辨率")
153
- prepared = prepare_swath_grid(
154
- swath.lon,
155
- swath.lat,
156
- swath.values,
157
- read_extent,
158
- use_res,
159
- info.geometry,
160
- smooth_sigma=use_smooth,
161
- )
162
- console.print(
163
- f" → 网格 {prepared.values.shape}, "
164
- f"区域内覆盖率 {prepared.coverage_pct:.1f}% "
165
- f"({prepared.n_valid_region}/{prepared.total_region_pixels})"
166
- )
150
+ if station_var not in STATION_VAR_META:
151
+ raise RsplotError(
152
+ "invalid_argument",
153
+ f"未知站点变量 '{station_var}'。"
154
+ f"可用: {', '.join(STATION_VAR_META)}",
155
+ option="--station-var",
156
+ )
167
157
 
168
- if vmin is not None and vmax is not None:
169
- use_vmin, use_vmax = vmin, vmax
170
- elif prod_info.vmin is not None and prod_info.vmax is not None:
171
- use_vmin = vmin if vmin is not None else prod_info.vmin
172
- use_vmax = vmax if vmax is not None else prod_info.vmax
173
- else:
174
- auto_min, auto_max = auto_vrange(prepared.values, prod_info)
175
- use_vmin = vmin if vmin is not None else auto_min
176
- use_vmax = vmax if vmax is not None else auto_max
177
158
  try:
178
- validate_color_range(use_vmin, use_vmax)
179
- except ValueError as e:
180
- console.print(f"[red]色标范围无效:{e}[/red]")
181
- raise typer.Exit(1) from e
182
- console.print(f" → 色标范围: {use_vmin:.1f} ~ {use_vmax:.1f}")
159
+ info = resolve_regions(region, cfg)
160
+ except RsplotError:
161
+ raise
162
+ except ValueError as error:
163
+ raise RsplotError(
164
+ "region_not_found", str(error), details={"region": region}
165
+ ) from error
183
166
 
184
- use_station_dir = (
185
- station_dir if station_dir is not None else cfg.get_data_dir("guokong")
186
- )
167
+ use_station_dir = cfg.get_data_dir("guokong")
187
168
  console.print(f"\n[bold]读取站点数据:[/bold] {use_station_dir}")
188
- console.print(f" 时间: {datetime_str}, 变量: {var}")
189
- station_extent = buffered_extent(info.extent, 0.5)
190
- data, resolved_dt = read_stations(
169
+ console.print(f" 时间: {station_hour}, 变量: {station_var}")
170
+ read, _ = read_stations(
191
171
  use_station_dir,
192
- datetime_str,
193
- var,
194
- extent=station_extent,
172
+ station_hour,
173
+ station_var,
174
+ extent=buffered_extent(info.extent, 0.5),
195
175
  )
196
- data = mask_stations_to_region(data, info.geometry)
197
- if resolved_dt != datetime_str:
198
- console.print(f" → 自动选择最新时次: [cyan]{resolved_dt}[/cyan]")
176
+ from shapely import contains_xy
177
+
178
+ in_region = contains_xy(info.geometry.buffer(1e-9), read.lon, read.lat)
179
+ n_valid = int((np.isfinite(read.values) & in_region).sum())
199
180
  console.print(
200
- f" → [green]{data.n_valid}[/green] 有效站点 (共 {data.n_stations} 站)"
181
+ f" → [green]{n_valid}[/green] 有效站点 (共 {int(in_region.sum())} 站)"
201
182
  )
183
+ threshold = get_exceedance_threshold(station_var)
184
+ unit, limit_key, limit_time = STATION_VAR_META[station_var]
202
185
 
203
- threshold = get_exceedance_threshold(var)
204
- if threshold is not None:
205
- n_exceed = int(
206
- np.sum(data.values[np.isfinite(data.values)] > threshold)
207
- )
208
- console.print(
209
- f" → 超标阈值: {threshold}, 超标站点: [red]{n_exceed}[/red]"
186
+ source = "GEMS" if sensor == "gems" else "TROPOMI"
187
+ if processing == "nrti":
188
+ source += " NRTI"
189
+ if window_mode:
190
+ period = f"{dates[0]}~{dates[-1]} mean"
191
+ else:
192
+ period = date_arg
193
+ if sensor == "gems":
194
+ period += " scan" if len(date_arg) == 12 else " daily mean"
195
+ if title is None:
196
+ title = (
197
+ f"{source} {product.upper()} {period} + "
198
+ f"Station {station_var} {station_hour} - {info.name}"
210
199
  )
211
200
 
212
- if output is None:
213
- output = f"/tmp/rsplot_overlay_{info.name}_{product}_{resolved_dt}.png"
214
- unit = STATION_VAR_META[var][0]
215
- station_label = f"{var} ({unit})" if unit else var
201
+ run = prepare_raster(
202
+ region=info,
203
+ date_arg=date_arg,
204
+ product=product,
205
+ sensor=sensor,
206
+ processing=processing,
207
+ days=days,
208
+ output=output,
209
+ dpi=dpi,
210
+ res=res,
211
+ basemap=basemap,
212
+ vmin=vmin,
213
+ vmax=vmax,
214
+ cmap=cmap,
215
+ smooth=smooth,
216
+ title=title,
217
+ qa=qa,
218
+ cf=cf,
219
+ console=console,
220
+ )
221
+ satellite_inputs = run.satellite
222
+ assert satellite_inputs is not None
223
+ image = str(Path(output).resolve())
224
+ sidecar = sidecar_path(image)
225
+
226
+ grid_path = data_path(image, "satellite", ".nc")
227
+ created.append(grid_path)
228
+ grid_entry = write_grid_netcdf(
229
+ grid_path,
230
+ satellite_inputs.lon,
231
+ satellite_inputs.lat,
232
+ satellite_inputs.grid,
233
+ satellite_inputs.counted,
234
+ extent=info.extent,
235
+ layer="satellite",
236
+ attrs={
237
+ "quantity": prod_info.quantity,
238
+ "unit": prod_info.unit,
239
+ "scale": prod_info.unit_scale,
240
+ "time_aggregation": satellite_inputs.time["aggregation"],
241
+ },
242
+ valid_days=satellite_inputs.valid_days,
243
+ )
244
+
245
+ station_path = data_path(image, "station", ".csv")
246
+ station_inputs = StationInputs(
247
+ read=read,
248
+ in_region=in_region,
249
+ var=station_var,
250
+ unit=unit,
251
+ threshold=threshold,
252
+ standard=(
253
+ f"AQ_LIMITS_2026 {limit_key} {limit_time}"
254
+ if threshold is not None
255
+ else None
256
+ ),
257
+ hour=station_hour,
258
+ data_root=str(use_station_dir),
259
+ )
260
+ admin_gdf = (
261
+ info.sub_boundary_gdf
262
+ if info.sub_boundary_gdf is not None and len(info.sub_boundary_gdf)
263
+ else load_fallback_city_boundaries(info, cfg.require_geojson_dir())
264
+ )
265
+ station_layer, station_flags, rows = build_station_layer(
266
+ station_inputs,
267
+ info,
268
+ admin_gdf=admin_gdf,
269
+ satellite_values=satellite_at_stations(
270
+ satellite_inputs.lon,
271
+ satellite_inputs.lat,
272
+ satellite_inputs.grid,
273
+ satellite_inputs.counted,
274
+ read.lon,
275
+ read.lat,
276
+ ),
277
+ data=str(station_path),
278
+ )
279
+ created.append(station_path)
280
+ station_entry = write_table_csv(
281
+ station_path,
282
+ rows,
283
+ TABLE_COLUMNS,
284
+ content="station_table",
285
+ layer="station",
286
+ )
216
287
 
288
+ region_stations = _subset(read, in_region)
289
+ plot_options = dict(run.plot_options)
290
+ for key in ("cmap", "vmin", "vmax"):
291
+ plot_options[f"raster_{key}"] = plot_options.pop(key)
292
+ plot_options["raster_label"] = plot_options.pop("colorbar_label")
217
293
  console.print("\n[bold]绘图中...[/bold]")
294
+ created.append(Path(image))
218
295
  plot_overlay(
219
- prepared.lon,
220
- prepared.lat,
221
- prepared.values,
222
- data,
296
+ run.lon,
297
+ run.lat,
298
+ run.grid,
299
+ region_stations,
223
300
  info,
224
- raster_cmap=use_cmap,
225
- raster_vmin=use_vmin,
226
- raster_vmax=use_vmax,
227
- raster_label=prod_info.colorbar_label,
228
301
  station_threshold=threshold,
229
- station_label=station_label,
230
- dpi=use_dpi,
231
- basemap=use_basemap,
232
- tianditu_key=cfg.tianditu_key,
233
- hcho_cmap_file=cfg.hcho_cmap_file,
234
- title=title,
235
- output=output,
302
+ station_label=f"{station_var} ({unit})" if unit else station_var,
303
+ **plot_options,
236
304
  )
237
- console.print(f"\n[bold green]✓ 已保存:[/bold green] {output}")
238
305
 
239
- result = build_overlay_result(
306
+ satellite_layer, satellite_flags = build_satellite_layer(
307
+ satellite_inputs, info, data=grid_entry["path"]
308
+ )
309
+ station_display = build_station_display(region_stations) or {
310
+ "range_method": "data_p5_p95"
311
+ }
312
+ render = {
313
+ "image": image,
314
+ **run.render,
315
+ "layers": {
316
+ **run.render["layers"],
317
+ "station": station_display,
318
+ },
319
+ }
320
+ payload = success_envelope(
321
+ command="overlay",
322
+ request=command_line(),
240
323
  region=info,
241
- product=product,
242
- date=date,
243
- prod_info=prod_info,
244
- LON=prepared.lon,
245
- LAT=prepared.lat,
246
- grid=prepared.values,
247
- swath_meta={
248
- "n_pixels": int(swath.n_pixels),
249
- "n_files": int(swath.n_files),
250
- "n_broken": int(swath.n_broken),
251
- "qa_threshold": use_qa,
252
- "cloud_fraction_max": cf,
253
- "resolution_deg": use_res,
324
+ layers=[satellite_layer, station_layer],
325
+ relations={
326
+ "time_matching": matching,
327
+ "colocation": colocation_block(rows, str(station_path)),
254
328
  },
255
- raster_vmin=use_vmin,
256
- raster_vmax=use_vmax,
257
- data=data,
258
- datetime_str=resolved_dt,
259
- threshold=threshold,
260
- unit=unit,
261
- cities_gdf=load_fallback_city_boundaries(
262
- info,
263
- cfg.require_geojson_dir(),
264
- ),
265
- output=output,
329
+ flags=satellite_flags + station_flags,
330
+ render=render,
331
+ artifacts={
332
+ "image": image,
333
+ "sidecar": sidecar,
334
+ "data": [grid_entry, station_entry],
335
+ },
336
+ )
337
+ created.append(Path(sidecar))
338
+ write_sidecar(payload, sidecar)
339
+ console.print(f"\n[bold green]✓ 已保存:[/bold green] {image}")
340
+
341
+
342
+ def _subset(data: Any, mask: np.ndarray) -> Any:
343
+ from rsplot.readers.guokong import StationData
344
+
345
+ values = np.asarray(data.values)[mask]
346
+ return StationData(
347
+ id=np.asarray(data.id)[mask],
348
+ lon=data.lon[mask],
349
+ lat=data.lat[mask],
350
+ values=values,
351
+ var_name=data.var_name,
352
+ n_stations=int(mask.sum()),
353
+ n_valid=int(np.isfinite(values).sum()),
266
354
  )
267
- emit_result(result, output)