#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
#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])
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]
l=1100
gal = np.zeros((50,50))
for i in range(201):
gal += datacube[l-i,:,:]
plt.imshow(gal)
from pylab import *
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
StaticInteract(plot,l=RangeWidget(500, 1500., 50.))