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.
Files changed (71) hide show
  1. rsplot/atomic.py +36 -0
  2. rsplot/cli.py +282 -469
  3. rsplot/commands/common.py +113 -1
  4. rsplot/commands/fnr.py +389 -104
  5. rsplot/commands/forecast.py +24 -7
  6. rsplot/commands/meteo.py +499 -186
  7. rsplot/commands/overlay.py +292 -205
  8. rsplot/commands/radius.py +526 -0
  9. rsplot/commands/raster.py +479 -230
  10. rsplot/commands/reconstruct.py +27 -6
  11. rsplot/commands/sidecar.py +106 -0
  12. rsplot/commands/station.py +154 -42
  13. rsplot/commands/station_trend.py +259 -174
  14. rsplot/config.py +46 -16
  15. rsplot/data_files.py +253 -0
  16. rsplot/errors.py +43 -0
  17. rsplot/fnr.py +38 -46
  18. rsplot/geo/boundaries.py +317 -11
  19. rsplot/geo/footprints.py +205 -0
  20. rsplot/geo/processing.py +84 -5
  21. rsplot/geo/radius.py +205 -0
  22. rsplot/plotting/colormap_22.txt +256 -0
  23. rsplot/plotting/colormaps.py +24 -29
  24. rsplot/plotting/map_frame.py +203 -9
  25. rsplot/plotting/meteo.py +10 -3
  26. rsplot/plotting/overlay.py +36 -40
  27. rsplot/plotting/raster.py +15 -3
  28. rsplot/plotting/station.py +86 -33
  29. rsplot/plotting/station_focus.py +84 -0
  30. rsplot/plotting/station_trend.py +60 -47
  31. rsplot/plotting/styles.py +3 -5
  32. rsplot/readers/__init__.py +89 -7
  33. rsplot/readers/_tropomi.py +121 -3
  34. rsplot/readers/base.py +16 -1
  35. rsplot/readers/era5.py +110 -10
  36. rsplot/readers/era5_wind.py +3 -2
  37. rsplot/readers/gems.py +429 -0
  38. rsplot/readers/guokong.py +125 -39
  39. rsplot/readers/netcdf.py +32 -0
  40. rsplot/readers/tropomi_hcho.py +1 -1
  41. rsplot/readers/tropomi_no2.py +1 -1
  42. rsplot/readers/tropomi_nrti.py +116 -0
  43. rsplot/readers/tropomi_o3.py +1 -1
  44. rsplot/readers/tropomi_o3pr.py +1 -1
  45. rsplot/result_builders/__init__.py +0 -14
  46. rsplot/result_builders/common.py +84 -0
  47. rsplot/result_builders/envelope.py +236 -0
  48. rsplot/result_builders/fnr.py +47 -131
  49. rsplot/result_builders/forecast.py +7 -0
  50. rsplot/result_builders/provenance.py +59 -0
  51. rsplot/result_builders/reconstruct.py +7 -0
  52. rsplot/result_builders/satellite.py +240 -0
  53. rsplot/result_builders/series_layer.py +289 -0
  54. rsplot/result_builders/station.py +23 -0
  55. rsplot/result_builders/station_layer.py +326 -0
  56. rsplot/results.py +0 -12
  57. rsplot/schemas/result.schema.json +566 -0
  58. rsplot/temporal.py +146 -16
  59. rsplot-0.3.2.dev37.dist-info/METADATA +996 -0
  60. rsplot-0.3.2.dev37.dist-info/RECORD +76 -0
  61. {rsplot-0.3.1.dev3.dist-info → rsplot-0.3.2.dev37.dist-info}/WHEEL +1 -1
  62. rsplot/commands/recent.py +0 -164
  63. rsplot/recent.py +0 -404
  64. rsplot/result_builders/meteo.py +0 -171
  65. rsplot/result_builders/overlay.py +0 -75
  66. rsplot/result_builders/raster.py +0 -72
  67. rsplot/result_builders/station_trend.py +0 -229
  68. rsplot-0.3.1.dev3.dist-info/METADATA +0 -477
  69. rsplot-0.3.1.dev3.dist-info/RECORD +0 -64
  70. {rsplot-0.3.1.dev3.dist-info → rsplot-0.3.2.dev37.dist-info}/entry_points.txt +0 -0
  71. {rsplot-0.3.1.dev3.dist-info → rsplot-0.3.2.dev37.dist-info}/licenses/LICENSE +0 -0
rsplot/geo/processing.py CHANGED
@@ -30,6 +30,8 @@ class PreparedGrid:
30
30
  coverage_pct: float
31
31
  n_valid_region: int
32
32
  total_region_pixels: int
33
+ # Prepared source before administrative center masking, for display only.
34
+ unmasked_values: np.ndarray | None = None
33
35
 
34
36
 
35
37
  def buffered_extent(
@@ -58,6 +60,7 @@ def prepare_existing_grid(
58
60
  prepared = (
59
61
  fill_nan_gaps(lon, lat, values) if fill_gaps else np.asarray(values)
60
62
  )
63
+ unmasked_values = prepared
61
64
  region_mask = region_grid_mask(lon, lat, geometry)
62
65
  prepared = mask_to_region(
63
66
  lon,
@@ -89,6 +92,7 @@ def prepare_existing_grid(
89
92
  coverage_pct=coverage,
90
93
  n_valid_region=n_valid,
91
94
  total_region_pixels=total,
95
+ unmasked_values=unmasked_values,
92
96
  )
93
97
 
94
98
 
@@ -99,10 +103,8 @@ def prepare_swath_grid(
99
103
  read_extent: tuple[float, float, float, float],
100
104
  resolution: float,
101
105
  geometry: BaseGeometry,
102
- *,
103
- smooth_sigma: float | None = None,
104
106
  ) -> PreparedGrid:
105
- """Grid a swath and apply the standard raster preparation sequence."""
107
+ """Grid a swath into observed cells only; filling is display-only."""
106
108
  lon, lat, raw = grid_data(
107
109
  swath_lon,
108
110
  swath_lat,
@@ -115,6 +117,83 @@ def prepare_swath_grid(
115
117
  lat,
116
118
  raw,
117
119
  geometry,
118
- fill_gaps=True,
119
- smooth_sigma=smooth_sigma,
120
+ fill_gaps=False,
120
121
  )
122
+
123
+
124
+ def region_cell_mask(
125
+ lon: np.ndarray,
126
+ lat: np.ndarray,
127
+ geometry: BaseGeometry,
128
+ ) -> np.ndarray:
129
+ """Select rectilinear cells touching the region, including exterior centers.
130
+
131
+ Edges match pcolormesh's midpoint convention. A singleton axis has zero
132
+ width, matching the renderer when only one center is supplied.
133
+ """
134
+ from shapely import box, intersects
135
+
136
+ if lon.ndim != 2 or lat.shape != lon.shape:
137
+ raise ValueError("显示网格经纬度必须为同形状二维数组。")
138
+ if not (np.allclose(lon, lon[0:1, :]) and np.allclose(lat, lat[:, 0:1])):
139
+ raise ValueError("行政边界显示裁剪需要规则经纬度网格。")
140
+
141
+ def edges(centers: np.ndarray) -> np.ndarray:
142
+ if centers.size == 1:
143
+ return np.repeat(centers, 2)
144
+ half_steps = np.diff(centers) / 2
145
+ return np.concatenate(
146
+ (
147
+ centers[:1] - half_steps[:1],
148
+ centers[:-1] + half_steps,
149
+ centers[-1:] + half_steps[-1:],
150
+ )
151
+ )
152
+
153
+ x = edges(lon[0])
154
+ y = edges(lat[:, 0])
155
+ cells = box(x[:-1][None, :], y[:-1, None], x[1:][None, :], y[1:, None])
156
+ return intersects(geometry, cells)
157
+
158
+
159
+ def prepare_display_grid(
160
+ lon: np.ndarray,
161
+ lat: np.ndarray,
162
+ values: np.ndarray,
163
+ geometry: BaseGeometry,
164
+ *,
165
+ smooth_sigma: float | None = None,
166
+ ) -> np.ndarray:
167
+ """Keep valid intersecting cells; exact geometry clipping is render-only.
168
+
169
+ Input must precede the administrative center mask. Smoothing can use the
170
+ surrounding buffer but cannot create newly valid cells. Statistics must
171
+ continue to use PreparedGrid.values, never this display array.
172
+ """
173
+ visible = region_cell_mask(lon, lat, geometry)
174
+ valid = np.isfinite(values)
175
+ display = np.asarray(values)
176
+ if smooth_sigma is not None and smooth_sigma > 0:
177
+ # Normalized convolution avoids NaN-gap warnings on sparse scans.
178
+ # This display-only operation does not change legacy statistics.
179
+ from scipy.ndimage import gaussian_filter
180
+
181
+ numerator = gaussian_filter(
182
+ np.where(valid, values, 0.0),
183
+ smooth_sigma,
184
+ mode="constant",
185
+ cval=0.0,
186
+ )
187
+ denominator = gaussian_filter(
188
+ valid.astype(float),
189
+ smooth_sigma,
190
+ mode="constant",
191
+ cval=0.0,
192
+ )
193
+ display = np.divide(
194
+ numerator,
195
+ denominator,
196
+ out=np.full(values.shape, np.nan),
197
+ where=denominator > 0,
198
+ )
199
+ return np.where(visible & valid, display, np.nan)
rsplot/geo/radius.py ADDED
@@ -0,0 +1,205 @@
1
+ """Geodesic station neighborhoods with independent administrative context."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ from dataclasses import replace
7
+
8
+ import geopandas as gpd
9
+ import numpy as np
10
+ import pandas as pd
11
+ from pyproj import Geod
12
+ from shapely.geometry import Point, Polygon, box
13
+
14
+ from rsplot.config import LEVEL_DEFAULTS, AppConfig
15
+ from rsplot.geo.boundaries import (
16
+ RegionInfo,
17
+ _city_subdivisions,
18
+ load_city_boundaries,
19
+ load_county_boundaries,
20
+ )
21
+
22
+ GEOD = Geod(ellps="WGS84")
23
+
24
+
25
+ def geodesic_square(lon: float, lat: float, km: float) -> Polygon:
26
+ """Build a north-oriented square in station-centered WGS84 AEQD meters."""
27
+ if not math.isfinite(km) or km <= 0:
28
+ raise ValueError("--km 必须是大于 0 的有限数字。")
29
+ if not (np.isfinite(lon) and np.isfinite(lat)):
30
+ raise ValueError("中心站坐标不是有效数字。")
31
+ if not (-180 <= lon <= 180 and -90 < lat < 90):
32
+ raise ValueError("中心站坐标超出有效经纬度范围。")
33
+ half_width = km * 1000
34
+ outline = box(-half_width, -half_width, half_width, half_width)
35
+ xy = np.asarray(outline.segmentize(half_width / 32).exterior.coords)
36
+ azimuth = np.degrees(np.arctan2(xy[:, 0], xy[:, 1]))
37
+ x, y, _ = GEOD.fwd(
38
+ np.full(len(xy), lon),
39
+ np.full(len(xy), lat),
40
+ azimuth,
41
+ np.hypot(xy[:, 0], xy[:, 1]),
42
+ )
43
+ square = Polygon(zip(x, y, strict=True))
44
+ # The existing rectilinear plotting pipeline cannot wrap the dateline.
45
+ pole_distance = min(
46
+ GEOD.inv(lon, lat, lon, 90)[2],
47
+ GEOD.inv(lon, lat, lon, -90)[2],
48
+ )
49
+ if (
50
+ km * 1000 * math.sqrt(2) >= pole_distance
51
+ or np.ptp(x) > 180
52
+ or not square.is_valid
53
+ ):
54
+ raise ValueError("正方形范围跨越极点或日期变更线,当前地图不支持。")
55
+ return square
56
+
57
+
58
+ def station_distances(
59
+ lon: float,
60
+ lat: float,
61
+ station_lon: np.ndarray,
62
+ station_lat: np.ndarray,
63
+ ) -> np.ndarray:
64
+ """Return WGS84 distances in km; invalid coordinates remain NaN."""
65
+ valid = (
66
+ np.isfinite(station_lon)
67
+ & np.isfinite(station_lat)
68
+ & (np.abs(station_lon) <= 180)
69
+ & (np.abs(station_lat) <= 90)
70
+ )
71
+ distances = np.full(station_lon.shape, np.nan)
72
+ _, _, meters = GEOD.inv(
73
+ np.full(valid.sum(), lon),
74
+ np.full(valid.sum(), lat),
75
+ station_lon[valid],
76
+ station_lat[valid],
77
+ )
78
+ distances[valid] = meters / 1000
79
+ return distances
80
+
81
+
82
+ def station_offsets_km(
83
+ lon: float,
84
+ lat: float,
85
+ station_lon: np.ndarray,
86
+ station_lat: np.ndarray,
87
+ ) -> tuple[np.ndarray, np.ndarray]:
88
+ """East and north offsets from the centre, in km, along the geodesic."""
89
+ azimuth, _, meters = GEOD.inv(
90
+ np.full(station_lon.shape, lon),
91
+ np.full(station_lat.shape, lat),
92
+ station_lon,
93
+ station_lat,
94
+ )
95
+ angle = np.radians(azimuth)
96
+ return meters * np.sin(angle) / 1000, meters * np.cos(angle) / 1000
97
+
98
+
99
+ def station_square_mask(
100
+ lon: float,
101
+ lat: float,
102
+ km: float,
103
+ station_lon: np.ndarray,
104
+ station_lat: np.ndarray,
105
+ ) -> np.ndarray:
106
+ """Select the square including its edges, rather than a radial disk."""
107
+ x_km, y_km = station_offsets_km(lon, lat, station_lon, station_lat)
108
+ x, y = x_km * 1000, y_km * 1000
109
+ return (
110
+ np.isfinite(x)
111
+ & np.isfinite(y)
112
+ & (np.abs(station_lon) <= 180)
113
+ & (np.abs(station_lat) <= 90)
114
+ & (np.abs(x) <= km * 1000 + 1e-6)
115
+ & (np.abs(y) <= km * 1000 + 1e-6)
116
+ )
117
+
118
+
119
+ def resolve_radius_region(
120
+ station_id: str,
121
+ lon: float,
122
+ lat: float,
123
+ km: float,
124
+ cfg: AppConfig,
125
+ ) -> RegionInfo:
126
+ """Resolve visible city and county/township context around a square."""
127
+ square = geodesic_square(lon, lat, km)
128
+ west, south, east, north = square.bounds
129
+ view = square
130
+ if not cfg.geojson_dir:
131
+ raise ValueError("请配置行政边界目录 geojson_dir。")
132
+ cities = load_city_boundaries(cfg.geojson_dir).to_crs("EPSG:4326")
133
+ counties = load_county_boundaries(cfg.geojson_dir).to_crs("EPSG:4326")
134
+ cities = cities[cities.geometry.intersects(view)].copy()
135
+ layers = []
136
+ for _, city in cities.iterrows():
137
+ override = _city_subdivisions(
138
+ city["name"],
139
+ city.geometry,
140
+ cities.crs,
141
+ cfg,
142
+ )
143
+ if override is None:
144
+ layer = counties[
145
+ counties.geometry.intersects(city.geometry)
146
+ & counties.geometry.intersects(view)
147
+ ].copy()
148
+ layer["administrative_level"] = "county"
149
+ else:
150
+ layer, level = override
151
+ layer = layer[layer.geometry.intersects(view)].copy()
152
+ layer["administrative_level"] = level
153
+ # Clip contextual units to their city, avoiding border-touch neighbors.
154
+ layer.geometry = layer.geometry.intersection(city.geometry)
155
+ layer = layer[
156
+ (~layer.geometry.is_empty)
157
+ & (layer.geometry.to_crs("EPSG:6933").area > 0)
158
+ ]
159
+ layer["city"] = city["name"]
160
+ layers.append(layer)
161
+ subdivisions = (
162
+ gpd.GeoDataFrame(pd.concat(layers, ignore_index=True), crs=cities.crs)
163
+ if layers
164
+ else None
165
+ )
166
+ return RegionInfo(
167
+ name=f"{station_id} 上下左右各 {km:g} km",
168
+ level="county",
169
+ geometry=square,
170
+ extent=(west, east, south, north),
171
+ params=replace(LEVEL_DEFAULTS["county"], pad=0, basemap=False),
172
+ main_boundary_gdf=cities,
173
+ sub_boundary_gdf=subdivisions,
174
+ geometry_kind="station_radius",
175
+ projection_center=(lon, lat),
176
+ )
177
+
178
+
179
+ def administrative_context(region: RegionInfo, lon: float, lat: float) -> dict:
180
+ """Describe the center's affiliations and the visible administrative units."""
181
+ point = Point(lon, lat)
182
+ cities = region.main_boundary_gdf
183
+ subdivisions = region.sub_boundary_gdf
184
+ visible_cities = [] if cities is None else cities["name"].tolist()
185
+ center_cities = (
186
+ []
187
+ if cities is None
188
+ else cities[cities.geometry.covers(point)]["name"].tolist()
189
+ )
190
+ units = []
191
+ if subdivisions is not None:
192
+ for _, row in subdivisions.iterrows():
193
+ units.append(
194
+ {
195
+ "name": row["name"],
196
+ "city": row["city"],
197
+ "level": row["administrative_level"],
198
+ "contains_center": bool(row.geometry.covers(point)),
199
+ }
200
+ )
201
+ return {
202
+ "center_cities": center_cities,
203
+ "visible_cities": visible_cities,
204
+ "subdivisions": units,
205
+ }
@@ -0,0 +1,256 @@
1
+ 1.00000 0.992157 0.992157
2
+ 1.00000 0.992157 0.992157
3
+ 1.00000 0.988235 0.988235
4
+ 1.00000 0.984314 0.984314
5
+ 1.00000 0.980392 0.980392
6
+ 1.00000 0.976471 0.976471
7
+ 1.00000 0.972549 0.972549
8
+ 1.00000 0.968627 0.972549
9
+ 1.00000 0.964706 0.968627
10
+ 1.00000 0.960784 0.968627
11
+ 1.00000 0.956863 0.964706
12
+ 1.00000 0.952941 0.964706
13
+ 1.00000 0.949020 0.960784
14
+ 1.00000 0.945098 0.960784
15
+ 1.00000 0.941176 0.956863
16
+ 1.00000 0.937255 0.956863
17
+ 1.00000 0.933333 0.956863
18
+ 1.00000 0.929412 0.956863
19
+ 1.00000 0.925490 0.952941
20
+ 1.00000 0.921569 0.952941
21
+ 1.00000 0.917647 0.952941
22
+ 1.00000 0.913725 0.952941
23
+ 1.00000 0.909804 0.952941
24
+ 1.00000 0.905882 0.952941
25
+ 1.00000 0.901961 0.952941
26
+ 1.00000 0.898039 0.952941
27
+ 1.00000 0.894118 0.956863
28
+ 1.00000 0.890196 0.956863
29
+ 1.00000 0.886275 0.956863
30
+ 1.00000 0.882353 0.956863
31
+ 1.00000 0.878431 0.960784
32
+ 1.00000 0.874510 0.960784
33
+ 1.00000 0.870588 0.964706
34
+ 1.00000 0.866667 0.964706
35
+ 1.00000 0.862745 0.968627
36
+ 1.00000 0.858824 0.968627
37
+ 1.00000 0.854902 0.972549
38
+ 1.00000 0.850980 0.976471
39
+ 1.00000 0.847059 0.980392
40
+ 1.00000 0.843137 0.980392
41
+ 1.00000 0.839216 0.984314
42
+ 1.00000 0.835294 0.988235
43
+ 1.00000 0.831373 0.992157
44
+ 1.00000 0.827451 0.996078
45
+ 0.996078 0.823529 1.00000
46
+ 0.992157 0.819608 1.00000
47
+ 0.988235 0.815686 1.00000
48
+ 0.984314 0.811765 1.00000
49
+ 0.976471 0.807843 1.00000
50
+ 0.972549 0.803922 1.00000
51
+ 0.968627 0.800000 1.00000
52
+ 0.964706 0.796078 1.00000
53
+ 0.956863 0.792157 1.00000
54
+ 0.952941 0.788235 1.00000
55
+ 0.945098 0.784314 1.00000
56
+ 0.941176 0.780392 1.00000
57
+ 0.933333 0.776471 1.00000
58
+ 0.929412 0.772549 1.00000
59
+ 0.921569 0.768627 1.00000
60
+ 0.913725 0.764706 1.00000
61
+ 0.905882 0.760784 1.00000
62
+ 0.901961 0.756863 1.00000
63
+ 0.894118 0.752941 1.00000
64
+ 0.886275 0.749020 1.00000
65
+ 0.878431 0.745098 1.00000
66
+ 0.870588 0.741176 1.00000
67
+ 0.862745 0.737255 1.00000
68
+ 0.854902 0.733333 1.00000
69
+ 0.847059 0.729412 1.00000
70
+ 0.835294 0.725490 1.00000
71
+ 0.827451 0.721569 1.00000
72
+ 0.819608 0.717647 1.00000
73
+ 0.811765 0.713726 1.00000
74
+ 0.800000 0.709804 1.00000
75
+ 0.792157 0.705882 1.00000
76
+ 0.780392 0.701961 1.00000
77
+ 0.772549 0.698039 1.00000
78
+ 0.760784 0.694118 1.00000
79
+ 0.752941 0.690196 1.00000
80
+ 0.741176 0.686275 1.00000
81
+ 0.733333 0.682353 1.00000
82
+ 0.721569 0.678431 1.00000
83
+ 0.709804 0.674510 1.00000
84
+ 0.698039 0.670588 1.00000
85
+ 0.686275 0.666667 1.00000
86
+ 0.674510 0.662745 1.00000
87
+ 0.666667 0.662745 1.00000
88
+ 0.658824 0.662745 1.00000
89
+ 0.654902 0.666667 1.00000
90
+ 0.650980 0.670588 1.00000
91
+ 0.647059 0.674510 1.00000
92
+ 0.643137 0.678431 1.00000
93
+ 0.639216 0.682353 1.00000
94
+ 0.635294 0.690196 1.00000
95
+ 0.631373 0.694118 1.00000
96
+ 0.627451 0.698039 1.00000
97
+ 0.623529 0.705882 1.00000
98
+ 0.619608 0.709804 1.00000
99
+ 0.615686 0.717647 1.00000
100
+ 0.611765 0.721569 1.00000
101
+ 0.607843 0.729412 1.00000
102
+ 0.603922 0.737255 1.00000
103
+ 0.600000 0.741176 1.00000
104
+ 0.596078 0.749020 1.00000
105
+ 0.592157 0.756863 1.00000
106
+ 0.588235 0.764706 1.00000
107
+ 0.584314 0.772549 1.00000
108
+ 0.580392 0.780392 1.00000
109
+ 0.576471 0.788235 1.00000
110
+ 0.572549 0.796078 1.00000
111
+ 0.568627 0.803922 1.00000
112
+ 0.564706 0.811765 1.00000
113
+ 0.560784 0.819608 1.00000
114
+ 0.556863 0.827451 1.00000
115
+ 0.552941 0.839216 1.00000
116
+ 0.549020 0.847059 1.00000
117
+ 0.545098 0.854902 1.00000
118
+ 0.541176 0.866667 1.00000
119
+ 0.537255 0.874510 1.00000
120
+ 0.533333 0.886275 1.00000
121
+ 0.529412 0.894118 1.00000
122
+ 0.525490 0.905882 1.00000
123
+ 0.521569 0.913725 1.00000
124
+ 0.517647 0.925490 1.00000
125
+ 0.513726 0.937255 1.00000
126
+ 0.509804 0.945098 1.00000
127
+ 0.505882 0.956863 1.00000
128
+ 0.501961 0.968627 1.00000
129
+ 0.498039 0.980392 1.00000
130
+ 0.494118 0.992157 1.00000
131
+ 0.490196 1.00000 0.992157
132
+ 0.486275 1.00000 0.980392
133
+ 0.482353 1.00000 0.968627
134
+ 0.478431 1.00000 0.956863
135
+ 0.474510 1.00000 0.945098
136
+ 0.470588 1.00000 0.929412
137
+ 0.466667 1.00000 0.917647
138
+ 0.462745 1.00000 0.905882
139
+ 0.458824 1.00000 0.890196
140
+ 0.454902 1.00000 0.878431
141
+ 0.450980 1.00000 0.862745
142
+ 0.447059 1.00000 0.850980
143
+ 0.443137 1.00000 0.835294
144
+ 0.439216 1.00000 0.823529
145
+ 0.435294 1.00000 0.807843
146
+ 0.431373 1.00000 0.796078
147
+ 0.427451 1.00000 0.780392
148
+ 0.423529 1.00000 0.764706
149
+ 0.419608 1.00000 0.749020
150
+ 0.415686 1.00000 0.733333
151
+ 0.411765 1.00000 0.717647
152
+ 0.407843 1.00000 0.701961
153
+ 0.403922 1.00000 0.686275
154
+ 0.400000 1.00000 0.670588
155
+ 0.396078 1.00000 0.654902
156
+ 0.392157 1.00000 0.639216
157
+ 0.388235 1.00000 0.623529
158
+ 0.384314 1.00000 0.607843
159
+ 0.380392 1.00000 0.588235
160
+ 0.376471 1.00000 0.572549
161
+ 0.372549 1.00000 0.556863
162
+ 0.368627 1.00000 0.537255
163
+ 0.364706 1.00000 0.521569
164
+ 0.360784 1.00000 0.501961
165
+ 0.356863 1.00000 0.486275
166
+ 0.352941 1.00000 0.466667
167
+ 0.349020 1.00000 0.447059
168
+ 0.345098 1.00000 0.431373
169
+ 0.341176 1.00000 0.411765
170
+ 0.337255 1.00000 0.392157
171
+ 0.333333 1.00000 0.372549
172
+ 0.333333 1.00000 0.352941
173
+ 0.329412 1.00000 0.337255
174
+ 0.329412 1.00000 0.325490
175
+ 0.345098 1.00000 0.321569
176
+ 0.356863 1.00000 0.317647
177
+ 0.368627 1.00000 0.313726
178
+ 0.380392 1.00000 0.309804
179
+ 0.392157 1.00000 0.305882
180
+ 0.403922 1.00000 0.301961
181
+ 0.419608 1.00000 0.298039
182
+ 0.431373 1.00000 0.294118
183
+ 0.447059 1.00000 0.290196
184
+ 0.458824 1.00000 0.286275
185
+ 0.474510 1.00000 0.282353
186
+ 0.486275 1.00000 0.278431
187
+ 0.501961 1.00000 0.274510
188
+ 0.513726 1.00000 0.270588
189
+ 0.529412 1.00000 0.266667
190
+ 0.545098 1.00000 0.262745
191
+ 0.560784 1.00000 0.258824
192
+ 0.572549 1.00000 0.254902
193
+ 0.588235 1.00000 0.250980
194
+ 0.603922 1.00000 0.247059
195
+ 0.619608 1.00000 0.243137
196
+ 0.635294 1.00000 0.239216
197
+ 0.650980 1.00000 0.235294
198
+ 0.666667 1.00000 0.231373
199
+ 0.682353 1.00000 0.227451
200
+ 0.701961 1.00000 0.223529
201
+ 0.717647 1.00000 0.219608
202
+ 0.733333 1.00000 0.215686
203
+ 0.749020 1.00000 0.211765
204
+ 0.768627 1.00000 0.207843
205
+ 0.784314 1.00000 0.203922
206
+ 0.803922 1.00000 0.200000
207
+ 0.819608 1.00000 0.196078
208
+ 0.839216 1.00000 0.192157
209
+ 0.854902 1.00000 0.188235
210
+ 0.874510 1.00000 0.184314
211
+ 0.894118 1.00000 0.180392
212
+ 0.913725 1.00000 0.176471
213
+ 0.929412 1.00000 0.172549
214
+ 0.949020 1.00000 0.168627
215
+ 0.968627 1.00000 0.164706
216
+ 0.988235 1.00000 0.160784
217
+ 1.00000 0.988235 0.156863
218
+ 1.00000 0.968627 0.152941
219
+ 1.00000 0.949020 0.149020
220
+ 1.00000 0.929412 0.145098
221
+ 1.00000 0.909804 0.141176
222
+ 1.00000 0.886275 0.137255
223
+ 1.00000 0.866667 0.133333
224
+ 1.00000 0.847059 0.129412
225
+ 1.00000 0.827451 0.125490
226
+ 1.00000 0.803922 0.121569
227
+ 1.00000 0.784314 0.117647
228
+ 1.00000 0.760784 0.113725
229
+ 1.00000 0.741176 0.109804
230
+ 1.00000 0.717647 0.105882
231
+ 1.00000 0.698039 0.101961
232
+ 1.00000 0.674510 0.0980392
233
+ 1.00000 0.650980 0.0941176
234
+ 1.00000 0.627451 0.0901961
235
+ 1.00000 0.607843 0.0862745
236
+ 1.00000 0.584314 0.0823529
237
+ 1.00000 0.560784 0.0784314
238
+ 1.00000 0.537255 0.0745098
239
+ 1.00000 0.513726 0.0705882
240
+ 1.00000 0.490196 0.0666667
241
+ 1.00000 0.466667 0.0627451
242
+ 1.00000 0.443137 0.0588235
243
+ 1.00000 0.419608 0.0549020
244
+ 1.00000 0.392157 0.0509804
245
+ 1.00000 0.368627 0.0470588
246
+ 1.00000 0.345098 0.0431373
247
+ 1.00000 0.317647 0.0509804
248
+ 1.00000 0.294118 0.0352941
249
+ 1.00000 0.270588 0.0313726
250
+ 1.00000 0.243137 0.0274510
251
+ 1.00000 0.219608 0.0235294
252
+ 1.00000 0.192157 0.0196078
253
+ 1.00000 0.164706 0.0156863
254
+ 1.00000 0.141176 0.0117647
255
+ 1.00000 0.113725 0.00784314
256
+ 1.00000 0.113725 0.00784314
@@ -2,7 +2,6 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import os
6
5
  from pathlib import Path
7
6
 
8
7
  import matplotlib as mpl
@@ -10,12 +9,31 @@ import matplotlib.colors as mcolors
10
9
  import numpy as np
11
10
 
12
11
  HCHO_CMAP = "rsplot_hcho"
12
+ NO2_CMAP = "rsplot_no2"
13
+ COLORMAP_22 = "rsplot_colormap_22"
13
14
  STATION_CONCENTRATION_CMAP = "rsplot_station_concentration"
14
15
 
15
16
 
16
- def register_rsplot_colormaps(hcho_cmap_file: str | None = None) -> None:
17
+ def register_rsplot_colormaps() -> None:
17
18
  """Register custom colormaps used by rsplot plots."""
18
- _register(_build_hcho_cmap(hcho_cmap_file))
19
+ _register(_build_colormap_22(COLORMAP_22))
20
+ _register(_build_colormap_22(HCHO_CMAP))
21
+ _register(
22
+ mcolors.LinearSegmentedColormap.from_list(
23
+ NO2_CMAP,
24
+ [
25
+ "#C2C8E1",
26
+ "#9BA9DC",
27
+ "#4C9DF4",
28
+ "#86D1F9",
29
+ "#A7E5EF",
30
+ "#FEFC59",
31
+ "#FD7822",
32
+ "#FC131F",
33
+ "#A3090E",
34
+ ],
35
+ )
36
+ )
19
37
  _register(
20
38
  mcolors.LinearSegmentedColormap.from_list(
21
39
  STATION_CONCENTRATION_CMAP,
@@ -34,32 +52,9 @@ def register_rsplot_colormaps(hcho_cmap_file: str | None = None) -> None:
34
52
  )
35
53
 
36
54
 
37
- def _build_hcho_cmap(hcho_cmap_file: str | None) -> mcolors.Colormap:
38
- if hcho_cmap_file:
39
- cmap_file = Path(os.path.expandvars(hcho_cmap_file)).expanduser()
40
- if not cmap_file.exists():
41
- raise FileNotFoundError(
42
- f"Configured HCHO colormap file does not exist: {cmap_file}"
43
- )
44
- data = np.loadtxt(cmap_file)
45
- if data.shape != (256, 3):
46
- raise ValueError(
47
- f"{cmap_file} must contain a 256x3 RGB colormap table, "
48
- f"got shape {data.shape}"
49
- )
50
- cmap = mcolors.ListedColormap(data, name=HCHO_CMAP)
51
- else:
52
- cmap = mcolors.LinearSegmentedColormap.from_list(
53
- HCHO_CMAP,
54
- [
55
- "#ffffff",
56
- "#fff7bc",
57
- "#fec44f",
58
- "#fd8d3c",
59
- "#e31a1c",
60
- "#800026",
61
- ],
62
- )
55
+ def _build_colormap_22(name: str) -> mcolors.Colormap:
56
+ cmap_file = Path(__file__).with_name("colormap_22.txt")
57
+ cmap = mcolors.ListedColormap(np.loadtxt(cmap_file), name=name)
63
58
  cmap.set_under("w")
64
59
  return cmap
65
60