Metadata-Version: 2.4
Name: snow-mhd
Version: 0.1.0
Summary: SNOW neural-operator inference for steady-state solar-wind MHD
Author: Prateek Mayank
License-Expression: MIT
Project-URL: Zenodo, https://doi.org/10.5281/zenodo.23090129
Keywords: solar wind,MHD,heliophysics,neural operator
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: torch>=2.6
Requires-Dist: torch-harmonics==0.7.4
Dynamic: license-file

# SNOW.py

SNOW (Solar Neural Operator for Wind) propagates a complete 20 R☉ solar-wind boundary into a steady-state, three-dimensional MHD prediction. The package runs the published SNOW checkpoint, trained on AWSoM simulations in a Sun-centered inertial frame. It predicts all eight plasma fields every 10 R☉ through 250 R☉. The manuscript analysis ends at 240 R☉.

## Installation

After the PyPI release, install Python 3.10 or newer and run:

```sh
python -m pip install snow-mhd
snowpy download-checkpoint
```

From a source checkout, use `python -m pip install .` in place of the PyPI command. For CUDA, install a CUDA-enabled PyTorch build appropriate for your system.

The optional setup command downloads the 3.05 GB epoch-399 checkpoint from the [published Zenodo record](https://doi.org/10.5281/zenodo.23090129). The first prediction downloads it automatically when the cache is empty. The wheel contains package code only and the download runs outside pip's build and installation hooks. The download is verified by size and SHA-256. The default cache is `~/.cache/snowpy` or `$XDG_CACHE_HOME/snowpy`. Override it with `SNOW_CACHE_DIR` or `--cache-dir`. A local copy is accepted via `--checkpoint /path/to/SNOW.pt` for offline use.

## Boundary format

Supply a NumPy array named `plasma` in `boundary.npz`. Its shape is `(8, 91, 180)` with axes in field, colatitude, longitude order. The radial coordinate is 20 R☉. Use the following channel order and units.

| Index | Name | Quantity | Unit |
| --- | --- | --- | --- |
| 0 | `n_p` | Proton number density | cm⁻³ |
| 1 | `v_r` | Outward radial velocity | km/s |
| 2 | `v_theta` | Southward velocity, along increasing colatitude | km/s |
| 3 | `v_phi` | Velocity along increasing longitude | km/s |
| 4 | `p` | Thermal pressure | nPa |
| 5 | `b_r` | Outward radial magnetic field | nT |
| 6 | `b_theta` | Southward magnetic field | nT |
| 7 | `b_phi` | Magnetic field along increasing longitude | nT |

Use colatitude `0°, 2°, …, 180°` from north to south and periodic longitude `0°, 2°, …, 358°`. Include both poles and omit the duplicate 360° column. Use finite values and positive density, radial velocity and pressure. Regrid external boundaries to this angular grid and express vectors in the spherical basis before supplying them. The checkpoint is calibrated to AWSoM-like boundaries.

```python
import numpy as np
from snowpy import write_boundary

plasma = np.stack([n_p, v_r, v_theta, v_phi, p, b_r, b_theta, b_phi])
write_boundary("boundary.npz", plasma)
```

For an existing manuscript-style AWSoM array in CGS units, the converter follows the original angular subsampling and accounts for the northward convention of the stored meridional components:

```sh
snowpy prepare-awsom AwSOM_data_009.npz boundary.npz
```

The converter expects the original south-to-north latitude ordering and a duplicated longitude endpoint. It accepts a full `(8, 231, 181, 361)` cube in the original layout or a pre-extracted `(8, 181, 361)` shell at 20 R☉, stored in an NPY file or under the `data` key in an NPZ. Use NPY for memory-mapped access to a full volume.

## Predict with the CLI

```sh
snowpy predict boundary.npz solution.npz
snowpy predict boundary.npz solution-240.npz --outer-radius 240 --device cpu
```

The solution contains a float32 `plasma` array with axes `(field, radius, colatitude, longitude)`. At 250 R☉, the shape is `(8, 24, 91, 180)`. At 240 R☉, it is `(8, 23, 91, 180)`. The first shell is the supplied boundary in float32. The remaining shells are autoregressive predictions. The NPZ also includes `radius_rs`, `theta_deg`, `phi_deg`, `fields`, `units`, and `theta_direction`.

## Predict from Python

```python
from snowpy import SNOW, read_boundary

model = SNOW(device="auto")  # CUDA when available, CPU otherwise
boundary = read_boundary("boundary.npz")
solution = model.predict(boundary, outer_radius=240)
radial_speed_240 = solution.plasma[1, -1]
solution.save("solution-240.npz")
```

Reuse the same model object for multiple boundaries. `outer_radius` accepts 30 through 250 R☉ in increments of 10 R☉.

## Release checks

```sh
python -m pip install build twine
python -m pip install .
python -m unittest discover -s tests -v
SNOW_TEST_CHECKPOINT=/path/to/SNOW.pt python -m unittest discover -s tests -v
python -m build
python -m twine check dist/*
```

On the first release, check name availability and upload the verified artifacts to PyPI using the project owner's account. `snow-mhd` is the distribution name, `snowpy` is the Python module and command, and PyPI normalizes the project name to `snow-mhd`.

The inference architecture and checkpoint originate from *SNOW: Fast and Differentiable MHD Surrogate for Solar Wind using Neural Operator*, Prateek Mayank, Enrico Camporeale, Thomas Berger, Zhenguang Huang, and Gabor Toth. [Zenodo archive](https://doi.org/10.5281/zenodo.23090129)
