eradiate.scenes.spectra.InterpolatedSpectrum#

class eradiate.scenes.spectra.InterpolatedSpectrum(id=None, quantity=None, *, wavelengths, values)[source]#

Bases: Spectrum

Linearly interpolated spectrum [interpolated].

Class method constructors

from_dataarray([id, quantity])

Construct an interpolated spectrum from an xarray data array.

Parameters:
  • id (str, optional) – Identifier of the current scene element.

  • quantity (PhysicalQuantity or str, optional, default: None) – Physical quantity which the spectrum represents. The specified quantity must be one which varies with wavelength. See PhysicalQuantity.spectrum() for allowed values.

    Child classes should implement value units validation and conversion based on quantity.

  • wavelengths (quantity) – Wavelengths defining the interpolation grid. Values must be monotonically increasing.

  • values (array-like) – Spectrum values. If a quantity is passed, units are checked for consistency. If a unitless array is passed, it is automatically converted to appropriate default configuration units, depending on the value of the quantity field. If no quantity is specified, this field can be a unitless value.

Fields:
  • id (str or None) – Identifier of the current scene element.

  • quantity (PhysicalQuantity or None) – Physical quantity which the spectrum represents.

  • wavelengths (quantity) – Wavelengths defining the interpolation grid.

  • values (quantity) – Spectrum values.

Notes

Interpolation uses numpy.interp(). Evaluation is as follows:

  • in mono_* modes, the spectrum is evaluated at the spectral context wavelength;

  • in ckd_* modes, the spectrum is evaluated as the average value over the spectral context bin (the integral is computed using a trapezoid rule).

eval(si)#

Evaluate spectrum at a given spectral index.

Parameters:

si (SpectralIndex) – Spectral index.

Returns:

value (quantity) – Evaluated spectrum.

Notes

This method dispatches evaluation to specialized methods depending on the spectral index type.

eval_ckd(w, g)[source]#

Evaluate spectrum in CKD modes.

Parameters:
  • w (quantity) – Spectral bin center wavelength.

  • g (float) – Absorption coefficient cumulative probability.

Returns:

value (quantity) – Evaluated spectrum as an array with shape w.

Notes

It is assumed that w and g have the same shape. In CKD mode, it is assumed that all spectra—except that of the absorption coefficient—are uniform over the spectral bin. These spectra are evaluated at the spectral bin center wavelength.

eval_mono(w)[source]#

Evaluate spectrum in monochromatic modes.

Parameters:

w (quantity) – Wavelength.

Returns:

value (quantity) – Evaluated spectrum as an array with the same shape as w.

classmethod from_dataarray(id=None, quantity=None, *, dataarray)[source]#

Construct an interpolated spectrum from an xarray data array.

Parameters:
  • id (str, optional) – Optional object identifier.

  • quantity (str or PhysicalQuantity, optional) – If set, quantity represented by the spectrum. This parameter and spectrum units must be consistent. This parameter takes precedence over the quantity field of the data array.

  • dataarray (DataArray) – An xarray.DataArray instance complying to the spectrum data array format (see Notes).

Notes

  • Expected data format:

    Coordinates (* means also dimension)

    • *w (float): wavelength (units specified as a units attribute).

    Metadata

    • quantity (str): physical quantity which the data describes (see PhysicalQuantity.spectrum() for allowed values), optional.

    • units (str): units of spectrum values (must be consistent with quantity).

integral(wmin, wmax)[source]#

Compute the integral of the spectrum on a given interval.

Parameters:
  • wmin (quantity) – Integration interval’s lower bound.

  • wmax (quantity) – Integration interval’s upper bound.

Returns:

value (quantity or ndarray) – Computed integral value, in units consistent with the specified quantity.

Warning

If the quantity field is unset (i.e. left to its default value None), the output of this method will inherit the units of value fields (the actual policy depends on the implementation, and unitless values are intepreted as dimnesionless). Note that leaving the quantity field unset is discouraged.

select_in(spectral_set)#

Select a subset of a spectral set.

Parameters:

spectral_set (BinSet or WavelengthSet) – Spectral set.

Returns:

subset (BinSet or WavelengthSet) – Subset of the spectral set.

Notes

This method is only relevant to subclasses used to represent spectral response function (the default implementation raises a NotImplementedError). In this context, the spectral response function acts as a sort of filter that selects a subset of a spectral set, e.g. where the response is non-zero. This method is useful for Experiment objects to determine which spectral set is relevant for a given sensor.

select_in_wavelength_set(wset)[source]#

Selects the wavelengths that are included in the wavelength interval where the spectrum evaluates to a non-zero value.

Parameters:

wset (WavelengthSet) – Wavelength set.

Returns:

WavelengthSet – Wavelength set.

traverse(callback)#

Traverse this scene element and collect kernel dictionary template and parameter update map contributions.

Parameters:

callback (SceneTraversal) – Callback data structure storing the collected data.

update()[source]#

Enforce internal state consistency. This method should be called when fields are modified. It is automatically called as a post-init step.

property objects#

Map of child objects associated with this scene element.

Returns:

dict – A dictionary mapping object names to a corresponding object to be inserted in the Eradiate scene graph.

property params#
Returns:

dict[str, UpdateParameter] or None – A dictionary mapping parameter paths, consisting of dot-separated strings, to a corresponding update protocol.

property template#

Kernel dictionary template contents associated with this scene element.

Returns:

dict – A flat dictionary mapping dot-separated strings describing the path of an item in the nested scene dictionary to values. Values may be objects which can be directly used by the mitsuba.load_dict() function, or InitParameter instances which must be rendered.