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.
- rsplot/atomic.py +36 -0
- rsplot/cli.py +282 -469
- rsplot/commands/common.py +113 -1
- rsplot/commands/fnr.py +389 -104
- rsplot/commands/forecast.py +24 -7
- rsplot/commands/meteo.py +499 -186
- rsplot/commands/overlay.py +292 -205
- rsplot/commands/radius.py +526 -0
- rsplot/commands/raster.py +479 -230
- rsplot/commands/reconstruct.py +27 -6
- rsplot/commands/sidecar.py +106 -0
- rsplot/commands/station.py +154 -42
- rsplot/commands/station_trend.py +259 -174
- rsplot/config.py +46 -16
- rsplot/data_files.py +253 -0
- rsplot/errors.py +43 -0
- rsplot/fnr.py +38 -46
- rsplot/geo/boundaries.py +317 -11
- rsplot/geo/footprints.py +205 -0
- rsplot/geo/processing.py +84 -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 +203 -9
- rsplot/plotting/meteo.py +10 -3
- rsplot/plotting/overlay.py +36 -40
- rsplot/plotting/raster.py +15 -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 +89 -7
- rsplot/readers/_tropomi.py +121 -3
- rsplot/readers/base.py +16 -1
- rsplot/readers/era5.py +110 -10
- rsplot/readers/era5_wind.py +3 -2
- rsplot/readers/gems.py +429 -0
- 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 +84 -0
- rsplot/result_builders/envelope.py +236 -0
- rsplot/result_builders/fnr.py +47 -131
- rsplot/result_builders/forecast.py +7 -0
- rsplot/result_builders/provenance.py +59 -0
- rsplot/result_builders/reconstruct.py +7 -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 +146 -16
- rsplot-0.3.2.dev37.dist-info/METADATA +996 -0
- rsplot-0.3.2.dev37.dist-info/RECORD +76 -0
- {rsplot-0.3.1.dev3.dist-info → rsplot-0.3.2.dev37.dist-info}/WHEEL +1 -1
- rsplot/commands/recent.py +0 -164
- rsplot/recent.py +0 -404
- rsplot/result_builders/meteo.py +0 -171
- rsplot/result_builders/overlay.py +0 -75
- rsplot/result_builders/raster.py +0 -72
- rsplot/result_builders/station_trend.py +0 -229
- rsplot-0.3.1.dev3.dist-info/METADATA +0 -477
- rsplot-0.3.1.dev3.dist-info/RECORD +0 -64
- {rsplot-0.3.1.dev3.dist-info → rsplot-0.3.2.dev37.dist-info}/entry_points.txt +0 -0
- {rsplot-0.3.1.dev3.dist-info → rsplot-0.3.2.dev37.dist-info}/licenses/LICENSE +0 -0
rsplot/commands/overlay.py
CHANGED
|
@@ -2,43 +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
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
97
|
+
date_arg: str,
|
|
36
98
|
product: str,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
"""
|
|
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.
|
|
57
|
-
from rsplot.geo.
|
|
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.
|
|
60
|
-
from rsplot.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
132
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
179
|
-
except
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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" 时间: {
|
|
189
|
-
|
|
190
|
-
data, resolved_dt = read_stations(
|
|
169
|
+
console.print(f" 时间: {station_hour}, 变量: {station_var}")
|
|
170
|
+
read, _ = read_stations(
|
|
191
171
|
use_station_dir,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
extent=
|
|
172
|
+
station_hour,
|
|
173
|
+
station_var,
|
|
174
|
+
extent=buffered_extent(info.extent, 0.5),
|
|
195
175
|
)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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]{
|
|
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
|
-
|
|
204
|
-
if
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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=
|
|
230
|
-
|
|
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
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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)
|