Clarify causal input contracts
Browse files- README.md +77 -13
- trackformer_1_2.py +32 -9
README.md
CHANGED
|
@@ -52,7 +52,8 @@ The model input at forecast issue time is limited to information available at
|
|
| 52 |
that time or earlier:
|
| 53 |
|
| 54 |
- observed IBTrACS history;
|
| 55 |
-
-
|
|
|
|
| 56 |
- current and lagged sea-surface-temperature summaries;
|
| 57 |
- causal nearby-storm and basin/global pressure context;
|
| 58 |
- static land/sea, coastline, terrain, land-cover, and location features.
|
|
@@ -73,7 +74,7 @@ is:
|
|
| 73 |
| Observed track and intensity history | `9 x 54` track window | issue time and earlier |
|
| 74 |
| Current storm-centred analysis | `4 x 17 x 17` | issue-time analysis |
|
| 75 |
| Older analysis context | `8 x 17 x 17` | -12 h and -24 h analysis |
|
| 76 |
-
| Whole-Pacific route state | `3
|
| 77 |
| SST, nearby systems, and pressure context | causal summaries and spatial features | issue time and earlier |
|
| 78 |
| Geography | land/sea, coastline, terrain, land-cover, and location features | static |
|
| 79 |
|
|
@@ -81,6 +82,64 @@ The data families are observations, analyses, reanalysis summaries, and static
|
|
| 81 |
geography. They are not agency forecast products. Missing radius labels are
|
| 82 |
masked rather than converted to zero.
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
## Outputs
|
| 85 |
|
| 86 |
For each of 20 six-hour leads from +6 h through +120 h, the model returns:
|
|
@@ -251,7 +310,7 @@ The exact public tensor contract is:
|
|
| 251 |
|
| 252 |
| API input | Shape | Meaning |
|
| 253 |
|---|---:|---|
|
| 254 |
-
| `field` | `[B, 6, 25, 61]` | normalized SLP/H500 grids ordered as
|
| 255 |
| `context` | `[B, 647]` | causal whole-Pacific context used by the released route checkpoint |
|
| 256 |
| `base_position` | `[B, 20, 2]` | cumulative local 100-km displacement before route correction |
|
| 257 |
| `causal_features` | `[B, 1020]` | exact pre-residual causal structure features |
|
|
@@ -261,9 +320,9 @@ The exact public tensor contract is:
|
|
| 261 |
### Published Feature Constructors
|
| 262 |
|
| 263 |
The constructors below are the supported bridge from causal source arrays to
|
| 264 |
-
the tensor contract.
|
| 265 |
-
|
| 266 |
-
|
| 267 |
|
| 268 |
| Constructor | Output | Purpose |
|
| 269 |
|---|---:|---|
|
|
@@ -293,6 +352,7 @@ system = build_route_system_features(
|
|
| 293 |
ncep_current_7ch, ncep_previous_7ch, ncep_lat, ncep_lon,
|
| 294 |
issue_latitude, issue_longitude, feature_mean=stats["system_mean"],
|
| 295 |
feature_std=stats["system_std"],
|
|
|
|
| 296 |
)
|
| 297 |
interaction = build_nearby_interaction_features(
|
| 298 |
nearby_latitude, nearby_longitude, nearby_vmax, nearby_age_hours,
|
|
@@ -328,14 +388,18 @@ encoded exactly. Then call `model.predict_intensity(features, anchor)`. The
|
|
| 328 |
persistence/trend fallback only; it is not the frozen incumbent anchor and
|
| 329 |
must be labeled as such in a benchmark.
|
| 330 |
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
`build_kinematic_base_position` and `build_causal_anchor_structure` provide
|
| 336 |
-
explicit persistence/trend fallbacks.
|
| 337 |
-
|
| 338 |
-
|
| 339 |
|
| 340 |
Use `prepare_route_field(slp, hgt500, ...)` when the three SLP and 500-hPa
|
| 341 |
height grids are still in physical units. Use
|
|
|
|
| 52 |
that time or earlier:
|
| 53 |
|
| 54 |
- observed IBTrACS history;
|
| 55 |
+
- route atmospheric analysis at t0, -6 h, and -12 h;
|
| 56 |
+
- storm-centred atmospheric patches at t0, -12 h, and -24 h;
|
| 57 |
- current and lagged sea-surface-temperature summaries;
|
| 58 |
- causal nearby-storm and basin/global pressure context;
|
| 59 |
- static land/sea, coastline, terrain, land-cover, and location features.
|
|
|
|
| 74 |
| Observed track and intensity history | `9 x 54` track window | issue time and earlier |
|
| 75 |
| Current storm-centred analysis | `4 x 17 x 17` | issue-time analysis |
|
| 76 |
| Older analysis context | `8 x 17 x 17` | -12 h and -24 h analysis |
|
| 77 |
+
| Whole-Pacific route state | `3 x 7 x 25 x 61` | route analysis at `t0`, `t-6 h`, `t-12 h` |
|
| 78 |
| SST, nearby systems, and pressure context | causal summaries and spatial features | issue time and earlier |
|
| 79 |
| Geography | land/sea, coastline, terrain, land-cover, and location features | static |
|
| 80 |
|
|
|
|
| 82 |
geography. They are not agency forecast products. Missing radius labels are
|
| 83 |
masked rather than converted to zero.
|
| 84 |
|
| 85 |
+
## Causal Input Contract
|
| 86 |
+
|
| 87 |
+
This section is the authoritative timing and coordinate contract. The names
|
| 88 |
+
`t1` and `t2` are not used in the public API because they hid the actual lag.
|
| 89 |
+
|
| 90 |
+
### Route Field
|
| 91 |
+
|
| 92 |
+
`prepare_route_field(slp, hgt500)` expects three analysis frames in exactly
|
| 93 |
+
this order: **t0, t-6 h, t-12 h**. It returns six channels in paired order:
|
| 94 |
+
|
| 95 |
+
```text
|
| 96 |
+
[SLP_t0, H500_t0, SLP_t-6, H500_t-6, SLP_t-12, H500_t-12]
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
The trained `[25, 61]` grid is not `100–190E` at 1.5 degrees. It is:
|
| 100 |
+
|
| 101 |
+
```text
|
| 102 |
+
latitude: 60.0, 57.5, ..., 0.0 N (25 points, descending)
|
| 103 |
+
longitude: 90.0, 92.5, ..., 240.0 E (61 points, ascending)
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
The exported constants `ROUTE_LATITUDES` and `ROUTE_LONGITUDES` contain these
|
| 107 |
+
vectors. The route field is an analysis-only input: use the latest analysis
|
| 108 |
+
available at the issue time and its two six-hour predecessors, never a
|
| 109 |
+
positive-lead forecast field.
|
| 110 |
+
|
| 111 |
+
### System Features
|
| 112 |
+
|
| 113 |
+
`build_route_system_features` expects the seven channels in this exact order:
|
| 114 |
+
|
| 115 |
+
```text
|
| 116 |
+
[H500, U850, V850, U500, V500, U200, V200]
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
The same order is available as `ROUTE_SYSTEM_CHANNELS`. If named arrays are
|
| 120 |
+
used, pass `channel_names=ROUTE_SYSTEM_CHANNELS`; the constructor raises an
|
| 121 |
+
error for a permutation instead of silently assigning the wrong Pacific-High
|
| 122 |
+
or steering descriptors.
|
| 123 |
+
|
| 124 |
+
### Structure and Intensity History
|
| 125 |
+
|
| 126 |
+
The storm-centred structure patches and ocean summaries use a separate timing
|
| 127 |
+
contract: **t0, t-12 h, t-24 h**. This is why the route field and structure
|
| 128 |
+
patches have different lag spacing. The `causal_features` vector combines
|
| 129 |
+
those patches with the issue-time-or-earlier track, nearby systems, basin and
|
| 130 |
+
global analysis context, SST/ocean summaries, and static geography.
|
| 131 |
+
|
| 132 |
+
### Static Geography Source
|
| 133 |
+
|
| 134 |
+
The eight published geography channels are derived from the packaged static
|
| 135 |
+
land/sea map, not downloaded as a forecast. The source is **Natural Earth 50m
|
| 136 |
+
land plus ESA WorldCover 10m 2021 v200**. The route-query map is sampled on a
|
| 137 |
+
global **0.25-degree grid** (`-60..70N`, `0..360E`, shape `521 x 1441`), with
|
| 138 |
+
WorldCover sampled remotely at `48 x 48` per 3 x 3 degree tile before the
|
| 139 |
+
derived coastline, multiscale land-fraction, land-buffer, and local-variance
|
| 140 |
+
features are computed. `land_fraction_75/150/300km` are derived features from
|
| 141 |
+
this same static map; they are not future weather fields.
|
| 142 |
+
|
| 143 |
## Outputs
|
| 144 |
|
| 145 |
For each of 20 six-hour leads from +6 h through +120 h, the model returns:
|
|
|
|
| 310 |
|
| 311 |
| API input | Shape | Meaning |
|
| 312 |
|---|---:|---|
|
| 313 |
+
| `field` | `[B, 6, 25, 61]` | normalized SLP/H500 grids ordered as `t0,-6 h,-12 h` pairs |
|
| 314 |
| `context` | `[B, 647]` | causal whole-Pacific context used by the released route checkpoint |
|
| 315 |
| `base_position` | `[B, 20, 2]` | cumulative local 100-km displacement before route correction |
|
| 316 |
| `causal_features` | `[B, 1020]` | exact pre-residual causal structure features |
|
|
|
|
| 320 |
### Published Feature Constructors
|
| 321 |
|
| 322 |
The constructors below are the supported bridge from causal source arrays to
|
| 323 |
+
the tensor contract. Route analysis frames are `t0, t-6 h, t-12 h`; structure
|
| 324 |
+
patches and ocean summaries are `t0, t-12 h, t-24 h`; and labels after the
|
| 325 |
+
issue time are never accepted as inputs.
|
| 326 |
|
| 327 |
| Constructor | Output | Purpose |
|
| 328 |
|---|---:|---|
|
|
|
|
| 352 |
ncep_current_7ch, ncep_previous_7ch, ncep_lat, ncep_lon,
|
| 353 |
issue_latitude, issue_longitude, feature_mean=stats["system_mean"],
|
| 354 |
feature_std=stats["system_std"],
|
| 355 |
+
channel_names=("hgt500", "uwnd850", "vwnd850", "uwnd500", "vwnd500", "uwnd200", "vwnd200"),
|
| 356 |
)
|
| 357 |
interaction = build_nearby_interaction_features(
|
| 358 |
nearby_latitude, nearby_longitude, nearby_vmax, nearby_age_hours,
|
|
|
|
| 388 |
persistence/trend fallback only; it is not the frozen incumbent anchor and
|
| 389 |
must be labeled as such in a benchmark.
|
| 390 |
|
| 391 |
+
### Frozen Upstream Inputs
|
| 392 |
+
|
| 393 |
+
Two inputs are frozen upstream members rather than standalone public neural
|
| 394 |
+
heads: the route model's incumbent route and the intensity model's 20-lead
|
| 395 |
+
structure anchor. The exact incumbent `base_position` arrays are row-aligned
|
| 396 |
+
to the private training/evaluation issue-window archive, so there is no
|
| 397 |
+
universal public dump that can be safely applied to an arbitrary storm. If an
|
| 398 |
+
issue packet contains the exact causal array, pass it directly. Otherwise,
|
| 399 |
`build_kinematic_base_position` and `build_causal_anchor_structure` provide
|
| 400 |
+
explicit persistence/trend fallbacks. These fallbacks do not reproduce the
|
| 401 |
+
incumbent members and must be labeled as fallback inputs in any benchmark;
|
| 402 |
+
they are not a way to select a favorable result.
|
| 403 |
|
| 404 |
Use `prepare_route_field(slp, hgt500, ...)` when the three SLP and 500-hPa
|
| 405 |
height grids are still in physical units. Use
|
trackformer_1_2.py
CHANGED
|
@@ -4,9 +4,9 @@ The release checkpoints are trained on causal issue-time inputs. This module
|
|
| 4 |
does not download or accept JMA/JTWC/ECMWF/GFS/GEFS forecast products. It
|
| 5 |
expects the same preprocessed arrays used by the released checkpoints:
|
| 6 |
|
| 7 |
-
* route: a six-channel [SLP, 500-hPa height] analysis field
|
| 8 |
-
a 647-dimensional causal context vector, and a 20-step base route
|
| 9 |
-
local displacement units;
|
| 10 |
* intensity: the 1,020-dimensional causal feature vector and the frozen
|
| 11 |
20-lead physical anchor structure;
|
| 12 |
* ocean structure calibration: the 66-dimensional three-time ocean summary,
|
|
@@ -38,6 +38,11 @@ INTENSITY_INPUT_DIM = 1320
|
|
| 38 |
OCEAN_FEATURE_DIM = 66
|
| 39 |
FIELD_HEIGHT = 25
|
| 40 |
FIELD_WIDTH = 61
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
ROUTE_SYNOPTIC_DIM = 270
|
| 42 |
ROUTE_SYSTEM_DIM = 46
|
| 43 |
ROUTE_INTERACTION_DIM = 16
|
|
@@ -88,10 +93,13 @@ def prepare_route_field(
|
|
| 88 |
"""Encode physical three-time SLP/H500 analysis grids for the route head.
|
| 89 |
|
| 90 |
``slp`` and ``hgt500`` are physical arrays with shape ``[B, 3, H, W]``.
|
| 91 |
-
The
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
| 95 |
"""
|
| 96 |
|
| 97 |
slp = _batch(slp, (3, slp.shape[-2], slp.shape[-1]) if np.asarray(slp).ndim == 4 else (3, FIELD_HEIGHT, FIELD_WIDTH), "slp")
|
|
@@ -491,8 +499,22 @@ def build_route_system_features(
|
|
| 491 |
valid: np.ndarray | float = 1.0,
|
| 492 |
feature_mean: np.ndarray | None = None,
|
| 493 |
feature_std: np.ndarray | None = None,
|
|
|
|
| 494 |
) -> np.ndarray:
|
| 495 |
-
"""Build the 46-feature causal Pacific-High/system context block.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
|
| 497 |
current = np.asarray(analysis_field, dtype="float32")
|
| 498 |
previous = np.asarray(previous_analysis_field, dtype="float32")
|
|
@@ -1198,7 +1220,8 @@ class Trackformer12:
|
|
| 1198 |
|
| 1199 |
__all__ = [
|
| 1200 |
"FIELD_HEIGHT", "FIELD_WIDTH", "INTENSITY_FEATURE_DIM", "INTENSITY_INPUT_DIM", "LEADS", "LEAD_HOURS",
|
| 1201 |
-
"OCEAN_FEATURE_DIM", "ROUTE_CONTEXT_DIM", "
|
|
|
|
| 1202 |
"build_base_position", "build_causal_anchor_structure", "build_causal_structure_features",
|
| 1203 |
"build_intensity_context_features", "build_kinematic_base_position", "build_ocean_features",
|
| 1204 |
"build_nearby_interaction_features", "build_patch_summary", "build_route_context",
|
|
|
|
| 4 |
does not download or accept JMA/JTWC/ECMWF/GFS/GEFS forecast products. It
|
| 5 |
expects the same preprocessed arrays used by the released checkpoints:
|
| 6 |
|
| 7 |
+
* route: a six-channel [SLP, 500-hPa height] analysis field at t0, t-6 h, and
|
| 8 |
+
t-12 h, a 647-dimensional causal context vector, and a 20-step base route
|
| 9 |
+
in 100-km local displacement units;
|
| 10 |
* intensity: the 1,020-dimensional causal feature vector and the frozen
|
| 11 |
20-lead physical anchor structure;
|
| 12 |
* ocean structure calibration: the 66-dimensional three-time ocean summary,
|
|
|
|
| 38 |
OCEAN_FEATURE_DIM = 66
|
| 39 |
FIELD_HEIGHT = 25
|
| 40 |
FIELD_WIDTH = 61
|
| 41 |
+
ROUTE_LATITUDES = np.arange(60.0, -0.1, -2.5, dtype="float32")
|
| 42 |
+
ROUTE_LONGITUDES = np.arange(90.0, 240.1, 2.5, dtype="float32")
|
| 43 |
+
ROUTE_SYSTEM_CHANNELS = (
|
| 44 |
+
"hgt500", "uwnd850", "vwnd850", "uwnd500", "vwnd500", "uwnd200", "vwnd200",
|
| 45 |
+
)
|
| 46 |
ROUTE_SYNOPTIC_DIM = 270
|
| 47 |
ROUTE_SYSTEM_DIM = 46
|
| 48 |
ROUTE_INTERACTION_DIM = 16
|
|
|
|
| 93 |
"""Encode physical three-time SLP/H500 analysis grids for the route head.
|
| 94 |
|
| 95 |
``slp`` and ``hgt500`` are physical arrays with shape ``[B, 3, H, W]``.
|
| 96 |
+
The three frames are ordered ``t0, t-6 h, t-12 h``. The output channel
|
| 97 |
+
order is ``SLP_t0, H500_t0, SLP_t-6, H500_t-6, SLP_t-12, H500_t-12``.
|
| 98 |
+
The trained route grid is ``ROUTE_LATITUDES`` x ``ROUTE_LONGITUDES``:
|
| 99 |
+
25 descending latitudes from 60N to 0N and 61 longitudes from 90E to
|
| 100 |
+
240E, both at 2.5 degrees. Missing-frame masks are 0/1 arrays with shape
|
| 101 |
+
``[B, 3]`` or ``[B, 3, 1, 1]``. The route checkpoint was trained with SLP
|
| 102 |
+
in hPa and H500 in geopotential metres.
|
| 103 |
"""
|
| 104 |
|
| 105 |
slp = _batch(slp, (3, slp.shape[-2], slp.shape[-1]) if np.asarray(slp).ndim == 4 else (3, FIELD_HEIGHT, FIELD_WIDTH), "slp")
|
|
|
|
| 499 |
valid: np.ndarray | float = 1.0,
|
| 500 |
feature_mean: np.ndarray | None = None,
|
| 501 |
feature_std: np.ndarray | None = None,
|
| 502 |
+
channel_names: Iterable[str] | None = None,
|
| 503 |
) -> np.ndarray:
|
| 504 |
+
"""Build the 46-feature causal Pacific-High/system context block.
|
| 505 |
+
|
| 506 |
+
The seven input channels must be ordered as
|
| 507 |
+
``[H500, U850, V850, U500, V500, U200, V200]``. Pass ``channel_names``
|
| 508 |
+
when loading named arrays to validate that order explicitly.
|
| 509 |
+
"""
|
| 510 |
+
|
| 511 |
+
if channel_names is not None:
|
| 512 |
+
supplied = tuple(str(name) for name in channel_names)
|
| 513 |
+
if supplied != ROUTE_SYSTEM_CHANNELS:
|
| 514 |
+
raise ValueError(
|
| 515 |
+
"analysis channels must be ordered as "
|
| 516 |
+
f"{ROUTE_SYSTEM_CHANNELS}, got {supplied}"
|
| 517 |
+
)
|
| 518 |
|
| 519 |
current = np.asarray(analysis_field, dtype="float32")
|
| 520 |
previous = np.asarray(previous_analysis_field, dtype="float32")
|
|
|
|
| 1220 |
|
| 1221 |
__all__ = [
|
| 1222 |
"FIELD_HEIGHT", "FIELD_WIDTH", "INTENSITY_FEATURE_DIM", "INTENSITY_INPUT_DIM", "LEADS", "LEAD_HOURS",
|
| 1223 |
+
"OCEAN_FEATURE_DIM", "ROUTE_CONTEXT_DIM", "ROUTE_LATITUDES", "ROUTE_LONGITUDES",
|
| 1224 |
+
"ROUTE_SYSTEM_CHANNELS", "STRUCTURE_DIM", "Trackformer12",
|
| 1225 |
"build_base_position", "build_causal_anchor_structure", "build_causal_structure_features",
|
| 1226 |
"build_intensity_context_features", "build_kinematic_base_position", "build_ocean_features",
|
| 1227 |
"build_nearby_interaction_features", "build_patch_summary", "build_route_context",
|