Exemplo n.º 1
0
def main():
    for i in range(5):

        file125 = data_dir + 'gal%s_UV_F125_scale_04_psfmatch.fits' % (i + 1)
        hd = fits.open(file125)
        photflam = float(hd[1].header['PHOTFLAM'])
        data_125 = hd[1].data
        section_gal = 'NULIRG%s' % (int(i + 1))
        params, params_gal = basic_params(config_file, 'basic', section_gal)
        cent_x, cent_y = UV_centers_drz(file125)

        print('=============================================\n')
        print('<<<<<<<<<<<<<<<<<<<<<ULIRG %s>>>>>>>>>>>>>>>>>>\n' % (i + 1))
        print('=============================================\n')

        print('Original shape', data_125.shape)
        print('UV 125 centers --> (%s, %s)' % (cent_x, cent_y))

        for extension in ext_list:

            data_ext = sum_ext(data_125, data_dir, i, extension)  #'A_lmfit_x'
            fits.writeto('%s/ULIRG%s_pos_m/%s%s_no_mask.fits' %
                         (extension, data_dir, i + 1, i + 1),
                         data=data_lya,
                         overwrite=True)
Exemplo n.º 2
0
def main(config_file):

    for i in range(5):
        section_gal = 'NULIRG%s' % (int(i + 1))
        params, params_gal = basic_params(config_file, 'basic', section_gal)

        combine_FLT(params, params_gal)
Exemplo n.º 3
0
def main(config_file):
	#im_drz =[(1320.2164578776137, 4232.254568212932),(3133.44270371664,	5998.802594324208),(1077.9077757159448, 1782.7589540070876),(4144.009171783876, 5989.1062047339765),(5859.227208853262, 4226.265089816052)]
	im_drz =[(1320.2164578776137, 4232.254568212932),(3133.44270371664,	5998.802594324208),(1078.92343744, 1784.99832295),(4144.009171783876, 5989.1062047339765),(5859.227208853262, 4226.265089816052)]
	for i in range(5):
		section_gal = 'NULIRG%s' % (int(i + 1))
		params, params_gal = basic_params(config_file, 'basic', section_gal)

		drizconfig = params['wfc_config']
		psfscale = float(params['psfscale'])
		order = int(params['order'])
		defkey = params['defkey']
		gal_name = params_gal['name']
		primary_dir = params['data_dir'] + gal_name + '/'
		txt_dir = primary_dir + 'HA_PSF/TXT/' 
		call('./tiny1')
		psf_out_dir = params['data_dir'] + 'OPTICAL_PSF/'

		for j in range(2):
			outpsf = params['outpsf']+'_%s_gal%s'%(filt[j], i+1)

			imlist = txt_dir + 'imlist%s_gal%s.txt' % (filt[j], i + 1)
			loclist = params['config_dir'] + 'loclist%s_gal%s.txt' % (filt[j], i + 1)
			tinybase = params['config_dir'] + 'tinybase%s_gal%s_v3.txt' % (filt[j], i + 1)
			simpos = params['config_dir']+ 'simpos%s_gal%s.txt' % (filt[j], i + 1)
			ha_psf(config_file, im_drz, psf_out_dir, i, imlist,loclist,tinybase,simpos,drizconfig,
			outpsf, psfscale,order,defkey)
	tmp_files = glob.glob(os.getcwd()+ '/psf*')
	[shutil.move(x,psf_out_dir+'RAW_PSF/'+os.path.basename(x) ) for x in tmp_files]
Exemplo n.º 4
0
def main(config_file):
    parser = argparse.ArgumentParser(description=__doc__,
                                     formatter_class=argparse.RawTextHelpFormatter,
                                     fromfile_prefix_chars='@')
    # parser.add_argument('imlst', type=str)
    # parser.add_argument('refdata', type=str)
    parser.add_argument('--noupd', action='store_true', help='do not update ' +
                        'header(s), print to std output instead')
    parser.add_argument('--hdrkey', type=str, default='DFOC_MOD',
                        help='header keyword')
    args = parser.parse_args()
    keys = ['galaxy', 'filter', 'exposures', 'defocus']
    dict_defoc = OrderedDict.fromkeys(keys)
    for x in keys:
        dict_defoc[x] = []
    for i in range(5):
        section_gal = 'NULIRG%s' % (int(i + 1))
        params, params_gal = basic_params(config_file, 'basic', section_gal)
        refdata = params['psf_defocus']
        gal_name = params_gal['name']
        primary_dir = params['data_dir'] + gal_name + '/'
        txt_dir = primary_dir + 'HA_PSF/TXT/'

        for j in range(2):

            imlist_file = primary_dir + 'HA_PSF/TXT/' + 'imlist%s_gal%s.txt' % (filt[j], i + 1)
            #loclist = txt_dir + 'loclist%s_gal%s.txt' % (filt[j], i + 1)
            simpos = txt_dir + 'simpos%s_gal%s.txt' % (filt[j], i + 1)

            images = params_gal['f%s' % (filt[j])].split(',')
            ar = []
            simpos_ra = []
            simpos_dec = []
            #loc_x = []
            #loc_y = []
            for x in images:
                name = primary_dir + 'HA_FLC/FITS/jcmc%s_flc.fits' % (x)
                ar.append(name)
                cent_x, cent_y, cent_ra, cent_dec = UV_centers(params, params_gal, i)
                # cent_x is UV center
                simpos_ra.append(cent_ra)
                simpos_dec.append(cent_dec)
                #pixx, pixy = FLC_centers(cent_ra, cent_dec, ar[1])
                # loc_x.append(pixx)
                # loc_y.append(pixy)

            with open(simpos, 'w') as f:
                [f.write("%s \t %s \n" % (simpos_ra[m], simpos_dec[m])) for m in range(len(ar))]
            with open(imlist_file, 'w') as f:
                [f.write("%s\n" % item) for item in ar]
            meandef = findfocus(imlist_file, refdata, args.noupd, args.hdrkey)

            print('Mean defocus of frames filter %s galaxy %s===> %s' % (filt[j], i + 1, str(meandef)))
            dict_defoc['galaxy'].append('gal_%s' % (i + 1))
            dict_defoc['filter'].append('f' + filt[j])
            dict_defoc['exposures'].append(images[0] + '_' + images[1])
            dict_defoc['defocus'].append(meandef)
    df = pd.DataFrame(dict_defoc)
    df.to_csv(os.path.dirname(config_file) + 'defocus_ULIRG.txt', index=False)
Exemplo n.º 5
0
def main(config_file):

    for i in range(5):
        section_gal = 'NULIRG%s' % (int(i + 1))
        params, params_gal = basic_params(config_file, 'basic', section_gal)

        for j in range(4):

            psf_match(params, params_gal, i, j)
Exemplo n.º 6
0
def main(config_file):
    for i in range(5):
        section_gal = 'NULIRG%s' % (int(i + 1))
        params, params_gal = basic_params(config_file, 'basic', section_gal)
        gal_name = params_gal['name']
        primary_dir = params['data_dir'] + gal_name + '/'

        for j in range(2):
            filename = primary_dir + "gal%s_%s.fits" % (i + 1, a[j])
            fileout = filename.replace('.fits', '_psfmatch.fits')
            ker = "ker%s_gal%s_ref165_rotate.fits" % (filt[j], i + 1)
            print(
                " i m running slowly. Takes 10 minutes for each galaxy filter = %s \n"
                % (filt[j]))
            print(filename, ker)
            psf_match(filename, fileout, ker)

        print("convolution data done galaxy %s \n" % (i + 1))
Exemplo n.º 7
0
def main(config_file):

    first_run = True
    dark_perform = True
    for i in range(5):
        section_gal = 'NULIRG%s' % (int(i + 1))

        params, params_gal = basic_params(config_file, 'basic', section_gal)
        gal_name = params_gal['name']
        global primary_dir
        primary_dir = params['data_dir'] + gal_name + '/'
        if first_run:
            remove_files('sky')

        if dark_perform:
            remove_files('drk')
        tab, bad, dark, primary_dir = rotate(params, params_gal, dark_perform)
        xreg(params, params_gal, tab, bad, dark, primary_dir, dark_perform)
Exemplo n.º 8
0
def main(config_file):

    for i in range(5):

        section_gal = 'NULIRG%s' % (int(i + 1))
        params, params_gal = basic_params(config_file, 'basic', section_gal)
        tab = Table.read(params['flt_files'], format='csv')
        gal_name = params_gal['name']
        primary_dir = params['data_dir'] + gal_name + '/'

        for j in range(2):
            for k in range(len(tab)):
                if tab['galaxy'][k] == gal_name and tab['filtername'][
                        k] == 'F775W':
                    angle = float(tab['orientation'][k])
            print(angle)
            psf = params['hapsf_dir'] + 'PSF_%s_gal%s.fits' % (filt[j], i + 1)
            psf_rot = psf.replace('gal%s' % (i + 1), 'gal%s_rotate' % (i + 1))
            psf_cut = psf_rot.replace("rotate", "rotate_cut")
            psf_rotate(psf, psf_rot, angle)
            size = 130
            psf_cutting(psf, angle, psf_rot, psf_cut, size)
            psf165 = params['hapsf_dir'] + 'f165psf.fits'
            data = fits.getdata(psf165)
            print(data.shape, data.sum())

            hdu = fits.open(psf_cut)
            data = hdu[0].data
            hdu[0].data = data / data.sum()
            hdu.writeto(psf_cut, overwrite=True)
            hdu.close()
            print(data.shape, data.sum())
    for j in range(2):
        psf_cut = params['hapsf_dir'] + 'PSF_%s_gal%s_rotate_cut.fits' % (
            filt[j], i + 1)
        psfref = params['hapsf_dir'] + 'PSF_775_gal%s_rotate_cut.fits' % (
            i + 1)  # 'f165psf.fits'  #
        ker = psf_matching(i, filt[j], psf_cut, psfref)
        ker_rot = ker.replace('165', '165_rotate')
        # rotate kernels
        psf_rotate(ker, ker_rot, -angle)
Exemplo n.º 9
0
def main(config_file):

    for i in range(5):
        section_gal = 'NULIRG%s' % (int(i + 1))
        params, params_gal = basic_params(config_file, 'basic', section_gal)
        drizzle_SBC(params, params_gal, i)
Exemplo n.º 10
0
def 
for i in range(5):
    file125 = 'gal%s_UV_F125_scale_04_psfmatch.fits'%(i+1)
    hd = fits.open(file125)
    photflam = float(hd[1].header['PHOTFLAM'])
    data_125 = hd[1].data
    section_gal = 'NULIRG%s' % (int(i + 1))
    params, params_gal = basic_params(config_file, 'basic', section_gal)
    cent_x, cent_y = UV_centers_drz(file125)


    print ('=============================================\n')
    print ('<<<<<<<<<<<<<<<<<<<<<ULIRG %s>>>>>>>>>>>>>>>>>>\n'%(i+1))
    print ('=============================================\n')

    print ('Original shape', data.shape)
    print ('UV 125 centers --> (%s, %s)'% (cent_x, cent_y))

    

    
    print (' ----> Making annuli masks\n')
    width = 4.0
    aper_lim = 300

    if i ==4:
        aper_lim = 300*0.158/0.131
    nx = data_125.shape[0]
    ny = data_125.shape[1]
    rad1, rad_annulus, masks, masks_annulus = masks_circular(cent_x, cent_y, width, aper_lim, nx, ny)

    ################## computing center boxes ################
    if i ==1:
        x = [150, 150, 150, 350, 350, 350, 550, 550, 550]
        y = [150, 350, 550, 150, 350, 550, 150, 350, 550]
    elif i ==2:
        x = [150, 150, 150, 150, 350, 350, 350, 350, 550, 550, 550, 550, 750, 750, 750, 750]
        y = [150, 350, 550, 750, 150, 350, 550, 750, 150, 350, 550, 750, 150, 350, 550, 750]
    else:
        x = [350, 350, 350, 550, 550, 550, 750, 750, 750]
        y = [350, 550, 750, 350, 550, 750, 350, 550, 750]
      
        
    fig,((ax1, ax2), (ax3, ax4)) = plt.subplots(2,2, figsize = (30,22))
    
    [plot_rectangle(x[i],y[i], szx, szy, color[i], ax1) for i in range(len(x))]
    norm = ImageNormalize(data_125, stretch=AsinhStretch())
    img = ax1.imshow(data_125, origin = 'lower', vmin =0.0005, vmax = 0.001, norm = norm, cmap = plt.cm.Greys_r, zorder =0)

    divider = make_axes_locatable(ax1)
    cax = divider.append_axes("right", size="5%", pad=0.0)
    cbar = plt.colorbar(img,cax=cax, orientation='vertical')
    cbar.minorticks_on
    

    data_lya = sum_ext(i, 'A_lmfit_x')
    err_lya = sum_ext(i, 'A_lmfit_err')
    ### positive flux cond
    
    #data_all[data_all<0] = 0.0
    cond_positive = data_lya < 0.0
    cond_negative = data_lya > 0.0

    #### SN >1 condition
    
    SN_all = abs(data_lya/err_lya)
    

    #SN_add = data_lya + err_lya
    #SN_diff = data_lya - err_lya

    #cond_sn = np.isnan(SN_all)
    #SN_all[cond_sn] = 0.0
    #SN_all[cond_sn_tot] = 0.0
    b_all = sum_ext(i, 'b_lmfit_x')
    cond_b = abs(abs(b_all)-3) <1e-5

    status_all = sum_ext(i, 'status_lmfit_x')
    cond_status = status_all == 0
    
    data_neg = np.copy(data_all)
    data_test = np.copy(data_all)
    aper_total =  [len(data_neg[masks_annulus[k]]) for k in range(len(rad1)-1) ]  
    
    aper_nonzero_total =  [non_zero(data_test[masks_annulus[k]]) for k in range(len(rad1)-1) ] 
    cond_test = cond_sn_tot + cond_b + cond_status
    data_test[cond_test] = 0.0
    aper_nonzero_total_cutoff = [non_zero(data_test[masks_annulus[k]]) for k in range(len(rad1)-1) ] 

    
    cond_all = cond_sn_tot + cond_b + cond_status + cond_positive   
    data_all[cond_all] = 0.0
    SN_add[cond_all] = 0.0
    SN_diff[cond_all] = 0.0
    
    cond_neg = cond_sn_tot + cond_b + cond_status + cond_negative   

    data_neg[cond_neg] = 0.0

    #data_neg = abs(data_neg)
    #img = ax1.imshow(data_all, origin = 'lower', vmin =-1e-15, vmax = 1e-20, norm = norm, cmap = plt.cm.Greys_r, zorder =0)

    
    fits.writeto('./ULIRG%s_test/data%s.fits'%(i+1, i+1), data = data_test, overwrite = True)
    fits.writeto('./ULIRG%s_test/SN%s.fits'%(i+1, i+1), data = SN_all, overwrite = True)
    fits.writeto('./ULIRG%s_test/b%s.fits'%(i+1, i+1), data = b_all, overwrite = True)
    fits.writeto('./ULIRG%s_test/status%s.fits'%(i+1, i+1), data = status_all, overwrite = True)

    

    aper_SN_low =  [np.mean(SN_add[masks_annulus[k]]) for k in range(len(rad1)-1) ]  
    aper_SN_high =  [np.mean(SN_diff[masks_annulus[k]]) for k in range(len(rad1)-1) ]  
    
    
    sum_SN_low =  [np.sum(SN_add[masks[k]]) for k in range(len(rad1)) ]  
    sum_SN_high =  [np.sum(SN_diff[masks[k]]) for k in range(len(rad1)) ]  

    
    sum_125 =  [np.sum(data_all[masks[k]]) for k in range(len(rad1)) ]  
    aper_125 =  [np.mean(data_all[masks_annulus[k]]) for k in range(len(rad1)-1) ]  
    
    sum_125_neg =  [np.sum(abs(data_neg[masks[k]])) for k in range(len(rad1)) ]  
    aper_125_neg =  [np.mean(abs(data_neg[masks_annulus[k]])) for k in range(len(rad1)-1) ]  
    
    sum_UV =  [np.nansum(data[masks[k]]*photflam*150) for k in range(len(rad1)) ]  
    aper_UV =  [np.nanmean(data[masks_annulus[k]]*photflam*150) for k in range(len(rad1)-1) ] 
    
    aper_nonzero =  [non_zero(data_all[masks_annulus[k]]) for k in range(len(rad1)-1) ] 
    aper_nonzero_neg =  [non_zero(data_neg[masks_annulus[k]]) for k in range(len(rad1)-1) ]  

    rad_kpc = [rad*0.04*scale[i] for rad in rad1]
    rad_annulus_kpc = [rad*0.04*scale[i] for rad in rad_annulus]
    diff = [(-aper_125_neg[k] + aper_125[k]) for k in range(len (rad_annulus))]
    
    diff_sum = [(-sum_125_neg[k] + sum_125[k]) for k in range(len (rad1))]

    #norm_sum = [x1/sum_125[-1] for x1 in sum_125]

    #low = [aper_125[i] -aper_125[i] /aper_SN[i] for i in range(len (rad_annulus))]
    #high = [aper_125[i] +aper_125[i]/aper_SN[i] for i in range(len (rad_annulus))]

    ax4.plot(rad_kpc, sum_125, 'r', label = r'$Ly\alpha$ positive')
    ax4.fill_between(rad_kpc, sum_SN_low, sum_SN_high, alpha =0.1, color = 'b', zorder =1)
    
    ax4.plot(rad_kpc, sum_125_neg, 'g', label = r'abs($Ly\alpha$ negative)')
    ax4.plot(rad_kpc, diff_sum, 'b', label = r'($Ly\alpha$ total)')
    ax4.plot(rad_kpc, sum_UV, 'k', label = 'F125 flux')

    
    
    ax3.plot(rad_annulus_kpc, aper_125, 'r', label = r'$Ly\alpha$ positive')

    ax3.fill_between(rad_annulus_kpc, aper_SN_low, aper_SN_high, alpha =0.1, color = 'b', zorder =1)

    ax3.plot(rad_annulus_kpc, aper_125_neg, 'g', label = r'abs($Ly\alpha$ negative)')
    ax3.plot(rad_annulus_kpc, diff, 'b', label = r'($Ly\alpha$ total)')
    ax3.plot(rad_annulus_kpc, aper_UV, 'k', lw = 2.0, label = 'F125 flux')
    
    
    theoretical = [2*np.pi*k*width for k in rad_annulus]
    ax2.plot(rad_annulus_kpc, theoretical, color = 'k', zorder =2,lw = 2.0, label = 'Expected')
    
    ax2.fill_between(rad_annulus_kpc, aper_total, alpha =0.1, color = 'b', zorder =1, label = 'Total')
    ax2.fill_between(rad_annulus_kpc, aper_nonzero_total, alpha =0.2, color = 'c', zorder =1, label = 'Total non-zero')
    ax2.fill_between(rad_annulus_kpc, aper_nonzero_total_cutoff, alpha =0.3, color = 'm', zorder =1, label = 'Quality fit cutoff')

    ax2.fill_between(rad_annulus_kpc, aper_nonzero, alpha =0.3, color = 'r', zorder =2, label ='Positive')
    ax2.fill_between(rad_annulus_kpc, aper_nonzero_neg, alpha =0.6, color = 'g', zorder =3, label = 'Negative')


    ''' #testing the total counts
    test = [aper_nonzero[k] + aper_nonzero_neg[k]- aper_nonzero_total_cutoff[k] for k in range(len (rad_annulus))]
    ax1.fill_between(rad_annulus_kpc, test, alpha =0.5, color = 'g', zorder =2, label = 'negative')
    '''
    #ax2.plot(rad_annulus_kpc, aper_UV, )
    
    
    
    ax3.set_xlim(0, 32)
    ax4.set_xlim(0, 32)
    ax2.set_xlim(0, 32)
    ax2.set_yscale('log')
    ax2.set_ylabel('Number of points')
    ax2.set_xlabel('Distance from UV center [kpc]')
    
    ax3.set_ylabel(r'Aperture mean Flux[in ergs-$s^{-1}$-$cm^{-2}$-arcsec$^{-2}$]')
    ax3.set_xlabel('Distance from UV center [kpc]')
    
    
    ax3.set_yscale('log')
    
    ax3.axvline(x = petro_all[i], color = 'm', linestyle='--', label = r'$2\times R_p$')
    ax4.axvline(x = petro_all[i], color = 'm', linestyle = '--', label = r'$2\times R_p$')
    
    ax2.legend(loc ='lower left')
    ax3.legend(loc ='upper right')
    
    ax1.set_xlim(0,1000)
    ax1.set_ylim(0,1000)
    ax1.plot(cent_x, cent_y, marker ='x', color = 'b', mew=5, ms=20)
    
    circle(cent_x, cent_y, aper_lim, 'c', ax1)
    circle(cent_x, cent_y, petro_all[i]/(0.05*scale[i]), 'm', ax1)
    
    new_label_x = np.linspace((cent_x-sz[i]), (cent_x+sz[i]), 10)#*0.05*phys )
    new_label_y = np.linspace((cent_y-sz[i]), (cent_y+sz[i]), 10)#*0.05*phys )
    ar_x = np.round((new_label_x- cent_x)*0.04*scale[i] )
    ar_y = np.round((new_label_y - cent_y)*0.04*scale[i] )

    ax1.set_yticks(new_label_y)
    ax1.set_yticklabels(int(x) for x in (ar_y))
    ax1.set_xticks(new_label_x)
    ax1.set_xticklabels((int(x) for x in (ar_x)))
    ax1.set_xlabel('kpc')
    ax1.set_ylabel('kpc')
    ax1.set_aspect(1.)
    ax4.legend(loc = 'upper left')
    
    
    ax4.set_ylabel(r'Cumulative Flux[in ergs-$s^{-1}$-$cm^{-2}$-arcsec$^{-2}$]')
    ax4.set_xlabel('Distance from UV center [kpc]')
    
    
    keys = ['radius', 'Lya_pos', 'UV', 'Lya_neg', 'Lya_total', ]
    
    dict_annuli = OrderedDict.fromkeys(keys)
    dict_annuli['radius'] = rad_annulus_kpc
    dict_annuli['Lya_pos'] = aper_125
    dict_annuli['UV'] = aper_UV
    dict_annuli['Lya_neg'] = aper_125_neg
    dict_annuli['Lya_total'] = diff
    
    
    df = pd.DataFrame.from_dict(dict_annuli)
    df.to_csv('ULIRG%s_annuli.csv'%(i+1), columns = keys, index = True)
    
    
    dict_sum = OrderedDict.fromkeys(keys)
    dict_sum['radius'] = rad_kpc
    dict_sum['Lya_pos'] = sum_125
    dict_sum['UV'] = sum_UV
    dict_sum['Lya_neg'] = sum_125_neg
    dict_sum['Lya_total'] = diff_sum
    
    
    df = pd.DataFrame.from_dict(dict_sum)
    df.to_csv('ULIRG%s_sum.csv'%(i+1), columns = keys, index = True)
    
    
    
    ax1.set_title('ULIRG %s F125 image'%(i+1), fontsize = 15)
    fig.savefig('ULIRG%s_radial.png'%(i+1), dvi = 400)
    plt.show()