Spectral-cube has several tools to enable reprojection of cubes onto different spatial and spectral grids.
Prior to reprojecting data, in order to minimize resampling artifacts, it is a good idea to smooth the data first. A worked example of spatial and spectral smoothing is given on the reprojection tutorial.
To reproject a cube onto a different spatial world coordinate system, use the
reproject() function. The function requires
a target header as an input. You might generate this header by grabbing it
from another FITS file, for example, from another
from spectral_cube import SpectralCube cube = SpectralCube.read('/some_path/some_file.fits') other_cube = SpectralCube.read('/some_path/other_file.fits') reprojected_cube = cube.reproject(other_cube.header)
Instead, the target header can be generated it with a helper tool (e.g., the find_optimal_celestial_wcs function in the reproject package), or by manually editing a FITS header.
The spatial reprojection tool uses reproject under the hood and defaults to
using a bilinear interpolation scheme, though this is configurable using the
order keyword in
Interpolation onto a differently-spaced grid, after appropriate smoothing, can
be used to rebin or decimate the data.
A simple example for rebinning, assuming no smoothing is needed (appropriate for when the data are oversampled):
from spectral_cube import SpectralCube cube = SpectralCube.read('/some_path/some_file.fits') # create a target header to reproject to by making the pixel size 2 times larger target_header = cube.wcs.celestial[::2, ::2].to_header() target_header['NAXIS1'] = cube.shape / 2 target_header['NAXIS2'] = cube.shape / 2 downsampled_cube = cube.reproject(target_header)
Reprojection for 2D images uses the same syntax with a
Slice object. For example, to match the spatial grid of a 2D image to that of a cube:
from spectral_cube import SpectralCube, Projection from astropy.io import fits cube = SpectralCube.read('/some_path/some_file.fits') image = Projection.from_hdu(fits.open('/some_path/twod_image.fits')) cube_header_spatial = cube.wcs.celestial.to_header() reprojected_image = image.reproject(cube_header_spatial)
Spectral reprojection behaves similar to spatial reprojection.
allows interpolation of the data onto a new spectral grid.
Unlike spatial reprojection, though, the expected input is a list
of pixel coordinates. See the example in the Spectral Smoothing section of
the Smoothing document.