Metadata-Version: 2.4
Name: tempest-wx1
Version: 0.1.2
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Rust
Requires-Dist: numpy>=1.26 ; extra == 'all'
Requires-Dist: xarray>=2024.1 ; extra == 'all'
Requires-Dist: dask[array]>=2024.1 ; extra == 'all'
Requires-Dist: netcdf4>=1.6 ; extra == 'all'
Requires-Dist: zarr>=2.17 ; extra == 'all'
Requires-Dist: cfgrib>=0.9.15 ; extra == 'all'
Requires-Dist: eccodes>=2.38 ; extra == 'all'
Requires-Dist: jax[cuda12]>=0.12 ; extra == 'all'
Requires-Dist: jax[cuda12]>=0.12 ; extra == 'cuda'
Requires-Dist: numpy>=1.26 ; extra == 'dask'
Requires-Dist: xarray>=2024.1 ; extra == 'dask'
Requires-Dist: dask[array]>=2024.1 ; extra == 'dask'
Requires-Dist: jax[cuda12]>=0.12 ; extra == 'gpu'
Requires-Dist: numpy>=1.26 ; extra == 'grib2'
Requires-Dist: xarray>=2024.1 ; extra == 'grib2'
Requires-Dist: cfgrib>=0.9.15 ; extra == 'grib2'
Requires-Dist: eccodes>=2.38 ; extra == 'grib2'
Requires-Dist: numpy>=1.26 ; extra == 'netcdf'
Requires-Dist: xarray>=2024.1 ; extra == 'netcdf'
Requires-Dist: netcdf4>=1.6 ; extra == 'netcdf'
Requires-Dist: numpy>=1.26 ; extra == 'numpy'
Requires-Dist: numpy>=1.26 ; extra == 'test'
Requires-Dist: xarray>=2024.1 ; extra == 'test'
Requires-Dist: scipy>=1.11 ; extra == 'test'
Requires-Dist: pytest>=8.0 ; extra == 'test'
Requires-Dist: numpy>=1.26 ; extra == 'xarray'
Requires-Dist: xarray>=2024.1 ; extra == 'xarray'
Requires-Dist: numpy>=1.26 ; extra == 'zarr'
Requires-Dist: xarray>=2024.1 ; extra == 'zarr'
Requires-Dist: zarr>=2.17 ; extra == 'zarr'
Provides-Extra: all
Provides-Extra: cuda
Provides-Extra: dask
Provides-Extra: gpu
Provides-Extra: grib2
Provides-Extra: netcdf
Provides-Extra: numpy
Provides-Extra: test
Provides-Extra: xarray
Provides-Extra: zarr
Summary: Tempest: WX-1 — High-Performance Scientific Weather Storage Format
Keywords: weather,meteorology,nwp,scientific-data,storage,xarray,grib2,netcdf4,zarr,geospatial
Author: Jordy van Gils
License: Apache-2.0
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/jordyvg013/tempest-wx1
Project-URL: Issues, https://github.com/jordyvg013/tempest-wx1/issues
Project-URL: Repository, https://github.com/jordyvg013/tempest-wx1

# Tempest: WX-1 — High-Performance Scientific Weather Storage Format

[![PyPI version](https://img.shields.io/pypi/v/tempest-wx1.svg)](https://pypi.org/project/tempest-wx1/)
[![Python](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue.svg)](https://pypi.org/project/tempest-wx1/)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![Determinism](https://img.shields.io/badge/IEEE%20754-Bit--Exact-success.svg)](#100-bit-exact-ieee-754-determinism)

**WX-1** is a high-performance, container-native scientific storage engine and file format engineered specifically for **Numerical Weather Prediction (NWP)**, atmospheric modeling, climate reanalysis, and earth system simulations.

Built on a memory-safe Rust core with native Python (PyO3) bindings and an `xarray` backend engine (`engine="wx1"`), WX-1 replaces legacy formats with deterministic, ultra-fast I/O for 3D/4D atmospheric tensors.

---

## Key Highlights

* **100% Bit-Exact Determinism**: Preserves raw IEEE 754 bit-patterns ($\Delta_{\max} = 0.0$ verified via `.view(np.uint32)`), guaranteeing bit-exact restarts for prognostic NWP dynamical cores.
* **Large Array & Chunk Capacity (up to 16 GiB)**: Supports massive high-resolution global grids, multi-layer soil matrices, and 137-level atmospheric columns without artificial 64 MB chunk restrictions.
* **Multi-Variable Datasets**: Bundle multiple atmospheric variables (e.g., surface $T_{2m}$, $MSLP$, $10m$ wind, precipitation) or 3D pressure levels in a unified container via `wx1.write_dataset()`.
* **Ultra-Fast Sub-Volume Slicing**:
  * Synoptic horizontal 2D map retrieval: **< 10 ms**.
  * Atmospheric vertical sounding extraction (e.g. De Bilt column): **< 25 ms**.
  * Instant container metadata open: **2.97 ms** (19.5× faster than NetCDF-4).
* **Native xarray Integration**: Open datasets directly with `xr.open_dataset("path.wx1", engine="wx1")` with lazy variable indexing and Dask chunking.
* **Pluggable Lossless & Bounded Lossy Codecs**: Choose `zstd_shuffle` (byte-shuffle + Zstandard), pure `lz4`, raw uncompressed, or bounded error quantization (`profile="output"`).
* **Format Adapters**: Bidirectional converters for WMO GRIB Edition 1 & 2, NetCDF-4 (HDF5), and Zarr v2/v3.

---

## Benchmark Evidence: Authentic ECMWF ERA5 Reanalysis

Benchmarks executed on authentic ECMWF ERA5 global reanalysis data ($0.25^\circ$, $721 \times 1440 = 1,038,240$ points/slice):

### Surface Reanalysis (7 Variables, 120 Timesteps, 872M float32 values)

| Variable | Description | Raw (f32) | NetCDF-4 (zlib) | WX-1 (Zstd+Shuffle) | WX-1 vs NetCDF-4 |
| :--- | :--- | :--- | :--- | :--- | :--- |
| **`tp`** | Total precipitation | 498.36 MB | 108.44 MB | **99.58 MB** | **-8.86 MB (-8.2%)** |
| **`t2m`** | 2m temperature | 498.36 MB | ~186.22 MB | **174.56 MB** | **-11.66 MB (-6.3%)** |
| **`msl`** | Mean sea level pressure | 498.36 MB | ~186.22 MB | **160.27 MB** | **-25.95 MB (-13.9%)** |
| **`sp`** | Surface pressure | 498.36 MB | ~186.22 MB | **163.73 MB** | **-22.49 MB (-12.1%)** |
| **`sst`** | Sea surface temp (NaN mask) | 498.36 MB | ~186.22 MB | **44.03 MB** | **-142.19 MB (-76.4%)** |
| **`u10`** | 10m U-wind component | 498.36 MB | ~186.22 MB | **245.49 MB** | +59.27 MB |
| **`v10`** | 10m V-wind component | 498.36 MB | ~186.22 MB | **246.88 MB** | +60.66 MB |
| **TOTAL** | **All 7 Variables** | **3,488.52 MB** | **1,225.78 MB** | **1,134.55 MB** | **-91.23 MB (-7.4%)** |

* **Comparison to GRIB1**: The original `era5_sfc_all.grib` is **1,675.46 MB**. WX-1 is **540.91 MB smaller (-32.3%)**.
* **Bit-Exactness**: All $872,121,600$ float32 values are 100% bit-exact ($\Delta_{\max} = 0.0$).
* **Read Latency**: Container open in **2.97 ms** (NetCDF-4: 57.91 ms). Sliced field read in **159 ms** (NetCDF-4: 883 ms).

---

## Installation

### Standard Installation
```bash
pip install tempest-wx1
```

### Installation with Scientific & NWP Extras
```bash
# Core meteorological stack (NumPy, xarray, Dask)
pip install "tempest-wx1[xarray,dask]"

# Format converters (GRIB2, NetCDF4, Zarr)
pip install "tempest-wx1[grib2,netcdf,zarr]"

# Full stack (including CUDA/GPU support)
pip install "tempest-wx1[all]"
```

---

## Quickstart Guide

### 1. Multi-Variable Forecast Export (`write_dataset`)
Bundle multiple surface variables into a single unified container:

```python
import wx1
import numpy as np

lats = np.linspace(90, -90, 721, dtype=np.float32)
lons = np.linspace(0, 359.75, 1440, dtype=np.float32)

variables = {
    "t2m": np.random.uniform(250.0, 310.0, size=(721, 1440)).astype(np.float32),
    "mslp": np.random.uniform(98000.0, 104000.0, size=(721, 1440)).astype(np.float32),
    "u10": np.random.uniform(-25.0, 25.0, size=(721, 1440)).astype(np.float32),
    "v10": np.random.uniform(-25.0, 25.0, size=(721, 1440)).astype(np.float32),
}

variable_attributes = {
    "t2m": {"units": "K", "long_name": "2 metre temperature"},
    "mslp": {"units": "Pa", "long_name": "Mean sea level pressure"},
    "u10": {"units": "m/s", "long_name": "10 metre U wind component"},
    "v10": {"units": "m/s", "long_name": "10 metre V wind component"},
}

wx1.write_dataset(
    "surface_forecast.wx1",
    variables=variables,
    dimensions={"latitude": 721, "longitude": 1440},
    dimension_roles={"latitude": "latitude", "longitude": "longitude"},
    variable_attributes=variable_attributes,
    variable_dimensions={k: ["latitude", "longitude"] for k in variables},
    dataset_id="tempest_surface_step03",
    codec="zstd_shuffle",
)
```

### 2. High-Dimensional Array Storage (`write_array`)
Write 3D/4D atmospheric tensor volumes (up to 16 GiB per variable/chunk):

```python
# 4D atmospheric temperature tensor: [time, level, lat, lon]
t_profile = np.random.randn(24, 137, 451, 900).astype(np.float32)

wx1.write_array(
    "pressure_levels.wx1",
    t_profile,
    dataset_id="t_profile_d1",
    variable_path="/temperature",
    dimensions=["time", "level", "lat", "lon"],
    chunk_shape=[1, 1, 451, 900],  # 1 level per chunk for instant vertical retrieval
    codec="zstd_shuffle",
    profile="restart",            # 100% bit-exact lossless
    attributes={"units": "K", "standard_name": "air_temperature"},
)
```

### 3. Ultra-Fast Slicing & Atmospheric Soundings
Extract specific vertical soundings or synoptic slices without decompressing the entire file:

```python
with wx1.open_file("pressure_levels.wx1") as f:
    # Read T500 hPa slice at step 0: shape [1, 1, 451, 900]
    t500 = f.read_array_slice("/temperature", start=[0, 10, 0, 0], count=[1, 1, 451, 900])
    print("T500 shape:", t500.shape)

    # Read full vertical atmospheric sounding at station coordinates (lat_idx=250, lon_idx=420)
    sounding = f.read_array_slice("/temperature", start=[0, 0, 250, 420], count=[1, 137, 1, 1])
    print("137-level sounding shape:", sounding.squeeze().shape)
```

### 4. Direct xarray Integration
Load WX-1 containers seamlessly into `xarray.Dataset` with lazy indexing:

```python
import xarray as xr

ds = xr.open_dataset("surface_forecast.wx1", engine="wx1")
print(ds)
print(ds["t2m"].values)
```

### 5. Format Conversion Utilities
Interoperate directly with existing GRIB2, NetCDF, and Zarr pipelines:

```python
# Convert operational GRIB2 feed to WX-1
wx1.from_grib("gfs_forecast.grib2", "gfs_forecast.wx1", variable_name="t2m")

# Export WX-1 back to CF-compliant NetCDF-4 or Zarr
wx1.to_netcdf("surface_forecast.wx1", "surface_forecast.nc")
wx1.to_zarr("surface_forecast.wx1", "surface_forecast.zarr")
```

---

## License & Attribution

* Licensed under the **Apache License, Version 2.0** ([LICENSE](https://www.apache.org/licenses/LICENSE-2.0)).
* Copyright 2026 Jordy van Gils.
* Developed for high-performance physics-based meteorological simulation and operational NWP pipelines.

