Spectrum1D¶

class
specutils.
Spectrum1D
(flux=None, spectral_axis=None, wcs=None, velocity_convention=None, rest_value=None, redshift=None, radial_velocity=None, **kwargs)[source]¶ Bases:
specutils.spectra.spectrum_mixin.OneDSpectrumMixin
,astropy.nddata.NDDataRef
Spectrum container for 1D spectral data.
 Parameters
 flux
astropy.units.Quantity
or astropy.nddata.NDData`like The flux data for this spectrum.
 spectral_axis
astropy.units.Quantity
Dispersion information with the same shape as the last (or only) dimension of flux.
 wcs
astropy.wcs.WCS
orgwcs.wcs.WCS
WCS information object.
 velocity_convention{“doppler_relativistic”, “doppler_optical”, “doppler_radio”}
Convention used for velocity conversions.
 rest_value
Quantity
Any quantity supported by the standard spectral equivalencies (wavelength, energy, frequency, wave number). Describes the rest value of the spectral axis for use with velocity conversions.
 redshift
See
redshift
for more information. radial_velocity
See
radial_velocity
for more information. uncertainty
NDUncertainty
Contains uncertainty information along with propagation rules for spectrum arithmetic. Can take a unit, but if none is given, will use the unit defined in the flux.
 metadict
Arbitrary container for any userspecific information to be carried around with the spectrum container object.
 flux
Attributes Summary
ndarray
like : The stored dataset.The energy of the spectral axis as a
Quantity
in units of eV.Converts the stored data and unit information into a quantity.
The frequency as a
Quantity
in units of GHzany type : Mask for the dataset, if any.
dict
like : Additional meta information about the dataset.The flux density of photons as a
Quantity
, in units of photons per cm^2 per second per spectral_axis unitThe radial velocity(s) of the objects represented by this spectrum.
read
(\*args, \*\*kwargs)The redshift(s) of the objects represented by this spectrum.
Returns a Quantity array with the values of the spectral axis.
Returns the units of the spectral axis.
Returns the spectral axes of the WCS
any type : Uncertainty in the dataset, if any.
Unit
: Unit for the dataset, if any.Converts the spectral axis array to the given velocity space unit given the rest value.
Returns the velocity convention
The wavelength as a
Quantity
in units of Angstromsany type : A world coordinate system (WCS) for the dataset, if any.
write
(\*args, \*\*kwargs)Methods Summary
add
(operand[, operand2])Performs addition by evaluating
self
+operand
.divide
(operand[, operand2])Performs division by evaluating
self
/operand
.multiply
(operand[, operand2])Performs multiplication by evaluating
self
*operand
.new_flux_unit
(self, unit[, equivalencies, …])Converts the flux data to the specified unit.
spectral_resolution
(self, true_dispersion, …)Evaluate the probability distribution of the spectral resolution.
subtract
(operand[, operand2])Performs subtraction by evaluating
self
operand
.with_spectral_unit
(self, unit[, …])Returns a new spectrum with a different spectral axis unit.
with_velocity_convention
(self, …)Attributes Documentation

bin_edges
¶

flux
¶ Converts the stored data and unit information into a quantity.
 Returns
Quantity
Spectral data as a quantity.

mask
¶ any type : Mask for the dataset, if any.
Masks should follow the
numpy
convention that valid data points are marked byFalse
and invalid ones withTrue
.

photon_flux
¶ The flux density of photons as a
Quantity
, in units of photons per cm^2 per second per spectral_axis unit

radial_velocity
¶ The radial velocity(s) of the objects represented by this spectrum. May be scalar (if this spectrum’s
flux
is 1D) or vector. Note that the concept of “RV of a spectrum” can be ambiguous, so the interpretation is set to some extent by either the user, or operations (like template fitting) that set this attribute when they are run on a spectrum.

read
(*args, **kwargs) = <astropy.nddata.mixins.ndio.NDDataRead object>¶

redshift
¶ The redshift(s) of the objects represented by this spectrum. May be scalar (if this spectrum’s
flux
is 1D) or vector. Note that the concept of “redshift of a spectrum” can be ambiguous, so the interpretation is set to some extent by either the user, or operations (like template fitting) that set this attribute when they are run on a spectrum.

rest_value
¶

shape
¶

spectral_axis
¶ Returns a Quantity array with the values of the spectral axis.

spectral_axis_unit
¶ Returns the units of the spectral axis.

spectral_wcs
¶ Returns the spectral axes of the WCS

uncertainty
¶ any type : Uncertainty in the dataset, if any.
Should have an attribute
uncertainty_type
that defines what kind of uncertainty is stored, such as'std'
for standard deviation or'var'
for variance. A metaclass defining such an interface isNDUncertainty
but isn’t mandatory.

velocity
¶ Converts the spectral axis array to the given velocity space unit given the rest value.
These aren’t input parameters but required Spectrum attributes
 Parameters
 unitstr or ~`astropy.units.Unit`
The unit to convert the dispersion array to.
 rest~`astropy.units.Quantity`
Any quantity supported by the standard spectral equivalencies (wavelength, energy, frequency, wave number).
 type{“doppler_relativistic”, “doppler_optical”, “doppler_radio”}
The type of doppler spectral equivalency.
 redshift or radial_velocity
If present, this shift is applied to the final output velocity to get into the rest frame of the object.
 Returns
 ~`astropy.units.Quantity`
The converted dispersion array in the new dispersion space.

velocity_convention
¶ Returns the velocity convention

wcs
¶ any type : A world coordinate system (WCS) for the dataset, if any.

write
(*args, **kwargs) = <astropy.nddata.mixins.ndio.NDDataWrite object>¶
Methods Documentation

classmethod
add
(operand, operand2=None, **kwargs)¶ Performs addition by evaluating
self
+operand
. Parameters
 operand, operand2
NDData
like instance or convertible to one. If
operand2
isNone
or not given it will perform the operationself
+operand
. Ifoperand2
is given it will performoperand
+operand2
. If the method was called on a class rather than on the instanceoperand2
must be given. propagate_uncertainties
bool
orNone
, optional If
None
the result will have no uncertainty. IfFalse
the result will have a copied version of the first operand that has an uncertainty. IfTrue
the result will have a correctly propagated uncertainty from the uncertainties of the operands but this assumes that the uncertainties areNDUncertainty
like. Default isTrue
.Changed in version 1.2: This parameter must be given as keywordparameter. Using it as positional parameter is deprecated.
None
was added as valid parameter value. handle_maskcallable,
'first_found'
orNone
, optional If
None
the result will have no mask. If'first_found'
the result will have a copied version of the first operand that has a mask). If it is a callable then the specified callable must create the resultsmask
and if necessary provide a copy. Default isnumpy.logical_or
.New in version 1.2.
 handle_metacallable,
'first_found'
orNone
, optional If
None
the result will have no meta. If'first_found'
the result will have a copied version of the first operand that has a (not empty) meta. If it is a callable then the specified callable must create the resultsmeta
and if necessary provide a copy. Default isNone
.New in version 1.2.
 compare_wcscallable,
'first_found'
orNone
, optional If
None
the result will have no wcs and no comparison between the wcs of the operands is made. If'first_found'
the result will have a copied version of the first operand that has a wcs. If it is a callable then the specified callable must compare thewcs
. The resultingwcs
will be like ifFalse
was given otherwise it raises aValueError
if the comparison was not successful. Default is'first_found'
.New in version 1.2.
 uncertainty_correlationnumber or
ndarray
, optional The correlation between the two operands is used for correct error propagation for correlated data as given in: https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas Default is 0.
New in version 1.2.
 kwargs :
Any other parameter that should be passed to the callables used.
 operand, operand2
 Returns
 result
NDData
like The resulting dataset
 result
Notes
If a
callable
is used formask
,wcs
ormeta
the callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargs
and must start with"wcs_"
(for wcs callable) or"meta_"
(for meta callable). This startstring is removed before the callable is called."first_found"
can also be abbreviated with"ff"
.

classmethod
divide
(operand, operand2=None, **kwargs)¶ Performs division by evaluating
self
/operand
. Parameters
 operand, operand2
NDData
like instance or convertible to one. If
operand2
isNone
or not given it will perform the operationself
/operand
. Ifoperand2
is given it will performoperand
/operand2
. If the method was called on a class rather than on the instanceoperand2
must be given. propagate_uncertainties
bool
orNone
, optional If
None
the result will have no uncertainty. IfFalse
the result will have a copied version of the first operand that has an uncertainty. IfTrue
the result will have a correctly propagated uncertainty from the uncertainties of the operands but this assumes that the uncertainties areNDUncertainty
like. Default isTrue
.Changed in version 1.2: This parameter must be given as keywordparameter. Using it as positional parameter is deprecated.
None
was added as valid parameter value. handle_maskcallable,
'first_found'
orNone
, optional If
None
the result will have no mask. If'first_found'
the result will have a copied version of the first operand that has a mask). If it is a callable then the specified callable must create the resultsmask
and if necessary provide a copy. Default isnumpy.logical_or
.New in version 1.2.
 handle_metacallable,
'first_found'
orNone
, optional If
None
the result will have no meta. If'first_found'
the result will have a copied version of the first operand that has a (not empty) meta. If it is a callable then the specified callable must create the resultsmeta
and if necessary provide a copy. Default isNone
.New in version 1.2.
 compare_wcscallable,
'first_found'
orNone
, optional If
None
the result will have no wcs and no comparison between the wcs of the operands is made. If'first_found'
the result will have a copied version of the first operand that has a wcs. If it is a callable then the specified callable must compare thewcs
. The resultingwcs
will be like ifFalse
was given otherwise it raises aValueError
if the comparison was not successful. Default is'first_found'
.New in version 1.2.
 uncertainty_correlationnumber or
ndarray
, optional The correlation between the two operands is used for correct error propagation for correlated data as given in: https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas Default is 0.
New in version 1.2.
 kwargs :
Any other parameter that should be passed to the callables used.
 operand, operand2
 Returns
 result
NDData
like The resulting dataset
 result
Notes
If a
callable
is used formask
,wcs
ormeta
the callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargs
and must start with"wcs_"
(for wcs callable) or"meta_"
(for meta callable). This startstring is removed before the callable is called."first_found"
can also be abbreviated with"ff"
.

classmethod
multiply
(operand, operand2=None, **kwargs)¶ Performs multiplication by evaluating
self
*operand
. Parameters
 operand, operand2
NDData
like instance or convertible to one. If
operand2
isNone
or not given it will perform the operationself
*operand
. Ifoperand2
is given it will performoperand
*operand2
. If the method was called on a class rather than on the instanceoperand2
must be given. propagate_uncertainties
bool
orNone
, optional If
None
the result will have no uncertainty. IfFalse
the result will have a copied version of the first operand that has an uncertainty. IfTrue
the result will have a correctly propagated uncertainty from the uncertainties of the operands but this assumes that the uncertainties areNDUncertainty
like. Default isTrue
.Changed in version 1.2: This parameter must be given as keywordparameter. Using it as positional parameter is deprecated.
None
was added as valid parameter value. handle_maskcallable,
'first_found'
orNone
, optional If
None
the result will have no mask. If'first_found'
the result will have a copied version of the first operand that has a mask). If it is a callable then the specified callable must create the resultsmask
and if necessary provide a copy. Default isnumpy.logical_or
.New in version 1.2.
 handle_metacallable,
'first_found'
orNone
, optional If
None
the result will have no meta. If'first_found'
the result will have a copied version of the first operand that has a (not empty) meta. If it is a callable then the specified callable must create the resultsmeta
and if necessary provide a copy. Default isNone
.New in version 1.2.
 compare_wcscallable,
'first_found'
orNone
, optional If
None
the result will have no wcs and no comparison between the wcs of the operands is made. If'first_found'
the result will have a copied version of the first operand that has a wcs. If it is a callable then the specified callable must compare thewcs
. The resultingwcs
will be like ifFalse
was given otherwise it raises aValueError
if the comparison was not successful. Default is'first_found'
.New in version 1.2.
 uncertainty_correlationnumber or
ndarray
, optional The correlation between the two operands is used for correct error propagation for correlated data as given in: https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas Default is 0.
New in version 1.2.
 kwargs :
Any other parameter that should be passed to the callables used.
 operand, operand2
 Returns
 result
NDData
like The resulting dataset
 result
Notes
If a
callable
is used formask
,wcs
ormeta
the callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargs
and must start with"wcs_"
(for wcs callable) or"meta_"
(for meta callable). This startstring is removed before the callable is called."first_found"
can also be abbreviated with"ff"
.

new_flux_unit
(self, unit, equivalencies=None, suppress_conversion=False)¶ Converts the flux data to the specified unit. This is an inplace change to the object.
 Parameters
 unitstr or
Unit
The unit to convert the flux array to.
 equivalencieslist of equivalencies
Custom equivalencies to apply to conversions. Set to spectral_density by default.
 suppress_conversionbool
Set to true if updating the unit without converting data values.
 unitstr or
 Returns
Spectrum1D
A new spectrum with the converted flux array

spectral_resolution
(self, true_dispersion, delta_dispersion, axis=1)[source]¶ Evaluate the probability distribution of the spectral resolution.
 Parameters
 true_dispersion
Quantity
True value(s) of dispersion for which the resolution should be evaluated.
 delta_dispersion
Quantity
Array of (observed  true) dispersion bin edges to integrate the resolution probability density over.
 axisint
Which axis of
delta_dispersion
contains the strictly increasing dispersion values to interpret as bin edges. The dimension ofdelta_dispersion
along this axis must be at least two.
 true_dispersion
 Returns
 numpy array
Array of dimensionless probabilities calculated as the integral of P(observed  true) over each bin in (observed  true). The output shape is the result of broadcasting the input shapes.
Examples
To tabulate a binned resolution function at 6000A covering +/10A in 0.2A steps:
>>> R = spectrum1d.spectral_resolution( ... 6000 * u.Angstrom, np.linspace(10, 10, 51) * u.Angstrom) >>> assert R.shape == (50,) >>> assert np.allclose(R.sum(), 1.)
To build a sparse resolution matrix for true wavelengths 40008000A in 0.1A steps:
>>> R = spectrum1d.spectral_resolution( ... np.linspace(4000, 8000, 40001)[:, np.newaxis] * u.Angstrom, ... np.linspace(10, +10, 201) * u.Angstrom) >>> assert R.shape == (40000, 200) >>> assert np.allclose(R.sum(axis=1), 1.)

classmethod
subtract
(operand, operand2=None, **kwargs)¶ Performs subtraction by evaluating
self
operand
. Parameters
 operand, operand2
NDData
like instance or convertible to one. If
operand2
isNone
or not given it will perform the operationself
operand
. Ifoperand2
is given it will performoperand
operand2
. If the method was called on a class rather than on the instanceoperand2
must be given. propagate_uncertainties
bool
orNone
, optional If
None
the result will have no uncertainty. IfFalse
the result will have a copied version of the first operand that has an uncertainty. IfTrue
the result will have a correctly propagated uncertainty from the uncertainties of the operands but this assumes that the uncertainties areNDUncertainty
like. Default isTrue
.Changed in version 1.2: This parameter must be given as keywordparameter. Using it as positional parameter is deprecated.
None
was added as valid parameter value. handle_maskcallable,
'first_found'
orNone
, optional If
None
the result will have no mask. If'first_found'
the result will have a copied version of the first operand that has a mask). If it is a callable then the specified callable must create the resultsmask
and if necessary provide a copy. Default isnumpy.logical_or
.New in version 1.2.
 handle_metacallable,
'first_found'
orNone
, optional If
None
the result will have no meta. If'first_found'
the result will have a copied version of the first operand that has a (not empty) meta. If it is a callable then the specified callable must create the resultsmeta
and if necessary provide a copy. Default isNone
.New in version 1.2.
 compare_wcscallable,
'first_found'
orNone
, optional If
None
the result will have no wcs and no comparison between the wcs of the operands is made. If'first_found'
the result will have a copied version of the first operand that has a wcs. If it is a callable then the specified callable must compare thewcs
. The resultingwcs
will be like ifFalse
was given otherwise it raises aValueError
if the comparison was not successful. Default is'first_found'
.New in version 1.2.
 uncertainty_correlationnumber or
ndarray
, optional The correlation between the two operands is used for correct error propagation for correlated data as given in: https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas Default is 0.
New in version 1.2.
 kwargs :
Any other parameter that should be passed to the callables used.
 operand, operand2
 Returns
 result
NDData
like The resulting dataset
 result
Notes
If a
callable
is used formask
,wcs
ormeta
the callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargs
and must start with"wcs_"
(for wcs callable) or"meta_"
(for meta callable). This startstring is removed before the callable is called."first_found"
can also be abbreviated with"ff"
.

with_spectral_unit
(self, unit, velocity_convention=None, rest_value=None)¶ Returns a new spectrum with a different spectral axis unit.
 Parameters
 unit
Unit
Any valid spectral unit: velocity, (wave)length, or frequency. Only vacuum units are supported.
 velocity_convention‘relativistic’, ‘radio’, or ‘optical’
The velocity convention to use for the output velocity axis. Required if the output type is velocity. This can be either one of the above strings, or an
astropy.units
equivalency. rest_value
Quantity
A rest wavelength or frequency with appropriate units. Required if output type is velocity. The spectrum’s WCS should include this already if the input type is velocity, but the WCS’s rest wavelength/frequency can be overridden with this parameter.
 unit

with_velocity_convention
(self, velocity_convention)¶