snow-mhd 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snow_mhd-0.1.0/LICENSE +21 -0
- snow_mhd-0.1.0/PKG-INFO +106 -0
- snow_mhd-0.1.0/README.md +87 -0
- snow_mhd-0.1.0/pyproject.toml +33 -0
- snow_mhd-0.1.0/setup.cfg +4 -0
- snow_mhd-0.1.0/src/snow_mhd.egg-info/PKG-INFO +106 -0
- snow_mhd-0.1.0/src/snow_mhd.egg-info/SOURCES.txt +19 -0
- snow_mhd-0.1.0/src/snow_mhd.egg-info/dependency_links.txt +1 -0
- snow_mhd-0.1.0/src/snow_mhd.egg-info/entry_points.txt +2 -0
- snow_mhd-0.1.0/src/snow_mhd.egg-info/requires.txt +3 -0
- snow_mhd-0.1.0/src/snow_mhd.egg-info/top_level.txt +1 -0
- snow_mhd-0.1.0/src/snowpy/__init__.py +18 -0
- snow_mhd-0.1.0/src/snowpy/__main__.py +4 -0
- snow_mhd-0.1.0/src/snowpy/_features.py +42 -0
- snow_mhd-0.1.0/src/snowpy/_model.py +612 -0
- snow_mhd-0.1.0/src/snowpy/awsom.py +40 -0
- snow_mhd-0.1.0/src/snowpy/checkpoint.py +62 -0
- snow_mhd-0.1.0/src/snowpy/cli.py +63 -0
- snow_mhd-0.1.0/src/snowpy/inference.py +164 -0
- snow_mhd-0.1.0/src/snowpy/io.py +81 -0
- snow_mhd-0.1.0/tests/test_snowpy.py +119 -0
snow_mhd-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Prateek Mayank and the SNOW contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
snow_mhd-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: snow-mhd
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: SNOW neural-operator inference for steady-state solar-wind MHD
|
|
5
|
+
Author: Prateek Mayank
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Zenodo, https://doi.org/10.5281/zenodo.23090129
|
|
8
|
+
Keywords: solar wind,MHD,heliophysics,neural operator
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy>=1.24
|
|
16
|
+
Requires-Dist: torch>=2.6
|
|
17
|
+
Requires-Dist: torch-harmonics==0.7.4
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# SNOW.py
|
|
21
|
+
|
|
22
|
+
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☉.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
After the PyPI release, install Python 3.10 or newer and run:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
python -m pip install snow-mhd
|
|
30
|
+
snowpy download-checkpoint
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
## Boundary format
|
|
38
|
+
|
|
39
|
+
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.
|
|
40
|
+
|
|
41
|
+
| Index | Name | Quantity | Unit |
|
|
42
|
+
| --- | --- | --- | --- |
|
|
43
|
+
| 0 | `n_p` | Proton number density | cm⁻³ |
|
|
44
|
+
| 1 | `v_r` | Outward radial velocity | km/s |
|
|
45
|
+
| 2 | `v_theta` | Southward velocity, along increasing colatitude | km/s |
|
|
46
|
+
| 3 | `v_phi` | Velocity along increasing longitude | km/s |
|
|
47
|
+
| 4 | `p` | Thermal pressure | nPa |
|
|
48
|
+
| 5 | `b_r` | Outward radial magnetic field | nT |
|
|
49
|
+
| 6 | `b_theta` | Southward magnetic field | nT |
|
|
50
|
+
| 7 | `b_phi` | Magnetic field along increasing longitude | nT |
|
|
51
|
+
|
|
52
|
+
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.
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import numpy as np
|
|
56
|
+
from snowpy import write_boundary
|
|
57
|
+
|
|
58
|
+
plasma = np.stack([n_p, v_r, v_theta, v_phi, p, b_r, b_theta, b_phi])
|
|
59
|
+
write_boundary("boundary.npz", plasma)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
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:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
snowpy prepare-awsom AwSOM_data_009.npz boundary.npz
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
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.
|
|
69
|
+
|
|
70
|
+
## Predict with the CLI
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
snowpy predict boundary.npz solution.npz
|
|
74
|
+
snowpy predict boundary.npz solution-240.npz --outer-radius 240 --device cpu
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
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`.
|
|
78
|
+
|
|
79
|
+
## Predict from Python
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from snowpy import SNOW, read_boundary
|
|
83
|
+
|
|
84
|
+
model = SNOW(device="auto") # CUDA when available, CPU otherwise
|
|
85
|
+
boundary = read_boundary("boundary.npz")
|
|
86
|
+
solution = model.predict(boundary, outer_radius=240)
|
|
87
|
+
radial_speed_240 = solution.plasma[1, -1]
|
|
88
|
+
solution.save("solution-240.npz")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Reuse the same model object for multiple boundaries. `outer_radius` accepts 30 through 250 R☉ in increments of 10 R☉.
|
|
92
|
+
|
|
93
|
+
## Release checks
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
python -m pip install build twine
|
|
97
|
+
python -m pip install .
|
|
98
|
+
python -m unittest discover -s tests -v
|
|
99
|
+
SNOW_TEST_CHECKPOINT=/path/to/SNOW.pt python -m unittest discover -s tests -v
|
|
100
|
+
python -m build
|
|
101
|
+
python -m twine check dist/*
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
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`.
|
|
105
|
+
|
|
106
|
+
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)
|
snow_mhd-0.1.0/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# SNOW.py
|
|
2
|
+
|
|
3
|
+
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☉.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
After the PyPI release, install Python 3.10 or newer and run:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
python -m pip install snow-mhd
|
|
11
|
+
snowpy download-checkpoint
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
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.
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
## Boundary format
|
|
19
|
+
|
|
20
|
+
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.
|
|
21
|
+
|
|
22
|
+
| Index | Name | Quantity | Unit |
|
|
23
|
+
| --- | --- | --- | --- |
|
|
24
|
+
| 0 | `n_p` | Proton number density | cm⁻³ |
|
|
25
|
+
| 1 | `v_r` | Outward radial velocity | km/s |
|
|
26
|
+
| 2 | `v_theta` | Southward velocity, along increasing colatitude | km/s |
|
|
27
|
+
| 3 | `v_phi` | Velocity along increasing longitude | km/s |
|
|
28
|
+
| 4 | `p` | Thermal pressure | nPa |
|
|
29
|
+
| 5 | `b_r` | Outward radial magnetic field | nT |
|
|
30
|
+
| 6 | `b_theta` | Southward magnetic field | nT |
|
|
31
|
+
| 7 | `b_phi` | Magnetic field along increasing longitude | nT |
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import numpy as np
|
|
37
|
+
from snowpy import write_boundary
|
|
38
|
+
|
|
39
|
+
plasma = np.stack([n_p, v_r, v_theta, v_phi, p, b_r, b_theta, b_phi])
|
|
40
|
+
write_boundary("boundary.npz", plasma)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
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:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
snowpy prepare-awsom AwSOM_data_009.npz boundary.npz
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
## Predict with the CLI
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
snowpy predict boundary.npz solution.npz
|
|
55
|
+
snowpy predict boundary.npz solution-240.npz --outer-radius 240 --device cpu
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
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`.
|
|
59
|
+
|
|
60
|
+
## Predict from Python
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from snowpy import SNOW, read_boundary
|
|
64
|
+
|
|
65
|
+
model = SNOW(device="auto") # CUDA when available, CPU otherwise
|
|
66
|
+
boundary = read_boundary("boundary.npz")
|
|
67
|
+
solution = model.predict(boundary, outer_radius=240)
|
|
68
|
+
radial_speed_240 = solution.plasma[1, -1]
|
|
69
|
+
solution.save("solution-240.npz")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Reuse the same model object for multiple boundaries. `outer_radius` accepts 30 through 250 R☉ in increments of 10 R☉.
|
|
73
|
+
|
|
74
|
+
## Release checks
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
python -m pip install build twine
|
|
78
|
+
python -m pip install .
|
|
79
|
+
python -m unittest discover -s tests -v
|
|
80
|
+
SNOW_TEST_CHECKPOINT=/path/to/SNOW.pt python -m unittest discover -s tests -v
|
|
81
|
+
python -m build
|
|
82
|
+
python -m twine check dist/*
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
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`.
|
|
86
|
+
|
|
87
|
+
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)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "snow-mhd"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "SNOW neural-operator inference for steady-state solar-wind MHD"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{name = "Prateek Mayank"}]
|
|
14
|
+
keywords = ["solar wind", "MHD", "heliophysics", "neural operator"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Intended Audience :: Science/Research",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"numpy>=1.24",
|
|
22
|
+
"torch>=2.6",
|
|
23
|
+
"torch-harmonics==0.7.4",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
snowpy = "snowpy.cli:main"
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Zenodo = "https://doi.org/10.5281/zenodo.23090129"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.packages.find]
|
|
33
|
+
where = ["src"]
|
snow_mhd-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: snow-mhd
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: SNOW neural-operator inference for steady-state solar-wind MHD
|
|
5
|
+
Author: Prateek Mayank
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Zenodo, https://doi.org/10.5281/zenodo.23090129
|
|
8
|
+
Keywords: solar wind,MHD,heliophysics,neural operator
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy>=1.24
|
|
16
|
+
Requires-Dist: torch>=2.6
|
|
17
|
+
Requires-Dist: torch-harmonics==0.7.4
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# SNOW.py
|
|
21
|
+
|
|
22
|
+
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☉.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
After the PyPI release, install Python 3.10 or newer and run:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
python -m pip install snow-mhd
|
|
30
|
+
snowpy download-checkpoint
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
## Boundary format
|
|
38
|
+
|
|
39
|
+
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.
|
|
40
|
+
|
|
41
|
+
| Index | Name | Quantity | Unit |
|
|
42
|
+
| --- | --- | --- | --- |
|
|
43
|
+
| 0 | `n_p` | Proton number density | cm⁻³ |
|
|
44
|
+
| 1 | `v_r` | Outward radial velocity | km/s |
|
|
45
|
+
| 2 | `v_theta` | Southward velocity, along increasing colatitude | km/s |
|
|
46
|
+
| 3 | `v_phi` | Velocity along increasing longitude | km/s |
|
|
47
|
+
| 4 | `p` | Thermal pressure | nPa |
|
|
48
|
+
| 5 | `b_r` | Outward radial magnetic field | nT |
|
|
49
|
+
| 6 | `b_theta` | Southward magnetic field | nT |
|
|
50
|
+
| 7 | `b_phi` | Magnetic field along increasing longitude | nT |
|
|
51
|
+
|
|
52
|
+
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.
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import numpy as np
|
|
56
|
+
from snowpy import write_boundary
|
|
57
|
+
|
|
58
|
+
plasma = np.stack([n_p, v_r, v_theta, v_phi, p, b_r, b_theta, b_phi])
|
|
59
|
+
write_boundary("boundary.npz", plasma)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
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:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
snowpy prepare-awsom AwSOM_data_009.npz boundary.npz
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
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.
|
|
69
|
+
|
|
70
|
+
## Predict with the CLI
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
snowpy predict boundary.npz solution.npz
|
|
74
|
+
snowpy predict boundary.npz solution-240.npz --outer-radius 240 --device cpu
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
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`.
|
|
78
|
+
|
|
79
|
+
## Predict from Python
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from snowpy import SNOW, read_boundary
|
|
83
|
+
|
|
84
|
+
model = SNOW(device="auto") # CUDA when available, CPU otherwise
|
|
85
|
+
boundary = read_boundary("boundary.npz")
|
|
86
|
+
solution = model.predict(boundary, outer_radius=240)
|
|
87
|
+
radial_speed_240 = solution.plasma[1, -1]
|
|
88
|
+
solution.save("solution-240.npz")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Reuse the same model object for multiple boundaries. `outer_radius` accepts 30 through 250 R☉ in increments of 10 R☉.
|
|
92
|
+
|
|
93
|
+
## Release checks
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
python -m pip install build twine
|
|
97
|
+
python -m pip install .
|
|
98
|
+
python -m unittest discover -s tests -v
|
|
99
|
+
SNOW_TEST_CHECKPOINT=/path/to/SNOW.pt python -m unittest discover -s tests -v
|
|
100
|
+
python -m build
|
|
101
|
+
python -m twine check dist/*
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
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`.
|
|
105
|
+
|
|
106
|
+
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)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/snow_mhd.egg-info/PKG-INFO
|
|
5
|
+
src/snow_mhd.egg-info/SOURCES.txt
|
|
6
|
+
src/snow_mhd.egg-info/dependency_links.txt
|
|
7
|
+
src/snow_mhd.egg-info/entry_points.txt
|
|
8
|
+
src/snow_mhd.egg-info/requires.txt
|
|
9
|
+
src/snow_mhd.egg-info/top_level.txt
|
|
10
|
+
src/snowpy/__init__.py
|
|
11
|
+
src/snowpy/__main__.py
|
|
12
|
+
src/snowpy/_features.py
|
|
13
|
+
src/snowpy/_model.py
|
|
14
|
+
src/snowpy/awsom.py
|
|
15
|
+
src/snowpy/checkpoint.py
|
|
16
|
+
src/snowpy/cli.py
|
|
17
|
+
src/snowpy/inference.py
|
|
18
|
+
src/snowpy/io.py
|
|
19
|
+
tests/test_snowpy.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
snowpy
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Steady-state solar-wind inference with SNOW."""
|
|
2
|
+
|
|
3
|
+
from .awsom import read_awsom_boundary
|
|
4
|
+
from .checkpoint import fetch_checkpoint
|
|
5
|
+
from .io import FIELDS, PHI_DEG, THETA_DEG, UNITS, Solution, read_boundary, write_boundary
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"FIELDS", "PHI_DEG", "THETA_DEG", "UNITS", "SNOW", "Solution",
|
|
9
|
+
"fetch_checkpoint", "read_awsom_boundary", "read_boundary", "write_boundary",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def __getattr__(name):
|
|
14
|
+
if name == "SNOW":
|
|
15
|
+
from .inference import SNOW
|
|
16
|
+
|
|
17
|
+
return SNOW
|
|
18
|
+
raise AttributeError(name)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Shared SNOW physical feature definitions.
|
|
2
|
+
|
|
3
|
+
These functions are intentionally batch-independent and contain no model or
|
|
4
|
+
dataset state, allowing training, inference, and invariant tests to use the
|
|
5
|
+
exact same implementation.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import torch
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
MASS_FLUX_STATS_VERSION = "rescaled_rho_ur_fixed_train_v1"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def signed_log_mass_flux_from_rescaled(
|
|
17
|
+
rho_rescaled: torch.Tensor,
|
|
18
|
+
ur: torch.Tensor,
|
|
19
|
+
r_ref_Rs: float = 20.0,
|
|
20
|
+
) -> torch.Tensor:
|
|
21
|
+
"""Return signed-log of the physical radial mass-flux invariant.
|
|
22
|
+
|
|
23
|
+
Dataset density is already ``rho_code * (r / r_ref)^2``. Therefore
|
|
24
|
+
``r_ref^2 * rho_rescaled * ur`` equals ``r^2 * rho_code * ur``. No live
|
|
25
|
+
radius factor belongs here.
|
|
26
|
+
"""
|
|
27
|
+
mass_flux = (float(r_ref_Rs) ** 2) * rho_rescaled * ur
|
|
28
|
+
return torch.sign(mass_flux) * torch.log10(1.0 + mass_flux.abs())
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def normalize_mass_flux(
|
|
32
|
+
signed_log_flux: torch.Tensor,
|
|
33
|
+
training_mean: torch.Tensor | float,
|
|
34
|
+
training_std: torch.Tensor | float,
|
|
35
|
+
eps: float = 1.0e-6,
|
|
36
|
+
) -> torch.Tensor:
|
|
37
|
+
"""Normalize with fixed training-set statistics; never use batch moments."""
|
|
38
|
+
mean = torch.as_tensor(
|
|
39
|
+
training_mean, device=signed_log_flux.device, dtype=signed_log_flux.dtype)
|
|
40
|
+
std = torch.as_tensor(
|
|
41
|
+
training_std, device=signed_log_flux.device, dtype=signed_log_flux.dtype)
|
|
42
|
+
return (signed_log_flux - mean) / std.clamp(min=float(eps))
|