Making Data Cubes

The CubeWidget provides a visual interface to a Fits datacube using ginga/astrowidgets/ipywidgets. It is developed to function on any FITS cube in which the 1st data axis represents the spectral dim provided the WCS is included. Click on any spatial region to see the spectrum at that pixel. Use the play button to scan through wavelength space or the slider to get a specfic wavelength.

from astropy import units as u

from hetdex_tools.interpolate import make_data_cube
from hetdex_api.cube_widget import CubeWidget

Make Your own data cube from a Detectid or SkyCoord object

# Here's an example low redshift galaxy at z=0.078.
hdu = make_data_cube(
    detectid=3090045971,
    pixscale=0.5*u.arcsec,
    imsize=30.*u.arcsec, 
    dwave=10, 
    fill_value=0.0,
    apply_mask=True,
    convolve_image=False)
w = CubeWidget(hdu=hdu)

To save the datacube:

hdu.writeto('data_cube.fits', overwrite=True)

For Data Cube Options:

help(make_data_cube)
Help on function make_data_cube in module hetdex_tools.interpolate:

make_data_cube(detectid=None, coords=None, shotid=None, pixscale=<Quantity 0.25 arcsec>, imsize=<Quantity 30. arcsec>, wave_range=[3470, 5540], dwave=2.0, dcont=50.0, convolve_image=False, ffsky=False, subcont=False, survey='hdr4', fiber_flux_offset=None, interp_kind='linear', apply_mask=False, fill_value=nan)
    Function to make a datacube from either a detectid or from a
    coordinate/shotid combination.
    
    Paramaters
    ----------
    detectid: int
        detectid from the continuum or lines catalog. Default is
        None. Provide a coords/shotid combo if this isn't given
    coords: SkyCoords object
        coordinates to define the centre of the data cube
    pixscale: astropy angle quantity
        plate scale
    imsize: astropy angle quantity
        spatial length of cube (equal dims is only option)
    wave_range: list
        start and stop value for the wavelength range in Angstrom
    dwave
        step in wavelength range in Angstrom
    convolve_image: bool
         option to convolve image with shotid seeing
    ffsky: bool
        option to use full frame calibrated fibers. Default is
        True.
    subcont: bool
        option to subtract continuum. Default is False. This
        will measure the continuum 50AA below and above the
        input wave_range
    dcont: float
        width in angstrom to measure the continuum. Default is to
        measure 50 AA wide regions on either side of the line
    fiber_flux_offset: 1036 array
        array of values in units of 10**-17 ergs/s/cm2/AA to add
        to each fiber spectrum used in the extraction. Defaults
        to None
    interp_kind: str
        Kind of interpolation to pixelated grid from fiber intensity.
        Options are 'linear', 'cubic', 'nearest'. Default is linear.
    apply_mask: bool                                                                                            Apply HETDEX fiber mask model. This will mask all fibers contributing
         to the spectral extraction before summation. Masked in place as NaNs                               fill_value: float, optional                                                                                Value used to fill in for requested points outside of coverage or in a mask                            region. If not provided, then the default is nan.
    
    Returns
    -------
    hdu: PrimaryHDU object
        the data cube 3D array and associated 3d header
        Units are '10^-17 erg cm-2 s-1 per spaxel'
    
    Examples
    --------
    
    Can either pass in a detectid:
    
    >>> detectid_obj=2101602788
    >>> hdu = make_data_cube( detectid=detectid_obj)
    >>> hdu.writeto( str(detectid_obj) + '.fits', overwrite=True)
    
    or can put in an SkyCoord object:
    
    >>> star_coords = SkyCoord(9.625181, -0.043587, unit='deg')
    >>> hdu = make_data_cube( coords=star_coords[0], shotid=20171016108, dwave=2.0)
    >>> hdu.writeto( 'star.fits', overwrite=True)

How to find a shotid for any coords:

# For other examples see FiberIndex.ipynb notebook
import numpy as np
from hetdex_api.survey import FiberIndex
from astropy.coordinates import SkyCoord
FibIndex = FiberIndex()
star_coords = SkyCoord(176.32574, 51.514133, unit='deg')
fiber_table_region = FibIndex.query_region(star_coords, radius=3.*u.arcsec, shotid=None)
print("Fibers within 3 arcsec of {} are in:\n {}".format(star_coords, np.unique(fiber_table_region['shotid'])))
Fibers within 3 arcsec of <SkyCoord (ICRS): (ra, dec) in deg
    (176.32574, 51.514133)> are in:
    shotid  
-----------
20190208022
hdu_star = make_data_cube(coords=star_coords, shotid=20190208022, fill_value=0.0) 
w = CubeWidget(hdu=hdu_star)