len(data_process_list[k].target_stamp) / 2) wcs = WCS(file_header) write_result = open( fit_folder + 'fit_result_{0}-band.txt'.format(band_seq[k]), 'w') write_result.write("#The fitting information for {0}:\n".format( filename_list[k])) #============================================================================== # fitting the QSO as a BH (PS) + Sersic #============================================================================== print("fitting the QSO as one BH + Sersic ") tag = fit_folder + 'fit_{0}-band_fit0_PS+Sersic'.format(band_seq[k]) _fit_sepc_0 = FittingSpeficy(data_process_list[k]) _fit_sepc_0.prepare_fitting_seq(point_source_num=1, fix_n_list=fix_n_list_0, fix_Re_list=fix_Re_list_0, ps_params=ps_param0, apertures_center_focus=True) _fit_sepc_0.build_fitting_seq() if k == run_list[0]: _fit_sepc_0.plot_fitting_sets( savename=fit_folder + 'fitting0_used_aper.pdf'.format(image_ID), show_plot=show_plot) _fit_run_0 = FittingProcess(_fit_sepc_0, savename=tag) _fit_run_0.run(algorithm_list=['PSO'], setting_list=[pso_setting]) _fit_run_0.translate_result() _fit_run_0.plot_final_qso_fit(target_ID=image_ID, save_plot=True, show_plot=show_plot)
try: data_process.generate_target_materials(radius=None, create_mask=False, nsigma=1.5, exp_sz=1.2, npixels=15, if_plot=False) except: continue 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. fit_sepc = FittingSpeficy(data_process) fit_sepc.prepare_fitting_seq( point_source_num=1 ) #, 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, savename='model_result/' + ids_file[i].split('/')[-1][:-5]) fit_run.run(algorithm_list=['PSO'], setting_list=[None]) fit_run.plot_final_qso_fit(save_plot=True, target_ID=ids_file[i].split('/')[-1][:-5]) fit_run.dump_result() # print(fit_run.final_result_galaxy[0]) filename = 'model_result/{0}_host_result.txt'.format(Bla_type) if_file = glob.glob(filename)
file_header['CRPIX2'] = file_header['CRPIX2'] - qso_center[1] + int( len(data_process_list[k].target_stamp) / 2) wcs = WCS(file_header) write_result = open( fit_folder + 'fit_result_{0}-band.txt'.format(band_seq[k]), 'w') write_result.write("#The fitting information for {0}:\n".format( filename_list[k])) #============================================================================== # fitting the QSO as a BH (PS) + Sersic #============================================================================== print("fitting the QSO as one BH + Sersic ") tag = fit_folder + 'fit_{0}-band_fit0_PS+Sersic'.format(band_seq[k]) _fit_sepc_0 = FittingSpeficy(data_process_list[k]) _fit_sepc_0.prepare_fitting_seq(point_source_num=1, fix_n_list=fix_n_list_0, fix_Re_list=fix_Re_list_0, ps_params=ps_param0) _fit_sepc_0.build_fitting_seq() if k == run_list[0]: _fit_sepc_0.plot_fitting_sets( savename=fit_folder + 'fitting0_used_aper.pdf'.format(image_ID), show_plot=show_plot) _fit_run_0 = FittingProcess(_fit_sepc_0, savename=tag) _fit_run_0.run(algorithm_list=['PSO'], setting_list=[pso_setting]) _fit_run_0.translate_result() _fit_run_0.plot_final_qso_fit(target_ID=image_ID, save_plot=True, show_plot=show_plot) source_result_0, ps_result_0 = _fit_run_0.final_result_galaxy, _fit_run_0.final_result_ps
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 = FittingSpeficy(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) comp_id = 0 #Change the component (galaxy) id = 0 into to components (i.e., bulge + disk) add_aperture0 = copy.deepcopy(apertures[comp_id])
print("Fiting the: " + filename_list[k]) print(claim) print("Comparing the fitting Chisq:") write_result = open( 'fit_result_detect/{0}/fit_result.txt'.format(qsoid), 'w') write_result.write("#The fitting information:\n") #============================================================================== # fitting the QSO as a BH (PS) + Sersic #============================================================================== for ft in range(1): #The fitting rounds for each band print("fitting the QSO as one BH + Sersic ") fit_time = ft tag = 'fit_result_detect/{0}/fit_image0_PS+Sersic_fittime-{1}'.format( qsoid, fit_time + 1) _fit_sepc = FittingSpeficy(data_process_list[k]) _fit_sepc.prepare_fitting_seq(point_source_num=1) _fit_sepc.build_fitting_seq() _fit_run = FittingProcess(_fit_sepc, savename=tag) _fit_run.run(algorithm_list=['PSO'], setting_list=[None]) _fit_run.translate_result() _fit_run.plot_final_qso_fit(target_ID=qsoid, save_plot=True, show_plot=show_plot) source_result_0, ps_result_0 = _fit_run.final_result_galaxy, _fit_run.final_result_ps host_mag, AGN_mag = source_result_0[0]['magnitude'], ps_result_0[ 0]['magnitude'] c_miss = np.sqrt((source_result_0[0]['center_x'] - ps_result_0[0]['ra_image'])**2 + (source_result_0[0]['center_y'] - ps_result_0[0]['dec_image'])**2) reduced_Chisq_0 = _fit_run.reduced_Chisq
data_process.generate_target_materials( radius=None, create_mask=False, nsigma=2.8, #radius=None, the target size would be automated set. exp_sz=1.2, npixels=15, if_plot=False) 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 decomprofile.fitting_specify import FittingSpeficy fit_sepc = FittingSpeficy(data_process) fit_sepc.prepare_fitting_seq(point_source_num=0) fit_sepc.build_fitting_seq() #%%Setting the fitting method and run. from decomprofile.fitting_process import FittingProcess savename = image_id + '-' + band fit_run = FittingProcess(fit_sepc, savename=savename) fit_run.run(algorithm_list=['PSO'], setting_list=[None]) #Only PSO, not MCMC # fit_run.plot_all() fit_run.plot_final_galaxy_fit(target_ID=savename, show_plot=False) fit_run.translate_result() # fit_run.dump_result() #To save result as pickle file # print(fit_run.final_result_galaxy[0]) #%% filename_ascii = image_id + '_result.txt'