apertures = data_process_list[l_idx].apertures from galight.tools.measure_tools import mask_obj for i in run_list: if i != l_idx: covers = mask_obj(data_process_list[i].target_stamp, apertures, if_plot=False, sum_mask = True) for j in range(len(data_process_list[i].apertures)): new_cover = mask_obj(data_process_list[i].target_stamp, [data_process_list[i].apertures[j]], if_plot=False, sum_mask = True) if np.sum(covers - new_cover*covers) > np.sum(1-new_cover)/2 : #If 1/2 of the area covered by the aperture is new) apertures.append(data_process_list[i].apertures[j]) fit_sepc_l, fit_run_l = [None]*5, [None]*5 for i in run_list: band = bands[i] print("Staring fitting band-"+band+"... ... ...") data_process_list[i].apertures = apertures #Pass apertures to the data fit_sepc_l[i] = FittingSpecify(data_process_list[i]) fix_n_list, fix_Re_list = None, None if i != l_idx: if fix_n == True: fix_n_list = [[0,fit_run_l[l_idx].final_result_galaxy[0]['n_sersic'] ]] if fix_re == True: fix_Re_list = [[0,fit_run_l[l_idx].final_result_galaxy[0]['R_sersic'] ]] fit_sepc_l[i].prepare_fitting_seq(point_source_num = point_source_num, supersampling_factor=3, fix_n_list= fix_n_list, fix_Re_list=fix_Re_list) fit_sepc_l[i].plot_fitting_sets(object_id+'/fitconfig-band-{0}.png'.format(band)) fit_sepc_l[i].build_fitting_seq() fit_run_l[i] = FittingProcess(fit_sepc_l[i], savename = object_id+'/result-band-{0}'.format(band), fitting_level=fitting_level) fit_run_l[i].run(algorithm_list = ['PSO'], setting_list=[None]) # fit_run.plot_all(target_ID = object_id) if fit_run_l[i].image_ps_list != []: fit_run_l[i].plot_final_qso_fit(save_plot=True, target_ID= object_id +'-'+ band )
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'], setting_list=[{ 'sigma_scale': 1., 'n_particles': 50, 'n_iterations': 50 }] * 2) fit_run_0.plot_final_qso_fit() bic_0 = fit_run_0.fitting_seq.bic
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. fit_sepc.plot_fitting_sets() #Setting the fitting method and run. from galight.fitting_process import FittingProcess fit_run = FittingProcess(fit_sepc, savename='savename', fitting_level='norm') fit_run.run(algorithm_list=['PSO', 'PSO']) fit_run.plot_final_galaxy_fit() print(fit_run.final_result_galaxy[0]) print(fit_run.final_result_ps[0])
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) apertures = apertures + [add_aperture1 ] #attach the added aperture into the group. data_process.apertures = apertures #Pass apertures to the data from galight.tools.measure_tools import plot_data_apertures plot_data_apertures(data_process.target_stamp, apertures) #%%Start to produce the class and params for lens fitting. from galight.fitting_specify import FittingSpecify fit_sepc = FittingSpecify(data_process) fit_sepc.prepare_fitting_seq( point_source_num=1, fix_n_list=[ [0, 4], [1, 1] ], #fix_Re_list= [[0,0.2], [1,1.14]], #First component fix n = 4 (bluge), second one fix to 1 (disk). fix_center_list=[[0, 0]]) fit_sepc.plot_fitting_sets() fit_sepc.build_fitting_seq() # #%%Setting the fitting method and run. from galight.fitting_process import FittingProcess
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=[{ 'sigma_scale': 1., 'n_particles': 50, 'n_iterations': 50 }] * 2) fit_run.plot_final_galaxy_fit() # fit_run.dump_result()
for j in range(len(data_process_list[i].apertures)): new_cover = mask_obj(data_process_list[i].target_stamp, [data_process_list[i].apertures[j]], if_plot=False, sum_mask=True) if np.sum(covers - new_cover * covers) > np.sum( 1 - new_cover ) / 2: #If 1/2 of the area covered by the aperture is new) apertures.append(data_process_list[i].apertures[j]) fit_sepc_l, fit_run_l = [None] * 5, [None] * 5 for i in run_list: band = bands[i] print("Staring fitting band-" + band + "... ... ...") data_process_list[i].apertures = apertures #Pass apertures to the data fit_sepc_l[i] = FittingSpecify(data_process_list[i]) fix_n_list, fix_Re_list = None, None if i != l_idx: if fix_n == True: fix_n_list = [[ 0, fit_run_l[l_idx].final_result_galaxy[0]['n_sersic'] ]] if fix_re == True: fix_Re_list = [[ 0, fit_run_l[l_idx].final_result_galaxy[0]['R_sersic'] ]] fit_sepc_l[i].prepare_fitting_seq( point_source_num=point_source_num, supersampling_factor=3, ps_pix_center_list=ps_pix_center_list, fix_n_list=fix_n_list,
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) fit_sepc.plot_fitting_sets( object_id + '_fitconfig-band-{0}-{1}.png'.format(band, rerun)) fit_sepc.build_fitting_seq() # if rerun != 's19a': # fit_sepc.kwargs_params['point_source_model'] = s21_res.fitting_specify_class.kwargs_params['point_source_model'] fit_run = FittingProcess(fit_sepc, savename=object_id + '_result-band-{0}-{1}'.format(band, rerun), fitting_level=fitting_level) fit_run.run(algorithm_list=['PSO', 'PSO'], setting_list=[None, None]) fit_run.plot_final_qso_fit(save_plot=True, target_ID=object_id + '-' + band) fit_run.dump_result()
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=True) data_process.PSF_list = [PSF] data_process.checkout() #Check if all the materials is known. #%%Start to produce the class and params for lens fitting. from galight.fitting_specify import FittingSpecify fit_sepc = FittingSpecify(data_process) fit_sepc.prepare_fitting_seq( point_source_num=1, supersampling_factor=3) #, 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. from galight.fitting_process import FittingProcess fit_run = FittingProcess(fit_sepc, savename='HSC_QSO', fitting_level='deep') fit_run.run(algorithm_list=['PSO'], setting_list=[None]) # fit_run.plot_all() # fit_run.dump_result() print(fit_run.final_result_galaxy[0])
plt.show() #%%Fitting as disk + bulge: picklename = save_name + 'single_Sersic.pkl' fit_run_0 = pickle.load(open(picklename, 'rb')) data_process_1 = copy.deepcopy(data_process_0) data_process_1.target_stamp -= fit_run_0.image_ps_list[0] apertures = copy.deepcopy(data_process_1.apertures) comp_id = 0 #Change the component (galaxy) id = 0 into to components (i.e., bulge + disk) add_aperture0 = copy.deepcopy(apertures[comp_id]) add_aperture0.a, add_aperture0.b = add_aperture0.a / 6, add_aperture0.a / 4 apertures = apertures[:comp_id + 1] + [add_aperture0 ] + apertures[comp_id + 1:] data_process_1.apertures = apertures #Pass apertures to the data fit_sepc_1 = FittingSpecify(data_process_1) fit_sepc_1.prepare_fitting_seq( point_source_num= 0, #fix_n_list= [[0,1]], #First component fix n = 4 (bluge), second one fix to 1 (disk). condition=condition_diskbulge) fit_sepc_1.plot_fitting_sets() fit_sepc_1.build_fitting_seq() # fit_sepc_1.kwargs_params['lens_light_model'][0][0] = fit_run_0.final_result_galaxy[0] #Input to bulge fit_run_1 = FittingProcess(fit_sepc_1, savename=save_name + 'bulge+disk') fit_run_1.run(algorithm_list=['PSO', 'PSO'], setting_list=[{ 'sigma_scale': 1.,
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) # apertures_0 = apertures_0 + [add_aperture1] #attach the added aperture into the group. # data_process_0.apertures = apertures_0 #Pass apertures to the data 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 + 'single_Sersic') fit_run_0.run(algorithm_list=['PSO'], setting_list=[None]) fit_run_0.plot_final_qso_fit() bic_0 = fit_run_0.fitting_seq.bic fit_run_0.dump_result() #%%Fitting as disk + bulge: data_process_1 = copy.deepcopy(data_process_0) apertures = copy.deepcopy(data_process_1.apertures)
masks = 1 - masks data_process.target_mask = masks # plt.imshow(masks, origin='lower') # plt.show() #%% savename = rebin_name + 'removebkg' #+ '.pkl' #Setting the fitting method and run. import glob, pickle if glob.glob(savename + '*pkl') == []: # apertures = copy.deepcopy(data_process.apertures) # apertures = [copy.deepcopy(apertures[0])] + apertures # apertures[0].a, apertures[0].b = apertures[0].a*0.2, apertures[0].b*0.2 # data_process.apertures = apertures from galight.fitting_specify import FittingSpecify fit_sepc = FittingSpecify(data_process) fit_sepc.prepare_fitting_seq( point_source_num=0) #, fix_n_list= [[0,4],[1,1]]) fit_sepc.build_fitting_seq() fit_sepc.plot_fitting_sets( ) #The apertures shows how the images will be modelled. from galight.fitting_process import FittingProcess fit_run = FittingProcess(fit_sepc, savename=savename, fitting_level='deep') fit_run.run(algorithm_list=['PSO'], setting_list=[None]) fit_run.dump_result() else: fit_run = pickle.load(open(glob.glob(savename + '*.pkl')[0], 'rb')) fit_run.fitting_specify_class.plot_fitting_sets() file_header = copy.deepcopy(fitsFile[1].header) file_header['CRPIX1'] = file_header['CRPIX1'] - data_process.target_pos[
data_process.generate_target_materials(radius=30, create_mask=False, nsigma=2.8, exp_sz=1.5, npixels=40, if_plot=False) plt_fits(data_process.PSF_list[0]) # data_process.apertures = [] #Assuming there is no host (i.e., as constant.) #!!! # Manually input the PSF: # data_process.PSF_list = [PSF] # Check if all the materials is given, if so to pass to the next step. data_process.checkout() #Check if all the materials is known. fit_sepc = FittingSpecify(data_process) # fit_sepc.prepare_fitting_seq(point_source_num = 2) fit_sepc.prepare_fitting_seq(point_source_num=2, ps_pix_center_list=[[-2.0, -1.0], [6.0, -1.0]]) # if fit_sepc.kwargs_params['point_source_model'][0][0] == fit_sepc.kwargs_params['point_source_model'][0][1]: # fit_sepc.prepare_fitting_seq(point_source_num = 2, ps_pix_center_list= [[-2.0, -1.0], [6.0, -1.0]]) # print(file) fit_sepc.build_fitting_seq() fit_sepc.plot_fitting_sets() # if rerun != 's19a': # fit_sepc.kwargs_params['point_source_model'] = s21_res.fitting_specify_class.kwargs_params['point_source_model'] fit_run = FittingProcess(fit_sepc, savename=name + '-{0}-band{1}'.format(folder, band), fitting_level='norm')