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/data_files.py
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"""Data files written next to images for agents' further analysis."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
from rsplot.atomic import atomic_write
|
|
11
|
+
from rsplot.result_builders.envelope import rsplot_version
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def data_path(output: str, layer: str, suffix: str) -> Path:
|
|
15
|
+
"""Return ``<base>.<layer><suffix>`` next to the image."""
|
|
16
|
+
image = Path(output)
|
|
17
|
+
return image.with_name(f"{image.stem}.{layer}{suffix}")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def write_grid_netcdf(
|
|
21
|
+
path: Path,
|
|
22
|
+
lon: np.ndarray,
|
|
23
|
+
lat: np.ndarray,
|
|
24
|
+
values: np.ndarray,
|
|
25
|
+
counted: np.ndarray,
|
|
26
|
+
*,
|
|
27
|
+
extent: tuple[float, float, float, float],
|
|
28
|
+
layer: str,
|
|
29
|
+
attrs: dict[str, Any],
|
|
30
|
+
valid_days: np.ndarray | None = None,
|
|
31
|
+
extra: dict[str, np.ndarray] | None = None,
|
|
32
|
+
content: str = "statistical_grid",
|
|
33
|
+
) -> dict[str, Any]:
|
|
34
|
+
"""Write a statistical grid cropped to the region extent.
|
|
35
|
+
|
|
36
|
+
``extra`` adds same-shaped float variables, e.g. ``u``/``v`` for wind.
|
|
37
|
+
|
|
38
|
+
``lon``/``lat`` are regular 2-D cell-centre grids. ``values`` is the
|
|
39
|
+
exact grid statistics were computed from (NaN = invalid) and
|
|
40
|
+
``counted`` marks cells whose centres count toward statistics.
|
|
41
|
+
"""
|
|
42
|
+
from netCDF4 import Dataset
|
|
43
|
+
|
|
44
|
+
lons = np.asarray(lon)[0, :]
|
|
45
|
+
lats = np.asarray(lat)[:, 0]
|
|
46
|
+
half_x = abs(float(lons[1] - lons[0])) / 2 if lons.size > 1 else 0.0
|
|
47
|
+
half_y = abs(float(lats[1] - lats[0])) / 2 if lats.size > 1 else 0.0
|
|
48
|
+
columns = np.flatnonzero(
|
|
49
|
+
(lons >= extent[0] - half_x) & (lons <= extent[1] + half_x)
|
|
50
|
+
)
|
|
51
|
+
rows = np.flatnonzero(
|
|
52
|
+
(lats >= extent[2] - half_y) & (lats <= extent[3] + half_y)
|
|
53
|
+
)
|
|
54
|
+
window = np.ix_(rows, columns)
|
|
55
|
+
|
|
56
|
+
with (
|
|
57
|
+
atomic_write(path) as temp,
|
|
58
|
+
Dataset(temp, "w", format="NETCDF4") as dataset,
|
|
59
|
+
):
|
|
60
|
+
# setncattr: netCDF4 reserves some Python attribute names.
|
|
61
|
+
dataset.setncattr("rsplot_version", rsplot_version())
|
|
62
|
+
dataset.setncattr("layer", layer)
|
|
63
|
+
for key, value in attrs.items():
|
|
64
|
+
if value is not None:
|
|
65
|
+
dataset.setncattr(key, value)
|
|
66
|
+
dataset.createDimension("lat", len(rows))
|
|
67
|
+
dataset.createDimension("lon", len(columns))
|
|
68
|
+
compression = {"zlib": True, "complevel": 4, "shuffle": True}
|
|
69
|
+
lat_var = dataset.createVariable("lat", "f8", ("lat",))
|
|
70
|
+
lat_var.units = "degrees_north"
|
|
71
|
+
lat_var[:] = lats[rows]
|
|
72
|
+
lon_var = dataset.createVariable("lon", "f8", ("lon",))
|
|
73
|
+
lon_var.units = "degrees_east"
|
|
74
|
+
lon_var[:] = lons[columns]
|
|
75
|
+
value = dataset.createVariable(
|
|
76
|
+
"value",
|
|
77
|
+
"f4",
|
|
78
|
+
("lat", "lon"),
|
|
79
|
+
fill_value=np.float32(np.nan),
|
|
80
|
+
**compression,
|
|
81
|
+
)
|
|
82
|
+
value.setncattr("units", attrs.get("unit", ""))
|
|
83
|
+
value.setncattr("scale_to_unit", attrs.get("scale", 1.0))
|
|
84
|
+
value.setncattr(
|
|
85
|
+
"description", "Statistical grid; NaN = no valid value."
|
|
86
|
+
)
|
|
87
|
+
value[:] = np.asarray(values, dtype=np.float32)[window]
|
|
88
|
+
mask = dataset.createVariable(
|
|
89
|
+
"counted", "u1", ("lat", "lon"), **compression
|
|
90
|
+
)
|
|
91
|
+
mask.description = (
|
|
92
|
+
"1 = cell centre strictly inside the region; counts toward "
|
|
93
|
+
"statistics."
|
|
94
|
+
)
|
|
95
|
+
mask[:] = np.asarray(counted, dtype=np.uint8)[window]
|
|
96
|
+
if valid_days is not None:
|
|
97
|
+
days = dataset.createVariable(
|
|
98
|
+
"valid_days", "i2", ("lat", "lon"), **compression
|
|
99
|
+
)
|
|
100
|
+
days.description = "Valid days per cell in the window."
|
|
101
|
+
days[:] = np.asarray(valid_days, dtype=np.int16)[window]
|
|
102
|
+
for name, data in (extra or {}).items():
|
|
103
|
+
variable = dataset.createVariable(
|
|
104
|
+
name,
|
|
105
|
+
"f4",
|
|
106
|
+
("lat", "lon"),
|
|
107
|
+
fill_value=np.float32(np.nan),
|
|
108
|
+
**compression,
|
|
109
|
+
)
|
|
110
|
+
variable.setncattr("units", attrs.get("unit", ""))
|
|
111
|
+
variable[:] = np.asarray(data, dtype=np.float32)[window]
|
|
112
|
+
return {
|
|
113
|
+
"path": str(path),
|
|
114
|
+
"format": "netcdf4",
|
|
115
|
+
"content": content,
|
|
116
|
+
"layer": layer,
|
|
117
|
+
"shape": [len(rows), len(columns)],
|
|
118
|
+
"bytes": path.stat().st_size,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def format_number(value: float | None) -> str:
|
|
123
|
+
"""Compact CSV text: up to 4 decimals, no trailing zeros, '' for NaN."""
|
|
124
|
+
if value is None or not np.isfinite(value):
|
|
125
|
+
return ""
|
|
126
|
+
text = f"{float(value):.4f}".rstrip("0").rstrip(".")
|
|
127
|
+
return "0" if text in ("-0", "") else text
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def write_table_csv(
|
|
131
|
+
path: Path,
|
|
132
|
+
rows: list[dict[str, Any]],
|
|
133
|
+
columns: list[str],
|
|
134
|
+
*,
|
|
135
|
+
content: str,
|
|
136
|
+
layer: str,
|
|
137
|
+
) -> dict[str, Any]:
|
|
138
|
+
"""Write one CSV row per item; floats use ``format_number``."""
|
|
139
|
+
import csv
|
|
140
|
+
|
|
141
|
+
with (
|
|
142
|
+
atomic_write(path) as temp,
|
|
143
|
+
open(temp, "w", encoding="utf-8", newline="") as handle,
|
|
144
|
+
):
|
|
145
|
+
writer = csv.writer(handle)
|
|
146
|
+
writer.writerow(columns)
|
|
147
|
+
for row in rows:
|
|
148
|
+
writer.writerow(
|
|
149
|
+
[
|
|
150
|
+
format_number(row[column])
|
|
151
|
+
if isinstance(row[column], (float, np.floating))
|
|
152
|
+
else row[column]
|
|
153
|
+
for column in columns
|
|
154
|
+
]
|
|
155
|
+
)
|
|
156
|
+
return {
|
|
157
|
+
"path": str(path),
|
|
158
|
+
"format": "csv",
|
|
159
|
+
"content": content,
|
|
160
|
+
"layer": layer,
|
|
161
|
+
"rows": len(rows),
|
|
162
|
+
"bytes": path.stat().st_size,
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def write_series_netcdf(
|
|
167
|
+
path: Path,
|
|
168
|
+
*,
|
|
169
|
+
station_ids: np.ndarray,
|
|
170
|
+
lon: np.ndarray,
|
|
171
|
+
lat: np.ndarray,
|
|
172
|
+
timestamps: list[str],
|
|
173
|
+
values: np.ndarray,
|
|
174
|
+
layer: str,
|
|
175
|
+
attrs: dict[str, Any],
|
|
176
|
+
regional_mean: np.ndarray | None = None,
|
|
177
|
+
hourly_counts: np.ndarray | None = None,
|
|
178
|
+
) -> dict[str, Any]:
|
|
179
|
+
"""Write hourly station values as ``value(station, time)``.
|
|
180
|
+
|
|
181
|
+
``time`` counts China clock hours, like every rsplot time, so readers
|
|
182
|
+
decode it to the CLI's ``YYYYMMDDHH`` hours without a UTC shift.
|
|
183
|
+
"""
|
|
184
|
+
from datetime import datetime
|
|
185
|
+
|
|
186
|
+
from netCDF4 import Dataset
|
|
187
|
+
|
|
188
|
+
epoch = datetime(1970, 1, 1)
|
|
189
|
+
hours = [
|
|
190
|
+
(datetime.strptime(stamp, "%Y%m%d%H") - epoch).total_seconds() / 3600
|
|
191
|
+
for stamp in timestamps
|
|
192
|
+
]
|
|
193
|
+
matrix = np.atleast_2d(np.asarray(values, dtype=np.float32))
|
|
194
|
+
with (
|
|
195
|
+
atomic_write(path) as temp,
|
|
196
|
+
Dataset(temp, "w", format="NETCDF4") as dataset,
|
|
197
|
+
):
|
|
198
|
+
dataset.setncattr("rsplot_version", rsplot_version())
|
|
199
|
+
dataset.setncattr("layer", layer)
|
|
200
|
+
for key, value in attrs.items():
|
|
201
|
+
if value is not None:
|
|
202
|
+
dataset.setncattr(key, value)
|
|
203
|
+
dataset.createDimension("station", matrix.shape[0])
|
|
204
|
+
dataset.createDimension("time", matrix.shape[1])
|
|
205
|
+
compression = {"zlib": True, "complevel": 4, "shuffle": True}
|
|
206
|
+
ids = dataset.createVariable("station_id", str, ("station",))
|
|
207
|
+
for index, station_id in enumerate(station_ids):
|
|
208
|
+
ids[index] = str(station_id)
|
|
209
|
+
for name, data, units in (
|
|
210
|
+
("lon", lon, "degrees_east"),
|
|
211
|
+
("lat", lat, "degrees_north"),
|
|
212
|
+
):
|
|
213
|
+
variable = dataset.createVariable(name, "f8", ("station",))
|
|
214
|
+
variable.setncattr("units", units)
|
|
215
|
+
variable[:] = np.atleast_1d(np.asarray(data, dtype=float))
|
|
216
|
+
time = dataset.createVariable("time", "f8", ("time",))
|
|
217
|
+
time.setncattr("units", "hours since 1970-01-01 00:00:00")
|
|
218
|
+
time.setncattr("calendar", "standard")
|
|
219
|
+
time[:] = hours
|
|
220
|
+
value = dataset.createVariable(
|
|
221
|
+
"value",
|
|
222
|
+
"f4",
|
|
223
|
+
("station", "time"),
|
|
224
|
+
fill_value=np.float32(np.nan),
|
|
225
|
+
**compression,
|
|
226
|
+
)
|
|
227
|
+
value.setncattr("units", attrs.get("unit", ""))
|
|
228
|
+
value.setncattr("description", "Hourly value; NaN = missing.")
|
|
229
|
+
value[:] = matrix
|
|
230
|
+
if regional_mean is not None:
|
|
231
|
+
mean = dataset.createVariable(
|
|
232
|
+
"regional_mean",
|
|
233
|
+
"f4",
|
|
234
|
+
("time",),
|
|
235
|
+
fill_value=np.float32(np.nan),
|
|
236
|
+
**compression,
|
|
237
|
+
)
|
|
238
|
+
mean.setncattr("description", "Mean over stations with a value.")
|
|
239
|
+
mean[:] = np.asarray(regional_mean, dtype=np.float32)
|
|
240
|
+
if hourly_counts is not None:
|
|
241
|
+
counts = dataset.createVariable(
|
|
242
|
+
"n_stations", "i4", ("time",), **compression
|
|
243
|
+
)
|
|
244
|
+
counts.setncattr("description", "Stations with a value per hour.")
|
|
245
|
+
counts[:] = np.asarray(hourly_counts, dtype=np.int32)
|
|
246
|
+
return {
|
|
247
|
+
"path": str(path),
|
|
248
|
+
"format": "netcdf4",
|
|
249
|
+
"content": "hourly_series",
|
|
250
|
+
"layer": layer,
|
|
251
|
+
"shape": [int(matrix.shape[0]), int(matrix.shape[1])],
|
|
252
|
+
"bytes": path.stat().st_size,
|
|
253
|
+
}
|
rsplot/errors.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Expected failures with machine-readable codes for the stderr error line."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
# Codes printed as ``rsplot error <code>`` (see docs/result-schema.md).
|
|
8
|
+
ERROR_CODES = (
|
|
9
|
+
"invalid_argument",
|
|
10
|
+
"invalid_time",
|
|
11
|
+
"region_not_found",
|
|
12
|
+
"region_ambiguous",
|
|
13
|
+
"config_invalid",
|
|
14
|
+
"data_not_configured",
|
|
15
|
+
"data_not_found",
|
|
16
|
+
"no_valid_data",
|
|
17
|
+
"read_failed",
|
|
18
|
+
"write_failed",
|
|
19
|
+
"internal_error",
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class RsplotError(ValueError):
|
|
24
|
+
"""An expected input or data error.
|
|
25
|
+
|
|
26
|
+
Subclasses ``ValueError`` so commands that still catch ``ValueError``
|
|
27
|
+
keep printing the same message and exiting with status 1.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
code: str,
|
|
33
|
+
message: str,
|
|
34
|
+
*,
|
|
35
|
+
option: str | None = None,
|
|
36
|
+
details: dict[str, Any] | None = None,
|
|
37
|
+
) -> None:
|
|
38
|
+
if code not in ERROR_CODES:
|
|
39
|
+
raise ValueError(f"Unknown rsplot error code: {code}")
|
|
40
|
+
super().__init__(message)
|
|
41
|
+
self.code = code
|
|
42
|
+
self.option = option
|
|
43
|
+
self.details = details or {}
|
rsplot/fnr.py
CHANGED
|
@@ -24,14 +24,13 @@ dimensionless and directly comparable with the literature.
|
|
|
24
24
|
|
|
25
25
|
from __future__ import annotations
|
|
26
26
|
|
|
27
|
-
from dataclasses import dataclass
|
|
28
|
-
from typing import TYPE_CHECKING
|
|
27
|
+
from dataclasses import dataclass, field
|
|
28
|
+
from typing import TYPE_CHECKING, Any
|
|
29
29
|
|
|
30
30
|
import numpy as np
|
|
31
31
|
from rich.console import Console
|
|
32
32
|
|
|
33
33
|
from rsplot.geo.gridding import (
|
|
34
|
-
fill_nan_gaps,
|
|
35
34
|
mask_to_region,
|
|
36
35
|
region_grid_mask,
|
|
37
36
|
smooth_grid,
|
|
@@ -115,11 +114,9 @@ class FnrResult:
|
|
|
115
114
|
|
|
116
115
|
LON: np.ndarray
|
|
117
116
|
LAT: np.ndarray
|
|
118
|
-
fnr: np.ndarray # HCHO_mean / NO2_mean, masked
|
|
117
|
+
fnr: np.ndarray # HCHO_mean / NO2_mean, masked, unsmoothed
|
|
119
118
|
hcho_mean: np.ndarray # raw masked mean, 10^15 molec/cm²
|
|
120
119
|
no2_mean: np.ndarray # raw masked mean, 10^15 molec/cm²
|
|
121
|
-
hcho_mean_filled: np.ndarray # small-gap-filled diagnostic field
|
|
122
|
-
no2_mean_filled: np.ndarray # small-gap-filled diagnostic field
|
|
123
120
|
n_valid_hcho: np.ndarray # int count of valid days per pixel
|
|
124
121
|
n_valid_no2: np.ndarray # same for NO2
|
|
125
122
|
dates_requested: list[str]
|
|
@@ -130,6 +127,9 @@ class FnrResult:
|
|
|
130
127
|
n_min: int
|
|
131
128
|
no2_min_column: float
|
|
132
129
|
diagnostic_masks: dict[str, np.ndarray]
|
|
130
|
+
processing: str | None = None
|
|
131
|
+
daily_metadata_no2: dict[str, Any] = field(default_factory=dict)
|
|
132
|
+
daily_metadata_hcho: dict[str, Any] = field(default_factory=dict)
|
|
133
133
|
|
|
134
134
|
|
|
135
135
|
# ---------------------------------------------------------------------------
|
|
@@ -142,11 +142,11 @@ def compute_fnr(
|
|
|
142
142
|
res: float,
|
|
143
143
|
qa_threshold: float,
|
|
144
144
|
cloud_fraction_max: float = 0.5,
|
|
145
|
+
processing: str | None = None,
|
|
145
146
|
n_min: int,
|
|
146
147
|
raster_dir_no2: str,
|
|
147
148
|
raster_dir_hcho: str,
|
|
148
149
|
no2_min_column: float = NO2_MIN_COLUMN,
|
|
149
|
-
smooth_sigma: float | None = None,
|
|
150
150
|
console: Console | None = None,
|
|
151
151
|
) -> FnrResult:
|
|
152
152
|
"""Read NO2 + HCHO over a date window and compute per-pixel FNR.
|
|
@@ -154,7 +154,8 @@ def compute_fnr(
|
|
|
154
154
|
Each daily swath/grid is first binned onto the same target grid, then
|
|
155
155
|
the two time-stacks are averaged and divided. Pixels with fewer than
|
|
156
156
|
``n_min`` valid days in *either* product, or with mean NO2 below
|
|
157
|
-
``no2_min_column``, are masked to NaN.
|
|
157
|
+
``no2_min_column``, are masked to NaN. Nothing is filled or smoothed;
|
|
158
|
+
smoothing is display-only (:func:`smooth_fnr_for_display`).
|
|
158
159
|
"""
|
|
159
160
|
if console is None:
|
|
160
161
|
console = Console()
|
|
@@ -167,8 +168,15 @@ def compute_fnr(
|
|
|
167
168
|
region.extent[3] + buf,
|
|
168
169
|
)
|
|
169
170
|
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
if processing is None:
|
|
172
|
+
no2_reader = get_product_info("no2").reader_cls()
|
|
173
|
+
hcho_reader = get_product_info("hcho").reader_cls()
|
|
174
|
+
else:
|
|
175
|
+
no2_info = get_product_info("no2", processing=processing)
|
|
176
|
+
hcho_info = get_product_info("hcho", processing=processing)
|
|
177
|
+
no2_reader = no2_info.create_reader()
|
|
178
|
+
hcho_reader = hcho_info.create_reader()
|
|
179
|
+
processing = no2_info.processing
|
|
172
180
|
no2_reader.cloud_fraction_max = cloud_fraction_max
|
|
173
181
|
hcho_reader.cloud_fraction_max = cloud_fraction_max
|
|
174
182
|
|
|
@@ -213,9 +221,6 @@ def compute_fnr(
|
|
|
213
221
|
with np.errstate(divide="ignore", invalid="ignore"):
|
|
214
222
|
fnr[valid] = hcho_win.grid[valid] / no2_win.grid[valid]
|
|
215
223
|
|
|
216
|
-
# Keep raw mean fields for JSON statistics, and separately prepare
|
|
217
|
-
# small-gap-filled diagnostic fields for users who want a less holey
|
|
218
|
-
# view of the underlying columns. The FNR field itself is never filled.
|
|
219
224
|
region_mask = region_grid_mask(LON, LAT, region.geometry)
|
|
220
225
|
hcho_raw = mask_to_region(
|
|
221
226
|
LON,
|
|
@@ -231,50 +236,20 @@ def compute_fnr(
|
|
|
231
236
|
region.geometry,
|
|
232
237
|
region_mask=region_mask,
|
|
233
238
|
)
|
|
234
|
-
hcho_filled = fill_nan_gaps(LON, LAT, hcho_win.grid)
|
|
235
|
-
no2_filled = fill_nan_gaps(LON, LAT, no2_win.grid)
|
|
236
|
-
|
|
237
239
|
# --- Mask to region boundary ---
|
|
238
240
|
fnr = mask_to_region(
|
|
239
241
|
LON, LAT, fnr, region.geometry, region_mask=region_mask
|
|
240
242
|
)
|
|
241
|
-
hcho_filled = mask_to_region(
|
|
242
|
-
LON,
|
|
243
|
-
LAT,
|
|
244
|
-
hcho_filled,
|
|
245
|
-
region.geometry,
|
|
246
|
-
region_mask=region_mask,
|
|
247
|
-
)
|
|
248
|
-
no2_filled = mask_to_region(
|
|
249
|
-
LON,
|
|
250
|
-
LAT,
|
|
251
|
-
no2_filled,
|
|
252
|
-
region.geometry,
|
|
253
|
-
region_mask=region_mask,
|
|
254
|
-
)
|
|
255
|
-
|
|
256
|
-
if smooth_sigma is not None:
|
|
257
|
-
fnr_valid_mask = np.isfinite(fnr)
|
|
258
|
-
fnr = smooth_grid(
|
|
259
|
-
fnr,
|
|
260
|
-
region.geometry,
|
|
261
|
-
LON,
|
|
262
|
-
LAT,
|
|
263
|
-
sigma=smooth_sigma,
|
|
264
|
-
region_mask=region_mask,
|
|
265
|
-
)
|
|
266
|
-
# smooth_grid interpolates over NaNs before convolution. Restore the
|
|
267
|
-
# scientific validity mask so smoothing cannot create new FNR pixels.
|
|
268
|
-
fnr[~fnr_valid_mask] = np.nan
|
|
269
243
|
|
|
270
244
|
return FnrResult(
|
|
245
|
+
processing=processing,
|
|
246
|
+
daily_metadata_no2=no2_win.daily_metadata,
|
|
247
|
+
daily_metadata_hcho=hcho_win.daily_metadata,
|
|
271
248
|
LON=LON,
|
|
272
249
|
LAT=LAT,
|
|
273
250
|
fnr=fnr,
|
|
274
251
|
hcho_mean=hcho_raw,
|
|
275
252
|
no2_mean=no2_raw,
|
|
276
|
-
hcho_mean_filled=hcho_filled,
|
|
277
|
-
no2_mean_filled=no2_filled,
|
|
278
253
|
n_valid_hcho=hcho_win.n_valid,
|
|
279
254
|
n_valid_no2=no2_win.n_valid,
|
|
280
255
|
dates_requested=list(dates),
|
|
@@ -293,6 +268,23 @@ def compute_fnr(
|
|
|
293
268
|
)
|
|
294
269
|
|
|
295
270
|
|
|
271
|
+
def smooth_fnr_for_display(
|
|
272
|
+
fnr: np.ndarray,
|
|
273
|
+
region: RegionInfo,
|
|
274
|
+
LON: np.ndarray,
|
|
275
|
+
LAT: np.ndarray,
|
|
276
|
+
sigma: float | None,
|
|
277
|
+
) -> np.ndarray:
|
|
278
|
+
"""Smooth FNR for the image only, keeping its valid-cell mask."""
|
|
279
|
+
if sigma is None:
|
|
280
|
+
return fnr
|
|
281
|
+
smoothed = smooth_grid(fnr, region.geometry, LON, LAT, sigma=sigma)
|
|
282
|
+
# smooth_grid interpolates over NaNs before convolution. Restore the
|
|
283
|
+
# validity mask so smoothing cannot create new FNR pixels.
|
|
284
|
+
smoothed[~np.isfinite(fnr)] = np.nan
|
|
285
|
+
return smoothed
|
|
286
|
+
|
|
287
|
+
|
|
296
288
|
# ---------------------------------------------------------------------------
|
|
297
289
|
# Regime helpers (used by the plotter and the JSON builder)
|
|
298
290
|
# ---------------------------------------------------------------------------
|