A way to inspect fits image cubes

This is just a quick hack to take a look at a FITS image cube, inspired by https://github.com/krislars/extinction_slider_hack.

Things to add :

  • the channel/velocity labelling on each of the channels
  • binning functionality ?
  • rms noise estimates
  • looking at FITS file headers sensibly
  • maybe even the spectral line plot for pixels/regions

In [410]:
import numpy as np
from astropy.io import fits
from astropy.wcs import WCS
from astropy.utils.data import get_pkg_data_filename
import aplpy
from matplotlib.colors import LogNorm
from IPython import display 
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

import matplotlib.pyplot as plt 
%matplotlib inline

In [419]:
def fitsSlider(i):
    axim.set_array(image[i,:,:])
    display.display(fig)

In [420]:
fitsfile = './co21-w-flagged_smt.fits'

In [421]:
apy_fits_obj = get_pkg_data_filename(fitsfile)
hdu = fits.open(apy_fits_obj)[0]
wcs = WCS(hdu.header).celestial

Cube = fits.open('./co21-w-flagged_smt.fits')
image = Cube[0].data[0,:,:,:]

In [422]:
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection=wcs)
lon = ax.coords[0]
lat = ax.coords[1]
lat.set_ticklabel(size=20)
lon.set_ticklabel(size=20)
ax.set_xlabel('Galactic Longitude', size=25)
ax.set_ylabel('Galactic Latitude', size=25)
axim = ax.imshow(image[0,:,:],vmin=1e-5, vmax=20.e-3, cmap='inferno_r') ; # say > fig to show the figure



In [423]:
interactive_plot = interactive(f, i=(0,613,1))
#output.layout.height = '150px'
interactive_plot



In [ ]: