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.

allocate(self) None

Allocate memory for arrays based on configured dimensions.

solve(self) None

Run the DISORT solver.

print_state(pad: int | None = 0) None[source]

Print to the terminal the full state of the DISORT solver.

Parameters:

pad (int or None, default: 0) – Minimal amount of padding space between variable name and first “=” sign. Set to None to automatically align “=” signs. By default, no padding is applied.

Boolean flags

usrtau: bool

Return radiant quantities at user-specified optical thicknesses.

usrang: bool

Return radiant quantities at user-specified polar angles.

lamber: bool

Isotropically reflecting bottom boundary.

planck: bool

Include thermal emission.

spher: bool

Pseudo-spherical geometry (vs plane-parallel).

onlyfl: bool

Return only fluxes (not intensities).

quiet: bool

Suppress output messages.

intensity_correction: bool

Apply intensity correction.

old_intensity_correction: bool

Apply old-style intensity correction (may be required for some tests).

Dimensions

nstr: int

Number of streams (discretization of the azimuth angle dimension).

nlyr: int

Number of computational layers (discretization of the vertical dimension).

nmom: int

Number of phase function moments. Set to -1 to disable scattering.

ntau: int

Number of user optical thicknesses.

numu: int

Number of user polar angles.

nphi: int

Number of user azimuth angles.

nphase: int

Number of phase angle grid points for Buras-Emde correction.

Boundary conditions

fbeam: float

Intensity of incident parallel beam.

umu0: float

Polar angle cosine of incident beam.

phi0: float

Azimuth angle of incident beam (degrees).

fisot: float

Intensity of top-boundary isotropic illumination.

fluor: float

Intensity of bottom-boundary isotropic illumination.

albedo: float

Albedo of bottom boundary.

btemp: float

Temperature [K] of bottom boundary.

ttemp: float

Temperature [K] of top boundary.

temis: float

Emissivity of top boundary.

brdf_type: BRDFType

Type of BRDF (0=none, 4=Hapke). Set lamber=False to activate.

Other scalar parameters

accur: float

Convergence criterion for azimuthal series.

wvnmlo: float

Wavenumber lower bound [cm⁻¹] for Planck function.

wvnmhi: float

Wavenumber upper bound [cm⁻¹] for Planck function.

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].

pmom: ndarray[tuple[Any, ...], dtype[float64]]

Phase function moments [nmom_nstr+1, 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

umu: ndarray[tuple[Any, ...], dtype[float64]]

Polar angle cosines [numu].

phi: ndarray[tuple[Any, ...], dtype[float64]]

Azimuthal angles [degrees] [nphi].

utau: ndarray[tuple[Any, ...], dtype[float64]]

User optical thicknesses [ntau].

temper: ndarray[tuple[Any, ...], dtype[float64]]

Temperatures [K] at levels [nlyr+1].

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].

flup: ndarray[tuple[Any, ...], dtype[float64]]

Diffuse upward flux [ntau].

dfdt: ndarray[tuple[Any, ...], dtype[float64]]

Flux divergence d(net flux)/d(optical thickness) [ntau].

uavg: ndarray[tuple[Any, ...], dtype[float64]]

Mean intensity including direct beam [ntau].

uavgdn: ndarray[tuple[Any, ...], dtype[float64]]

Mean diffuse downward intensity [ntau].

uavgup: ndarray[tuple[Any, ...], dtype[float64]]

Mean diffuse upward intensity [ntau].

uavgso: ndarray[tuple[Any, ...], dtype[float64]]

Mean direct solar intensity [ntau].

Output arrays (read-only, intensity)

uu: ndarray[tuple[Any, ...], dtype[float64]]

Intensity at user angles [numu, ntau, nphi].

u0u: ndarray[tuple[Any, ...], dtype[float64]]

Azimuthally averaged intensity [numu, ntau].

uum: ndarray[tuple[Any, ...], dtype[float64]]

Intensity (corrected) at user angles [numu, ntau, nphi].

Output arrays (read-only, special boundary condition)

albmed: ndarray[tuple[Any, ...], dtype[float64]]

Albedo of medium [numu].

trnmed: ndarray[tuple[Any, ...], dtype[float64]]

Transmissivity of medium [numu].

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=True and lamber=True. These are enforced at allocation time, which means that this class does not achieve feature parity with DisortState.

__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.

solve(self) None

Solve all batch problems in parallel.

Status

nbatch: int

Number of batch items.

nthreads: int

Number of worker threads.

allocated: bool

Memory allocation status.

solved: bool

Whether solve() has been called.

Boolean flags

usrtau: bool

Return radiant quantities at user-specified optical thicknesses.

usrang: bool

Return radiant quantities at user-specified polar angles.

lamber: bool

Isotropically reflecting bottom boundary (must be True).

planck: bool

Include thermal emission.

spher: bool

Pseudo-spherical geometry.

onlyfl: bool

Return only fluxes (not intensities).

quiet: bool

Suppress output messages (must be True).

intensity_correction: bool

Apply intensity correction.

old_intensity_correction: bool

Apply old-style intensity correction.

Dimensions

nstr: int

Number of streams.

nlyr: int

Number of computational layers.

nmom: int

Number of phase function moments.

ntau: int

Number of user optical thicknesses.

numu: int

Number of user polar angles.

nphi: int

Number of user azimuth angles.

Shared boundary conditions

umu0: float

Polar angle cosine of incident beam.

phi0: float

Azimuth angle of incident beam (degrees).

fisot: float

Intensity of top-boundary isotropic illumination.

fluor: float

Intensity of bottom-boundary isotropic illumination.

btemp: float

Temperature [K] of bottom boundary.

ttemp: float

Temperature [K] of top boundary.

temis: float

Emissivity of top boundary.

Other shared scalar parameters

accur: float

Convergence criterion for azimuthal series.

wvnmlo: float

Wavenumber lower bound [cm⁻¹].

wvnmhi: float

Wavenumber upper bound [cm⁻¹].

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)

rfldir: ndarray[tuple[Any, ...], dtype[float64]]

Direct beam flux [nbatch, ntau].

rfldn: ndarray[tuple[Any, ...], dtype[float64]]

Diffuse downward flux [nbatch, ntau].

flup: ndarray[tuple[Any, ...], dtype[float64]]

Diffuse upward flux [nbatch, ntau].

dfdt: ndarray[tuple[Any, ...], dtype[float64]]

Flux divergence [nbatch, ntau].

uavg: ndarray[tuple[Any, ...], dtype[float64]]

Mean intensity [nbatch, ntau].

uavgdn: ndarray[tuple[Any, ...], dtype[float64]]

Mean diffuse downward intensity [nbatch, ntau].

uavgup: ndarray[tuple[Any, ...], dtype[float64]]

Mean diffuse upward intensity [nbatch, ntau].

uavgso: ndarray[tuple[Any, ...], dtype[float64]]

Mean direct solar intensity [nbatch, ntau].

Output arrays (read-only, intensity)

uu: ndarray[tuple[Any, ...], dtype[float64]]

Intensity [nbatch, numu, ntau, nphi].

class nanodisort.BRDFType[source]

BRDF model type for non-Lambertian surface reflection.

Pass to DisortState.brdf_type together with lamber=False to activate a bidirectional reflectance model.

NONE = 0
HAPKE = 4
__new__(value)