Download code/bifurcation/fid/passive_scalar.py from coarse-grained-forecasting-benchmark/forecasting-models: direct link, hf CLI and curl.
- Browser
- Download file 1.76 kB
-
https://huggingface.co/coarse-grained-forecasting-benchmark/forecasting-models/resolve/main/code/bifurcation/fid/passive_scalar.py
- Command line
-
hf download hf://coarse-grained-forecasting-benchmark/forecasting-models/code/bifurcation/fid/passive_scalar.py
-
curl -L -o passive_scalar.py https://huggingface.co/coarse-grained-forecasting-benchmark/forecasting-models/resolve/main/code/bifurcation/fid/passive_scalar.py
1.76 kB
| """Passive-scalar FID adapter: the SAME 196-D coarse spectral observable as Euler (98 complex modes | |
| |k| <= 8, Hermitian half, coefficients / N^2, shared mode order from ``bifurcation.models.spectral``) -> the exact | |
| low-pass scalar field theta on a 128x128 grid -> symmetric clip -> uint8 -> 3 identical channels. | |
| The reconstruction is byte-identical to the Euler adapter's (one inverse FFT, one mode-index map); only the | |
| physical reading differs: the field is a passive scalar concentration anomaly, signed and zero-mean, so the | |
| symmetric clip about zero is the right quantization. Physical diagnostic: the scalar-variance ratio (mean sum|theta_hat_k|^2 of the generated cloud over the truth's) — the passive scalar's analogue of | |
| Euler's enstrophy ratio. | |
| """ | |
| from __future__ import annotations | |
| import numpy as np | |
| from .adapters import register_adapter | |
| from .euler import EulerVorticityAdapter | |
| class PassiveScalarAdapter(EulerVorticityAdapter): | |
| field_kind = "signed" | |
| def card(self) -> dict: | |
| c = super().card() | |
| c.update({"state": "196-D coarse spectral passive scalar (98 complex modes |k| <= 8, Hermitian half, theta_hat / N^2)", | |
| "clip": "symmetric [-c, c], c = Q_q(|theta|) over the training pool", | |
| "physical_diagnostic": "scalar_variance_ratio = mean_gen sum|theta_hat_k|^2 / mean_truth sum|theta_hat_k|^2"}) | |
| return c | |
| def physical_diagnostics(self, gen_raw: np.ndarray, true_raw: np.ndarray) -> dict: | |
| def var(v): | |
| v = np.asarray(v, np.float64) | |
| return float(np.mean(np.sum(v ** 2, axis=1))) | |
| vt = var(true_raw) | |
| return {"scalar_variance_ratio": var(gen_raw) / vt if vt > 0 else float("nan")} | |