Spectrum1D¶
- class specutils.Spectrum1D(flux=None, spectral_axis=None, wcs=None, velocity_convention=None, rest_value=None, redshift=None, radial_velocity=None, bin_specification=None, **kwargs)[source]¶
Bases:
OneDSpectrumMixin
,NDCube
,NDIOMixin
,NDArithmeticMixin
Spectrum container for 1D spectral data.
Note that “1D” in this case refers to the fact that there is only one spectral axis.
Spectrum1D
can contain “vector 1D spectra” by having theflux
have a shape with dimension greater than 1. The requirement is that the last dimension offlux
match the length of thespectral_axis
.For multidimensional spectra that are all the same shape but have different spectral axes, use a
SpectrumCollection
. For a collection of spectra that have different shapes, useSpectrumList
. For more on this topic, see Overview of How Specutils Represents Spectra.- Parameters:
- flux
Quantity
orNDData
-like The flux data for this spectrum. This can be a simple
Quantity
, or an existingSpectrum1D
orNDCube
object.- spectral_axis
Quantity
orSpectralAxis
Dispersion information with the same shape as the last (or only) dimension of flux, or one greater than the last dimension of flux if specifying bin edges.
- wcs
WCS
orWCS
WCS information object that either has a spectral component or is only spectral.
- 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.- bin_specificationstr
Either “edges” or “centers” to indicate whether the
spectral_axis
values represent edges of the wavelength bin, or centers of the bin.- 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.
- mask
ndarray
-like Array where values in the flux to be masked are those that
astype(bool)
converts to True. (For example, integer arrays are not masked where they are 0, and masked for any other value.)- metadict
Arbitrary container for any user-specific information to be carried around with the spectrum container object.
- flux
Attributes Summary
Returns the physical types associated with each array axis.
A
BaseHighLevelWCS
object which combines.wcs
with.extra_coords
.ndarray
-like : The stored dataset.The array dimensions of the cube.
The energy of the spectral axis as a
Quantity
in units of eV.An
ExtraCoords
object holding extra coordinates aligned to array axes.Converts the stored data and unit information into a quantity.
The
spectral_axis
as aQuantity
in units of GHzA
GlobalCoords
object holding coordinate metadata not aligned to an array axis.any 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 unitA
MatplotlibPlotter
instance providing visualization methods.The radial velocity(s) of the objects represented by this spectrum.
Read and parse gridded N-dimensional data and return as an NDData-derived object.
The redshift(s) of the objects represented by this spectrum.
Returns the SpectralCoord object.
Deprecated since version v1.1.
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
spectral_axis
as aQuantity
in units of Angstromsany type : A world coordinate system (WCS) for the dataset, if any.
Write this CCDData object out in the specified format.
Methods Summary
add
(operand[, operand2])Performs addition by evaluating
self
+operand
.axis_world_coords
(*axes[, pixel_corners, wcs])Returns WCS coordinate values of all pixels for all axes.
axis_world_coords_values
(*axes[, ...])Returns WCS coordinate values of all pixels for desired axes.
collapse
(method[, axis])Collapse the flux array given a method.
crop
(*points[, wcs])Crop to the smallest cube in pixel space containing the world coordinate points.
crop_by_values
(*points[, units, wcs])Crop to the smallest cube in pixel space containing the world coordinate points.
divide
(operand[, operand2])Performs division by evaluating
self
/operand
.explode_along_axis
(axis)Separates slices of NDCubes along a given axis into an NDCubeSequence of (N-1)DCubes.
max
(**kwargs)mean
(**kwargs)median
(**kwargs)min
(**kwargs)multiply
(operand[, operand2])Performs multiplication by evaluating
self
*operand
.new_flux_unit
(unit[, equivalencies, ...])Converts the flux data to the specified unit.
plot
(*args, **kwargs)A convenience function for the plotters default
plot()
method.reproject_to
(target_wcs[, algorithm, ...])Reprojects this NDCube to the coordinates described by another WCS object.
set_radial_velocity_to
(radial_velocity)This sets the radial velocity of the spectrum to be
radial_velocity
without changing the values of thespectral_axis
.set_redshift_to
(redshift)This sets the redshift of the spectrum to be
redshift
without changing the values of thespectral_axis
.shift_spectrum_to
(*[, redshift, radial_velocity])This shifts in-place the values of the
spectral_axis
, given either a redshift or radial velocity.subtract
(operand[, operand2])Performs subtraction by evaluating
self
-operand
.sum
(**kwargs)with_spectral_unit
(unit[, ...])Returns a new spectrum with a different spectral axis unit.
with_velocity_convention
(velocity_convention)Attributes Documentation
- array_axis_physical_types¶
Returns the physical types associated with each array axis.
Returns an iterable of tuples where each tuple corresponds to an array axis and holds strings denoting the physical types associated with that array axis. Since multiple physical types can be associated with one array axis, tuples can be of different lengths. Likewise, as a single physical type can correspond to multiple array axes, the same physical type string can appear in multiple tuples.
The physical types are drawn from the WCS ExtraCoords objects.
- bin_edges¶
- combined_wcs¶
A
BaseHighLevelWCS
object which combines.wcs
with.extra_coords
.
- dimensions¶
- extra_coords¶
An
ExtraCoords
object holding extra coordinates aligned to array axes.
- flux¶
Converts the stored data and unit information into a quantity.
- Returns:
Quantity
Spectral data as a quantity.
- frequency¶
The
spectral_axis
as aQuantity
in units of GHz
- global_coords¶
A
GlobalCoords
object holding coordinate metadata not aligned to an array axis.
- 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
- plotter = None¶
A
MatplotlibPlotter
instance providing visualization methods.The type of this attribute can be changed to provide custom visualization functionality.
- 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¶
Read and parse gridded N-dimensional data and return as an NDData-derived object.
This function provides the NDDataBase interface to the astropy unified I/O layer. This allows easily reading a file in the supported data formats, for example:
>>> from astropy.nddata import CCDData >>> dat = CCDData.read('image.fits')
Get help on the available readers for
CCDData
using the``help()`` method:>>> CCDData.read.help() # Get help reading CCDData and list supported formats >>> CCDData.read.help('fits') # Get detailed help on CCDData FITS reader >>> CCDData.read.list_formats() # Print list of available formats
See also:
- Parameters:
- *argstuple, optional
Positional arguments passed through to data reader. If supplied the first argument is the input filename.
- formatstr, optional
File format specifier.
- cachebool, optional
Caching behavior if file is a URL.
- **kwargsdict, optional
Keyword arguments passed through to data reader.
- Returns:
- out
NDData
subclass NDData-basd object corresponding to file contents
- out
- 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 the SpectralCoord object.
- spectral_axis_unit¶
Deprecated since version v1.1: The spectral_axis_unit function is deprecated and may be removed in a future version. Use spectral_axis.unit instead.
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
- wavelength¶
The
spectral_axis
as aQuantity
in units of Angstroms
- wcs¶
any type : A world coordinate system (WCS) for the dataset, if any.
- write¶
Write this CCDData object out in the specified format.
This function provides the NDData interface to the astropy unified I/O layer. This allows easily writing a file in many supported data formats using syntax such as:
>>> from astropy.nddata import CCDData >>> dat = CCDData(np.zeros((12, 12)), unit='adu') # 12x12 image of zeros >>> dat.write('zeros.fits')
Get help on the available writers for
CCDData
using the``help()`` method:>>> CCDData.write.help() # Get help writing CCDData and list supported formats >>> CCDData.write.help('fits') # Get detailed help on CCDData FITS writer >>> CCDData.write.list_formats() # Print list of available formats
See also:
- Parameters:
- *argstuple, optional
Positional arguments passed through to data writer. If supplied the first argument is the output filename.
- formatstr, optional
File format specifier.
- **kwargsdict, optional
Keyword arguments passed through to data writer.
Methods Documentation
- classmethod add(operand, operand2=None, **kwargs)¶
Performs addition by evaluating
self
+operand
.- Parameters:
- operand, operand2
NDData
-like instance 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 keyword-parameter. 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"
.
- axis_world_coords(*axes, pixel_corners=False, wcs=None)¶
Returns WCS coordinate values of all pixels for all axes.
- Parameters:
- axes: `int` or `str`, or multiple `int` or `str`, optional
Axis number in numpy ordering or unique substring of
world_axis_physical_types
of axes for which real world coordinates are desired. axes=None implies all axes will be returned.- pixel_corners: `bool`, optional
If
True
then instead of returning the coordinates at the centers of the pixels, the coordinates at the pixel corners will be returned. This increases the size of the output by 1 in all dimensions as all corners are returned.- wcs: `astropy.wcs.wcsapi.BaseHighLevelWCS`, optional
The WCS object to used to calculate the world coordinates. Although technically this can be any valid WCS, it will typically be
self.wcs
,self.extra_coords
, orself.combined_wcs
which combines both the WCS and extra coords. Defaults to the.wcs
property.
- Returns:
- axes_coords:
list
An iterable of “high level” objects giving the real world coords for the axes requested by user. For example, a tuple of
SkyCoord
objects. The types returned are determined by the WCS object. The dimensionality of these objects should match that of their corresponding array dimensions, unlesspixel_corners=True
in which case the length along each axis will be 1 greater than the number of pixels.
- axes_coords:
- axis_world_coords_values(*axes, pixel_corners=False, wcs=None)¶
Returns WCS coordinate values of all pixels for desired axes.
- Parameters:
- axes: `int` or `str`, or multiple `int` or `str`, optional
Axis number in numpy ordering or unique substring of
world_axis_physical_types
of axes for which real world coordinates are desired. axes=None implies all axes will be returned.- pixel_corners: `bool`, optional
If
True
then instead of returning the coordinates of the pixel centers the coordinates of the pixel corners will be returned. This increases the size of the output along each dimension by 1 as all corners are returned.- wcs: `astropy.wcs.wcsapi.BaseHighLevelWCS`, optional
The WCS object to used to calculate the world coordinates. Although technically this can be any valid WCS, it will typically be
self.wcs
,self.extra_coords
, orself.combined_wcs
, combing both the WCS and extra coords. Defaults to the.wcs
property.
- Returns:
- axes_coords:
list
An iterable of “high level” objects giving the real world coords for the axes requested by user. For example, a tuple of
SkyCoord
objects. The types returned are determined by the WCS object. The dimensionality of these objects should match that of their corresponding array dimensions, unlesspixel_corners=True
in which case the length along each axis will be 1 greater than the number of pixels.
- axes_coords:
- collapse(method, axis=None)[source]¶
Collapse the flux array given a method. Will collapse either to a single value (default), over a specified numerical axis or axes if specified, or over the spectral or non-spectral axes if
physical_type
is specified.If the collapse leaves the spectral axis unchanged, a
Spectrum1D
will be returned. Otherwise anQuantity
array will be returned.Note that these calculations are not currently uncertainty-aware, but do respect masks.
- Parameters:
- methodstr, function
The method by which the flux will be collapsed. String options are ‘mean’, ‘min’, ‘max’, ‘sum’, and ‘median’. Also accepts a function as input, which must take an
astropy.units.Quantity
array as input and accept an ‘axis’ argument.- axisint, tuple, str, optional
The axis or axes over which to collapse the flux array. May also be a string, either ‘spectral’ to collapse over the spectral axis, or ‘spatial’ to collapse over all other axes.
- Returns:
- :class:`~specutils.Spectrum1D` orclass:
Quantity
- :class:`~specutils.Spectrum1D` orclass:
- crop(*points, wcs=None)¶
Crop to the smallest cube in pixel space containing the world coordinate points.
- Parameters:
- points: iterable of iterables
Tuples of high level coordinate objects e.g.
SkyCoord
. The coordinates of the points must be specified in Cartesian (WCS) order as they are passed toworld_to_array_index
. Therefore their number and order must be compatible with the API of that method.It is possible to not specify a coordinate for an axis by replacing any object with
None
. Any coordinate replaced byNone
will not be used to calculate pixel coordinates, and therefore not affect the calculation of the final bounding box.- wcs: `astropy.wcs.wcsapi.BaseLowLevelWCS`
The WCS to use to calculate the pixel coordinates based on the input. Will default to the
.wcs
property if not given. While any valid WCS could be used it is expected that either the.wcs
,.combined_wcs
, or.extra_coords
properties will be used.
- Returns:
- result:
ndcube.NDCube
- result:
- crop_by_values(*points, units=None, wcs=None)¶
Crop to the smallest cube in pixel space containing the world coordinate points.
- Parameters:
- points: iterable of iterables
Tuples of coordinates as
Quantity
objects. The coordinates of the points must be specified in Cartesian (WCS) order as they are passed toworld_to_array_index_values
. Therefore their number and order must be compatible with the API of that method.It is possible to not specify a coordinate for an axis by replacing any coordinate with
None
. Any coordinate replaced byNone
will not be used to calculate pixel coordinates, and therefore not affect the calculation of the final bounding box. Note that you must specify either none or all coordinates for any correlated axes, e.g. both spatial coordinates.- units: iterable of `astropy.units.Unit`
The unit of the corresponding entries in each point. Must therefore be the same length as the number of world axes. Only used if the corresponding type is not a
astropy.units.Quantity
orNone
.- wcs: `astropy.wcs.wcsapi.BaseLowLevelWCS`
The WCS to use to calculate the pixel coordinates based on the input. Will default to the
.wcs
property if not given. While any valid WCS could be used it is expected that either the.wcs
,.combined_wcs
, or.extra_coords
properties will be used.
- Returns:
- result:
ndcube.NDCube
- result:
- classmethod divide(operand, operand2=None, **kwargs)¶
Performs division by evaluating
self
/operand
.- Parameters:
- operand, operand2
NDData
-like instance 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 keyword-parameter. 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"
.
- explode_along_axis(axis)¶
Separates slices of NDCubes along a given axis into an NDCubeSequence of (N-1)DCubes.
- Parameters:
- axis
int
The array axis along which the data is to be changed.
- axis
- Returns:
- result
ndcube.NDCubeSequence
- result
- classmethod multiply(operand, operand2=None, **kwargs)¶
Performs multiplication by evaluating
self
*operand
.- Parameters:
- operand, operand2
NDData
-like instance 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 keyword-parameter. 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(unit, equivalencies=None, suppress_conversion=False)¶
Converts the flux data to the specified unit. This is an in-place 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
- plot(*args, **kwargs)¶
A convenience function for the plotters default
plot()
method.Calling this method is the same as calling
cube.plotter.plot
, the behaviour of this method can change if theNDCube.plotter
class is set to a differentPlotter
class.
- reproject_to(target_wcs, algorithm='interpolation', shape_out=None, order='bilinear', output_array=None, parallel=False, return_footprint=False)¶
Reprojects this NDCube to the coordinates described by another WCS object.
- Parameters:
- algorithm: `str`
The algorithm to use for reprojecting. This can be any of: ‘interpolation’, ‘adaptive’, and ‘exact’.
- target_wcs
astropy.wcs.wcsapi.BaseHighLevelWCS
,astropy.wcs.wcsapi.BaseLowLevelWCS
, or
astropy.io.fits.Header
The WCS object to which theNDCube
is to be reprojected.- shape_out: `tuple`, optional
The shape of the output data array. The ordering of the dimensions must follow NumPy ordering and not the WCS pixel shape. If not specified,
array_shape
attribute (if available) from the low level API of thetarget_wcs
is used.- order: `int` or `str`
The order of the interpolation (used only when the ‘interpolation’ or ‘adaptive’ algorithm is selected). For ‘interpolation’ algorithm, this can be any of: ‘nearest-neighbor’, ‘bilinear’, ‘biquadratic’, and ‘bicubic’. For ‘adaptive’ algorithm, this can be either ‘nearest-neighbor’ or ‘bilinear’.
- output_array: `numpy.ndarray`, optional
An array in which to store the reprojected data. This can be any numpy array including a memory map, which may be helpful when dealing with extremely large files.
- parallel: `bool` or `int`
Flag for parallel implementation (used only when the ‘exact’ algorithm is selected). If
True
, a parallel implementation is chosen and the number of processes is selected automatically as the number of logical CPUs detected on the machine. IfFalse
, a serial implementation is chosen. If the flag is a positive integer n greater than one, a parallel implementation using n processes is chosen.- return_footprint: `bool`
Whether to return the footprint in addition to the output NDCube.
- Returns:
- resampled_cube
ndcube.NDCube
A new resultant NDCube object, the supplied
target_wcs
will be the.wcs
attribute of the outputNDCube
.- footprint:
numpy.ndarray
Footprint of the input array in the output array. Values of 0 indicate no coverage or valid values in the input image, while values of 1 indicate valid values.
- resampled_cube
Notes
This method doesn’t support handling of the
mask
,extra_coords
, anduncertainty
attributes yet. However,meta
andglobal_coords
are copied to the outputNDCube
.
- set_radial_velocity_to(radial_velocity)[source]¶
This sets the radial velocity of the spectrum to be
radial_velocity
without changing the values of thespectral_axis
.If you want to shift the
spectral_axis
based on this value, useshift_spectrum_to
.
- set_redshift_to(redshift)[source]¶
This sets the redshift of the spectrum to be
redshift
without changing the values of thespectral_axis
.If you want to shift the
spectral_axis
based on this value, useshift_spectrum_to
.
- shift_spectrum_to(*, redshift=None, radial_velocity=None)[source]¶
This shifts in-place the values of the
spectral_axis
, given either a redshift or radial velocity.If you do not want to change the
spectral_axis
, useset_redshift_to
orset_radial_velocity_to
.
- classmethod subtract(operand, operand2=None, **kwargs)¶
Performs subtraction by evaluating
self
-operand
.- Parameters:
- operand, operand2
NDData
-like instance 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 keyword-parameter. 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(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(velocity_convention)¶