# SpectralQuantity¶

class astropy.coordinates.SpectralQuantity(value, unit=None, doppler_rest=None, doppler_convention=None, **kwargs)[source]

One or more value(s) with spectral units.

The spectral units should be those for frequencies, wavelengths, energies, wavenumbers, or velocities (interpreted as Doppler velocities relative to a rest spectral value). The advantage of using this class over the regular Quantity class is that in SpectralQuantity, the u.spectral equivalency is enabled by default (allowing automatic conversion between spectral units), and a preferred Doppler rest value and convention can be stored for easy conversion to/from velocities.

Parameters
valuendarray or Quantity or SpectralQuantity

Spectral axis data values.

unitstr or Unit

Unit for the given data.

doppler_restQuantity, optional

The rest value to use for conversions from/to velocities

doppler_conventionstr, optional

The convention to use when converting the spectral data to/from velocities.

Attributes Summary

 doppler_convention The defined convention for conversions to/from velocity space. doppler_rest The rest value of the spectrum used for transformations to/from velocity space.

Methods Summary

 to(unit[, equivalencies, doppler_rest, …]) Return a new SpectralQuantity object with the specified unit. to_value(*args, **kwargs) The numerical value, possibly in a different unit.

Attributes Documentation

doppler_convention

The defined convention for conversions to/from velocity space.

Returns
str

One of ‘optical’, ‘radio’, or ‘relativistic’ representing the equivalency used in the unit conversions.

doppler_rest

The rest value of the spectrum used for transformations to/from velocity space.

Returns
Quantity

Rest value as an astropy Quantity object.

Methods Documentation

to(unit, equivalencies=[], doppler_rest=None, doppler_convention=None)[source]

Return a new SpectralQuantity object with the specified unit.

By default, the spectral equivalency will be enabled, as well as one of the Doppler equivalencies if converting to/from velocities.

Parameters
unitUnitBase instance, str

An object that represents the unit to convert to. Must be an UnitBase object or a string parseable by the units package, and should be a spectral unit.

equivalencieslist of equivalence pairs, optional

A list of equivalence pairs to try if the units are not directly convertible (along with spectral). See Equivalencies. If not provided or [], spectral equivalencies will be used. If None, no equivalencies will be applied at all, not even any set globally or within a context.

doppler_restQuantity, optional

The rest value used when converting to/from velocities. This will also be set at an attribute on the output SpectralQuantity.

The Doppler convention used when converting to/from velocities. This will also be set at an attribute on the output SpectralQuantity.

Returns
SpectralQuantity

New spectral coordinate object with data converted to the new unit.

to_value(*args, **kwargs)[source]

The numerical value, possibly in a different unit.

Parameters
unitUnitBase instance or str, optional

The unit in which the value should be given. If not given or None, use the current unit.

equivalencieslist of equivalence pairs, optional

A list of equivalence pairs to try if the units are not directly convertible (see Equivalencies). If not provided or [], class default equivalencies will be used (none for Quantity, but may be set for subclasses). If None, no equivalencies will be applied at all, not even any set globally or within a context.

Returns
valuendarray or scalar

The value in the units specified. For arrays, this will be a view of the data if no unit conversion was necessary.

to