Пример #1
0
         # continue
     else:
         print("cutout:", '{0}-band{1}'.format(folder,band))
         fitsFile = pyfits.open(file)
         #Load the fov image data:
         fov_image = fitsFile[1].data # check the back grounp
         #Derive the header informaion, might be used to obtain the pixel scale and the exposure time.
         header = fitsFile[1].header # if target position is add in WCS, the header should have the wcs information, i.e. header['EXPTIME']
         #Derive the fov noise level map:
         err_data= fitsFile[3].data ** 0.5
         #Load the PSF data:
         PSF_files = glob.glob('psf*{0}*.fits'.format(HSCband))
         PSF = pyfits.getdata(PSF_files[0])
         
         data_process = DataProcess(fov_image = fov_image, fov_noise_map = err_data, target_pos = [QSO_RA, QSO_DEC],
                                     pos_type = 'wcs', header = header,
                                   rm_bkglight = True, if_plot=False, zp = zp)
         
         #Generate the fitting materials
         data_process.generate_target_materials(radius=120, create_mask = False, nsigma=2.8,
                                               exp_sz= 1.5, npixels = 40, if_plot=False)
         
         # data_process.apertures = [] #Assuming there is no host (i.e., as constant.) #!!!
 
         #Manually input the PSF:
         data_process.PSF_list = [PSF]
         print('{0}-band{1}'.format(folder,band))
         
         file_header = copy.deepcopy(fitsFile[1].header)
         file_header['CRPIX1'] = file_header['CRPIX1']-data_process.target_pos[0]+len(data_process.target_stamp)/2
         file_header['CRPIX2'] = file_header['CRPIX2']-data_process.target_pos[1]+len(data_process.target_stamp)/2
Пример #2
0
header0 = im[0].header
img_filter = header0['FILTER']
img_cam = header0['APERNAME']  #In JDAT'simulation it is 'DETECTOR'
exptime = header0['TEXPTIME']  #The assumed exp time.
from galight.tools.astro_tools import plt_fits
plt_fits(data)

#%% Model using galight
from galight.data_process import DataProcess
zp = 31.4 - 2.5 * np.log10(
    header['PHOTMJSR']
)  #Calculate the correspondingly zp as DN/S #This is wrong! See 3_...
data_process = DataProcess(fov_image=data,
                           target_pos=[1170., 940.],
                           pos_type='pixel',
                           header=header,
                           rm_bkglight=False,
                           exptime=np.ones_like(data) * exptime,
                           if_plot=False,
                           zp=zp)  #Gain value assuming as 1
data_process.generate_target_materials(radius=65,
                                       create_mask=False,
                                       nsigma=2.8,
                                       if_select_obj=False,
                                       exp_sz=1.2,
                                       npixels=15,
                                       if_plot=True)
data_process.find_PSF(radius=30, user_option=True)
data_process.plot_overview(label='Example', target_label=None)

#Start to produce the class and params for lens fitting.
from galight.fitting_specify import FittingSpecify
Пример #3
0
     ra, dec = pos.ra.degree, pos.dec.degree
 
 #%%
 data_process_list = []
 for band in bands:
     fitsFile = pyfits.open(glob.glob(object_id+'/*-cutout-HSC-{0}*.fits'.format(band))[0])
     file_header0 = fitsFile[0].header
     try:
         FLUXMAG0 = file_header0['FLUXMAG0']
         zp =  2.5 * np.log10(FLUXMAG0)   # This is something Xuheng can't make sure.
     except:
         zp = 27.0
     PSF_file = glob.glob(object_id+'/*-psf*HSC-{0}*.fits'.format(band))[0]
     PSF = pyfits.getdata(PSF_file)
     data_process = DataProcess(fov_image = fitsFile[1].data, fov_noise_map = fitsFile[3].data ** 0.5, target_pos = [ra, dec],
                                 pos_type = 'wcs', header = fitsFile[1].header,
                                 rm_bkglight = True, if_plot=False, zp = zp)
     data_process.generate_target_materials(radius=None, #detect_tool='sep'
                                             )
     data_process.PSF_list = [PSF]
     data_process_list.append(data_process)
 
 # % Determining the common settings for all bands, including cutout radius and apertures.
 l_idx = [i for i in range(len(bands)) if bands[i] == lband][0]  #The first index to run
 run_list = [i for i in range(len(bands))]
 del(run_list[l_idx])
 run_list = [l_idx] + run_list  #The list define the order to run
 
 cut_radius = np.median([int(len(data_process_list[i].target_stamp)/2) for i in range(len(data_process_list))])
 for i in range(len(bands)):    
     data_process_list[i].generate_target_materials(radius=cut_radius, create_mask = False, nsigma=2.8,  #detect_tool='sep',
Пример #4
0
                        kwargs_numerics=kwargs_numerics)
image_sim = imageModel.image(kwargs_lens_light=kwargs_light)
poisson = image_util.add_poisson(image_sim, exp_time=exp_time)
bkg = image_util.add_background(image_sim, sigma_bkd=background_rms)
image_noisy = image_sim + bkg + poisson
plt.imshow(image_noisy, origin='lower')
plt.show()

#%%
from galight.data_process import DataProcess
from galight.fitting_specify import FittingSpecify
from galight.fitting_process import FittingProcess
data_process = DataProcess(fov_image=image_noisy,
                           target_pos=[25, 25],
                           pos_type='pixel',
                           exptime=100,
                           rm_bkglight=False,
                           if_plot=False,
                           zp=25)

data_process.PSF_list = [psf_class.kernel_pixel]

data_process.generate_target_materials(radius=25,
                                       create_mask=False,
                                       nsigma=2.8,
                                       exp_sz=1,
                                       npixels=10,
                                       if_plot=True,
                                       bkg_std=background_rms)
data_process.deltaPix = 1
data_process.checkout()  #Check if all the materials is known.
Пример #5
0
file_header0 = fits[0].header
zp = 27.0  # This is something Xuheng can't make sure.
PSF = pyfits.getdata(PSF_filename)

# Start to use galight
picklename = save_name + ID + '_single_Sersic.pkl'
picklename_l = glob.glob(picklename)
if picklename_l != []:
    fit_run_0 = pickle.load(open(picklename_l[0], 'rb'))
else:
    data_process_0 = DataProcess(fov_image=fov_image,
                                 fov_noise_map=err_data,
                                 target_pos=[float(QSO_RA),
                                             float(QSO_DEC)],
                                 pos_type='wcs',
                                 header=header,
                                 rm_bkglight=True,
                                 if_plot=False,
                                 zp=zp)

    data_process_0.noise_map = err_data

    data_process_0.generate_target_materials(radius=None,
                                             detect_tool='sep',
                                             create_mask=False,
                                             nsigma=2.8,
                                             exp_sz=1.2,
                                             npixels=15,
                                             if_plot=True)
    data_process_0.PSF_list = [PSF]
Пример #6
0
    exp =  astro_tools.read_fits_exp(fitsFile[0].header)  #Read the exposure time 
    pixel_scale = astro_tools.read_pixel_scale(fitsFile[1].header)  #Read pixel scale
    mean_wht = exp * (pixel_scale/0.135)**2
    exp_map = exp * wht/mean_wht
    # print(pixel_scale, exp, exp_map.max())
        
    idx = [i for i in range(len(ra_dec_info)) if ID in ra_dec_info[i]][0]
    # print(ID, idx)
    RA, Dec = ra_dec_info[idx].split(' ')[:2]
    RA, Dec = np.float(RA), np.float(Dec)
    if ID == 'J2100-1715':
        RA = 315.2279713
        Dec = -17.25608967

    fov_image = fitsFile[1].data # check the back grounp
    data_process = DataProcess(fov_image = fov_image, target_pos = [RA, Dec], pos_type = 'wcs', header = header,
                          rm_bkglight = True, exptime = exp_map, if_plot=False, zp = 25.9463)  #!!! zp use F160W for now
    data_process.generate_target_materials(radius=20, cut_kernel = 'center_bright', create_mask = False, 
                                           # detect_tool = 'sep', if_select_obj= True, nsigma=2.5, thresh = 2.5, exp_sz= 1.2, npixels = 15, 
                                           if_plot=False)
    
    #Lines used to find PSF and set the PSF_loc_dic.
    data_process.find_PSF(radius = 30, user_option = True, if_filter=True, psf_edge =30)
    # data_process.profiles_compare(norm_pix = 5, if_annuli=False, y_log = False,
    #               prf_name_list = (['target'] + ['PSF{0}'.format(i) for i in range(len(data_process.PSF_list))]) )
    # PSF_loc = PSF_loc_dic[str(i)]
    data_process.plot_overview(label = ID, target_label = None)
    # data_process.find_PSF(radius = 30, PSF_pos_list = [PSF_loc])
    data_process.checkout()
    #Start to produce the class and params for lens fitting.
    # data_process.apertures = []
    print(ID, i)
Пример #7
0
file_header0 = fitsFile[0].header
FLUXMAG0 = file_header0['FLUXMAG0']
zp = 2.5 * np.log10(FLUXMAG0)  # This is something Xuheng can't make sure.
PSF = pyfits.getdata(
    '../example_data/HSC/QSO/000017.88+002612.6_HSC-I_psf.fits')

#%%Start to use galight
from galight.data_process import DataProcess

QSO_RA = 0.07452999800443649
QSO_DEC = 0.4368380010128021
data_process = DataProcess(fov_image=fov_image,
                           fov_noise_map=err_data,
                           target_pos=[QSO_RA, QSO_DEC],
                           pos_type='wcs',
                           header=header,
                           rm_bkglight=True,
                           if_plot=False,
                           zp=zp)

data_process.generate_target_materials(radius=None,
                                       create_mask=False,
                                       nsigma=2.8,
                                       exp_sz=1.2,
                                       npixels=15,
                                       if_plot=False)

data_process.PSF_list = [PSF]

data_process.checkout()  #Check if all the materials is known.
Пример #8
0
    #Plot and save sim details
    plot_sim_name = filename + '_sim.pdf'
    labels = ['org_gal_img', 'project_gal_img', 'conv_gal_img', 'add_ps_noise']
    plt_many_fits([
        hd_gal_img, project_gal_img, conv_project_gal_img,
        noise_conv_project_qso_img
    ],
                  labels=labels,
                  savename=plot_sim_name,
                  if_plot=False)
    #%%Obtain PSF stars:

    data_process = DataProcess(fov_image=data_mock,
                               target_pos=pos,
                               pos_type='pixel',
                               header=header,
                               rm_bkglight=True,
                               exptime=np.ones_like(data_sb) * exptime,
                               if_plot=False,
                               zp=zp)  #Gain value assuming as 1
    data_process.generate_target_materials(radius=rad * 0.8,
                                           create_mask=False,
                                           nsigma=2.8,
                                           if_select_obj=False,
                                           exp_sz=1.2,
                                           npixels=15,
                                           if_plot=False)
    data_process.plot_overview(label=filt + '_' + str(fov_cut_idx) + '_FOV',
                               target_label=name[:7],
                               ifsave=True,
                               filename=filename + '_FOV',
                               if_plot=if_plot)
Пример #9
0
     zp = 2.5 * np.log10(
         FLUXMAG0)  # This is something Xuheng can't make sure.
 except:
     zp = 27.0
 PSF_file = glob.glob('hscdata_web_download' +
                      '/psf*{1}*-{0}*.fits'.format(band, rerun))
 if PSF_file != []:
     PSF_file = PSF_file[0]
 else:
     PSF_file = glob.glob('hscdata_web_download' +
                          '/psf*{1}*-{0}*.fits'.format(band, 's20a'))[0]
 PSF = pyfits.getdata(PSF_file)
 data_process = DataProcess(fov_image=fitsFile[1].data,
                            fov_noise_map=fitsFile[3].data**0.5,
                            target_pos=[ra, dec],
                            pos_type='wcs',
                            header=fitsFile[1].header,
                            rm_bkglight=False,
                            if_plot=False,
                            zp=zp)
 data_process.PSF_list = [PSF]
 data_process.generate_target_materials(radius=cut_radius,
                                        create_mask=False,
                                        nsigma=2.8,
                                        exp_sz=1.2,
                                        npixels=25,
                                        if_plot=False)
 import copy
 apr0 = copy.deepcopy(data_process.apertures[0])
 apr1 = copy.deepcopy(data_process.apertures[0])
 apr0.positions = np.array([48., 49.])
 apr1.positions = np.array([56., 48.])
Пример #10
0
#%%
fitsFile = pyfits.open('../example_data/HST/QSO/1147_final_drz.fits')
fov_image = fitsFile[1].data # check the back grounp
header = fitsFile[1].header # if target position is add in WCS, the header should have the wcs information, i.e. header['EXPTIME']

#%%
wht = fitsFile[2].data # The WHT map
import galight.tools.astro_tools as astro_tools
exp =  astro_tools.read_fits_exp(fitsFile[0].header)  #Read the exposure time 
mean_wht = exp * (0.0642/0.135)**2
exp_map = exp * wht/mean_wht

#%%Start to use galight
from galight.data_process import DataProcess
data_process = DataProcess(fov_image = fov_image, target_pos = [1142., 637.], pos_type = 'pixel', header = header,
                          rm_bkglight = False, exptime = exp_map, if_plot=False, zp = 27.0)
data_process.generate_target_materials(radius=65, create_mask = True, nsigma=2.8, if_select_obj=True,
                                      exp_sz= 1.2, npixels = 15, if_plot=True)


#%%PSF works.
data_process.find_PSF(radius = 30, user_option = True)
# data_process.find_PSF(radius = 50, PSF_pos_list = [[ 350., 1055.], [2078., 1910.]], user_option = False)
data_process.plot_overview(label = 'Example', target_label = None)
data_process.profiles_compare(norm_pix = 5, if_annuli=False, y_log = False,
                  prf_name_list = (['target'] + ['PSF{0}'.format(i) for i in range(len(data_process.PSF_list))]) )

# data_process.psf_id_for_fitting = 11

data_process.checkout() #Check if all the materials is known.
Пример #11
0
from galight.data_process import DataProcess
from galight.tools.cutout_tools import psf_clean
psfs, FWHMs = [], []
for data_sb in data_sbs:
    zp = -2.5 * np.log10(2.350443 * 10**(-5) * 0.01499**2 / 3631)
    header0 = im[0].header
    img_filter = header0['FILTER']
    img_cam = header0['APERNAME']  #In JDAT'simulation it is 'DETECTOR'
    exptime = header0['TEXPTIME']  #The assumed exp time.
    plt_fits(data_sb)
    # Obtain PSF stars:
    # zp = 31.4 - 2.5*np.log10(header['PHOTMJSR'])  #Calculate the correspondingly zp as DN/S #This is wrong! See 3_...
    data_process_ = DataProcess(fov_image=data_sb,
                                target_pos=[1170., 940.],
                                pos_type='pixel',
                                header=header,
                                rm_bkglight=True,
                                exptime=np.ones_like(data_sb) * exptime,
                                if_plot=False,
                                zp=zp)  #Gain value assuming as 1
    # data_process_.generate_target_materials(radius=65, create_mask = False, nsigma=2.8, if_select_obj=False,
    #                                       exp_sz= 1.2, npixels = 15, if_plot=True)
    data_process_.find_PSF(radius=60,
                           user_option=True,
                           psf_edge=150,
                           select_all=True)
    # data_process_.plot_overview(label = 'Example', target_label = None)
    FWHM_list = np.array(data_process_.PSF_FWHM_list)
    POS_list = np.array(data_process_.PSF_pos_list)
    psf_list = np.array(data_process_.PSF_list)
    fwhm_bools = [FWHM_list < 4.3][0]
    psf_list = psf_list[fwhm_bools]
Пример #12
0
                  flux_list_1d,
                  label_list_1d,
                  deltaPix=deltaPix,
                  target_ID='Simulation',
                  if_annuli=True)
    #%%Model:
    from galight.data_process import DataProcess
    from galight.fitting_specify import FittingSpecify
    from galight.fitting_process import FittingProcess

    save_name = 'sim_result_bulge_n{1}_/round0_ID{0}_'.format(j, bulge_n)
    data_process_0 = DataProcess(
        fov_image=sim_image_noise,
        fov_noise_map=rms,
        target_pos=[len(sim_image_noise) / 2,
                    len(sim_image_noise) / 2],
        pos_type='pixel',
        header=None,
        rm_bkglight=False,
        if_plot=False,
        zp=zp)
    data_process_0.deltaPix = deltaPix
    data_process_0.generate_target_materials(radius=None,
                                             create_mask=False,
                                             nsigma=2.8,
                                             exp_sz=1.2,
                                             npixels=15,
                                             if_plot=False)

    data_process_0.PSF_list = [psf_data]
    data_process_0.checkout()  #Check if all the materials is known.
    #%%Start to produce the class and params for lens fitting.
Пример #13
0
# plt_fits(PSF_rebin)

pyfits.PrimaryHDU(fov_image_rebin).writeto(rebin_name + '.fits',
                                           overwrite=True)

# #%%
import galight.tools.astro_tools as astro_tools

exp = astro_tools.read_fits_exp(fitsFile[0].header)  #Read the exposure time
exp_map = exp * np.ones_like(fov_image_rebin)  #* factor**2
from galight.data_process import DataProcess

data_process = DataProcess(fov_image=fov_image_rebin,
                           target_pos=[318.0, 239.6],
                           pos_type='pixel',
                           rm_bkglight=True,
                           exptime=exp_map,
                           if_plot=False,
                           zp=27.0)
data_process.generate_target_materials(radius=len(fov_image_rebin) / 2,
                                       create_mask=False,
                                       nsigma=2.8,
                                       if_select_obj=False,
                                       exp_sz=1.2,
                                       npixels=300,
                                       if_plot=False,
                                       bkg_std=bkg_std)
data_process.PSF_list = [PSF_rebin]
data_process.deltaPix = 1
data_process.noise_map[np.isnan(data_process.noise_map)] = bkg_std
from galight.tools.measure_tools import mask_obj
Пример #14
0
            FLUXMAG0)  # This is something Xuheng can't make sure.
        print(file, zp)
        #Load the fov image data:
        fov_image = fitsFile[1].data  # check the back grounp
        #Derive the header informaion, might be used to obtain the pixel scale and the exposure time.
        header = fitsFile[
            1].header  # if target position is add in WCS, the header should have the wcs information, i.e. header['EXPTIME']
        #Derive the fov noise level map:
        err_data = fitsFile[3].data**0.5
        #Load the PSF data:
        # PSF_files = glob.glob('psf*{0}*.fits'.format(HSCband))
        # PSF = pyfits.getdata(PSF_files[0])
        data_process = DataProcess(fov_image=fov_image,
                                   fov_noise_map=err_data,
                                   target_pos=[QSO_RA, QSO_DEC],
                                   pos_type='wcs',
                                   header=header,
                                   rm_bkglight=True,
                                   if_plot=False,
                                   zp=zp)

        PSF_loc = [35.29689501, -4.685896878]
        data_process.find_PSF(
            radius=20,
            PSF_pos_list=[PSF_loc],
            pos_type='wcs',
        )

        #Generate the fitting materials
        data_process.generate_target_materials(radius=30,
                                               create_mask=False,
                                               nsigma=2.8,