EmmaScharfmann HF Staff commited on
Commit
b2b8a15
·
verified ·
1 Parent(s): 3346207

Quantitative difference map: purple-grey-orange with a label bar

Browse files
Files changed (4) hide show
  1. ABOUT.md +3 -4
  2. app.py +11 -6
  3. maps.py +23 -6
  4. rainmaps.js +12 -0
ABOUT.md CHANGED
@@ -8,10 +8,9 @@
8
  - **PARDIG is not a ground truth**, but an experimental dataset. It tends to underestimate snow and drizzle, is less accurate over high mountains and
9
  near the poles, and caps precipitation rates at 75 mm/h.
10
  - **PARDIG is the first global, high-resolution precipitation dataset** with realistic rain structures, which makes it a much better reference than ERA5 to evaluate precipitation predictions.
11
- - **Who sees rain?** compares the two cell by cell, hour by hour, after averaging PARDIG onto ERA5's 28 km cells
12
- (area-conservative). A cell rains when it gets at least 0.1 mm in the hour. Grey: both rain. Purple: only ERA5.
13
- Orange: only PARDIG. Dark orange: PARDIG has heavy rain (10 mm or more) where ERA5 has at most light rain
14
- (under 2.5 mm). Clear: both dry.
15
  - Times are UTC. Each view plays 48 hours from the chosen day. Maps cover 2026 from 1 January, a few days behind
16
  real time.
17
 
 
8
  - **PARDIG is not a ground truth**, but an experimental dataset. It tends to underestimate snow and drizzle, is less accurate over high mountains and
9
  near the poles, and caps precipitation rates at 75 mm/h.
10
  - **PARDIG is the first global, high-resolution precipitation dataset** with realistic rain structures, which makes it a much better reference than ERA5 to evaluate precipitation predictions.
11
+ - **ERA5 minus PARDIG** compares the two cell by cell, hour by hour, after averaging PARDIG onto ERA5's 28 km cells
12
+ (area-conservative). Purple: ERA5 has more rain; orange: less; grey: within 0.2 mm. Classes change at 0.2, 1, 3 and
13
+ 10 mm. Cells where both have less than 0.1 mm are left clear.
 
14
  - Times are UTC. Each view plays 48 hours from the chosen day. Maps cover 2026 from 1 January, a few days behind
15
  real time.
16
 
app.py CHANGED
@@ -43,16 +43,14 @@ INTRO = """
43
  PROBLEM = """
44
  <div class="story">
45
  <section>
46
- <p><b>There is no ground truth for rain</b>: To evaluate a prediction, it needs to be compared with a ground truth. As we do not record rain at every point of the planet, there is no perfect ground truth, only references, which have their own errors. Observations (such as rain gauges) are accurate, but sparse and only measure a single point. Radars have a better spatial coverage but are not accurate in mountains and heavy storms. Reanalyses (such as ERA5 or CERRA) and satellite-based estimates (such as IMERG or PARDIG) are global, but they estimate the rain from a physics model or from satellite measurements, and therefore have their own biases.</p>
47
- </section>
48
- </div>
49
  """
50
 
51
  STORY = """
52
  <div class="story">
53
  <section>
54
  <div class="kicker"><span class="tag tag-map">Left map</span></div>
55
- <h3>ERA5: the most used reference</h3>
56
  <p>ERA5 is a reanalysis produced by the European Centre for Medium-Range Weather Forecasts (ECMWF). It
57
  reconstructs the past weather hour by hour since 1940, by combining a physics model of the atmosphere with
58
  observations from satellites, weather stations and weather balloons. It is the dataset most AI weather models
@@ -62,7 +60,7 @@ STORY = """
62
  </section>
63
  <section>
64
  <div class="kicker"><span class="tag tag-map">Middle map</span></div>
65
- <h3>PARDIG: a new satellite-based reference</h3>
66
  <p>PARDIG (Precipitation AI Reanalysis, Densely Inferred GPM) is a precipitation dataset recently released by
67
  Google DeepMind and Google Research. It estimates the rain over the whole planet every 15 minutes, on a 10 km
68
  grid. An AI model converts geostationary satellite images and weather
@@ -86,7 +84,7 @@ COMPONENT_HTML = """
86
  <div class="rm-map" data-map="pardig"></div>
87
  </div>
88
  <div class="rm-panel">
89
- <div class="rm-title">Who sees rain? Both on the 28 km grid</div>
90
  <div class="rm-map" data-map="diff"></div>
91
  </div>
92
  <div class="rm-legend rm-legend-rain" data-for="rain"></div>
@@ -126,6 +124,13 @@ COMPONENT_CSS = """
126
  .rm-leg-swatch { height: 14px; }
127
  .rm-leg-name { font-size: 13px; font-weight: 600; margin-top: 4px; color: var(--body-text-color); }
128
  .rm-leg-text { font-size: 11px; color: var(--body-text-color-subdued); white-space: nowrap; }
 
 
 
 
 
 
 
129
  .rm-chips { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-top: 18px; }
130
  .rm-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
131
  .rm-chip-note { font-weight: 400; color: var(--body-text-color-subdued); }
 
43
  PROBLEM = """
44
  <div class="story">
45
  <section>
46
+ <p><b>There is no ground truth for rain.</b> Evaluating a prediction requires comparing it to a reference. But since rain is not measured everywhere on the planet, the references we have are not perfect. Rain gauges are accurate but sparse, and each one measures only a single point. Radars cover larger areas but struggle over mountains and in heavy storms. Reanalyses (such as ERA5 or CERRA) and satellite-based estimates (such as IMERG or PARDIG) offer much wider coverage, but they infer rain from a physics model or from satellite measurements, so they come with their own biases.</p></div>
 
 
47
  """
48
 
49
  STORY = """
50
  <div class="story">
51
  <section>
52
  <div class="kicker"><span class="tag tag-map">Left map</span></div>
53
+ <h3>ERA5: a reconstruction of the past weather hour by hour since 1940e</h3>
54
  <p>ERA5 is a reanalysis produced by the European Centre for Medium-Range Weather Forecasts (ECMWF). It
55
  reconstructs the past weather hour by hour since 1940, by combining a physics model of the atmosphere with
56
  observations from satellites, weather stations and weather balloons. It is the dataset most AI weather models
 
60
  </section>
61
  <section>
62
  <div class="kicker"><span class="tag tag-map">Middle map</span></div>
63
+ <h3>PARDIG: a new satellite-based reconstruction</h3>
64
  <p>PARDIG (Precipitation AI Reanalysis, Densely Inferred GPM) is a precipitation dataset recently released by
65
  Google DeepMind and Google Research. It estimates the rain over the whole planet every 15 minutes, on a 10 km
66
  grid. An AI model converts geostationary satellite images and weather
 
84
  <div class="rm-map" data-map="pardig"></div>
85
  </div>
86
  <div class="rm-panel">
87
+ <div class="rm-title">ERA5 minus PARDIG, both on the 28 km grid</div>
88
  <div class="rm-map" data-map="diff"></div>
89
  </div>
90
  <div class="rm-legend rm-legend-rain" data-for="rain"></div>
 
124
  .rm-leg-swatch { height: 14px; }
125
  .rm-leg-name { font-size: 13px; font-weight: 600; margin-top: 4px; color: var(--body-text-color); }
126
  .rm-leg-text { font-size: 11px; color: var(--body-text-color-subdued); white-space: nowrap; }
127
+ .rm-bar-scale { display: flex; height: 14px; border-radius: 4px; overflow: hidden; }
128
+ .rm-ticks { position: relative; height: 16px; }
129
+ .rm-tick { position: absolute; transform: translateX(-50%); font-size: 11px; color: var(--body-text-color-subdued);
130
+ top: 2px; }
131
+ .rm-bar-ends { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; }
132
+ .rm-bar-ends .wet { color: #542788; } .rm-bar-ends .dry { color: #b35806; }
133
+ .rm-bar-ends .mid { color: var(--body-text-color-subdued); font-weight: 400; }
134
  .rm-chips { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-top: 18px; }
135
  .rm-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
136
  .rm-chip-note { font-weight: 400; color: var(--body-text-color-subdued); }
maps.py CHANGED
@@ -252,6 +252,20 @@ def _weights(da: xr.DataArray) -> np.ndarray:
252
  return np.cos(np.deg2rad(da[da.dims[-2]].values))[:, None] * np.ones(da.shape[-2:])
253
 
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  def agreement(era5: np.ndarray, pardig: np.ndarray) -> np.ndarray:
256
  """Per cell and hour: 0 both dry, 1 both rain, 2 only ERA5, 3 only PARDIG, 4 PARDIG heavy where ERA5 is light."""
257
  e, p = np.nan_to_num(era5), np.nan_to_num(pardig)
@@ -284,13 +298,13 @@ def payload(start: str, n_days: int, box: tuple) -> tuple[str, str]:
284
  """(JSON for the three-panel map component, one-line summary) for ``n_days`` from ``start``, hourly."""
285
  era5, pardig = load_span(start, n_days, box, False)
286
  _, pardig_coarse = load_span(start, n_days, box, True)
287
- agree = agreement(era5.values, pardig_coarse.values)
288
  times = pd.DatetimeIndex(era5["time"].values)
289
  re, rp = Raster(era5), Raster(pardig)
290
  rain = [lower for _, lower, _ in RAIN_CLASSES]
291
  rain_colors = [None, *RAIN_CLASS_COLORS]
292
- agree_levels = [0.5, 1.5, 2.5, 3.5]
293
- agree_colors = [None, *(c for _, _, c in AGREEMENT)]
294
  data = {
295
  "key": f"{box}",
296
  "view": view(box),
@@ -298,14 +312,17 @@ def payload(start: str, n_days: int, box: tuple) -> tuple[str, str]:
298
  "panels": [
299
  {"key": "era5", "corners": re.corners, "frames": [re.png(v, rain, rain_colors) for v in era5.values]},
300
  {"key": "pardig", "corners": rp.corners, "frames": [rp.png(v, rain, rain_colors) for v in pardig.values]},
301
- {"key": "diff", "corners": re.corners, "frames": [re.png(v, agree_levels, agree_colors) for v in agree]},
302
  ],
303
  "legends": [
304
  {"target": "rain", "style": "classes", "title": "Rain in the hour, mm · clear: dry",
305
  "names": [name for name, _, _ in RAIN_CLASSES], "labels": [r for _, _, r in RAIN_CLASSES],
306
  "colors": RAIN_CLASS_COLORS},
307
- {"target": "diff", "style": "chips", "title": "Clear: both dry",
308
- "names": [label for _, label, _ in AGREEMENT], "colors": [c for _, _, c in AGREEMENT]},
 
 
 
309
  ],
310
  }
311
  return json.dumps(data), summary(era5, pardig)
 
252
  return np.cos(np.deg2rad(da[da.dims[-2]].values))[:, None] * np.ones(da.shape[-2:])
253
 
254
 
255
+ # ERA5 - PARDIG (mm in the hour) in 9 classes; cells where both are dry stay clear.
256
+ DIFF_BOUNDS = [-10, -3, -1, -0.2, 0.2, 1, 3, 10]
257
+ # from "ERA5 much drier" (d <= -10) to "ERA5 much wetter" (d >= 10), grey in the middle
258
+ DIFF_CLASS_COLORS = ["#7f3b08", "#b35806", "#e08214", "#fdb863", "#bdbcb5",
259
+ "#b2abd2", "#8073ac", "#542788", "#2d004b"]
260
+
261
+
262
+ def difference_classes(era5: np.ndarray, pardig: np.ndarray) -> np.ndarray:
263
+ """0 where both are dry, else 1 + the class of ERA5 - PARDIG in DIFF_BOUNDS."""
264
+ e, p = np.nan_to_num(era5), np.nan_to_num(pardig)
265
+ codes = 1 + np.digitize(e - p, DIFF_BOUNDS)
266
+ return np.where((e < WET) & (p < WET), 0, codes).astype(np.float32)
267
+
268
+
269
  def agreement(era5: np.ndarray, pardig: np.ndarray) -> np.ndarray:
270
  """Per cell and hour: 0 both dry, 1 both rain, 2 only ERA5, 3 only PARDIG, 4 PARDIG heavy where ERA5 is light."""
271
  e, p = np.nan_to_num(era5), np.nan_to_num(pardig)
 
298
  """(JSON for the three-panel map component, one-line summary) for ``n_days`` from ``start``, hourly."""
299
  era5, pardig = load_span(start, n_days, box, False)
300
  _, pardig_coarse = load_span(start, n_days, box, True)
301
+ diff = difference_classes(era5.values, pardig_coarse.values)
302
  times = pd.DatetimeIndex(era5["time"].values)
303
  re, rp = Raster(era5), Raster(pardig)
304
  rain = [lower for _, lower, _ in RAIN_CLASSES]
305
  rain_colors = [None, *RAIN_CLASS_COLORS]
306
+ diff_levels = [i + 0.5 for i in range(len(DIFF_CLASS_COLORS))]
307
+ diff_colors = [None, *DIFF_CLASS_COLORS]
308
  data = {
309
  "key": f"{box}",
310
  "view": view(box),
 
312
  "panels": [
313
  {"key": "era5", "corners": re.corners, "frames": [re.png(v, rain, rain_colors) for v in era5.values]},
314
  {"key": "pardig", "corners": rp.corners, "frames": [rp.png(v, rain, rain_colors) for v in pardig.values]},
315
+ {"key": "diff", "corners": re.corners, "frames": [re.png(v, diff_levels, diff_colors) for v in diff]},
316
  ],
317
  "legends": [
318
  {"target": "rain", "style": "classes", "title": "Rain in the hour, mm · clear: dry",
319
  "names": [name for name, _, _ in RAIN_CLASSES], "labels": [r for _, _, r in RAIN_CLASSES],
320
  "colors": RAIN_CLASS_COLORS},
321
+ # Bar drawn wettest first (purple on the left); ticks are the class boundaries, as sizes in mm.
322
+ {"target": "diff", "style": "bar", "title": "ERA5 minus PARDIG, mm in the hour · clear: both dry",
323
+ "colors": DIFF_CLASS_COLORS[::-1],
324
+ "ticks": [f"{abs(b):g}" for b in DIFF_BOUNDS[::-1]],
325
+ "ends": ["ERA5 wetter", "about the same", "ERA5 drier"]},
326
  ],
327
  }
328
  return json.dumps(data), summary(era5, pardig)
rainmaps.js CHANGED
@@ -102,6 +102,18 @@ function legends(specs) {
102
  for (const spec of specs) {
103
  const box = $(`.rm-legend[data-for="${spec.target}"]`);
104
  if (!box) continue;
 
 
 
 
 
 
 
 
 
 
 
 
105
  if (spec.style === "chips") {
106
  const chips = spec.colors.map((c, i) =>
107
  `<span class="rm-chip"><span class="rm-chip-sw" style="background:${c}"></span>${spec.names[i]}</span>`).join("");
 
102
  for (const spec of specs) {
103
  const box = $(`.rm-legend[data-for="${spec.target}"]`);
104
  if (!box) continue;
105
+ if (spec.style === "bar") {
106
+ const n = spec.colors.length;
107
+ const swatches = spec.colors.map((c) => `<div style="flex:1;background:${c}"></div>`).join("");
108
+ const ticks = spec.ticks.map((t, i) =>
109
+ `<span class="rm-tick" style="left:${((i + 1) / n) * 100}%">${t}</span>`).join("");
110
+ const [left, mid, right] = spec.ends;
111
+ box.innerHTML = `<div class="rm-leg-title">${spec.title}</div>` +
112
+ `<div class="rm-bar-scale">${swatches}</div><div class="rm-ticks">${ticks}</div>` +
113
+ `<div class="rm-bar-ends"><span class="wet">← ${left}</span><span class="mid">${mid}</span>` +
114
+ `<span class="dry">${right} →</span></div>`;
115
+ continue;
116
+ }
117
  if (spec.style === "chips") {
118
  const chips = spec.colors.map((c, i) =>
119
  `<span class="rm-chip"><span class="rm-chip-sw" style="background:${c}"></span>${spec.names[i]}</span>`).join("");