Metadata-Version: 2.4
Name: snow-mhd
Version: 0.1.1
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) gives a steady-state 3D MHD solution for a given boundary condition of solar wind plasma. 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☉.

## Install

Requires Python 3.10 or newer.

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

The 3.05 GB checkpoint is downloaded from [Zenodo](https://doi.org/10.5281/zenodo.23090129) and verified by size and SHA-256. You can skip the download command and let the first prediction fetch it automatically.

For GPU inference, install a CUDA-enabled PyTorch build for your system. For installation from this source directory, run `python -m pip install` .

## Boundary format

Provide the eight fields at **20 R☉** as a `plasma` array in `input.npz`, with shape `(8, 91, 180)`. The axes are field, colatitude, and longitude.

| Index | Field | Quantity | Unit |
| --- | --- | --- | --- |
| 0 | `n_p` | Proton number density | cm⁻³ |
| 1 | `v_r` | Outward radial velocity | km/s |
| 2 | `v_theta` | Southward velocity | 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 longitude `0°, 2°, …, 358°`. Include both poles and exclude the duplicate 360° column. Express vectors in this spherical basis, with theta components positive southward. All values must be finite, and density, radial velocity, and pressure must be positive.

Stack the eight field arrays in the order above and save them as `input.npz` using the following example.

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

# Each field is a (91, 180) array in the units above.
plasma = np.stack([n_p, v_r, v_theta, v_phi, p, b_r, b_theta, b_phi])
write_boundary("input.npz", plasma)
```

### Convert original AWSoM data

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

This command accepts the SNOW manuscript's original CGS data as a full `(8, 231, 181, 361)` cube or a `(8, 181, 361)` shell at 20 R☉. Supply an NPY file or an NPZ containing a `data` array. The converter downsamples the grid, reverses the original south-to-north row order, removes the duplicate longitude column, and converts units and northward meridional components to the conventions above. NPY allows memory-mapped access to full cubes.

## Run the model

```sh
snowpy predict input.npz output.npz
```

The default endpoint is 250 R☉. The model uses CUDA when available, otherwise CPU. To change the endpoint and device, run

```sh
snowpy predict input.npz output.npz --outer-radius 210 --device cpu
```

Use `--device cuda:0` to select a GPU. Endpoints from 30 to 250 R☉ are supported in steps of 10 R☉.

For an existing checkpoint, add `--checkpoint /path/to/SNOW.pt`. Downloaded checkpoints are cached under `~/.cache/snowpy`, or `$XDG_CACHE_HOME/snowpy` when set. Override the cache location with `SNOW_CACHE_DIR` or `--cache-dir`.

### Python API

```python
from snowpy import SNOW, read_boundary

model = SNOW(device="auto")
solution = model.predict(read_boundary("input.npz"), outer_radius=250)
solution.save("output.npz")

radial_speed_250 = solution.plasma[1, -1]  # (91, 180), km/s
```

## Output

`output.npz` contains the float32 `plasma` array with axes `(field, radius, colatitude, longitude)`.

| Endpoint | Shape | Radial coordinates |
| --- | --- | --- |
| 250 R☉ | `(8, 24, 91, 180)` | 20, 30, …, 250 R☉ |

The first shell preserves the supplied boundary in float32. Subsequent shells are predicted autoregressively. The file includes `radius_rs`, `theta_deg`, `phi_deg`, `fields`, `units`, and `theta_direction`. The saved arrays can be used for analysis and plotting.

## Source 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/*
```

## Reference

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