In [6]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
from array_io import *
from astropy import wcs
In [26]:
fname_img = 'F090W_8exp.fits'
hdulist = fits.open(fname_img)
header = hdulist[0].header
print header
nx = hdulist[0].header['NAXIS1']
ny = hdulist[0].header['NAXIS2']
In [9]:
#convert pixel location of objectes extracted from image to ra and dec
def world(filename, x, y):
hdu_list = fits.open(filename)
w = wcs.WCS(hdu_list[0].header)
hdu_list.close()
wrd = w.all_pix2world(x, y, 0)
ra = wrd[:][0]
dec = wrd[:][1]
return ra, dec
In [20]:
#imports fits and puts into numpy array
def load_fits(filename):
hdu_list = fits.open(filename, do_not_scale_image_data=True)
tbdat = hdu_list[0].data
tbdat = tbdat.byteswap().newbyteorder()
return tbdat
In [10]:
m_AB_cat, ra_cat, dec_cat = read_three_arrays("25_bright_cat.txt")
In [13]:
m_AB_mosaic, ra_mosaic, dec_mosaic, x_mosaic, y_mosaic = read_five_arrays("25_bright_mosaic.txt")
In [15]:
ra, dec = world(fname_img, x_mosaic, y_mosaic)
In [16]:
print ra[0:10]
In [17]:
print ra_mosaic[0:10]
In [18]:
print ra_cat[0:10]
In [21]:
tbdat = load_fits(fname_img)
tbdat = np.nan_to_num(tbdat)
for i in range(len(tbdat)):
for j in range(len(tbdat)):
if tbdat[i][j] == 0:
tbdat[i][j] = 0.00001
In [22]:
#convert pixel location of corners of image to ra and dec
def world_area(filename, tbdat):
hdu_list = fits.open(filename)
w = wcs.WCS(hdu_list[0].header)
hdu_list.close()
world_min = w.all_pix2world(0,0,0)
world_max = w.all_pix2world(len(tbdat), len(tbdat), 0)
return world_min, world_max
In [23]:
world_min, world_max = world_area(fname_img, tbdat)
print world_min, world_max
In [25]:
print ra_mosaic.max(), dec_mosaic.max()
print ra_mosaic.min(), dec_mosaic.min()
In [28]:
x_test = (0,0,nx-1,nx-1)
y_test = (0,ny-1,0,ny-1)
ra_test, dec_test = world(fname_img, x_test, y_test)
print ra_test, dec_test
In [ ]: