In [1]:
#import pandas as pd
from ipywidgets import StaticInteract, RangeWidget, RadioWidget
import astropy.io.fits as pf
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import glob
import os
In [2]:
#list = sorted(glob.glob('*/*red*.fits'))
#known_positives = ['36894','208612','278995','592466','65410','383283','534753', 'J215942.63-073028.6']
known_positives = ['36894']
list = []
for item in known_positives:
    list.append(glob.glob(item+'/*red*.fits')[0])
In [3]:
hdu = pf.open(list[0])
naxis1 = hdu[0].header['NAXIS1']
naxis2 = hdu[0].header['NAXIS2']
naxis3 = hdu[0].header['NAXIS3']

start = hdu[0].header['CRVAL3']-(hdu[0].header['CRPIX3']-1)*hdu[0].header['CDELT3']
end = start + (hdu[0].header['NAXIS3']-1)*hdu[0].header['CDELT3']
inc = hdu[0].header['CDELT3']

name = os.path.split(item)[0]
print name, "GAMA ID", naxis1, "naxis1",naxis2, "naxis2", naxis3, "naxis3", "wavelength range -", start, end, inc, "cdelt3"
#    lamda = np.arange(start,end+inc,inc)
lamda = np.linspace(start,end,naxis3)

datacube = np.ndarray(shape=(naxis3,naxis1,naxis2),dtype=float)
datacube = hdu[0].data
datacube = np.nan_to_num(datacube)

#gal = np.zeros(naxis3)
#for i in xrange(10,39):
#    for j in xrange(10,39):
#        gal += datacube[:,i,j]
 GAMA ID 50 naxis1 50 naxis2 2048 naxis3 wavelength range - 6210.35107421 7375.83691406 0.569362891961 cdelt3

In [12]:
l=1100
gal = np.zeros((50,50))
for i in range(201):
    gal += datacube[l-i,:,:]
plt.imshow(gal)
Out[12]:
<matplotlib.image.AxesImage at 0xab1512ec>
In [35]:
from pylab import *
In [19]:
hdu = pf.open(list[0])
naxis1 = hdu[0].header['NAXIS1']
naxis2 = hdu[0].header['NAXIS2']
naxis3 = hdu[0].header['NAXIS3']

start = hdu[0].header['CRVAL3']-(hdu[0].header['CRPIX3']-1)*hdu[0].header['CDELT3']
end = start + (hdu[0].header['NAXIS3']-1)*hdu[0].header['CDELT3']
inc = hdu[0].header['CDELT3']

name = os.path.split(item)[0]
print name, "GAMA ID", naxis1, "naxis1",naxis2, "naxis2", naxis3, "naxis3", "wavelength range -", start, end, inc, "cdelt3"
#    lamda = np.arange(start,end+inc,inc)
lamda = np.linspace(start,end,naxis3)

datacube = np.ndarray(shape=(naxis3,naxis1,naxis2),dtype=float)
datacube = hdu[0].data
datacube = np.nan_to_num(datacube)

#gal = np.zeros(naxis3)
#for i in xrange(10,39):
#    for j in xrange(10,39):
#        gal += datacube[:,i,j]

def plot(l):
    fig = plt.figure(figsize=(4, 4))
    gal = np.zeros((50,50))
    for i in range(201):
        gal += datacube[l-i,:,:]
    plt.imshow(gal)
    #imshow(gal)
#    ax.set_xlim(-50, 50)
#    ax.set_ylim(-2.5, 2.5)
    #return plt.imshow(gal)
    return fig
 GAMA ID 50 naxis1 50 naxis2 2048 naxis3 wavelength range - 6210.35107421 7375.83691406 0.569362891961 cdelt3

In [22]:
StaticInteract(plot,l=RangeWidget(500, 1500., 50.))
/usr/lib/pymodules/python2.7/matplotlib/pyplot.py:412: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_num_figures`).
  max_open_warning, RuntimeWarning)

Out[22]:
l:
In []: