SpectrumFile#

class ansys.speos.core.input_files.spectrum_file.SpectrumFile(wavelengths=_DEFAULT_WAVELENGTHS, values=_DEFAULT_VALUES, description=_DEFAULT_DESCRIPTION, *, percent=True)#

Bases: ansys.speos.core.input_files._base.SpeosTextFileFormat

Speos *.spectrum file, holding a sampled spectral distribution.

The file is the text (v1) flavor of the format: a header line, a description, the number of samples, then one wavelengthvalue line per sample. Files are read and written locally, no Speos server is needed.

Parameters:
wavelengthsSequence[float], optional

Wavelengths of the samples, in nm. By default, 11 wavelengths from 360 nm to 830 nm in 47 nm steps.

valuesSequence[float], optional

Relative spectral values of the samples, in percent (0 to 100). By default, the values of the default 5200 K blackbody spectrum, normalized to 100 at its sampled maximum.

descriptionstr, optional

Free text written on the second line of the file. By default, "Blackbody at 5200.0 K".

percentbool, optional

Whether values are percentages limited to 0 to 100. By default, True. Set it to False for spectra in other units, such as the absorption and excitance spectra of a fluorescent dye in mm-1, whose values only need to be finite.

Parameters:
  • wavelengths (Sequence[float])

  • values (Sequence[float])

  • description (str)

  • percent (bool)

Notes

Called without arguments, the constructor creates the default 5200 K blackbody spectrum. Pass wavelengths and values together to describe another spectrum.

SpectrumFile.percent is a validation setting: it is not written to the file, and a loaded *.spectrum file has it set to True.

Construction and setters validate numeric data before storing it. List getters return copies; assign an edited list back to change the model. Empty columns permit staged construction, while SpectrumFile.validate() and save() require complete matching columns. To resize a populated spectrum, clear SpectrumFile.values, replace SpectrumFile.wavelengths, then assign the new values.

Examples

>>> from ansys.speos.core.input_files.spectrum_file import SpectrumFile
>>> SpectrumFile(wavelengths=[400.0, 700.0], values=[100.0, 50.0]).save("led.spectrum")

Overview#

from_sampled

Build a spectrum file from a sampled spectrum feature.

validate

Check the spectrum against the constraints of the *.spectrum format.

percent

Whether values are percentages limited to 0 to 100.

wavelengths

Wavelengths in nm, returned as a copy.

values

Spectral values, returned as a copy.

description

Single-line description.

EXTENSION

Usual file extension of the format.

HEADER

First line of the file. Empty when the format has no header line.

HEADER_PREFIX

Version-agnostic start of HEADER, used to validate a file being read.

Import detail#

from ansys.speos.core.input_files.spectrum_file import SpectrumFile

Property detail#

property SpectrumFile.percent: bool#

Whether values are percentages limited to 0 to 100.

Parameters:
valuebool

True to limit values to 0 to 100, False to only require finite values.

Returns:
bool

True if values are percentages.

Raises:
ValueError

If set to True while a stored value is outside 0 to 100.

property SpectrumFile.wavelengths: List[float]#

Wavelengths in nm, returned as a copy.

Parameters:
valuesSequence[float]

New wavelengths of the samples, in nm.

Returns:
List[float]

Finite sample wavelengths.

property SpectrumFile.values: List[float]#

Spectral values, returned as a copy.

Parameters:
valuesSequence[float]

New spectral values of the samples. In percent (0 to 100) when SpectrumFile.percent is True, otherwise any finite values.

Returns:
List[float]

Spectral values.

property SpectrumFile.description: str#

Single-line description.

Parameters:
valuestr

New free text written on the second line of the file.

Returns:
str

Free text written after the header.

Attribute detail#

SpectrumFile.EXTENSION = '.spectrum'#

Usual file extension of the format.

SpectrumFile.HEADER = 'OPTIS - Spectrum file v1'#

First line of the file. Empty when the format has no header line.

SpectrumFile.HEADER_PREFIX = 'OPTIS - Spectrum'#

Version-agnostic start of HEADER, used to validate a file being read.

Method detail#

SpectrumFile.validate()#

Check the spectrum against the constraints of the *.spectrum format.

Raises:
ValueError

If the sample lists are empty, do not have the same length, hold more than 32767 samples, or if SpectrumFile.percent is True and a value is outside the 0 to 100 percent range.

classmethod SpectrumFile.from_sampled(spectrum, description='')#

Build a spectrum file from a sampled spectrum feature.

The feature is a ansys.speos.core.spectrum.Spectrum object.

Parameters:
spectrumansys.speos.core.spectrum.Spectrum

Spectrum feature configured with Spectrum.set_sampled().

descriptionstr, optional

Free text written on the second line of the file. By default, "", which uses the name of the spectrum feature.

Returns:
ansys.speos.core.input_files.spectrum_file.SpectrumFile

Spectrum file model.

Raises:
ValueError

If spectrum is not of sampled type.