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/temporal.py
CHANGED
|
@@ -7,9 +7,9 @@ remain available for compatibility.
|
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
-
from dataclasses import dataclass
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
11
|
from datetime import datetime, timedelta
|
|
12
|
-
from typing import TYPE_CHECKING
|
|
12
|
+
from typing import TYPE_CHECKING, Any
|
|
13
13
|
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
|
14
14
|
|
|
15
15
|
import numpy as np
|
|
@@ -135,6 +135,7 @@ class WindowResult:
|
|
|
135
135
|
n_pixels_total: int
|
|
136
136
|
n_files_total: int
|
|
137
137
|
n_broken_total: int
|
|
138
|
+
daily_metadata: dict[str, Any] = field(default_factory=dict)
|
|
138
139
|
|
|
139
140
|
|
|
140
141
|
def compute_window_mean(
|
|
@@ -156,6 +157,7 @@ def compute_window_mean(
|
|
|
156
157
|
valid_counts: np.ndarray | None = None
|
|
157
158
|
dates_found: list[str] = []
|
|
158
159
|
dates_failed: dict[str, str] = {}
|
|
160
|
+
daily_metadata: dict[str, Any] = {}
|
|
159
161
|
n_pix_total = 0
|
|
160
162
|
n_files_total = 0
|
|
161
163
|
n_broken_total = 0
|
|
@@ -164,19 +166,22 @@ def compute_window_mean(
|
|
|
164
166
|
|
|
165
167
|
for date in track(dates, description=f"[cyan]读取 {label} 窗口..."):
|
|
166
168
|
try:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
batch = read_scan_mean(
|
|
170
|
+
reader=reader,
|
|
171
|
+
data_dir=data_dir,
|
|
172
|
+
request=date,
|
|
173
|
+
extent=extent,
|
|
174
|
+
res=res,
|
|
171
175
|
qa_threshold=qa_threshold,
|
|
172
176
|
)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
)
|
|
177
|
+
if batch.metadata:
|
|
178
|
+
daily_metadata[date] = batch.metadata
|
|
179
|
+
n_pix_total += batch.n_pixels
|
|
180
|
+
n_files_total += batch.n_files
|
|
181
|
+
n_broken_total += batch.n_broken
|
|
182
|
+
day_lon, day_lat, grid = batch.LON, batch.LAT, batch.grid
|
|
183
|
+
if not np.isfinite(grid).any():
|
|
184
|
+
raise ValueError(batch.failure_message())
|
|
180
185
|
LON, LAT = day_lon, day_lat
|
|
181
186
|
if sum_grid is None:
|
|
182
187
|
sum_grid = np.zeros(grid.shape, dtype=float)
|
|
@@ -185,9 +190,6 @@ def compute_window_mean(
|
|
|
185
190
|
np.add(sum_grid, grid, out=sum_grid, where=finite)
|
|
186
191
|
valid_counts += finite
|
|
187
192
|
dates_found.append(date)
|
|
188
|
-
n_pix_total += int(swath.n_pixels)
|
|
189
|
-
n_files_total += int(swath.n_files)
|
|
190
|
-
n_broken_total += int(swath.n_broken)
|
|
191
193
|
except (FileNotFoundError, ValueError) as e:
|
|
192
194
|
dates_failed[date] = str(e).splitlines()[0]
|
|
193
195
|
|
|
@@ -221,4 +223,132 @@ def compute_window_mean(
|
|
|
221
223
|
n_pixels_total=n_pix_total,
|
|
222
224
|
n_files_total=n_files_total,
|
|
223
225
|
n_broken_total=n_broken_total,
|
|
226
|
+
daily_metadata=daily_metadata,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
@dataclass
|
|
231
|
+
class ScanMean:
|
|
232
|
+
"""An unfilled grid mean with per-cell temporal sample counts."""
|
|
233
|
+
|
|
234
|
+
LON: np.ndarray
|
|
235
|
+
LAT: np.ndarray
|
|
236
|
+
grid: np.ndarray
|
|
237
|
+
n_valid: np.ndarray
|
|
238
|
+
n_pixels: int
|
|
239
|
+
n_files: int
|
|
240
|
+
n_broken: int
|
|
241
|
+
metadata: dict[str, Any]
|
|
242
|
+
|
|
243
|
+
def failure_message(self) -> str:
|
|
244
|
+
"""Keep CLI errors compact; full per-file diagnostics stay in JSON."""
|
|
245
|
+
message = (
|
|
246
|
+
f"{self.metadata.get('request', '')} 区域内无有效扫描 "
|
|
247
|
+
f"({self.n_files} 文件, {self.n_broken} 损坏)。"
|
|
248
|
+
)
|
|
249
|
+
examples = list(self.metadata.get("failed_files", {}).items())[:3]
|
|
250
|
+
if examples:
|
|
251
|
+
from pathlib import Path
|
|
252
|
+
|
|
253
|
+
message += " " + "; ".join(
|
|
254
|
+
f"{Path(path).name}: {error}" for path, error in examples
|
|
255
|
+
)
|
|
256
|
+
return message
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def read_scan_mean(
|
|
260
|
+
*,
|
|
261
|
+
reader: BaseReader,
|
|
262
|
+
data_dir: str,
|
|
263
|
+
request: str,
|
|
264
|
+
extent: tuple[float, float, float, float],
|
|
265
|
+
res: float,
|
|
266
|
+
qa_threshold: float = 0.5,
|
|
267
|
+
) -> ScanMean:
|
|
268
|
+
"""Grid each scan independently, then average valid scans equally."""
|
|
269
|
+
# A NaN sentinel establishes the grid even if every scan is invalid.
|
|
270
|
+
lon, lat, template = grid_data(
|
|
271
|
+
np.array([extent[0]]),
|
|
272
|
+
np.array([extent[2]]),
|
|
273
|
+
np.array([np.nan]),
|
|
274
|
+
extent,
|
|
275
|
+
res,
|
|
276
|
+
)
|
|
277
|
+
footprints = getattr(reader, "uses_footprints", False)
|
|
278
|
+
if footprints:
|
|
279
|
+
from rsplot.geo.footprints import overlap_mean, regular_grid
|
|
280
|
+
|
|
281
|
+
lon, lat = regular_grid(extent, res)
|
|
282
|
+
template = np.full(lon.shape, np.nan)
|
|
283
|
+
total = np.zeros(template.shape, dtype=float)
|
|
284
|
+
counts = np.zeros(template.shape, dtype=np.int32)
|
|
285
|
+
n_pixels = n_files = n_broken = 0
|
|
286
|
+
scans = []
|
|
287
|
+
iterator = getattr(reader, "iter_scans", None)
|
|
288
|
+
scans_iter = (
|
|
289
|
+
iterator(data_dir, request, extent, qa_threshold)
|
|
290
|
+
if iterator is not None
|
|
291
|
+
else (reader.read(data_dir, request, extent, qa_threshold),)
|
|
292
|
+
)
|
|
293
|
+
for scan in scans_iter:
|
|
294
|
+
n_pixels += scan.n_pixels
|
|
295
|
+
n_files += scan.n_files
|
|
296
|
+
n_broken += scan.n_broken
|
|
297
|
+
if scan.metadata:
|
|
298
|
+
scans.append(scan.metadata)
|
|
299
|
+
if not scan.n_pixels:
|
|
300
|
+
continue
|
|
301
|
+
if footprints:
|
|
302
|
+
if scan.corner_lon is None or scan.corner_lat is None:
|
|
303
|
+
raise ValueError("GEMS 扫描缺少像元边界,不能退回中心点分箱。")
|
|
304
|
+
grid = overlap_mean(
|
|
305
|
+
scan.corner_lon, scan.corner_lat, scan.values, lon, lat, res
|
|
306
|
+
)
|
|
307
|
+
else:
|
|
308
|
+
_, _, grid = grid_data(
|
|
309
|
+
scan.lon, scan.lat, scan.values, extent, res
|
|
310
|
+
)
|
|
311
|
+
valid = np.isfinite(grid)
|
|
312
|
+
np.add(total, grid, out=total, where=valid)
|
|
313
|
+
counts += valid
|
|
314
|
+
mean = np.full(template.shape, np.nan)
|
|
315
|
+
np.divide(total, counts, out=mean, where=counts > 0)
|
|
316
|
+
covered = counts[counts > 0]
|
|
317
|
+
metadata = {
|
|
318
|
+
"request": request,
|
|
319
|
+
"input_timezone": "Asia/Shanghai",
|
|
320
|
+
"aggregation": "scan" if len(request) == 12 else "equal_scan_mean",
|
|
321
|
+
"scans": scans,
|
|
322
|
+
"n_scans_found": len(scans),
|
|
323
|
+
"n_scans_valid": sum(s.get("n_pixels", 0) > 0 for s in scans),
|
|
324
|
+
"failed_files": {s["file"]: s["error"] for s in scans if "error" in s},
|
|
325
|
+
"coverage_scope": "read_extent",
|
|
326
|
+
"read_extent": list(extent),
|
|
327
|
+
"coverage_scans": {
|
|
328
|
+
"min": int(covered.min()) if covered.size else 0,
|
|
329
|
+
"max": int(covered.max()) if covered.size else 0,
|
|
330
|
+
"mean": float(covered.mean()) if covered.size else 0.0,
|
|
331
|
+
},
|
|
332
|
+
}
|
|
333
|
+
if getattr(reader, "processing", None) == "nrti" and scans:
|
|
334
|
+
metadata = {
|
|
335
|
+
**scans[0],
|
|
336
|
+
"request": request,
|
|
337
|
+
"coverage_scope": "read_extent",
|
|
338
|
+
"read_extent": list(extent),
|
|
339
|
+
}
|
|
340
|
+
if footprints:
|
|
341
|
+
metadata["spatial_aggregation"] = "footprint_overlap_area_mean"
|
|
342
|
+
metadata["area_crs"] = "EPSG:6933"
|
|
343
|
+
metadata["analysis_resolution_deg"] = res
|
|
344
|
+
metadata["grid_alignment"] = "global_multiples_of_resolution"
|
|
345
|
+
return ScanMean(
|
|
346
|
+
lon,
|
|
347
|
+
lat,
|
|
348
|
+
mean,
|
|
349
|
+
counts,
|
|
350
|
+
n_pixels,
|
|
351
|
+
n_files,
|
|
352
|
+
n_broken,
|
|
353
|
+
metadata if scans else {},
|
|
224
354
|
)
|