Beispiel #1
0
        #==============================================================================
        # 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)
        source_result_0, ps_result_0 = _fit_run_0.final_result_galaxy, _fit_run_0.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_0.reduced_Chisq
Beispiel #2
0
 # if band_seq[k] == 'I':   #Get the parameters of I band to fix to the other band.     
 #     fix_Re_list_1 = [[i, source_result_1[i]['R_sersic']] for i in range(len(source_result_1))] 
 #     fix_n_list_1 = [[i, source_result_1[i]['n_sersic']] for i in range(len(source_result_1))]
 #     ps_param1 =  _fit_sepc_1.ps_params        
 #==============================================================================
 # fitting the QSO as a BHBH (PS+PS) + Sersic       
 #==============================================================================
 print("fitting the QSO as {0} point sources + Sersic".format(len(arr_x)))
 num_BHBH = max(len(arr_x), 2)
 fit_time = 1
 tag = 'fit_result_detect/{0}/fit_{2}-band_image2_PSPS+Sersic_fittime-{1}'.format(qsoid,fit_time+1, band_seq[k])
 _fit_sepc_2 = FittingSpeficy(data_process_list[k])
 _fit_sepc_2.prepare_fitting_seq(point_source_num = num_BHBH, fix_n_list= fix_n_list_2, fix_Re_list= fix_Re_list_2, ps_params = ps_param2, neighborhood_size = neighborhood_size, threshold = threshold)
 _fit_sepc_2.build_fitting_seq()
 if k == run_list[0]:
     _fit_sepc_2.plot_fitting_sets(savename = 'fit_result_detect/{0}/fitting_used_aper.pdf'.format(qsoid),
                                 show_plot=show_plot)        
 _fit_run_2 = FittingProcess(_fit_sepc_2, savename = tag)
 _fit_run_2.run(algorithm_list = ['PSO'], setting_list= [pso_setting]) 
 _fit_run_2.translate_result()
 _fit_run_2.plot_final_qso_fit(target_ID = qsoid, save_plot = True, show_plot = show_plot)     
 source_result_2, ps_result_2 = _fit_run_2.final_result_galaxy, _fit_run_2.final_result_ps 
 host_mag = source_result_2[0]['magnitude']
 AGN_mags = [ps_result_2[i]['magnitude'] for i in range(len(ps_result_2))]
 if len(ps_result_2) == 2:
     c_miss = np.sqrt((ps_result_2[0]['ra_image']-ps_result_2[1]['ra_image'])**2+(ps_result_2[0]['dec_image']-ps_result_2[1]['dec_image'])**2)
 elif len(ps_result_2) > 2:
     c_miss = [np.sqrt((ps_result_2[0]['ra_image']-ps_result_2[1]['ra_image'])**2+(ps_result_2[0]['dec_image']-ps_result_2[1]['dec_image'])**2)]
     c_miss.append(np.sqrt((ps_result_2[1]['ra_image']-ps_result_2[2]['ra_image'])**2+(ps_result_2[1]['dec_image']-ps_result_2[2]['dec_image'])**2))
     c_miss.append(np.sqrt((ps_result_2[2]['ra_image']-ps_result_2[0]['ra_image'])**2+(ps_result_2[2]['dec_image']-ps_result_2[0]['dec_image'])**2))
     c_miss = np.average(c_miss)
 reduced_Chisq_2 = _fit_run_2.reduced_Chisq
Beispiel #3
0
                                                   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)
        if if_file == []:
            write_file = open(filename, 'w')
Beispiel #4
0
    #%%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])
    add_aperture0.a, add_aperture0.b = add_aperture0.a / 3, add_aperture0.b / 3