feat: Zarr export bridge for ensemble probabilistic forecasts - #521
feat: Zarr export bridge for ensemble probabilistic forecasts#521Debadri-das wants to merge 6 commits into
Conversation
- Support 4D tensors (S, T, N, F) for ensemble predictions - Add ensemble_member dimension to dims list - Implement ensemble_member coordinate binding logic - Maintain backward compatibility with 2D/3D tensors - Update docstring to document ensemble support Fixes mllam#520
- Update docstring to document 4D tensor support - Clarify parameter expectations for ensemble vs deterministic - Add Returns section with coordinate details - Enable Zarr export for probabilistic forecasts Refs mllam#520
- Test tensor with shape (S, T, N, F) where S=ensemble members - Verify ensemble_member coordinate exists and has correct size - Verify time coordinate is properly mapped - Verify all dimensions are correctly named - Ensure values are preserved in conversion Refs mllam#520
Document all changes related to issue mllam#520: - weather_dataset.py 4D tensor support with ensemble_member coordinate - ar_model.py ensemble prediction handling in _create_dataarray_from_tensor() - ar_model.py ensemble dimension stacking in unroll_prediction() - Test coverage for 4D ensemble DataArray creation Closes mllam#520
|
Hi @joeloskarsson @sadamov , due to an ongoing nan bounds check issue, I am observing a local failure in test_clamping.py::test_clamping. Should we create a different issue to monitor it even if it has nothing to do with these DataArray modifications? |
|
I reproduced a follow-up break in I kept that as a separate narrow stacked PR here: Debadri-das#1 Scope is intentionally small: it preserves the existing example-plotting path by collapsing ensemble predictions to their ensemble mean before plotting, with a focused regression test. |
…-plots Plot ensemble means in example prediction views
|
Nice work on the ensemble support. The One thing I noticed while looking through: the current reshape sits inside However, for CVAE-like probabilistic models (the Graph-EFM direction in #62), each ensemble member would have its own latent variable z sampled during predict_step(). In that case, the reshape to (BS, ...) before predict_step() would need the Z sampling to happen per-member within that call - which it would, since each of the BS items in the batch gets an independent sample. So the batch-fold approach actually generalizes naturally to latent variable models too, as long as the stochasticity is internal to predict_step(). Just wanted to flag this since it connects to the broader #62 roadmap. The approach here looks solid for the current scope. |
kshirajahere
left a comment
There was a problem hiding this comment.
@Debadri-das this PR adds 4D ensemble support to WeatherDataset.create_dataarray_from_tensor(), which is needed for probabilistic / ensemble exports. But ARModel.plot_examples() still assumes that the prediction side of the example plot is a single deterministic field.
With an ensemble prediction tensor shaped (B, S, T, N, F), the current plotting path reaches vis.plot_prediction() with an ensemble_member dimension still present on the prediction DataArray. In the existing two-panel example view (Ground Truth vs Prediction), that leaves no defined scalar field to plot and crashes during plotting / color-range handling.
Observed failure:
ValueError: can only convert an array of size 1 to a Python scalar
|
Closing this in favour of #649, which consolidates the probabilistic metrics + ensemble plumbing track for v0.8.0. The 4D ensemble tensor support and zarr export bridge will inform the consolidated PR. Note that this PR touches |
Describe your changes
This PR adds comprehensive support for 4D ensemble tensors
(S, T, N, F)to enable probabilistic weather forecast exports to Zarr format formllam-verificationintegration.Problem: Because the
neural-lamcodebase did not support 4D ensemble tensors and could only handle 2D/3D deterministic forecasts, probabilistic predictions could not be exported to Zarr format for external verification usingmllam-verification.Solution: Implemented full ensemble support across the data pipeline:
WeatherDataset (
neural_lam/weather_dataset.py):elif len(tensor.shape) == 4:branchensemble_memberdimension in dims list:["ensemble_member", "time", "grid_index", f"{category}_feature"]np.arange()ARModel Documentation (
neural_lam/models/ar_model.py):_create_dataarray_from_tensor()docstring with detailed ensemble support documentationARModel Ensemble Handling (
neural_lam/models/ar_model.py):unroll_prediction()to detect and handle 5D ensemble inputs (vs 4D deterministic)(B, S, T, N, F)→(B*S, T, N, F)(B*S, T, N, F)→(B, S, T, N, F)Test Coverage (
tests/test_datasets.py):test_dataset_item_create_dataarray_from_tensor_4d_ensemble()testDocumentation (
CHANGELOG.md):Motivation and Context
As stated in #62, the core evaluation pipeline is moving toward using
mllam-verification(supported by thescorespackage). We require a bridge to export ensemble predictions to Zarr in order to support probabilistic models (such as Graph-EFM). Ensemble forecasts cannot be used with external verification tools.Dependencies
No new dependencies are required. All code uses existing packages: PyTorch, xarray, and numpy.
Issue Link
#520
Type of change
Checklist before requesting a review
Commits
Related Issues
prob_model_lambranch #62 (evaluation pipeline migration to mllam-verification)