In [1]:
import numpy as np
import matplotlib.pyplot as plt
from astropy.stats import bootstrap as BS
from astropy.io import fits
%matplotlib inline
In [2]:
hdulist = fits.open('KiDS_G15_2015.cat')
hdulist.info()
In [3]:
hdu2= hdulist[2]
hdu1= hdulist[1]
In [ ]:
hdu1.data['OBJECT_POS']
In [4]:
hdu2.header
Out[4]:
In [ ]:
#for i in range (1200):
for i in [0,2749998]:
d = hdu2.data[i]
#plt.plot
print d[13],d[14]
#plt.plot(d[13],d[14])
#hdu2.data[0]['Xpos']
# TTYPE1 = 'FIELD_POS'
# TTYPE14 = 'Xpos
# TTYPE15 = 'Ypos
# TTYPE16 = 'ALPHA_J2000' /
# TTYPE17 = 'DELTA_J2000' /
# TTYPE87 = 'e1 ' /
# TTYPE88 = 'e2 ' /
# TTYPE96 = 'c1_best ' / Updated empirical correction c1
# TTYPE97 = 'c2_best ' / Updated empirical correction c2
# TTYPE98 = 'm_cor_best' / calibration correction m_cor pixel scale correc
# TTYPE101= 'TILE_SYS_OK' / Pass = 1, Fail = 0
In [12]:
import astropy.io.fits as fits
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches
KiDS_field = 'G15'
hdu = fits.open('KiDS_G15_2015.cat')
fields = hdu[2].data["FIELD_POS"]
ra = hdu[2].data["ALPHA_J2000"]
dec = hdu[2].data["DELTA_J2000"]
hdu.close()
field_info = []
print "min/max RA Global: ", np.min(ra), np.max(ra)
print "min/max DEC Global: ", np.min(dec), np.max(dec)
for i in range(np.max(fields)):
x = ra[fields == i+1]
y = dec[fields == i+1]
x_min = np.min(x)
x_max = np.max(x)
y_min = np.min(y)
y_max = np.max(y)
field_info.append([x_min, x_max, y_min, y_max])
# print("Field {}.".format(i+1))
# print("RA: {} - {}".format(x_min, x_max))
# print("Dec: {} - {}".format(y_min, y_max))
field_info = np.array(field_info)
hdu = fits.open("G3CFoFGroupv06.fits")
hdu[1].verify("fix")
mask = hdu[1].data["Nfof"] >= 5
group_ra = hdu[1].data["BCGRA"][mask]
group_dec = hdu[1].data["BCGDec"][mask]
group_z = hdu[1].data["Zfof"][mask]
hdu.close()
ax = plt.gca()
for i in range(field_info.shape[0]):
bbox_pos = ((field_info[i,1]+field_info[i,0])/2.0 , (field_info[i,3]+field_info[i,2])/2.0 )
bbox_size = ((field_info[i,1]-field_info[i,0]), field_info[i,3]-field_info[i,2])
ax.add_patch(matplotlib.patches.Rectangle(bbox_pos, bbox_size[0] , bbox_size[1], fill=True, alpha=1.0, facecolor='m'))
plt.scatter(group_ra, group_dec)
plt.xlim(np.min(field_info[:,0]-1), np.max(field_info[:,1])+1)
plt.ylim(np.min(field_info[:,2]-1), np.max(field_info[:,3])+1)
plt.xlabel("RA")
plt.ylabel("DEC")
plt.suptitle(KiDS_field)
#plt.savefig(KiDS_field+'_footprint.pdf')
Out[12]:
In [23]:
ra_min = np.min(ra)
ra_max = np.max(ra)
dec_min = np.min(dec)
dec_max = np.max(dec)
nx = int((ra_max-ra_min)*60.)
ny = int((dec_max-dec_min)*60.)
In [ ]:
# For output
def create_KiDS_standard_catalog_file(KiDS_catalog, output_filename):
hdu = fits.open(KiDS_catalog)
w = hdu[2].data["weight"]
z = hdu[2].data["z_B"]
pf = hdu[2].data["TILE_SYS_OK"]
mask = np.logical_and(w > 0.0,
np.logical_and(0.005 < z,
np.logical_and( z < 1.2,
np.logical_and(pf == 1, hdu[2].data["SNratio"] > 0))))
print("Number of objects in {}: {}. Number of objects after masking: {}.".format(KiDS_catalog, len(mask), np.count_nonzero(mask)))
fields = hdu[2].data["FIELD_POS"][mask]
ra = hdu[2].data["ALPHA_J2000"][mask]
dec = hdu[2].data["DELTA_J2000"][mask]
e1 = hdu[2].data["e1"][mask]
e2 = hdu[2].data["e2"][mask]
c1 = hdu[2].data["c1_best"][mask]
c2 = hdu[2].data["c2_best"][mask]
m = hdu[2].data["m_cor_best"][mask]
hdu.close()
w = w[mask]
z = z[mask]
c1_mask = c1 > -99
c2_mask = c2 > -99
e1[c1_mask] -= c1[c1_mask]
e2[c2_mask] -= c2[c2_mask]
x_min = np.min(ra)
x_max = np.max(ra)
y_min = np.min(dec)
y_max = np.max(dec)
# with open(output_filename + "_info.dat", "w") as f:
# f.write("#RA background: {} -> {}.\n".format(x_min, x_max))
# f.write("#DEC background: {} -> {}.\n".format(y_min, y_max))
# f.write("#Size: {}, {}\n".format(x_max-x_min, y_max-y_min))
# f.write("#center(RA, Dec): {}, {}\n".format((x_max+x_min)/2, (y_max+y_min)/2))
# f.write("{} {}\n".format(x_min, x_max))
# f.write("{} {}\n".format(y_min, y_max))
# f.write("{} {}\n".format(x_max-x_min, y_max-y_min))
# f.write("{} {}\n".format((x_max+x_min)/2, (y_max+y_min)/2))
print("Writing to file " + output_filename)
np.savetxt(output_filename, np.vstack((ra, dec, z, e1, e2, w, m)).T)
In [ ]:
KiDS_catalog=['/data/waerbeke/KiDSdata/KiDS_G09_2015.cat','/data/waerbeke/KiDSdata/KiDS_G12_2015.cat','/data/waerbeke/KiDSdata/KiDS_G15_2015.cat']
output_filename = ['KiDS_G09_cat','KiDS_G12_cat', 'KiDS_G09_cat']
for i, field in enumerate(KiDS_catalog):
create_KiDS_standard_catalog_file(KiDS_catalog[i], output_filename[i])