Standalone Python implementation of the optimized 2S-ESS forward model.
Project description
py2sess
py2sess is a Python implementation of the optimized 2S-ESS radiative-transfer
model. It supports solar and thermal forward calculations with NumPy and
optional torch backends. It does not call the original Fortran code.
Install
python3 -m pip install .
python3 -m pip install -e ".[torch,dev]"
The optional native backend requires PyTorch:
python3 -m pip install "py2sess[native]"
For source-tree runs without installation, set PYTHONPATH=src.
Build
py2sess uses CMake through scikit-build-core. By default, source builds
prepare the Python package without compiling the optional native backend.
cmake -S . -B build
cmake --build build
python3 -m build
To build a local wheel with the native backend, install PyTorch and build without PEP 517 isolation so CMake can find Torch:
python3 -m pip install build scikit-build-core setuptools-scm torch
python3 -m build --wheel --no-isolation -Ccmake.define.PY2SESS_BUILD_NATIVE=ON
Native wheels link against the PyTorch shared libraries supplied by the
installed torch package.
Releases are tagged from merged PRs by GitHub Actions. Add a release:major,
release:minor, or release:patch label to the PR before merging; the default
is release:patch.
PyPI publication uses Trusted Publishing. Configure PyPI to trust
happysky19/py2sess, workflow .github/workflows/release.yml, and the pypi
GitHub environment, then run the Publish to PyPI GitHub Actions workflow for
the tag. The release workflow currently publishes macOS arm64 native wheels and
the source distribution.
Quick Start
Solar:
import numpy as np
from py2sess import TwoStreamEss, TwoStreamEssOptions
solver = TwoStreamEss(TwoStreamEssOptions(nlyr=3, mode="solar"))
result = solver.forward(
tau=np.full(3, 0.02),
ssa=np.full(3, 0.2),
g=np.full(3, 0.1),
z=np.array([3.0, 2.0, 1.0, 0.0]),
angles=[30.0, 20.0, 0.0], # sza, vza, relative azimuth
albedo=0.3,
)
print(result.radiance)
Thermal:
solver = TwoStreamEss(TwoStreamEssOptions(nlyr=3, mode="thermal"))
result = solver.forward(
tau=np.full(3, 0.1),
ssa=np.zeros(3),
g=np.zeros(3),
z=np.array([3.0, 2.0, 1.0, 0.0]),
angles=20.0,
planck=np.array([1.0, 1.1, 1.2, 1.3]),
surface_planck=1.4,
emissivity=1.0,
)
Batched wavelengths use leading dimensions:
solver = TwoStreamEss(TwoStreamEssOptions(nlyr=3, mode="thermal"))
tau = np.full((100, 3), 0.02)
result = solver.forward(
tau=tau,
ssa=np.zeros_like(tau),
g=np.zeros_like(tau),
z=np.array([3.0, 2.0, 1.0, 0.0]),
angles=20.0,
planck=np.ones((100, 4)),
surface_planck=np.ones(100),
emissivity=np.ones(100),
)
print(result.radiance.shape) # (100,)
Level fluxes use the final axis for TOA-to-BOA levels. This clear absorbing solar case has an analytic Beer-Lambert flux solution:
import numpy as np
from py2sess import TwoStreamEss, TwoStreamEssOptions
sza = 30.0
mu0 = np.cos(np.deg2rad(sza))
fbeam = 1.0
tau = np.array([0.1, 0.2])
z = np.array([2.0, 1.0, 0.0])
solver = TwoStreamEss(
TwoStreamEssOptions(
nlyr=tau.size,
mode="solar",
plane_parallel=True,
delta_scaling=False,
downwelling=True,
output_levels=True,
output_fluxes=True,
fo_flux_n_mu=8,
)
)
result = solver.forward(
tau=tau,
ssa=np.zeros_like(tau), # pure absorption
g=np.zeros_like(tau),
z=z,
angles=[sza, 0.0, 0.0],
fbeam=fbeam,
albedo=0.0, # black surface: no upward reflected flux
delta_m_truncation_factor=np.zeros_like(tau),
include_fo=True,
)
level_tau = np.concatenate(([0.0], np.cumsum(tau)))
analytic_down = fbeam * mu0 * np.exp(-level_tau / mu0)
np.testing.assert_allclose(result.flux_down[0], analytic_down, atol=1.0e-9)
np.testing.assert_allclose(result.flux_up[0], 0.0, atol=1.0e-8)
np.testing.assert_allclose(result.flux_net, result.flux_up - result.flux_down)
print(result.flux_down[0])
Torch CPU float64:
solver = TwoStreamEss(
TwoStreamEssOptions(nlyr=3, mode="solar", backend="torch", torch_dtype="float64")
)
API Notes
Core inputs are tau, ssa, g, z, angles, and the surface/source terms
needed by the selected mode. Solar angles are [sza, vza, raz] in degrees;
thermal angles are viewing zenith angles. Heights are in km, ordered top to
bottom.
See docs/api_arguments.md for the full argument
table and conventions.
Level-flux conventions are summarized in
docs/level_fluxes.md.
Examples
python3 examples/level_flux_beer_lambert.py
python3 examples/build_thermal_source_from_temperature.py
python3 examples/retrieve_synthetic_spectra.py --case uv --noise-level 0
Scene/profile runs:
from py2sess.scene import load_scene
scene = load_scene(profile="profile.txt", config="scene.yaml")
result = scene.forward(backend="numpy", include_fo=True)
Full-spectrum benchmark details are in
docs/full_spectrum_benchmarks.md.
Tests
python3 -m unittest discover -s tests -v
python3 -m ruff check .
python3 -m ruff format --check .
Full-spectrum benchmarks use profile text plus scene YAML inputs and Python optical preprocessing. Keep large local cross-section tables, benchmark bundles, and generated outputs out of git.
References
- Fortran repository: vnatraj1/2S-ESS
- Paper: Natraj et al., 2022, JQSRT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py2sess-0.4.2.tar.gz.
File metadata
- Download URL: py2sess-0.4.2.tar.gz
- Upload date:
- Size: 13.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dad35b2be977df482971a4714b965e7bafcf8046d8d87bf8ae64d3235e3e513
|
|
| MD5 |
64690fb1c91a2386c686b031d14aedeb
|
|
| BLAKE2b-256 |
6d1b83f54f4b1d42d91bed712de4bb682ab9fa9390520fb780babf0391e18357
|
Provenance
The following attestation bundles were made for py2sess-0.4.2.tar.gz:
Publisher:
release.yml on happysky19/py2sess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py2sess-0.4.2.tar.gz -
Subject digest:
3dad35b2be977df482971a4714b965e7bafcf8046d8d87bf8ae64d3235e3e513 - Sigstore transparency entry: 1630245688
- Sigstore integration time:
-
Permalink:
happysky19/py2sess@666689b5dc5968fdda461a51f113058a3ec6e3aa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/happysky19
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@666689b5dc5968fdda461a51f113058a3ec6e3aa -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file py2sess-0.4.2-cp313-cp313-macosx_15_0_arm64.whl.
File metadata
- Download URL: py2sess-0.4.2-cp313-cp313-macosx_15_0_arm64.whl
- Upload date:
- Size: 816.7 kB
- Tags: CPython 3.13, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd76f008c8c4db6dacc3dbe6277c2cc5821e7ecbfe8d71e254f293ec56b63f7a
|
|
| MD5 |
906f03b7bebfe04b420ba36612aca15b
|
|
| BLAKE2b-256 |
722002d48acdf9af200851c467dad5fa6c2e2efc2f294eb1e85c8c954cd5eb29
|
Provenance
The following attestation bundles were made for py2sess-0.4.2-cp313-cp313-macosx_15_0_arm64.whl:
Publisher:
release.yml on happysky19/py2sess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py2sess-0.4.2-cp313-cp313-macosx_15_0_arm64.whl -
Subject digest:
cd76f008c8c4db6dacc3dbe6277c2cc5821e7ecbfe8d71e254f293ec56b63f7a - Sigstore transparency entry: 1630245705
- Sigstore integration time:
-
Permalink:
happysky19/py2sess@666689b5dc5968fdda461a51f113058a3ec6e3aa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/happysky19
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@666689b5dc5968fdda461a51f113058a3ec6e3aa -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file py2sess-0.4.2-cp312-cp312-macosx_15_0_arm64.whl.
File metadata
- Download URL: py2sess-0.4.2-cp312-cp312-macosx_15_0_arm64.whl
- Upload date:
- Size: 816.7 kB
- Tags: CPython 3.12, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccdeb779891cf416e8a7821fbff273b33ae04a9021de8580c8663bb3ab8da9a7
|
|
| MD5 |
f6ace30167ee95460034fcbc03dfb43d
|
|
| BLAKE2b-256 |
fb88b1c7dd32a52205cdebb1974be64e58b9a4dfa318ff3ea69df3415f9d484a
|
Provenance
The following attestation bundles were made for py2sess-0.4.2-cp312-cp312-macosx_15_0_arm64.whl:
Publisher:
release.yml on happysky19/py2sess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py2sess-0.4.2-cp312-cp312-macosx_15_0_arm64.whl -
Subject digest:
ccdeb779891cf416e8a7821fbff273b33ae04a9021de8580c8663bb3ab8da9a7 - Sigstore transparency entry: 1630245719
- Sigstore integration time:
-
Permalink:
happysky19/py2sess@666689b5dc5968fdda461a51f113058a3ec6e3aa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/happysky19
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@666689b5dc5968fdda461a51f113058a3ec6e3aa -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file py2sess-0.4.2-cp311-cp311-macosx_15_0_arm64.whl.
File metadata
- Download URL: py2sess-0.4.2-cp311-cp311-macosx_15_0_arm64.whl
- Upload date:
- Size: 816.0 kB
- Tags: CPython 3.11, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d2c6b629ea900810e931c603ff1aff509eb8b4e2114204658458ea2438a3a6c
|
|
| MD5 |
f6ad02f154a48e762ad493caacf2ea7e
|
|
| BLAKE2b-256 |
9cf0d2868b2119d3996b42c8dd2ad870df1d2f094cf496a65f870cd367fe700c
|
Provenance
The following attestation bundles were made for py2sess-0.4.2-cp311-cp311-macosx_15_0_arm64.whl:
Publisher:
release.yml on happysky19/py2sess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py2sess-0.4.2-cp311-cp311-macosx_15_0_arm64.whl -
Subject digest:
0d2c6b629ea900810e931c603ff1aff509eb8b4e2114204658458ea2438a3a6c - Sigstore transparency entry: 1630245697
- Sigstore integration time:
-
Permalink:
happysky19/py2sess@666689b5dc5968fdda461a51f113058a3ec6e3aa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/happysky19
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@666689b5dc5968fdda461a51f113058a3ec6e3aa -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file py2sess-0.4.2-cp310-cp310-macosx_15_0_arm64.whl.
File metadata
- Download URL: py2sess-0.4.2-cp310-cp310-macosx_15_0_arm64.whl
- Upload date:
- Size: 814.8 kB
- Tags: CPython 3.10, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8c64f75aa3fe2f04338d260b04e480e4f4ab2960d27155d186c8d6e070cf935
|
|
| MD5 |
4df456edcc818606e6517c22d0710bbf
|
|
| BLAKE2b-256 |
e0cf0dee0bfd1afb165f4c8db6d377f8d2585176ea7efeaf0618734405f614cf
|
Provenance
The following attestation bundles were made for py2sess-0.4.2-cp310-cp310-macosx_15_0_arm64.whl:
Publisher:
release.yml on happysky19/py2sess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py2sess-0.4.2-cp310-cp310-macosx_15_0_arm64.whl -
Subject digest:
d8c64f75aa3fe2f04338d260b04e480e4f4ab2960d27155d186c8d6e070cf935 - Sigstore transparency entry: 1630245732
- Sigstore integration time:
-
Permalink:
happysky19/py2sess@666689b5dc5968fdda461a51f113058a3ec6e3aa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/happysky19
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@666689b5dc5968fdda461a51f113058a3ec6e3aa -
Trigger Event:
workflow_dispatch
-
Statement type: