Installation and Quickstart
Install
pydisort is published on PyPI with prebuilt binary wheels, so no compiler or Fortran toolchain is needed on a matching platform:
python -m pip install pydisort
pip pulls in a compatible torch automatically.
Supported platforms
Requirement |
Supported |
|---|---|
Python |
CPython 3.10, 3.11, 3.12, 3.13, 3.14 |
Linux wheels |
x86-64, glibc 2.28 or newer (including the PyTorch dependency) |
macOS wheels |
Apple Silicon (arm64), macOS 15 or newer |
Dependencies |
|
The release workflow targets these platforms; consult the PyPI download files for available wheels. The workflow does not build wheels for Windows, Intel macOS, Linux ARM or free-threaded Python. A source build is not a guarantee of support on those targets.
The glibc floor of 2.28 is inherited from PyTorch v2.7 and later. Wheels are
built and published automatically with cibuildwheel through GitHub Actions.
Installing from source
PyPI releases publish wheels, not a source distribution. If no wheel matches,
pip install pydisort cannot automatically fall back to a source build.
Build from a repository checkout instead. Use the same activated Python
environment for CMake and pip:
git clone https://github.com/zoeyzyhu/pydisort.git
cd pydisort
python3 -m venv env
source env/bin/activate
python -m pip install --upgrade pip
python -m pip install 'torch==2.10.0' numpy 'cmake>=3.20' ninja \
setuptools 'setuptools-scm>=8' wheel
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF
cmake --build build --parallel
python -m pip install --no-build-isolation .
This builds the CPU configuration. A C++17 compiler is required (GCC 9 or
newer on Linux, or a compatible Apple Clang on macOS). CMake builds the C++
library first; setup.py only builds the Python bindings and links that
library. Build isolation is disabled to keep both stages on the same PyTorch
installation. To reproduce a release, check out its tag before building.
Verify the installation
>>> import pydisort
>>> pydisort.__version__
'1.8.5'
The quickstart below works directly with an installed wheel. For the Beer-Lambert example and the test suite, first obtain the repository files:
git clone https://github.com/zoeyzyhu/pydisort.git
cd pydisort
python examples/example_01_beam_attenuation.py
Use a checkout matching your installed release when validating a release.
The example ends with OK: direct beam reproduces the Beer-Lambert law to
machine precision. See Automated Tests for the full test suite.
Quickstart
Every pydisort program has the same two steps: describe the problem with a
pydisort.DisortOptions object, then run it by calling
forward on a tensor of optical properties.
import torch
from pydisort import Disort, DisortOptions
torch.set_default_dtype(torch.float64)
op = DisortOptions().flags("onlyfl,lamber")
op.ds().nlyr = 4
op.ds().nstr = 4
op.ds().nmom = 4
op.ds().nphase = 4
ds = Disort(op)
tau = torch.tensor([0.1, 0.2, 0.3, 0.4]).unsqueeze(-1)
flux = ds.forward(tau, fbeam=torch.tensor([3.14159]))
assert flux.shape == (1, 1, 5, 2)
print(flux)
tensor([[[[0.0000, 3.1416],
[0.0000, 2.8426],
[0.0000, 2.3273],
[0.0000, 1.7241],
[0.0000, 1.1557]]]])
The returned tensor has shape (nwave, ncol, nlvl, 2): wavelength, column,
level, and then upward and downward flux. User Guide explains those
dimensions in detail, and Example Usage works through complete calculations.
Tip
DISORT is a double-precision code. Call
torch.set_default_dtype(torch.float64) at the top of your script so that
accuracy is not limited by float32.
Common flags
Flags are passed as one comma-separated string to
flags. The ones needed most often are:
Flag |
Meaning |
|---|---|
|
Lambertian lower boundary. Almost always required; without it DISORT looks for a BRDF model and aborts. |
|
Compute fluxes only, skipping radiances. This is the fast path; use it unless you need directional intensities. |
|
Enable thermal emission. Requires a level temperature profile ( |
|
Return radiances at user-specified viewing angles. |
|
Return results at user-specified optical depths rather than at layer boundaries. |
|
Suppress cdisort’s internal printout. |
The full list is documented on pydisort.DisortOptions. Some backend
flags are recognized but not supported through Python; see
Flag availability in Python before enabling additional flags.
Where to go next
User Guide, input/output shapes, batching and singleton dimensions.
Example Usage, four complete, self-checking calculations, ending with a real-world solver-validation study.
API Reference, the full API reference.
Automated Tests, how to run and extend the test suite.
Performance, performance against cdisort and PythonicDISORT.
Building the C++ library
pydisort also ships a C++ API for embedding the solver in larger C or C++
simulation frameworks. Building it requires cmake (>= 3.20), a C++17
compiler and Python 3.10 or newer. Use the environment and source-build
procedure above. To enable the C, C++ and Python test targets afterwards:
python -m pip install pytest
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON
cmake --build build --parallel
python -m pip install --no-build-isolation .
ctest --test-dir build --output-on-failure
See Contributing for the contributor workflow.
Getting help
Bug reports and feature requests: GitHub issues
Common runtime errors are covered in Troubleshooting.