nanodisort¶
- class nanodisort.DisortState[source]¶
DISORT solver state.
This class provides an interface to the CDISORT radiative transfer model. CDISORT is a C port of the original DISORT Fortran package. The main differences are:
Improved memory management. CDISORT allocates memory dynamically to use memory buffers of the right size, and internally encapsulates data in structs. This overall improves performance compared to the Fortran implementation.
Double precision. CDISORT operates entirely with double-precision arithmetics for improved numerical stability.
Correction of intensity fields by Buras-Emde algorithm, included by Robert Buras.
Pseudospherical geometry for direct beam source, included by Arve Kylling.
Solution for a general source term, included by Arve Kylling.
- __init__() None[source]¶
Initialize the DISORT state. All parameters are initialized with their default values.
- print_state(pad: int | None = 0) None[source]¶
Print to the terminal the full state of the DISORT solver.
Boolean flags
- old_intensity_correction: bool¶
Apply old-style intensity correction (may be required for some tests).
Dimensions
Boundary conditions
Other scalar parameters
Optical property arrays
- dtauc: ndarray[tuple[Any, ...], dtype[float64]]¶
Optical thicknesses of computational layers [nlyr].
- ssalb: ndarray[tuple[Any, ...], dtype[float64]]¶
Single-scattering albedo of computational layers [nlyr].
- phase: ndarray[tuple[Any, ...], dtype[float64]]¶
Phase function values [nlyr, nphase] for Buras-Emde correction.
- mu_phase: ndarray[tuple[Any, ...], dtype[float64]]¶
Phase angle cosines [nphase] for Buras-Emde correction.
Other input arrays
Output arrays (read-only, always present)
- rfldir: ndarray[tuple[Any, ...], dtype[float64]]¶
Direct beam flux (without delta-M scaling) [ntau].
- rfldn: ndarray[tuple[Any, ...], dtype[float64]]¶
Diffuse downward flux (without delta-M scaling) [ntau].
- dfdt: ndarray[tuple[Any, ...], dtype[float64]]¶
Flux divergence d(net flux)/d(optical thickness) [ntau].
Output arrays (read-only, intensity)
- uum: ndarray[tuple[Any, ...], dtype[float64]]¶
Intensity (corrected) at user angles [numu, ntau, nphi].
Output arrays (read-only, special boundary condition)
- class nanodisort.BatchSolver[source]¶
Parallel batch DISORT solver.
Solves multiple independent spectral problems in parallel using a C++ thread pool. Shared geometry and control flags are configured once on the solver instance; spectrally-varying optical properties (optical depths, single-scattering albedos, phase function moments, beam intensities, surface albedos) are provided as arrays with a leading batch dimension.
Examples
>>> import nanodisort as nd >>> import numpy as np >>> solver = nd.BatchSolver(nthreads=4) >>> solver.nstr = 8 >>> solver.nlyr = 1 >>> solver.nmom = 8 >>> solver.ntau = 2 >>> solver.usrtau = True >>> solver.usrang = False >>> solver.lamber = True >>> solver.onlyfl = True >>> solver.quiet = True >>> solver.umu0 = 1.0 >>> solver.phi0 = 0.0 >>> solver.set_utau(np.array([0.0, 1.0])) >>> nbatch = 10 >>> solver.allocate(nbatch) >>> solver.set_dtauc(np.ones((nbatch, 1))) >>> solver.set_ssalb(np.full((nbatch, 1), 0.9)) >>> pmom = np.zeros((9, 1, nbatch)) >>> pmom[0, :, :] = 1.0 >>> solver.set_pmom(pmom) >>> solver.set_fbeam(np.full(nbatch, np.pi)) >>> solver.set_albedo(np.zeros(nbatch)) >>> solver.solve() >>> rfldir = solver.rfldir # shape (nbatch, 2)
Warning
Thread safety requires
quiet=Trueandlamber=True. These are enforced at allocation time, which means that this class does not achieve feature parity withDisortState.- __init__(nthreads: int = 0) None[source]¶
Initialize the batch solver.
- Parameters:
nthreads (
int, optional) – Number of worker threads. 0 (default) uses hardware concurrency.
- allocate(self, nbatch: int) None¶
Allocate memory for nbatch parallel DISORT problems.
Must be called after setting shared dimensions and flags.
Status
Boolean flags
Dimensions
Shared boundary conditions
Other shared scalar parameters
Shared input arrays
- set_umu(self, umu: ndarray[dtype=float64, shape=(*), order='C', device='cpu']) None¶
Set shared polar angle cosines [numu].
- set_phi(self, phi: ndarray[dtype=float64, shape=(*), order='C', device='cpu']) None¶
Set shared azimuthal angles [nphi].
- set_utau(self, utau: ndarray[dtype=float64, shape=(*), order='C', device='cpu']) None¶
Set shared user optical thicknesses [ntau].
- set_temper(self, temper: ndarray[dtype=float64, shape=(*), order='C', device='cpu']) None¶
Set shared level temperatures [nlyr+1].
Batched input setters
- set_dtauc(self, dtauc: ndarray[dtype=float64, shape=(*, *), order='C', device='cpu']) None¶
Set optical thicknesses [nbatch, nlyr].
- set_ssalb(self, ssalb: ndarray[dtype=float64, shape=(*, *), order='C', device='cpu']) None¶
Set single-scattering albedos [nbatch, nlyr].
- set_pmom(self, pmom: ndarray[dtype=float64, shape=(*, *, *), order='F', device='cpu']) None¶
Set phase function moments [nmom_nstr+1, nlyr, nbatch] Fortran-contiguous.
- set_fbeam(self, fbeam: ndarray[dtype=float64, shape=(*), order='C', device='cpu']) None¶
Set incident beam intensities [nbatch].
- set_albedo(self, albedo: ndarray[dtype=float64, shape=(*), order='C', device='cpu']) None¶
Set bottom boundary albedos [nbatch].
- set_utau_batched(self, utau: ndarray[dtype=float64, shape=(*, *), order='C', device='cpu']) None¶
Set per-batch user optical thicknesses [nbatch, ntau].
Output arrays (read-only, always present)
Output arrays (read-only, intensity)