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.
- rsplot/atomic.py +36 -0
- rsplot/cli.py +272 -497
- rsplot/commands/common.py +52 -3
- rsplot/commands/fnr.py +389 -104
- rsplot/commands/forecast.py +0 -2
- rsplot/commands/meteo.py +499 -186
- rsplot/commands/overlay.py +284 -326
- rsplot/commands/radius.py +526 -0
- rsplot/commands/raster.py +418 -293
- rsplot/commands/reconstruct.py +0 -1
- rsplot/commands/sidecar.py +106 -0
- rsplot/commands/station.py +154 -42
- rsplot/commands/station_trend.py +259 -174
- rsplot/config.py +43 -16
- rsplot/data_files.py +253 -0
- rsplot/errors.py +43 -0
- rsplot/fnr.py +38 -46
- rsplot/geo/boundaries.py +212 -9
- rsplot/geo/footprints.py +3 -0
- rsplot/geo/processing.py +2 -5
- rsplot/geo/radius.py +205 -0
- rsplot/plotting/colormap_22.txt +256 -0
- rsplot/plotting/colormaps.py +24 -29
- rsplot/plotting/map_frame.py +84 -6
- rsplot/plotting/meteo.py +10 -3
- rsplot/plotting/overlay.py +31 -40
- rsplot/plotting/raster.py +10 -3
- rsplot/plotting/station.py +86 -33
- rsplot/plotting/station_focus.py +84 -0
- rsplot/plotting/station_trend.py +60 -47
- rsplot/plotting/styles.py +3 -5
- rsplot/readers/__init__.py +52 -4
- rsplot/readers/_tropomi.py +121 -3
- rsplot/readers/era5.py +110 -10
- rsplot/readers/era5_wind.py +3 -2
- rsplot/readers/gems.py +11 -8
- rsplot/readers/guokong.py +125 -39
- rsplot/readers/netcdf.py +32 -0
- rsplot/readers/tropomi_hcho.py +1 -1
- rsplot/readers/tropomi_no2.py +1 -1
- rsplot/readers/tropomi_nrti.py +116 -0
- rsplot/readers/tropomi_o3.py +1 -1
- rsplot/readers/tropomi_o3pr.py +1 -1
- rsplot/result_builders/__init__.py +0 -14
- rsplot/result_builders/common.py +4 -1
- rsplot/result_builders/envelope.py +236 -0
- rsplot/result_builders/fnr.py +47 -131
- rsplot/result_builders/provenance.py +59 -0
- rsplot/result_builders/satellite.py +240 -0
- rsplot/result_builders/series_layer.py +289 -0
- rsplot/result_builders/station.py +23 -0
- rsplot/result_builders/station_layer.py +326 -0
- rsplot/results.py +0 -12
- rsplot/schemas/result.schema.json +566 -0
- rsplot/temporal.py +7 -0
- {rsplot-0.3.2.dev4.dist-info → rsplot-0.4.0.dist-info}/METADATA +426 -121
- rsplot-0.4.0.dist-info/RECORD +76 -0
- {rsplot-0.3.2.dev4.dist-info → rsplot-0.4.0.dist-info}/WHEEL +1 -1
- rsplot/commands/recent.py +0 -186
- rsplot/recent.py +0 -447
- rsplot/result_builders/meteo.py +0 -171
- rsplot/result_builders/overlay.py +0 -105
- rsplot/result_builders/raster.py +0 -104
- rsplot/result_builders/station_trend.py +0 -229
- rsplot-0.3.2.dev4.dist-info/RECORD +0 -66
- {rsplot-0.3.2.dev4.dist-info → rsplot-0.4.0.dist-info}/entry_points.txt +0 -0
- {rsplot-0.3.2.dev4.dist-info → rsplot-0.4.0.dist-info}/licenses/LICENSE +0 -0
rsplot/commands/overlay.py
CHANGED
|
@@ -2,49 +2,106 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from
|
|
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
12
|
resolve_satellite,
|
|
14
|
-
satellite_errors,
|
|
15
|
-
satellite_filter_label,
|
|
16
|
-
validate_color_range,
|
|
17
|
-
validate_non_negative,
|
|
18
|
-
validate_positive,
|
|
19
|
-
validate_unit_interval,
|
|
20
|
-
warn_missing_tianditu_key,
|
|
21
13
|
)
|
|
14
|
+
from rsplot.commands.raster import parse_raster_dates, prepare_raster
|
|
22
15
|
from rsplot.config import AppConfig
|
|
16
|
+
from rsplot.errors import RsplotError
|
|
23
17
|
|
|
24
18
|
if TYPE_CHECKING:
|
|
25
19
|
from rich.console import Console
|
|
26
20
|
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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.
|
|
33
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
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
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],
|
|
37
95
|
*,
|
|
38
96
|
region: str,
|
|
39
|
-
|
|
97
|
+
date_arg: str,
|
|
40
98
|
product: str,
|
|
41
99
|
sensor: str = "tropomi",
|
|
100
|
+
processing: str | None = None,
|
|
101
|
+
days: int | None = None,
|
|
42
102
|
station_datetime: str | None = None,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
raster_dir: str | None,
|
|
46
|
-
station_dir: str | None,
|
|
47
|
-
output: str | None,
|
|
103
|
+
station_var: str,
|
|
104
|
+
output: str,
|
|
48
105
|
dpi: int | None,
|
|
49
106
|
res: float | None,
|
|
50
107
|
basemap: str | None,
|
|
@@ -57,340 +114,241 @@ def run_overlay(
|
|
|
57
114
|
title: str | None,
|
|
58
115
|
console: Console,
|
|
59
116
|
) -> None:
|
|
60
|
-
"""
|
|
117
|
+
"""Read one station hour, reuse raster preparation, write the sidecar."""
|
|
61
118
|
from rsplot.config import STATION_VAR_META, get_exceedance_threshold
|
|
119
|
+
from rsplot.data_files import data_path, write_grid_netcdf, write_table_csv
|
|
62
120
|
from rsplot.geo.boundaries import resolve_regions
|
|
63
|
-
from rsplot.geo.processing import
|
|
64
|
-
buffered_extent,
|
|
65
|
-
prepare_display_grid,
|
|
66
|
-
prepare_existing_grid,
|
|
67
|
-
prepare_swath_grid,
|
|
68
|
-
)
|
|
121
|
+
from rsplot.geo.processing import buffered_extent
|
|
69
122
|
from rsplot.plotting.overlay import plot_overlay
|
|
70
|
-
from rsplot.
|
|
71
|
-
from rsplot.
|
|
72
|
-
|
|
73
|
-
|
|
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,
|
|
129
|
+
)
|
|
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,
|
|
138
|
+
)
|
|
74
139
|
|
|
75
140
|
cfg = AppConfig.load()
|
|
76
|
-
prod_info,
|
|
141
|
+
prod_info, _ = resolve_satellite(
|
|
142
|
+
product, sensor, qa, cfg, console, processing
|
|
143
|
+
)
|
|
77
144
|
sensor = prod_info.sensor
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
station_request, pairing = match_station_hour(
|
|
84
|
-
datetime_str, station_datetime
|
|
85
|
-
)
|
|
86
|
-
if product.lower() == "hcho" and var is None:
|
|
87
|
-
raise ValueError("GEMS HCHO 叠加需通过 --var 显式指定站点变量。")
|
|
88
|
-
elif station_datetime is not None:
|
|
89
|
-
raise ValueError("--station-datetime 在此命令中仅用于 GEMS。")
|
|
90
|
-
setup_fonts(cfg.font_dir)
|
|
91
|
-
|
|
92
|
-
if var is None:
|
|
93
|
-
var = PRODUCT_STATION_PAIR.get(product.lower(), "AQI")
|
|
94
|
-
if var not in STATION_VAR_META:
|
|
95
|
-
available = ", ".join(STATION_VAR_META)
|
|
96
|
-
console.print(f"[red]未知站点变量 '{var}'[/red]。可用: {available}")
|
|
97
|
-
raise typer.Exit(1)
|
|
145
|
+
processing = prod_info.processing
|
|
146
|
+
station_hour, matching, dates, window_mode = resolve_station_hour(
|
|
147
|
+
date_arg, sensor, days, station_datetime
|
|
148
|
+
)
|
|
98
149
|
|
|
99
|
-
if
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
f"
|
|
104
|
-
"
|
|
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",
|
|
105
156
|
)
|
|
106
|
-
raise typer.Exit(1)
|
|
107
|
-
date = datetime_str[:8]
|
|
108
157
|
|
|
109
|
-
console.print(f"[bold]解析区域:[/bold] {region}")
|
|
110
|
-
info = resolve_regions(region, cfg, level_override=level)
|
|
111
|
-
console.print(f" → [green]{info.name}[/green] (级别: {info.level})")
|
|
112
|
-
if info.members:
|
|
113
|
-
console.print(
|
|
114
|
-
" → 成员: "
|
|
115
|
-
+ "、".join(
|
|
116
|
-
member.qualified_name or member.name for member in info.members
|
|
117
|
-
)
|
|
118
|
-
)
|
|
119
|
-
console.print(
|
|
120
|
-
f" → 范围: {info.extent[0]:.2f}°~{info.extent[1]:.2f}°E, "
|
|
121
|
-
f"{info.extent[2]:.2f}°~{info.extent[3]:.2f}°N"
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
params = info.params
|
|
125
|
-
use_dpi = dpi if dpi is not None else cfg.dpi
|
|
126
|
-
product_defaults = prod_info.defaults_for_level(info.level)
|
|
127
|
-
use_res = (
|
|
128
|
-
res
|
|
129
|
-
if res is not None
|
|
130
|
-
else product_defaults.res
|
|
131
|
-
if product_defaults.res is not None
|
|
132
|
-
else params.res
|
|
133
|
-
)
|
|
134
|
-
use_cmap = cmap if cmap is not None else prod_info.cmap
|
|
135
|
-
use_smooth = (
|
|
136
|
-
smooth
|
|
137
|
-
if smooth is not None
|
|
138
|
-
else product_defaults.smooth_sigma
|
|
139
|
-
if product_defaults.smooth_sigma is not None
|
|
140
|
-
else params.smooth_sigma
|
|
141
|
-
)
|
|
142
158
|
try:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
validate_non_negative(use_smooth, "--smooth")
|
|
151
|
-
except ValueError as e:
|
|
152
|
-
console.print(f"[red]{e}[/red]")
|
|
153
|
-
raise typer.Exit(1) from e
|
|
154
|
-
if use_smooth == 0:
|
|
155
|
-
use_smooth = None
|
|
156
|
-
warn_missing_tianditu_key(
|
|
157
|
-
basemap=use_basemap,
|
|
158
|
-
default_basemap=params.basemap,
|
|
159
|
-
tianditu_key=cfg.tianditu_key,
|
|
160
|
-
console=console,
|
|
161
|
-
)
|
|
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
|
|
162
166
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
+
use_station_dir = cfg.get_data_dir("guokong")
|
|
168
|
+
console.print(f"\n[bold]读取站点数据:[/bold] {use_station_dir}")
|
|
169
|
+
console.print(f" 时间: {station_hour}, 变量: {station_var}")
|
|
170
|
+
read, _ = read_stations(
|
|
171
|
+
use_station_dir,
|
|
172
|
+
station_hour,
|
|
173
|
+
station_var,
|
|
174
|
+
extent=buffered_extent(info.extent, 0.5),
|
|
167
175
|
)
|
|
168
|
-
|
|
169
|
-
reader.cloud_fraction_max = cf
|
|
170
|
-
analysis_res = use_res
|
|
171
|
-
if sensor == "gems":
|
|
172
|
-
from rsplot.readers.gems import GEMS_ANALYSIS_RESOLUTION
|
|
176
|
+
from shapely import contains_xy
|
|
173
177
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
f" → GEMS 分析网格 {analysis_res}°,显示网格 {use_res}°"
|
|
177
|
-
)
|
|
178
|
-
read_extent = buffered_extent(info.extent, 1.0)
|
|
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())
|
|
179
180
|
console.print(
|
|
180
|
-
f"
|
|
181
|
+
f" → [green]{n_valid}[/green] 有效站点 (共 {int(in_region.sum())} 站)"
|
|
181
182
|
)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
)
|
|
185
|
-
statistics_grid = None
|
|
186
|
-
if sensor == "gems":
|
|
187
|
-
from rsplot.temporal import read_scan_mean
|
|
183
|
+
threshold = get_exceedance_threshold(station_var)
|
|
184
|
+
unit, limit_key, limit_time = STATION_VAR_META[station_var]
|
|
188
185
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
res=analysis_res,
|
|
195
|
-
)
|
|
196
|
-
prepared = prepare_existing_grid(
|
|
197
|
-
batch.LON,
|
|
198
|
-
batch.LAT,
|
|
199
|
-
batch.grid,
|
|
200
|
-
info.geometry,
|
|
201
|
-
fill_gaps=False,
|
|
202
|
-
)
|
|
203
|
-
display_source = prepared.unmasked_values
|
|
204
|
-
statistics_grid = prepared.values.copy()
|
|
205
|
-
swath_meta = {
|
|
206
|
-
"n_pixels": batch.n_pixels,
|
|
207
|
-
"n_files": batch.n_files,
|
|
208
|
-
"n_broken": batch.n_broken,
|
|
209
|
-
"resolution_deg": use_res,
|
|
210
|
-
"cloud_fraction_max": cf,
|
|
211
|
-
**batch.metadata,
|
|
212
|
-
}
|
|
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"
|
|
213
191
|
else:
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
f" → [green]{swath.n_pixels}[/green] 有效像元 "
|
|
222
|
-
f"({swath.n_files} 文件, {swath.n_broken} 损坏)"
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
console.print(f"\n[bold]网格化:[/bold] {use_res}° 分辨率")
|
|
226
|
-
prepared = prepare_swath_grid(
|
|
227
|
-
swath.lon,
|
|
228
|
-
swath.lat,
|
|
229
|
-
swath.values,
|
|
230
|
-
read_extent,
|
|
231
|
-
use_res,
|
|
232
|
-
info.geometry,
|
|
233
|
-
smooth_sigma=use_smooth,
|
|
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}"
|
|
234
199
|
)
|
|
235
|
-
display_source = prepared.unmasked_values
|
|
236
|
-
swath_meta = {
|
|
237
|
-
"n_pixels": int(swath.n_pixels),
|
|
238
|
-
"n_files": int(swath.n_files),
|
|
239
|
-
"n_broken": int(swath.n_broken),
|
|
240
|
-
"qa_threshold": use_qa,
|
|
241
|
-
"cloud_fraction_max": cf,
|
|
242
|
-
"resolution_deg": use_res,
|
|
243
|
-
}
|
|
244
|
-
display_lon, display_lat = prepared.lon, prepared.lat
|
|
245
|
-
display_support = None
|
|
246
|
-
if sensor == "gems":
|
|
247
|
-
from rsplot.geo.footprints import prepare_footprint_display
|
|
248
200
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
display_source,
|
|
269
|
-
info.geometry,
|
|
270
|
-
smooth_sigma=use_smooth,
|
|
271
|
-
)
|
|
272
|
-
if not np.isfinite(display_grid).any():
|
|
273
|
-
console.print("[red]目标区域没有相交的有效卫星网格。[/red]")
|
|
274
|
-
raise typer.Exit(1)
|
|
275
|
-
console.print(
|
|
276
|
-
f" → 网格 {prepared.values.shape}, "
|
|
277
|
-
f"区域内覆盖率 {prepared.coverage_pct:.1f}% "
|
|
278
|
-
f"({prepared.n_valid_region}/{prepared.total_region_pixels})"
|
|
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,
|
|
279
220
|
)
|
|
221
|
+
satellite_inputs = run.satellite
|
|
222
|
+
assert satellite_inputs is not None
|
|
223
|
+
image = str(Path(output).resolve())
|
|
224
|
+
sidecar = sidecar_path(image)
|
|
280
225
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
raise typer.Exit(1) from e
|
|
300
|
-
console.print(f" → 色标范围: {use_vmin:.1f} ~ {use_vmax:.1f}")
|
|
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
|
+
)
|
|
301
244
|
|
|
302
|
-
|
|
303
|
-
|
|
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),
|
|
304
259
|
)
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
use_station_dir,
|
|
310
|
-
station_request,
|
|
311
|
-
var,
|
|
312
|
-
extent=station_extent,
|
|
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())
|
|
313
264
|
)
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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",
|
|
319
286
|
)
|
|
320
287
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
console.print(
|
|
327
|
-
f" → 超标阈值: {threshold}, 超标站点: [red]{n_exceed}[/red]"
|
|
328
|
-
)
|
|
329
|
-
|
|
330
|
-
if output is None and sensor == "gems":
|
|
331
|
-
output = (
|
|
332
|
-
f"/tmp/rsplot_overlay_gems_{info.name}_{product}_"
|
|
333
|
-
f"{datetime_str}_{resolved_dt}.png"
|
|
334
|
-
)
|
|
335
|
-
if title is None and sensor == "gems":
|
|
336
|
-
period = "daily mean" if len(datetime_str) == 8 else "scan"
|
|
337
|
-
title = (
|
|
338
|
-
f"GEMS {product.upper()} {datetime_str} {period} CST + "
|
|
339
|
-
f"Station {var} {resolved_dt} CST - {info.name}"
|
|
340
|
-
)
|
|
341
|
-
if output is None:
|
|
342
|
-
output = f"/tmp/rsplot_overlay_{info.name}_{product}_{resolved_dt}.png"
|
|
343
|
-
unit = STATION_VAR_META[var][0]
|
|
344
|
-
station_label = f"{var} ({unit})" if unit else var
|
|
345
|
-
|
|
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")
|
|
346
293
|
console.print("\n[bold]绘图中...[/bold]")
|
|
294
|
+
created.append(Path(image))
|
|
347
295
|
plot_overlay(
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
296
|
+
run.lon,
|
|
297
|
+
run.lat,
|
|
298
|
+
run.grid,
|
|
299
|
+
region_stations,
|
|
352
300
|
info,
|
|
353
|
-
raster_cmap=use_cmap,
|
|
354
|
-
raster_vmin=use_vmin,
|
|
355
|
-
raster_vmax=use_vmax,
|
|
356
|
-
raster_label=prod_info.colorbar_label,
|
|
357
301
|
station_threshold=threshold,
|
|
358
|
-
station_label=
|
|
359
|
-
|
|
360
|
-
basemap=use_basemap,
|
|
361
|
-
tianditu_key=cfg.tianditu_key,
|
|
362
|
-
hcho_cmap_file=cfg.hcho_cmap_file,
|
|
363
|
-
title=title,
|
|
364
|
-
output=output,
|
|
365
|
-
**({"coverage_geometry": display_support} if sensor == "gems" else {}),
|
|
302
|
+
station_label=f"{station_var} ({unit})" if unit else station_var,
|
|
303
|
+
**plot_options,
|
|
366
304
|
)
|
|
367
|
-
console.print(f"\n[bold green]✓ 已保存:[/bold green] {output}")
|
|
368
305
|
|
|
369
|
-
|
|
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(),
|
|
370
323
|
region=info,
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
324
|
+
layers=[satellite_layer, station_layer],
|
|
325
|
+
relations={
|
|
326
|
+
"time_matching": matching,
|
|
327
|
+
"colocation": colocation_block(rows, str(station_path)),
|
|
328
|
+
},
|
|
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()),
|
|
395
354
|
)
|
|
396
|
-
emit_result(result, output)
|