This is a short demo code for visualizing the KiDS G15 lensing data and its overlap with the GAMMA group cataloge. Data is output in a proper format to be fed into the cross correlation pipeline.


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

Loading G15 KiDS field :


In [2]:
hdulist = fits.open('KiDS_G15_2015.cat')
hdulist.info()


Filename: KiDS_G15_2015.cat
No.    Name         Type      Cards   Dimensions   Format
0    PRIMARY     PrimaryHDU     105   ()              
1    FIELDS      BinTableHDU    279   24R x 135C   [1J, 1J, 16A, 16A, 1J, 1J, 1J, 1J, 1J, 1B, 1J, 1D, 64A, 64A, 64A, 1D, 1D, 1D, 1D, 64A, 64A, 1D, 1D, 1D, 1D, 64A, 64A, 64A, 64A, 64A, 64A, 64A, 64A, 64A, 64A, 64A, 64A, 64A, 64A, 64A, 64A, 1D, 64A, 64A, 64A, 64A, 1D, 1D, 1D, 64A, 64A, 1D, 1D, 1J, 1J, 1J, 64A, 64A, 64A, 64A, 64A, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1D, 1D, 1D, 64A, 64A, 64A, 64A, 1D, 1D, 1D, 1D, 1D, 1J, 1J, 1J, 1D, 1D, 64A, 1D, 1B, 64A, 1J, 1J, 1D, 1B, 1D, 1J, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1J, 1J, 1J, 1J, 1J, 1J, 1J, 1D, 1D, 1J]   
2    OBJECTS     BinTableHDU    320   2749999R x 101C   [1I, 1J, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1D, 1D, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1I, 1E, 1J, 1E, 1I, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1I, 1I, 1I, 1I, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1J, 1J, 1J, 1J, 1J, 1J, 70D, 1E, 1I, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1J, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 16A, 16A, 1I]   

In [3]:
hdu2= hdulist[2]
hdu1= hdulist[1]

In [ ]:
hdu1.data['OBJECT_POS']

In [4]:
hdu2.header


Out[4]:
XTENSION= 'BINTABLE'           / THIS IS A BINARY TABLE (FROM THE LDACTOOLS)    
BITPIX  =                    8 /                                                
NAXIS   =                    2 /                                                
NAXIS1  =                 1006 / BYTES PER ROW                                  
NAXIS2  =              2749999 / NUMBER OF ROWS                                 
PCOUNT  =                    0 / RANDOM PARAMETER COUNT                         
GCOUNT  =                    1 / GROUP COUNT                                    
TFIELDS =                  101 / FIELDS PER ROWS                                
EXTNAME = 'OBJECTS '           / TABLE NAME                                     
TTYPE1  = 'FIELD_POS'          /                                                
TFORM1  = '1I      '           /                                                
TTYPE2  = 'SeqNr   '           /                                                
TFORM2  = '1J      '           /                                                
TDISP2  = 'I10     '           /                                                
TTYPE3  = 'FLUX_AUTO'          /                                                
TFORM3  = '1E      '           /                                                
TUNIT3  = 'count   '           /                                                
TDISP3  = 'G12     '           /                                                
TTYPE4  = 'FLUXERR_AUTO'       /                                                
TFORM4  = '1E      '           /                                                
TUNIT4  = 'count   '           /                                                
TDISP4  = 'G12     '           /                                                
TTYPE5  = 'MAG_AUTO'           /                                                
TFORM5  = '1E      '           /                                                
TUNIT5  = 'mag     '           /                                                
TDISP5  = 'F8.4    '           /                                                
TTYPE6  = 'MAGERR_AUTO'        /                                                
TFORM6  = '1E      '           /                                                
TUNIT6  = 'mag     '           /                                                
TDISP6  = 'F8.4    '           /                                                
TTYPE7  = 'KRON_RADIUS'        /                                                
TFORM7  = '1E      '           /                                                
TDISP7  = 'F5.2    '           /                                                
TTYPE8  = 'BackGr  '           /                                                
TFORM8  = '1E      '           /                                                
TUNIT8  = 'count   '           /                                                
TDISP8  = 'G12     '           /                                                
TTYPE9  = 'Level   '           /                                                
TFORM9  = '1E      '           /                                                
TUNIT9  = 'count   '           /                                                
TDISP9  = 'G12     '           /                                                
TTYPE10 = 'MU_THRESHOLD'       /                                                
TFORM10 = '1E      '           /                                                
TUNIT10 = 'mag * arcsec**(-2)' /                                                
TDISP10 = 'F8.4    '           /                                                
TTYPE11 = 'MaxVal  '           /                                                
TFORM11 = '1E      '           /                                                
TUNIT11 = 'count   '           /                                                
TDISP11 = 'G12     '           /                                                
TTYPE12 = 'MU_MAX  '           /                                                
TFORM12 = '1E      '           /                                                
TUNIT12 = 'mag * arcsec**(-2)' /                                                
TDISP12 = 'F8.4    '           /                                                
TTYPE13 = 'ISOAREA_WORLD'      /                                                
TFORM13 = '1E      '           /                                                
TUNIT13 = 'deg**2  '           /                                                
TDISP13 = 'G12     '           /                                                
TTYPE14 = 'Xpos    '           /                                                
TFORM14 = '1E      '           /                                                
TUNIT14 = 'pixel   '           /                                                
TDISP14 = 'F10.3   '           /                                                
TTYPE15 = 'Ypos    '           /                                                
TFORM15 = '1E      '           /                                                
TUNIT15 = 'pixel   '           /                                                
TDISP15 = 'F10.3   '           /                                                
TTYPE16 = 'ALPHA_J2000'        /                                                
TFORM16 = '1D      '           /                                                
TUNIT16 = 'deg     '           /                                                
TDISP16 = 'F11.7   '           /                                                
TTYPE17 = 'DELTA_J2000'        /                                                
TFORM17 = '1D      '           /                                                
TUNIT17 = 'deg     '           /                                                
TDISP17 = 'F11.7   '           /                                                
TTYPE18 = 'A_WORLD '           /                                                
TFORM18 = '1E      '           /                                                
TUNIT18 = 'deg     '           /                                                
TDISP18 = 'G12     '           /                                                
TTYPE19 = 'B_WORLD '           /                                                
TFORM19 = '1E      '           /                                                
TUNIT19 = 'deg     '           /                                                
TDISP19 = 'G12     '           /                                                
TTYPE20 = 'THETA_J2000'        /                                                
TFORM20 = '1E      '           /                                                
TUNIT20 = 'deg     '           /                                                
TDISP20 = 'F6.2    '           /                                                
TTYPE21 = 'ERRA_WORLD'         /                                                
TFORM21 = '1E      '           /                                                
TUNIT21 = 'pixel   '           /                                                
TDISP21 = 'G12     '           /                                                
TTYPE22 = 'ERRB_WORLD'         /                                                
TFORM22 = '1E      '           /                                                
TUNIT22 = 'pixel   '           /                                                
TDISP22 = 'G12     '           /                                                
TTYPE23 = 'ERRTHETA_J2000'     /                                                
TFORM23 = '1E      '           /                                                
TUNIT23 = 'deg     '           /                                                
TDISP23 = 'F5.1    '           /                                                
TTYPE24 = 'FWHM_IMAGE'         /                                                
TFORM24 = '1E      '           /                                                
TUNIT24 = 'pixel   '           /                                                
TDISP24 = 'F8.2    '           /                                                
TTYPE25 = 'FWHM_WORLD'         /                                                
TFORM25 = '1E      '           /                                                
TUNIT25 = 'deg     '           /                                                
TDISP25 = 'G12     '           /                                                
TTYPE26 = 'Flag    '           /                                                
TFORM26 = '1I      '           /                                                
TDISP26 = 'I3      '           /                                                
TTYPE27 = 'FLUX_RADIUS'        /                                                
TFORM27 = '1E      '           /                                                
TUNIT27 = 'pixel   '           /                                                
TDISP27 = 'F10.3   '           /                                                
TTYPE28 = 'NIMAFLAGS_ISO'      /                                                
TFORM28 = '1J      '           /                                                
TDISP28 = 'I9      '           /                                                
TTYPE29 = 'CLASS_STAR'         /                                                
TFORM29 = '1E      '           /                                                
TDISP29 = 'F5.2    '           /                                                
TTYPE30 = 'MAN_MASK'           /                                                
TFORM30 = '1I      '           /                                                
TTYPE31 = 'SG_FLAG '           /                                                
TFORM31 = '1E      '           /                                                
TUNIT31 = '""      '           /                                                
TTYPE32 = 'Agaper  '           /                                                
TFORM32 = '1E      '           /                                                
TUNIT32 = 'degrees '           /                                                
TTYPE33 = 'Bgaper  '           /                                                
TFORM33 = '1E      '           /                                                
TUNIT33 = 'degrees '           /                                                
TTYPE34 = 'PAgaap  '           /                                                
TFORM34 = '1E      '           /                                                
TUNIT34 = 'degrees '           /                                                
TTYPE35 = 'MAGERR_GAAP_u'      /                                                
TFORM35 = '1E      '           /                                                
TUNIT35 = 'mag     '           /                                                
TTYPE36 = 'MAGERR_GAAP_g'      /                                                
TFORM36 = '1E      '           /                                                
TUNIT36 = 'mag     '           /                                                
TTYPE37 = 'MAGERR_GAAP_r'      /                                                
TFORM37 = '1E      '           /                                                
TUNIT37 = 'mag     '           /                                                
TTYPE38 = 'MAGERR_GAAP_i'      /                                                
TFORM38 = '1E      '           /                                                
TUNIT38 = 'mag     '           /                                                
TTYPE39 = 'Flag_GAAP_u'        /                                                
TFORM39 = '1I      '           /                                                
TUNIT39 = 'mag     '           /                                                
TTYPE40 = 'Flag_GAAP_g'        /                                                
TFORM40 = '1I      '           /                                                
TUNIT40 = 'mag     '           /                                                
TTYPE41 = 'Flag_GAAP_r'        /                                                
TFORM41 = '1I      '           /                                                
TUNIT41 = 'mag     '           /                                                
TTYPE42 = 'Flag_GAAP_i'        /                                                
TFORM42 = '1I      '           /                                                
TUNIT42 = '""      '           /                                                
TTYPE43 = 'EXTINCTION_u'       /                                                
TFORM43 = '1E      '           /                                                
TUNIT43 = 'mag     '           /                                                
TTYPE44 = 'EXTINCTION_g'       /                                                
TFORM44 = '1E      '           /                                                
TUNIT44 = 'mag     '           /                                                
TTYPE45 = 'EXTINCTION_r'       /                                                
TFORM45 = '1E      '           /                                                
TUNIT45 = 'mag     '           /                                                
TTYPE46 = 'EXTINCTION_i'       /                                                
TFORM46 = '1E      '           /                                                
TUNIT46 = 'mag     '           /                                                
TTYPE47 = 'MAG_LIM_u'          /                                                
TFORM47 = '1E      '           /                                                
TTYPE48 = 'MAG_LIM_g'          /                                                
TFORM48 = '1E      '           /                                                
TTYPE49 = 'MAG_LIM_r'          /                                                
TFORM49 = '1E      '           /                                                
TTYPE50 = 'MAG_LIM_i'          /                                                
TFORM50 = '1E      '           /                                                
TTYPE51 = 'Z_B     '           /                                                
TFORM51 = '1D      '           /                                                
TUNIT51 = '""      '           /                                                
TTYPE52 = 'Z_B_MIN '           /                                                
TFORM52 = '1D      '           /                                                
TUNIT52 = '""      '           /                                                
TTYPE53 = 'Z_B_MAX '           /                                                
TFORM53 = '1D      '           /                                                
TUNIT53 = '""      '           /                                                
TTYPE54 = 'T_B     '           /                                                
TFORM54 = '1D      '           /                                                
TUNIT54 = '""      '           /                                                
TTYPE55 = 'ODDS    '           /                                                
TFORM55 = '1D      '           /                                                
TUNIT55 = '""      '           /                                                
TTYPE56 = 'Z_ML    '           /                                                
TFORM56 = '1D      '           /                                                
TUNIT56 = '""      '           /                                                
TTYPE57 = 'T_ML    '           /                                                
TFORM57 = '1D      '           /                                                
TUNIT57 = '""      '           /                                                
TTYPE58 = 'CHI_SQUARED_BPZ'    /                                                
TFORM58 = '1D      '           /                                                
TUNIT58 = '""      '           /                                                
TTYPE59 = 'BPZ_FILT'           /                                                
TFORM59 = '1J      '           /                                                
TUNIT59 = '""      '           /                                                
TTYPE60 = 'NBPZ_FILT'          /                                                
TFORM60 = '1J      '           /                                                
TUNIT60 = '""      '           /                                                
TTYPE61 = 'BPZ_NONDETFILT'     /                                                
TFORM61 = '1J      '           /                                                
TUNIT61 = '""      '           /                                                
TTYPE62 = 'NBPZ_NONDETFILT'    /                                                
TFORM62 = '1J      '           /                                                
TUNIT62 = '""      '           /                                                
TTYPE63 = 'BPZ_FLAGFILT'       /                                                
TFORM63 = '1J      '           /                                                
TUNIT63 = '""      '           /                                                
TTYPE64 = 'NBPZ_FLAGFILT'      /                                                
TFORM64 = '1J      '           /                                                
TUNIT64 = '""      '           /                                                
TTYPE65 = 'PZ_full '           /                                                
TFORM65 = '70D     '           /                                                
TUNIT65 = '""      '           /                                                
TTYPE66 = 'weight  '           /                                                
TFORM66 = '1E      '           /                                                
TUNIT66 = 'weight  '           /                                                
TTYPE67 = 'fitclass'           /                                                
TFORM67 = '1I      '           /                                                
TUNIT67 = '""      '           /                                                
TTYPE68 = 'scalelength'        /                                                
TFORM68 = '1E      '           /                                                
TUNIT68 = 'pixels  '           /                                                
TTYPE69 = 'bulge_fraction'     /                                                
TFORM69 = '1E      '           /                                                
TUNIT69 = 'b/t ratio'          /                                                
TTYPE70 = 'model_flux'         /                                                
TFORM70 = '1E      '           /                                                
TUNIT70 = '""      '           /                                                
TTYPE71 = 'SNratio '           /                                                
TFORM71 = '1E      '           /                                                
TUNIT71 = '""      '           /                                                
TTYPE72 = 'PSF_e1  '           /                                                
TFORM72 = '1E      '           /                                                
TUNIT72 = '""      '           /                                                
TTYPE73 = 'PSF_e2  '           /                                                
TFORM73 = '1E      '           /                                                
TUNIT73 = '""      '           /                                                
TTYPE74 = 'PSF_Strehl_ratio'   /                                                
TFORM74 = '1E      '           /                                                
TUNIT74 = '""      '           /                                                
TTYPE75 = 'catmag  '           /                                                
TFORM75 = '1E      '           /                                                
TUNIT75 = '""      '           /                                                
TTYPE76 = 'n_exposures_used'   /                                                
TFORM76 = '1J      '           /                                                
TUNIT76 = '""      '           /                                                
TTYPE77 = 'PSF_e1_exp1'        /                                                
TFORM77 = '1E      '           /                                                
TUNIT77 = '""      '           /                                                
TTYPE78 = 'PSF_e2_exp1'        /                                                
TFORM78 = '1E      '           /                                                
TUNIT78 = '""      '           /                                                
TTYPE79 = 'PSF_e1_exp2'        /                                                
TFORM79 = '1E      '           /                                                
TUNIT79 = '""      '           /                                                
TTYPE80 = 'PSF_e2_exp2'        /                                                
TFORM80 = '1E      '           /                                                
TUNIT80 = '""      '           /                                                
TTYPE81 = 'PSF_e1_exp3'        /                                                
TFORM81 = '1E      '           /                                                
TUNIT81 = '""      '           /                                                
TTYPE82 = 'PSF_e2_exp3'        /                                                
TFORM82 = '1E      '           /                                                
TUNIT82 = '""      '           /                                                
TTYPE83 = 'PSF_e1_exp4'        /                                                
TFORM83 = '1E      '           /                                                
TUNIT83 = '""      '           /                                                
TTYPE84 = 'PSF_e2_exp4'        /                                                
TFORM84 = '1E      '           /                                                
TUNIT84 = '""      '           /                                                
TTYPE85 = 'PSF_e1_exp5'        /                                                
TFORM85 = '1E      '           /                                                
TUNIT85 = '""      '           /                                                
TTYPE86 = 'PSF_e2_exp5'        /                                                
TFORM86 = '1E      '           /                                                
TUNIT86 = '""      '           /                                                
TTYPE87 = 'e1      '           /                                                
TFORM87 = '1E      '           /                                                
TTYPE88 = 'e2      '           /                                                
TFORM88 = '1E      '           /                                                
TTYPE89 = 'c1      '           / empirical correction c1                        
TFORM89 = '1E      '           /                                                
TUNIT89 = 'ellipticity cor'    /                                                
TTYPE90 = 'c2      '           / empirical correction c2                        
TFORM90 = '1E      '           /                                                
TUNIT90 = 'ellipticity cor'    /                                                
TTYPE91 = 'm_cor   '           / calibration correction m_cor                   
TFORM91 = '1E      '           /                                                
TUNIT91 = 'ellipticity cor'    /                                                
TTYPE92 = 'MAG_GAAP_u_CALIB'   / MAG_GAAP_u calibrated to SDSS                  
TFORM92 = '1E      '           /                                                
TTYPE93 = 'MAG_GAAP_g_CALIB'   / MAG_GAAP_g calibrated to SDSS                  
TFORM93 = '1E      '           /                                                
TTYPE94 = 'MAG_GAAP_r_CALIB'   / MAG_GAAP_r calibrated to SDSS                  
TFORM94 = '1E      '           /                                                
TTYPE95 = 'MAG_GAAP_i_CALIB'   / MAG_GAAP_i calibrated to SDSS                  
TFORM95 = '1E      '           /                                                
TTYPE96 = 'c1_best '           / Updated empirical correction c1                
TFORM96 = '1E      '           /                                                
TUNIT96 = 'ellipticity cor'    /                                                
TTYPE97 = 'c2_best '           / Updated empirical correction c2                
TFORM97 = '1E      '           /                                                
TUNIT97 = 'ellipticity cor'    /                                                
TTYPE98 = 'm_cor_best'         / calibration correction m_cor pixel scale correc
TFORM98 = '1E      '           /                                                
TUNIT98 = 'ellipticity cor'    /                                                
TTYPE99 = 'THELI_NAME'         / THELI name for the tile                        
TFORM99 = '16A     '           /                                                
TTYPE100= 'KIDS_TILE'          / Name of survey tile                            
TFORM100= '16A     '           /                                                
TTYPE101= 'TILE_SYS_OK'        / Pass = 1, Fail = 0                             
TFORM101= '1I      '           /                                                

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

Reading data in the G15 field and creating rectangular boxes from sub-field coordinates.

Visualizing the overlap with GAMMA groups in the same region:


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')


min/max RA  Global:  211.481216762 225.145184529
min/max DEC Global:  -3.03177225347 3.0395671613
Out[12]:
<matplotlib.text.Text at 0x106d4efd0>

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.)

Creating masked cataloge for cross correlation pipeline:


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])