6.8. tracer.spectrum Submodule

6.8.1. tracer.spectrum.light_spectrum

class optrace.tracer.spectrum.light_spectrum.LightSpectrum(spectrum_type='Blackbody', T=5500, **sargs)

Create a LightSpectrum, compared to the Spectrum parent class this provides rendering of spectra and the generation of random wavelengths. As well as two additional types (Blackbody and Histogram)

Parameters:
  • spectrum_type (str) – spectrum type, one of “spectrum_types”

  • T (float) – blackbody temperature in Kelvin

  • sargs

static render(wl, w, **kwargs)

Render a LightSpectrum from a list of wavelengths and powers. The resulting LightSpectrum has type “Histogram” and unit W/nm

Parameters:
  • wl (ndarray) – wavelength array

  • w (ndarray) – weight array

  • kwargs – additional keyword arguments when creating the LightSpectrum

Returns:

the LightSpectrum object

Return type:

Self

__call__(wl)

Get the spectrum values

Parameters:

wl (list | ndarray | float) – wavelength array

Returns:

values at provided wavelengths

Return type:

ndarray

centroid_wavelength()

The centroid wavelength. This is the center of mass wavelength according to its spectral power. Another name would be “power-weighted average wavelength”.

Returns:

centroid wavelength in nm

Return type:

float

color(rendering_intent='Ignore', clip=False, L_th=0.0, chroma_scale=0.0)

Get the sRGB color of the spectrum

Parameters:
  • rendering_intent (str) – rendering intent for the sRGB conversion

  • clip (bool) – if values are clipped to the [0, 1] data range

  • L_th (float)

  • chroma_scale (float)

Returns:

tuple of 3 sRGB values

Return type:

tuple[float, float, float]

complementary_wavelength()

Complementary wavelength of the spectrum, that is the wavelength with the opposite hue.

Returns:

complementary wavelength in nm if any exists, else np.nan

Return type:

float

dominant_wavelength()

Dominant wavelength of the spectrum, that is the wavelength with the same hue.

Returns:

dominant wavelength in nm if any exists, else np.nan

Return type:

float

fwhm()

Return the full width half maximum (FWHM). The smallest distance to the half height is calculated on both sides of the highest peak in the spectrum.

Returns:

FWHM

Return type:

float

luminous_power()

Luminous power in lm of the spectrum

Returns:

luminous power

Return type:

float

peak()

Peak value of the spectrum.

Returns:

peak value in self.unit

Return type:

float

peak_wavelength()

Peak wavelength of the spectrum. For a spectrum with a constant maximum region (Constant, Rectangle) or multiple maxima the first one is returned.

Returns:

peak wavelength in nm

Return type:

float

power()

Power in W of the spectrum

Returns:

power

Return type:

float

random_wavelengths(N)

Generate random wavelengths following the spectral distribution.

Parameters:

N (int) – number of wavelengths

Returns:

wavelength array, shape (N,)

Return type:

ndarray

xyz()

Get the XYZ color of the spectrum

Returns:

3 element array of XYZ values

Return type:

ndarray

spectrum_types: list[str] = ['Monochromatic', 'Constant', 'Data', 'Lines', 'Rectangle', 'Gaussian', 'Function', 'Blackbody', 'Histogram']

possible spectrum types

6.8.2. tracer.spectrum.spectrum

class optrace.tracer.spectrum.spectrum.Spectrum(spectrum_type='Gaussian', val=1.0, lines=None, line_vals=None, wl=550.0, wl0=400.0, wl1=600.0, wls=None, vals=None, func=None, mu=550.0, sig=50.0, unit=None, quantity=None, func_args={}, **kwargs)

Create a Spectrum object. Most of the time this class isn’t used, as there are specific subclasses.

Parameters:
  • spectrum_type (str) – one of “spectrum_types”

  • val (float) – factor for types “Rectangle”, “Constant”, “Gaussian” etc.

  • lines (ndarray | list) – line wavelengths for “Lines” type

  • line_vals (ndarray | list) – line values for “Lines” type

  • wl (float) – wavelength for “Monochromatic” type

  • wl0 (float) – lower wavelength for “Rectangle” type

  • wl1 (float) – upper wavelength for “Rectangle” type

  • wls (ndarray) – wavelength list for “List” type

  • vals (ndarray) – values for “List” type

  • mu (float) – center wavelength for “Gaussian” type

  • sig (float) – standard deviation for “Gaussian” type

  • unit (str) – unit string

  • quantity (str) – quantity string

  • func (Callable[[ndarray], ndarray]) – spectrum function, must take a wavelength vector and return float values

  • func_args (dict) – dict of optional keyword arguments for func

  • kwargs – additional keyword arguments for the parent class

__call__(wl)

get spectrum values

Parameters:

wl (list | ndarray | float) – wavelength array

Returns:

values at provided wavelengths

Return type:

ndarray

get_desc(fallback=None)

get description :param fallback: unused parameter :return:

Parameters:

fallback (str)

Return type:

str

is_continuous()
Returns:

if the spectrum is continuous, thus not discrete

Return type:

bool

quantity: str = ''

spectrum quantity

spectrum_types: list[str] = ['Monochromatic', 'Constant', 'Data', 'Lines', 'Rectangle', 'Gaussian', 'Function']

possible spectrum types. Can be changed by subclasses

unit: str = ''

spectrum unit

6.8.3. tracer.spectrum.transmission_spectrum

class optrace.tracer.spectrum.transmission_spectrum.TransmissionSpectrum(spectrum_type='Gaussian', inverse=False, **sargs)

Define a TransmissionSpectrum object.

Parameters:
  • spectrum_type (str) – spectrum type, one of spectrum_types

  • inverse (bool) – if the function is inversed, meaning subtracted from 1. A transmittance function becomes an absorptance function.

  • sargs – additional parameters (See the Spectrum() constuctor)

__call__(wl)

Get the spectrum values

Parameters:

wl (list | ndarray | float) – wavelength array

Returns:

values at provided wavelengths

Return type:

ndarray

color(rendering_intent='Absolute', clip=True, L_th=0, chroma_scale=None)

Get the Spectrum sRGB color and the opacity.

Parameters:
  • rendering_intent – rendering_intent for sRGB conversion

  • clip – if values are clipped towards the sRGB data range

Returns:

tuple of R, G, B, and the opacity, all with data range [0, 1]

Return type:

tuple[float, float, float, float]

xyz()

Get the Spectrum XYZ Color under daylight D65

Returns:

3 element XYZ color array

Return type:

ndarray

spectrum_types: list[str] = ['Constant', 'Data', 'Rectangle', 'Gaussian', 'Function']

possible spectrum types. Can be changed by subclasses