eradiate.radprops.ParticleProperties#
- class eradiate.radprops.ParticleProperties(data)#
Bases:
objectAn interface to scattering particle radiative properties.
This class manages scattering particle radiative properties and implements interpolation routines to produce kernel-level input data.
The wrapped dataset is in the Prt-Core v1 format, optionally extended with any number of state dimensions inserted right after
w(see Extensions). Evaluation methods return one value per state-dimension grid point; interpolation along state dimensions is left to the caller (seeinterp()).- Parameters:
data (
xarray.Dataset) – Single-scattering property dataset.- Fields:
data (
xarray.Dataset) – Single-scattering property dataset.
- classmethod convert(value)#
Conversion logic:
If value is a ParticleProperties instance, return it.
If value is a string, attempt resolving it as a dataset keyword.
If value is a path-like, load the dataset into memory and close the file.
If value is a Dataset, initialize a ParticleProperties with it.
Notes
xr.load_dataset(eager) is used instead ofxr.open_dataset(lazy) so that the underlying file handle is closed immediately after reading. With lazy loading, the handle stays open until the dataset is garbage-collected. If construction later raises (e.g. a validator rejects the arguments), the partial object is kept alive by pytest’s traceback capture and the handle is never closed. This leads to handle accumulation and eventual C-level crashes in the HDF5/netCDF4 library.
- eval_ext(w)#
Evaluate the extinction coefficient at wavelength(s)
wby plain linear interpolation.
- eval_phase(w, resample_mu=False, n_mu=None)#
Evaluate the phase function at a single wavelength by spectral interpolation between the two bracketing dataset wavelengths.
- Parameters:
w (
quantity) – Query wavelength (scalar). Each call interpolates a single wavelength, since it may have a different bracketing pair and thus a different union mu grid; looping over an array of wavelengths, if ever needed, is left to the caller.resample_mu (
bool, optional) – IfFalse(default), return each state-dimension grid point’s own union of its two bracketing wavelengths’ native mu grids, as-is (see_eval_phase_interp_spectral()). IfTrue, additionally resample every grid point onto a common, fixed-size mu grid ofn_mupoints (see_eval_phase_resample_mu()).n_mu (
int, optional) – Target mu point count, used only whenresample_muisTrue. Defaults ton_iangleifhas_fixed_mu_grid, else2 * n_iangle, wheren_iangle = data.sizes["iangle"].
- Returns:
Notes
The spectral interpolation scheme is similar to libRadtran’s and weighs bracketing wavelengths by their scattering coefficient. When the two bracketing wavelengths have different mu grids, the phase function is resampled onto their union grid before interpolation.
- eval_pmom(w, clip=False)#
Evaluate Legendre moments at wavelength
wby interpolation.The two bracketing wavelengths are weighted by their scattering coefficient (extinction × single-scattering albedo). This ensures that a wavelength with no scattering contributes nothing to the interpolated phase function regardless of its spectral proximity. NaN values in the source data are treated as zero.
- Parameters:
- Returns:
- eval_ssa(w)#
Evaluate the single-scattering albedo at wavelength
w.- Parameters:
w (
quantity) – Query wavelength(s); scalar or array.- Returns:
quantity– Dimensionless SSA, shape(nw, *state_shape).
Notes
The spectral interpolation scheme weighs bracketing wavelengths with the extinction coefficient, similar to libRadtran. The interpolated SSA is computed as:
ssa(w) = [(1-t)*ext_l*ssa_l + t*ext_r*ssa_r] / ext(w)where
ext(w)is the linearly interpolated extinction coefficient. Whenext(w)is zero the method falls back to plain linear interpolation.
- interp(grid, query)#
Interpolate the array
gridat the points described byquery.grid’s axes correspond to some of this dataset’s dimensions. The coordinate values for those dimensions are read from this dataset. Each axis must have a matching entry inquery, keyed by dimension name. The axis order ofgridmust match the key order ofquery. Interpolation is linear. Query points are clipped to each dimension’s own coordinate range.- Parameters:
grid (
quantity) – Array of values to interpolate. Each axis corresponds to one of this dataset’s dimensions.query (
dict[str,quantity]) – Query points. One same-shaped array per dimension ofgrid, keyed by dimension name, in the same order asgrid’s axes.
- Returns:
quantity– Interpolated value, with the same shape asquery’s arrays.
- phase_dataset_at(w, state_idx=(), ext=None)#
Build a single-point Prt-Core v1 dataset at the given wavelength, from the exact state-dimension grid point
state_idx(no interpolation along state dimensions).- Parameters:
w (
quantity) – Wavelength at whichext/ssa/the phase function are evaluated (interpolated along the wavelength axis only).state_idx (
tuple[int,], optional) – Index along each ofstate_dims, in the same order. Empty (default) for a dataset without state dimensions.ext (
quantity, optional) – Extinction coefficient stored in the output dataset. Defaults to the value interpolated atwat grid pointstate_idx.
- Returns:
xr.Dataset– A Prt-Core v1 dataset with a single wavelength and no state dimension.- Raises:
ValueError – If
state_idxdoes not have one entry per state dimension.
- state_coord(name)#
Get the coordinate values of a state dimension.
- Parameters:
name (
str) – Name of the requested state dimension.- Returns:
quantity– Coordinate values of state dimensionname.- Raises:
ValueError – If
nameis not one ofstate_dims.
- property abs#
- Returns:
pint.Quantity– Absorption coefficient array, cached to minimize overhead.
- property ext#
- Returns:
pint.Quantity– Extinction coefficient array, cached to minimize overhead.
- property has_fixed_mu_grid#
- Returns:
bool–Trueiff all wavelengths and state-dimension grid points share an identical mu grid (samenanglesand samemuvalues). WhenTrue,eval_phaseusesn_iangleoutput points instead of2 * n_iangle, preserving the original grid exactly.
- property max_union_size#
- property particle_shape#
- Returns:
str– Particle shape, described as a string, inferred from dataset contents and cached to minimize overhead.
- property phase#
- Returns:
xarray.DataArray– Thephasevariable ofdata, transposed to(phamat, iangle, w, *state_dims)to ensure a correct layout during interpolation, cached to minimize overhead.
- property pmom#
- Returns:
xarray.DataArrayorNone– Thepmomvariable ofdata, transposed to(imom, w, *state_dims), cached to minimize overhead.Noneifdatahas nopmomvariable.
- property scat#
- Returns:
pint.Quantity– Scattering coefficient array, cached to minimize overhead.
- property ssa#
- Returns:
pint.Quantity– Single-scattering albedo array, cached to minimize overhead.
- property state_dims#
- Returns:
tuple[str,]– Names ofdata’s state dimensions: itsextvariable’s dimensions, excludingw. Empty for a plain Prt-Core v1 dataset.
- property state_shape#
- Returns:
tuple[int,]– Sizes ofstate_dims, in the same order.
- property w#
- Returns:
pint.Quantity– Wavelength array, cached to minimize overhead.