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 py2sess
For local development:
python3 -m pip install -e ".[torch,dev]"
The optional native backend uses the installed PyTorch shared libraries. Install PyTorch first when building native wheels from source or when using a backend that needs torch tensors.
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.
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
Metadata
Release files for py2sess 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py2sess-1.0.0.tar.gz | 13.3 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| py2sess-1.0.0-cp313-cp313-manylinux_2_27_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.27+ x86-64 | Details |
| py2sess-1.0.0-cp313-cp313-macosx_15_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 15.0+ ARM64 | Details |
| py2sess-1.0.0-cp312-cp312-manylinux_2_27_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.27+ x86-64 | Details |
| py2sess-1.0.0-cp312-cp312-macosx_15_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 15.0+ ARM64 | Details |
| py2sess-1.0.0-cp311-cp311-manylinux_2_27_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.27+ x86-64 | Details |
| py2sess-1.0.0-cp311-cp311-macosx_15_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 15.0+ ARM64 | Details |
| py2sess-1.0.0-cp310-cp310-manylinux_2_27_x86_64.whl | CPython 3.10 | CPython 3.10 | Linux glibc 2.27+ x86-64 | Details |
| py2sess-1.0.0-cp310-cp310-macosx_15_0_arm64.whl | CPython 3.10 | CPython 3.10 | macOS 15.0+ ARM64 | Details |
Total release size: 61.8 MB
Release files / py2sess-1.0.0.tar.gz
| Download URL | py2sess-1.0.0.tar.gz |
|---|---|
| Size | 13.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f79e34d92fc70558a0e8f867ea9ebcdda1a5ce3a55ec7ca8d34d6b3cd9114fe7
|
|
BLAKE2b-256 checksum How to use checksums |
c2326b56975853abcda5902a3b0215692f552c446919dc2472c43e9b722213ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / py2sess-1.0.0-cp313-cp313-manylinux_2_27_x86_64.whl
| Download URL | py2sess-1.0.0-cp313-cp313-manylinux_2_27_x86_64.whl |
|---|---|
| Size | 11.3 MB |
| Tags | CPython 3.13 Linux glibc 2.27+ x86-64 |
|
SHA-256 checksum How to use checksums |
95f418cbf6e094379909be8088160f3812c7aa1e98acfd5dc7b8a5a26ff6973a
|
|
BLAKE2b-256 checksum How to use checksums |
49bf26e7c048a25f125775bf84b447f1b6c671f036705e43eb22f05eecb2e9c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / py2sess-1.0.0-cp313-cp313-macosx_15_0_arm64.whl
| Download URL | py2sess-1.0.0-cp313-cp313-macosx_15_0_arm64.whl |
|---|---|
| Size | 826.2 kB |
| Tags | CPython 3.13 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0cdec79c9772f70c18687c3bb64b9b8f125a7f39b23ba34d46eab32e81695d6d
|
|
BLAKE2b-256 checksum How to use checksums |
69c72017c49f7deecfcfa0a118fe169ad456f583d0c4b0c930a4674f5f527121
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / py2sess-1.0.0-cp312-cp312-manylinux_2_27_x86_64.whl
| Download URL | py2sess-1.0.0-cp312-cp312-manylinux_2_27_x86_64.whl |
|---|---|
| Size | 11.3 MB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 |
|
SHA-256 checksum How to use checksums |
d0714626cd49cbc488780a338a8b8a750cdd4fdb2e29d382cedd1be03ba69163
|
|
BLAKE2b-256 checksum How to use checksums |
d848c4c4931ef43aa92873ec507be8296e588f88f1fe3427132d0bc4dfa3fb0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / py2sess-1.0.0-cp312-cp312-macosx_15_0_arm64.whl
| Download URL | py2sess-1.0.0-cp312-cp312-macosx_15_0_arm64.whl |
|---|---|
| Size | 832.5 kB |
| Tags | CPython 3.12 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c6dca613c0a97426e1bc5f3148b69981d58f39c0f77060514598d1b4c32b1fa5
|
|
BLAKE2b-256 checksum How to use checksums |
429ba8dc7b3ac99ad87f02a3faa98aa894651a5b4e83d94b4e2cdc180b8715bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / py2sess-1.0.0-cp311-cp311-manylinux_2_27_x86_64.whl
| Download URL | py2sess-1.0.0-cp311-cp311-manylinux_2_27_x86_64.whl |
|---|---|
| Size | 11.3 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 |
|
SHA-256 checksum How to use checksums |
e0cf0fd221a52bc02ba5b4277b40d32cf4a1eb1251e7a1af26d071203ad2381b
|
|
BLAKE2b-256 checksum How to use checksums |
53943d10d0f5bbef4530117bfe1fdba54fecec259501db2a32886764dadc40d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / py2sess-1.0.0-cp311-cp311-macosx_15_0_arm64.whl
| Download URL | py2sess-1.0.0-cp311-cp311-macosx_15_0_arm64.whl |
|---|---|
| Size | 825.5 kB |
| Tags | CPython 3.11 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
10f18f32baa3040c1f71954e1f7a83247efa42e43ee12a7c4ddaa8172e990e7d
|
|
BLAKE2b-256 checksum How to use checksums |
9102d5db9c387719e2ad99058972890b9c0e3efadf56c02ca52c8a1d133f9010
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / py2sess-1.0.0-cp310-cp310-manylinux_2_27_x86_64.whl
| Download URL | py2sess-1.0.0-cp310-cp310-manylinux_2_27_x86_64.whl |
|---|---|
| Size | 11.3 MB |
| Tags | CPython 3.10 Linux glibc 2.27+ x86-64 |
|
SHA-256 checksum How to use checksums |
0a7f13fc54ea4ade5e1fad54f0802ce1810d7af3c23abb9ce5fd214038431193
|
|
BLAKE2b-256 checksum How to use checksums |
9a07f4889e7bb94292c2a82691f4f551d2e944674e603ffe9cf713ec5c7e03ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency logRelease files / py2sess-1.0.0-cp310-cp310-macosx_15_0_arm64.whl
| Download URL | py2sess-1.0.0-cp310-cp310-macosx_15_0_arm64.whl |
|---|---|
| Size | 824.2 kB |
| Tags | CPython 3.10 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
55b6dff334da8a8a26fa92380a8d610ce93ab2fdd38df722afe0c11118256b1a
|
|
BLAKE2b-256 checksum How to use checksums |
4bd271af583d6271694ef027a17f86cdf4f7adfe46da650ea1cd77777b5f2348
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 25, 2026.
Transparency log