#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 pyfits.PrimaryHDU(data_process.target_stamp,header=file_header).writeto('{0}-band{1}.fits'.format(folder,band) ,overwrite=True) pyfits.PrimaryHDU(data_process.noise_map,header=file_header).writeto('{0}-band{1}_noise.fits'.format(folder,band) ,overwrite=True)
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 # data_process.apertures = [] fit_sepc = FittingSpecify(data_process) fit_sepc.prepare_fitting_seq(point_source_num=1) #, fix_n_list= [[0,4],[1,1]]) fit_sepc.build_fitting_seq() #Plot the initial settings for fittings.
#%% 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', exp_sz= 1.2, npixels = 15, if_plot=False) data_process_list[i].checkout()
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. fit_sepc = FittingSpecify(data_process) fit_sepc.prepare_fitting_seq( point_source_num=0, sersic_major_axis=False ) #, fix_n_list= [[0,4]], fix_center_list = [[0,0]]) fit_sepc.plot_fitting_sets() fit_sepc.build_fitting_seq() #Setting the fitting method and run. fit_run = FittingProcess(fit_sepc) fit_run.run(algorithm_list=['PSO', 'PSO'], setting_list=[{
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] data_process_0.checkout() #Check if all the materials is known. fit_sepc_0 = FittingSpecify(data_process_0) fit_sepc_0.prepare_fitting_seq( point_source_num=1) #, fix_n_list= [[0,4]], fix_center_list = [[0,0]]) fit_sepc_0.plot_fitting_sets() fit_sepc_0.build_fitting_seq() # Setting the fitting method and run. fit_run_0 = FittingProcess(fit_sepc_0, savename=save_name + ID + '_single_Sersic') fit_run_0.run(algorithm_list=['PSO', 'PSO'],
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) 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)):
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) fit_sepc = FittingSpecify(data_process) fit_sepc.prepare_fitting_seq(point_source_num = 1) #, fix_n_list= [[0,4],[1,1]])
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.]) data_process.apertures = [apr0, apr1] # if rerun != 's21a': # picklename = 'fit_result/'+'dual_result-band-{0}-s21a.pkl'.format(band) # s21_res = pickle.load(open(picklename,'rb')) # data_process.target_stamp -= s21_res.image_host_list[0] fit_sepc = FittingSpecify(data_process) fit_sepc.prepare_fitting_seq(point_source_num=point_source_num, supersampling_factor=3)
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. # #Manually input another component: # apertures_0 = copy.deepcopy(data_process_0.apertures) # add_aperture1 = copy.deepcopy(apertures_0[0]) # add_pos = [60, 60] #The position of the component. # if isinstance(add_aperture1.positions[0],float): # add_aperture1.positions = np.array(add_pos) # elif isinstance(add_aperture1.positions[0],np.ndarray): # add_aperture1.positions = np.array([add_pos]) # add_aperture1.a, add_aperture1.b = 2, 2 #define the a, b value of this component, i.e., Reff = sqrt(a^2 +b^2)
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 import copy apertures = copy.deepcopy(data_process.apertures) apertures[0].a, apertures[0].b = apertures[0].a * expzs, apertures[0].b * expzs apertures[1].a, apertures[1].b = apertures[1].a * expzs, apertures[1].b * expzs masks = mask_obj(data_process.target_stamp, apertures, sum_mask=True) masks = 1 - masks data_process.target_mask = masks