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/fnr.py
CHANGED
|
@@ -2,85 +2,122 @@
|
|
|
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
|
parse_basemap,
|
|
12
|
+
parse_explicit_window,
|
|
12
13
|
print_failed_dates,
|
|
14
|
+
resolve_satellite,
|
|
13
15
|
validate_non_negative,
|
|
14
16
|
validate_positive,
|
|
15
17
|
validate_unit_interval,
|
|
16
18
|
warn_missing_tianditu_key,
|
|
17
19
|
)
|
|
18
20
|
from rsplot.config import AppConfig
|
|
21
|
+
from rsplot.errors import RsplotError
|
|
22
|
+
from rsplot.result_builders.provenance import combined_fingerprint
|
|
19
23
|
|
|
20
24
|
if TYPE_CHECKING:
|
|
21
25
|
from rich.console import Console
|
|
22
26
|
|
|
27
|
+
REGIMES = ("voc_limited", "transition", "nox_limited")
|
|
23
28
|
|
|
24
|
-
|
|
29
|
+
|
|
30
|
+
def run_fnr(**kwargs: Any) -> None:
|
|
31
|
+
"""Map the HCHO/NO2 ratio and its ozone-sensitivity regimes."""
|
|
32
|
+
from rsplot.commands.sidecar import run_with_sidecar
|
|
33
|
+
|
|
34
|
+
run_with_sidecar(
|
|
35
|
+
kwargs=kwargs,
|
|
36
|
+
emit=lambda created: _emit_fnr(created, **kwargs),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _emit_fnr(
|
|
41
|
+
created: list[Path],
|
|
25
42
|
*,
|
|
26
43
|
region: str,
|
|
27
44
|
date_arg: str,
|
|
28
|
-
days: int,
|
|
45
|
+
days: int | None,
|
|
29
46
|
n_min: int | None,
|
|
30
47
|
no2_min: float,
|
|
31
48
|
voc_threshold: float,
|
|
32
49
|
nox_threshold: float,
|
|
33
50
|
display_max: float,
|
|
34
|
-
|
|
35
|
-
raster_dir_no2: str | None,
|
|
36
|
-
raster_dir_hcho: str | None,
|
|
37
|
-
output: str | None,
|
|
51
|
+
output: str,
|
|
38
52
|
dpi: int | None,
|
|
39
53
|
res: float | None,
|
|
40
54
|
basemap: str | None,
|
|
41
55
|
smooth: float | None,
|
|
42
56
|
qa: float | None,
|
|
43
57
|
cf: float = 0.5,
|
|
58
|
+
processing: str | None = None,
|
|
44
59
|
title: str | None,
|
|
45
60
|
console: Console,
|
|
46
61
|
) -> None:
|
|
47
|
-
"""
|
|
62
|
+
"""Compute FNR over a window, plot it, and write the sidecar."""
|
|
63
|
+
from rsplot.data_files import data_path, write_grid_netcdf
|
|
48
64
|
from rsplot.fnr import (
|
|
49
65
|
compute_fnr,
|
|
50
66
|
regime_percentages,
|
|
67
|
+
smooth_fnr_for_display,
|
|
51
68
|
validate_fnr_thresholds,
|
|
52
69
|
)
|
|
53
|
-
from rsplot.geo.boundaries import
|
|
54
|
-
from rsplot.geo.gridding import grid_coverage_in_region
|
|
70
|
+
from rsplot.geo.boundaries import resolve_regions
|
|
71
|
+
from rsplot.geo.gridding import grid_coverage_in_region, region_grid_mask
|
|
55
72
|
from rsplot.plotting.fnr import plot_fnr
|
|
56
73
|
from rsplot.plotting.styles import setup_fonts
|
|
57
|
-
from rsplot.
|
|
58
|
-
from rsplot.
|
|
74
|
+
from rsplot.result_builders.common import top_hotspots
|
|
75
|
+
from rsplot.result_builders.envelope import (
|
|
76
|
+
capped,
|
|
77
|
+
command_line,
|
|
78
|
+
coverage_block,
|
|
79
|
+
coverage_flags,
|
|
80
|
+
sidecar_path,
|
|
81
|
+
stats_block,
|
|
82
|
+
subdivision_level,
|
|
83
|
+
success_envelope,
|
|
84
|
+
write_sidecar,
|
|
85
|
+
)
|
|
86
|
+
from rsplot.result_builders.fnr import (
|
|
87
|
+
fnr_member_stats,
|
|
88
|
+
fnr_per_admin_stats,
|
|
89
|
+
)
|
|
90
|
+
from rsplot.result_builders.satellite import (
|
|
91
|
+
SatelliteInputs,
|
|
92
|
+
build_satellite_layer,
|
|
93
|
+
)
|
|
59
94
|
|
|
60
95
|
cfg = AppConfig.load()
|
|
96
|
+
no2_info, _ = resolve_satellite(
|
|
97
|
+
"no2", "tropomi", qa, cfg, console, processing
|
|
98
|
+
)
|
|
99
|
+
hcho_info, _ = resolve_satellite(
|
|
100
|
+
"hcho", "tropomi", qa, cfg, console, processing
|
|
101
|
+
)
|
|
102
|
+
processing = no2_info.processing
|
|
61
103
|
setup_fonts(cfg.font_dir)
|
|
62
104
|
|
|
63
|
-
|
|
64
|
-
console.print("[red]--days 必须 >= 1。[/red]")
|
|
65
|
-
raise typer.Exit(1)
|
|
66
|
-
try:
|
|
67
|
-
dates = parse_date_window(date_arg, default_days=days)
|
|
68
|
-
except ValueError as e:
|
|
69
|
-
console.print(f"[red]{e}[/red]")
|
|
70
|
-
raise typer.Exit(1) from e
|
|
105
|
+
dates = parse_explicit_window(date_arg, days)
|
|
71
106
|
|
|
72
107
|
window_n = len(dates)
|
|
73
108
|
if n_min is not None and n_min < 1:
|
|
74
|
-
|
|
75
|
-
|
|
109
|
+
raise RsplotError(
|
|
110
|
+
"invalid_argument", "--n-min 必须 >= 1。", option="--n-min"
|
|
111
|
+
)
|
|
76
112
|
use_n_min = (
|
|
77
113
|
n_min if n_min is not None else min(window_n, max(3, window_n // 2))
|
|
78
114
|
)
|
|
79
115
|
if use_n_min > window_n:
|
|
80
|
-
|
|
81
|
-
|
|
116
|
+
raise RsplotError(
|
|
117
|
+
"invalid_argument",
|
|
118
|
+
f"--n-min ({use_n_min}) 大于窗口天数 ({window_n})",
|
|
119
|
+
option="--n-min",
|
|
82
120
|
)
|
|
83
|
-
raise typer.Exit(1)
|
|
84
121
|
try:
|
|
85
122
|
use_voc_threshold, use_nox_threshold, use_display_max = (
|
|
86
123
|
validate_fnr_thresholds(
|
|
@@ -89,9 +126,10 @@ def run_fnr(
|
|
|
89
126
|
display_max=display_max,
|
|
90
127
|
)
|
|
91
128
|
)
|
|
92
|
-
except ValueError as
|
|
93
|
-
|
|
94
|
-
|
|
129
|
+
except ValueError as error:
|
|
130
|
+
raise RsplotError(
|
|
131
|
+
"invalid_argument", f"FNR 阈值错误 (threshold): {error}"
|
|
132
|
+
) from error
|
|
95
133
|
|
|
96
134
|
console.print(
|
|
97
135
|
f"[bold]时间窗口:[/bold] {dates[0]} ~ {dates[-1]} "
|
|
@@ -104,7 +142,14 @@ def run_fnr(
|
|
|
104
142
|
)
|
|
105
143
|
|
|
106
144
|
console.print(f"[bold]解析区域:[/bold] {region}")
|
|
107
|
-
|
|
145
|
+
try:
|
|
146
|
+
info = resolve_regions(region, cfg)
|
|
147
|
+
except RsplotError:
|
|
148
|
+
raise
|
|
149
|
+
except ValueError as error:
|
|
150
|
+
raise RsplotError(
|
|
151
|
+
"region_not_found", str(error), details={"region": region}
|
|
152
|
+
) from error
|
|
108
153
|
console.print(f" → [green]{info.name}[/green] (级别: {info.level})")
|
|
109
154
|
|
|
110
155
|
params = info.params
|
|
@@ -122,9 +167,8 @@ def run_fnr(
|
|
|
122
167
|
validate_non_negative(no2_min, "--no2-min")
|
|
123
168
|
if use_smooth is not None:
|
|
124
169
|
validate_non_negative(use_smooth, "--smooth")
|
|
125
|
-
except ValueError as
|
|
126
|
-
|
|
127
|
-
raise typer.Exit(1) from e
|
|
170
|
+
except ValueError as error:
|
|
171
|
+
raise RsplotError("invalid_argument", str(error)) from error
|
|
128
172
|
if use_smooth == 0:
|
|
129
173
|
use_smooth = None
|
|
130
174
|
warn_missing_tianditu_key(
|
|
@@ -134,76 +178,56 @@ def run_fnr(
|
|
|
134
178
|
console=console,
|
|
135
179
|
)
|
|
136
180
|
|
|
137
|
-
use_no2_dir = (
|
|
138
|
-
|
|
139
|
-
if raster_dir_no2 is not None
|
|
140
|
-
else cfg.get_data_dir("no2")
|
|
141
|
-
)
|
|
142
|
-
use_hcho_dir = (
|
|
143
|
-
raster_dir_hcho
|
|
144
|
-
if raster_dir_hcho is not None
|
|
145
|
-
else cfg.get_data_dir("hcho")
|
|
146
|
-
)
|
|
181
|
+
use_no2_dir = cfg.get_data_dir(no2_info.data_key or "no2")
|
|
182
|
+
use_hcho_dir = cfg.get_data_dir(hcho_info.data_key or "hcho")
|
|
147
183
|
console.print("\n[bold]读取数据:[/bold]")
|
|
148
184
|
console.print(f" NO2 : {use_no2_dir}")
|
|
149
185
|
console.print(f" HCHO: {use_hcho_dir}")
|
|
150
186
|
console.print(f" QA > {use_qa}, CF <= {cf}")
|
|
151
187
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
188
|
+
try:
|
|
189
|
+
fnr_out = compute_fnr(
|
|
190
|
+
info,
|
|
191
|
+
dates,
|
|
192
|
+
res=use_res,
|
|
193
|
+
qa_threshold=use_qa,
|
|
194
|
+
cloud_fraction_max=cf,
|
|
195
|
+
n_min=use_n_min,
|
|
196
|
+
raster_dir_no2=use_no2_dir,
|
|
197
|
+
raster_dir_hcho=use_hcho_dir,
|
|
198
|
+
processing=processing,
|
|
199
|
+
no2_min_column=no2_min,
|
|
200
|
+
console=console,
|
|
201
|
+
)
|
|
202
|
+
except (RsplotError, OSError):
|
|
203
|
+
raise
|
|
204
|
+
except ValueError as error:
|
|
205
|
+
# The window readers raise ValueError when every day failed.
|
|
206
|
+
raise RsplotError("no_valid_data", str(error)) from error
|
|
165
207
|
|
|
166
|
-
n_fail_no2 = len(fnr_out.dates_failed_no2)
|
|
167
|
-
n_fail_hcho = len(fnr_out.dates_failed_hcho)
|
|
168
208
|
n_found_no2 = len(fnr_out.dates_found_no2)
|
|
169
209
|
n_found_hcho = len(fnr_out.dates_found_hcho)
|
|
170
210
|
console.print(
|
|
171
|
-
f" → NO2 有效天数 {n_found_no2}/{window_n}
|
|
211
|
+
f" → NO2 有效天数 {n_found_no2}/{window_n} "
|
|
212
|
+
f"(失败 {len(fnr_out.dates_failed_no2)})"
|
|
172
213
|
)
|
|
173
214
|
console.print(
|
|
174
|
-
f" → HCHO 有效天数 {n_found_hcho}/{window_n}
|
|
215
|
+
f" → HCHO 有效天数 {n_found_hcho}/{window_n} "
|
|
216
|
+
f"(失败 {len(fnr_out.dates_failed_hcho)})"
|
|
175
217
|
)
|
|
176
|
-
if use_n_min > min(n_found_no2, n_found_hcho):
|
|
177
|
-
console.print(
|
|
178
|
-
f" → [yellow]注意:[/yellow] n_min={use_n_min} 大于 NO2/HCHO "
|
|
179
|
-
f"共同可用天数上限 {min(n_found_no2, n_found_hcho)},"
|
|
180
|
-
"本次不可能产生有效 FNR 像元。"
|
|
181
|
-
)
|
|
182
|
-
|
|
183
218
|
finite = fnr_out.fnr[np.isfinite(fnr_out.fnr)]
|
|
184
219
|
if len(finite) == 0:
|
|
185
|
-
print_failed_dates(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
"HCHO",
|
|
192
|
-
fnr_out.dates_failed_hcho,
|
|
193
|
-
console=console,
|
|
220
|
+
print_failed_dates("NO2", fnr_out.dates_failed_no2, console=console)
|
|
221
|
+
print_failed_dates("HCHO", fnr_out.dates_failed_hcho, console=console)
|
|
222
|
+
raise RsplotError(
|
|
223
|
+
"no_valid_data",
|
|
224
|
+
"FNR 全区无有效像元,可能原因:窗口内 NO2/HCHO 都覆盖不足,"
|
|
225
|
+
"或 --n-min 太严,或 --no2-min 过高。可放宽 --n-min / 扩大窗口。",
|
|
194
226
|
)
|
|
195
|
-
console.print(
|
|
196
|
-
"[red]FNR 全区无有效像元,可能原因:窗口内 NO2/HCHO 都覆盖不足,"
|
|
197
|
-
"或 --n-min 太严。可放宽 --n-min / 扩大窗口。[/red]"
|
|
198
|
-
)
|
|
199
|
-
raise typer.Exit(1)
|
|
200
227
|
|
|
201
228
|
coverage_pct, n_valid_region, total_region_pixels = (
|
|
202
229
|
grid_coverage_in_region(
|
|
203
|
-
fnr_out.LON,
|
|
204
|
-
fnr_out.LAT,
|
|
205
|
-
fnr_out.fnr,
|
|
206
|
-
info.geometry,
|
|
230
|
+
fnr_out.LON, fnr_out.LAT, fnr_out.fnr, info.geometry
|
|
207
231
|
)
|
|
208
232
|
)
|
|
209
233
|
console.print(
|
|
@@ -211,7 +235,6 @@ def run_fnr(
|
|
|
211
235
|
f"({n_valid_region}/{total_region_pixels}), "
|
|
212
236
|
f"中位数 {float(np.median(finite)):.2f}"
|
|
213
237
|
)
|
|
214
|
-
|
|
215
238
|
percentages = regime_percentages(
|
|
216
239
|
fnr_out.fnr,
|
|
217
240
|
voc_threshold=use_voc_threshold,
|
|
@@ -223,40 +246,302 @@ def run_fnr(
|
|
|
223
246
|
f"[blue]NOx-limited {percentages['nox_limited']}%[/blue]"
|
|
224
247
|
)
|
|
225
248
|
|
|
226
|
-
if
|
|
227
|
-
|
|
228
|
-
|
|
249
|
+
if title is None and processing == "nrti":
|
|
250
|
+
title = f"TROPOMI NRTI FNR - {info.name}"
|
|
251
|
+
# The renderer's default title, recorded so the sidecar states it.
|
|
252
|
+
use_title = title or f"FNR regime — {info.name}"
|
|
253
|
+
image = str(Path(output).resolve())
|
|
254
|
+
sidecar = sidecar_path(image)
|
|
229
255
|
subtitle = (
|
|
230
256
|
f"{dates[0]}~{dates[-1]} · N_days={window_n} "
|
|
231
257
|
f"(n_min={use_n_min}) · NO2≥{no2_min:g}×10¹⁵ molec/cm²"
|
|
232
258
|
)
|
|
259
|
+
|
|
260
|
+
lon, lat = fnr_out.LON, fnr_out.LAT
|
|
261
|
+
counted = region_grid_mask(lon, lat, info.geometry)
|
|
262
|
+
time = {
|
|
263
|
+
"aggregation": "window_mean",
|
|
264
|
+
"start": dates[0],
|
|
265
|
+
"end": dates[-1],
|
|
266
|
+
"basis": "calendar_day",
|
|
267
|
+
}
|
|
268
|
+
product_method = {
|
|
269
|
+
"qa_min_exclusive": use_qa,
|
|
270
|
+
"cloud_fraction_max": cf,
|
|
271
|
+
"grid_deg": use_res,
|
|
272
|
+
"day_weighting": "equal_days",
|
|
273
|
+
"cell_selection": "center_strictly_inside",
|
|
274
|
+
"cell_weighting": "equal",
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
def days_block(found, failed, valid_days):
|
|
278
|
+
return {
|
|
279
|
+
"requested": window_n,
|
|
280
|
+
"found": len(found),
|
|
281
|
+
"failed": dict(failed),
|
|
282
|
+
"n_min": use_n_min,
|
|
283
|
+
"valid_days_per_cell": stats_block(
|
|
284
|
+
valid_days[counted & (valid_days > 0)].astype(float)
|
|
285
|
+
),
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
layers: list[dict[str, Any]] = []
|
|
289
|
+
flags: list[dict[str, Any]] = []
|
|
290
|
+
data_entries: list[dict[str, Any]] = []
|
|
291
|
+
products = (
|
|
292
|
+
(
|
|
293
|
+
"no2",
|
|
294
|
+
no2_info,
|
|
295
|
+
fnr_out.no2_mean,
|
|
296
|
+
fnr_out.n_valid_no2,
|
|
297
|
+
fnr_out.dates_found_no2,
|
|
298
|
+
fnr_out.dates_failed_no2,
|
|
299
|
+
fnr_out.daily_metadata_no2,
|
|
300
|
+
use_no2_dir,
|
|
301
|
+
),
|
|
302
|
+
(
|
|
303
|
+
"hcho",
|
|
304
|
+
hcho_info,
|
|
305
|
+
fnr_out.hcho_mean,
|
|
306
|
+
fnr_out.n_valid_hcho,
|
|
307
|
+
fnr_out.dates_found_hcho,
|
|
308
|
+
fnr_out.dates_failed_hcho,
|
|
309
|
+
fnr_out.daily_metadata_hcho,
|
|
310
|
+
use_hcho_dir,
|
|
311
|
+
),
|
|
312
|
+
)
|
|
313
|
+
for name, prod, mean, valid_days, found, failed, daily, root in products:
|
|
314
|
+
path = data_path(image, name, ".nc")
|
|
315
|
+
created.append(path)
|
|
316
|
+
entry = write_grid_netcdf(
|
|
317
|
+
path,
|
|
318
|
+
lon,
|
|
319
|
+
lat,
|
|
320
|
+
mean,
|
|
321
|
+
counted,
|
|
322
|
+
extent=info.extent,
|
|
323
|
+
layer=name,
|
|
324
|
+
attrs={
|
|
325
|
+
"quantity": prod.quantity,
|
|
326
|
+
"unit": prod.unit,
|
|
327
|
+
"scale": prod.unit_scale,
|
|
328
|
+
"time_aggregation": "window_mean",
|
|
329
|
+
},
|
|
330
|
+
valid_days=valid_days,
|
|
331
|
+
)
|
|
332
|
+
data_entries.append(entry)
|
|
333
|
+
product_layer, product_flags = build_satellite_layer(
|
|
334
|
+
SatelliteInputs(
|
|
335
|
+
prod_info=prod,
|
|
336
|
+
lon=lon,
|
|
337
|
+
lat=lat,
|
|
338
|
+
grid=mean,
|
|
339
|
+
counted=counted,
|
|
340
|
+
time=time,
|
|
341
|
+
data_root=str(root),
|
|
342
|
+
metadata=list(daily.values()),
|
|
343
|
+
method=dict(product_method),
|
|
344
|
+
valid_days=valid_days,
|
|
345
|
+
days=days_block(found, failed, valid_days),
|
|
346
|
+
),
|
|
347
|
+
info,
|
|
348
|
+
data=entry["path"],
|
|
349
|
+
layer_id=name,
|
|
350
|
+
coverage_checks=False,
|
|
351
|
+
)
|
|
352
|
+
layers.append(product_layer)
|
|
353
|
+
flags.extend(product_flags)
|
|
354
|
+
|
|
355
|
+
both_valid = np.minimum(fnr_out.n_valid_no2, fnr_out.n_valid_hcho)
|
|
356
|
+
fnr_path = data_path(image, "fnr", ".nc")
|
|
357
|
+
created.append(fnr_path)
|
|
358
|
+
fnr_entry = write_grid_netcdf(
|
|
359
|
+
fnr_path,
|
|
360
|
+
lon,
|
|
361
|
+
lat,
|
|
362
|
+
fnr_out.fnr,
|
|
363
|
+
counted,
|
|
364
|
+
extent=info.extent,
|
|
365
|
+
layer="fnr",
|
|
366
|
+
attrs={
|
|
367
|
+
"quantity": "fnr",
|
|
368
|
+
"unit": "1",
|
|
369
|
+
"scale": 1.0,
|
|
370
|
+
"time_aggregation": "window_mean",
|
|
371
|
+
},
|
|
372
|
+
valid_days=both_valid,
|
|
373
|
+
)
|
|
374
|
+
data_entries.append(fnr_entry)
|
|
375
|
+
|
|
376
|
+
fnr_values = fnr_out.fnr[counted]
|
|
377
|
+
fnr_valid = np.isfinite(fnr_values)
|
|
378
|
+
coverage = coverage_block(
|
|
379
|
+
int(fnr_valid.sum()), int(counted.sum()), "cells"
|
|
380
|
+
)
|
|
381
|
+
classified = fnr_values[fnr_valid]
|
|
382
|
+
categories = {
|
|
383
|
+
"voc_limited": int((classified < use_voc_threshold).sum()),
|
|
384
|
+
"transition": int(
|
|
385
|
+
(
|
|
386
|
+
(classified >= use_voc_threshold)
|
|
387
|
+
& (classified <= use_nox_threshold)
|
|
388
|
+
).sum()
|
|
389
|
+
),
|
|
390
|
+
"nox_limited": int((classified > use_nox_threshold).sum()),
|
|
391
|
+
}
|
|
392
|
+
masks = {
|
|
393
|
+
key: mask & counted for key, mask in fnr_out.diagnostic_masks.items()
|
|
394
|
+
}
|
|
395
|
+
sub_gdf = info.sub_boundary_gdf
|
|
396
|
+
has_subdivisions = sub_gdf is not None and len(sub_gdf) > 0
|
|
397
|
+
by_admin = []
|
|
398
|
+
if has_subdivisions:
|
|
399
|
+
level_name = subdivision_level(info)
|
|
400
|
+
by_admin = [
|
|
401
|
+
{
|
|
402
|
+
"name": row["name"],
|
|
403
|
+
"level": level_name,
|
|
404
|
+
"n": int(row["n_pixels"]),
|
|
405
|
+
"mean": row["mean_fnr"],
|
|
406
|
+
"category": row["regime"],
|
|
407
|
+
}
|
|
408
|
+
for row in fnr_per_admin_stats(
|
|
409
|
+
lon,
|
|
410
|
+
lat,
|
|
411
|
+
fnr_out.fnr,
|
|
412
|
+
sub_gdf,
|
|
413
|
+
voc_threshold=use_voc_threshold,
|
|
414
|
+
nox_threshold=use_nox_threshold,
|
|
415
|
+
)
|
|
416
|
+
]
|
|
417
|
+
hotspots = top_hotspots(
|
|
418
|
+
lon, lat, fnr_out.fnr, sub_gdf if has_subdivisions else None, n=10
|
|
419
|
+
)
|
|
420
|
+
found_both = sorted(
|
|
421
|
+
set(fnr_out.dates_found_no2) & set(fnr_out.dates_found_hcho)
|
|
422
|
+
)
|
|
423
|
+
failed_either = {
|
|
424
|
+
**{d: f"NO2: {m}" for d, m in fnr_out.dates_failed_no2.items()},
|
|
425
|
+
**{d: f"HCHO: {m}" for d, m in fnr_out.dates_failed_hcho.items()},
|
|
426
|
+
}
|
|
427
|
+
fnr_layer: dict[str, Any] = {
|
|
428
|
+
"id": "fnr",
|
|
429
|
+
"kind": "grid",
|
|
430
|
+
"quantity": {
|
|
431
|
+
"name": "fnr",
|
|
432
|
+
"unit": "1",
|
|
433
|
+
"scale": 1,
|
|
434
|
+
"label": "FNR (HCHO / NO2)",
|
|
435
|
+
},
|
|
436
|
+
"time": {
|
|
437
|
+
**time,
|
|
438
|
+
"days": days_block(found_both, failed_either, both_valid),
|
|
439
|
+
},
|
|
440
|
+
"source": {
|
|
441
|
+
"sensor": "tropomi",
|
|
442
|
+
"processing": processing or "offl",
|
|
443
|
+
"data_root": str(use_no2_dir),
|
|
444
|
+
"files_total": sum(
|
|
445
|
+
item["source"]["files_total"] for item in layers
|
|
446
|
+
),
|
|
447
|
+
"failed_files": {},
|
|
448
|
+
**combined_fingerprint(item["source"] for item in layers),
|
|
449
|
+
},
|
|
450
|
+
"method": {
|
|
451
|
+
"ratio": "hcho_window_mean / no2_window_mean",
|
|
452
|
+
"n_min_each_product": use_n_min,
|
|
453
|
+
"no2_min_column": no2_min,
|
|
454
|
+
"no2_min_unit": "1e15 molec/cm2",
|
|
455
|
+
"hcho_min_column": 0,
|
|
456
|
+
"regime_thresholds": {
|
|
457
|
+
"voc_limited_below": use_voc_threshold,
|
|
458
|
+
"nox_limited_above": use_nox_threshold,
|
|
459
|
+
},
|
|
460
|
+
"mask_counts": {
|
|
461
|
+
"region_cells": int(counted.sum()),
|
|
462
|
+
"coverage_ge_n_min": int(masks["coverage_ok"].sum()),
|
|
463
|
+
"no2_ge_threshold": int(masks["no2_ok"].sum()),
|
|
464
|
+
"hcho_nonnegative": int(masks["hcho_ok"].sum()),
|
|
465
|
+
"final_valid": coverage["valid"],
|
|
466
|
+
},
|
|
467
|
+
"inputs": ["no2", "hcho"],
|
|
468
|
+
"cell_selection": "center_strictly_inside",
|
|
469
|
+
"cell_weighting": "equal",
|
|
470
|
+
},
|
|
471
|
+
"coverage": coverage,
|
|
472
|
+
"stats": stats_block(fnr_values),
|
|
473
|
+
"categories": categories,
|
|
474
|
+
"by_admin": by_admin,
|
|
475
|
+
"extremes": capped(
|
|
476
|
+
[
|
|
477
|
+
{
|
|
478
|
+
"lon": item["lon"],
|
|
479
|
+
"lat": item["lat"],
|
|
480
|
+
"value": item["value"],
|
|
481
|
+
"admin": item["city"],
|
|
482
|
+
}
|
|
483
|
+
for item in hotspots
|
|
484
|
+
],
|
|
485
|
+
coverage["valid"],
|
|
486
|
+
"value_desc",
|
|
487
|
+
),
|
|
488
|
+
"data": fnr_entry["path"],
|
|
489
|
+
}
|
|
490
|
+
if info.members:
|
|
491
|
+
fnr_layer["by_member"] = fnr_member_stats(
|
|
492
|
+
lon,
|
|
493
|
+
lat,
|
|
494
|
+
fnr_out.fnr,
|
|
495
|
+
info,
|
|
496
|
+
voc_threshold=use_voc_threshold,
|
|
497
|
+
nox_threshold=use_nox_threshold,
|
|
498
|
+
)
|
|
499
|
+
layers.append(fnr_layer)
|
|
500
|
+
flags.extend(coverage_flags("fnr", coverage))
|
|
233
501
|
console.print("\n[bold]绘图中...[/bold]")
|
|
502
|
+
created.append(Path(image))
|
|
234
503
|
plot_fnr(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
fnr_out.fnr,
|
|
504
|
+
lon,
|
|
505
|
+
lat,
|
|
506
|
+
smooth_fnr_for_display(fnr_out.fnr, info, lon, lat, use_smooth),
|
|
238
507
|
info,
|
|
239
508
|
dpi=use_dpi,
|
|
240
509
|
basemap=use_basemap,
|
|
241
510
|
tianditu_key=cfg.tianditu_key,
|
|
242
511
|
title=title,
|
|
243
|
-
output=
|
|
512
|
+
output=image,
|
|
244
513
|
subtitle=subtitle,
|
|
245
514
|
voc_threshold=use_voc_threshold,
|
|
246
515
|
nox_threshold=use_nox_threshold,
|
|
247
516
|
display_max=use_display_max,
|
|
248
517
|
)
|
|
249
|
-
console.print(f"\n[bold green]✓ 已保存:[/bold green] {output}")
|
|
250
518
|
|
|
251
|
-
|
|
519
|
+
effective_basemap = (
|
|
520
|
+
use_basemap if use_basemap is not None else params.basemap
|
|
521
|
+
)
|
|
522
|
+
payload = success_envelope(
|
|
523
|
+
command="fnr",
|
|
524
|
+
request=command_line(),
|
|
252
525
|
region=info,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
526
|
+
layers=layers,
|
|
527
|
+
flags=flags,
|
|
528
|
+
render={
|
|
529
|
+
"image": image,
|
|
530
|
+
"dpi": int(use_dpi),
|
|
531
|
+
"basemap": "satellite" if effective_basemap else "none",
|
|
532
|
+
"title": use_title,
|
|
533
|
+
"layers": {
|
|
534
|
+
"fnr": {
|
|
535
|
+
"voc_threshold": use_voc_threshold,
|
|
536
|
+
"nox_threshold": use_nox_threshold,
|
|
537
|
+
"display_max": use_display_max,
|
|
538
|
+
"display_smoothing_sigma": use_smooth or 0,
|
|
539
|
+
"subtitle": subtitle,
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
artifacts={"image": image, "sidecar": sidecar, "data": data_entries},
|
|
261
544
|
)
|
|
262
|
-
|
|
545
|
+
created.append(Path(sidecar))
|
|
546
|
+
write_sidecar(payload, sidecar)
|
|
547
|
+
console.print(f"\n[bold green]✓ 已保存:[/bold green] {image}")
|
rsplot/commands/forecast.py
CHANGED
|
@@ -315,7 +315,6 @@ def run_forecast(
|
|
|
315
315
|
vmax=use_vmax,
|
|
316
316
|
basemap=use_basemap,
|
|
317
317
|
tianditu_key=cfg.tianditu_key,
|
|
318
|
-
hcho_cmap_file=cfg.hcho_cmap_file,
|
|
319
318
|
title=title,
|
|
320
319
|
output=output,
|
|
321
320
|
colorbar_label=var_info.colorbar_label,
|
|
@@ -336,7 +335,6 @@ def run_forecast(
|
|
|
336
335
|
dpi=use_dpi,
|
|
337
336
|
basemap=use_basemap,
|
|
338
337
|
tianditu_key=cfg.tianditu_key,
|
|
339
|
-
hcho_cmap_file=cfg.hcho_cmap_file,
|
|
340
338
|
title=title,
|
|
341
339
|
output=output,
|
|
342
340
|
)
|