def transfer_to_result_ps(data, ps_result, image_ps, image_host, error_map, filt, fixcenter, ID, cut=0, plot_compare=True, QSO_msk_list="", pix_sz='drz06', QSO_msk=None, tag=None): #============================================================================== # Translate the e1, e2 to phi_G and q #============================================================================== #============================================================================== # Save the result #============================================================================== from roundme import roundme result = {} ##============================================================================== ##Plot the images for adopting in the paper ##============================================================================== from flux_profile import total_compare data = data QSO = image_ps if QSO_msk is None: QSO_mask = data * 0 + 1 else: QSO_mask = QSO_msk if len(image_host) == 0: host = data * 0 label = ['data', 'QSO', 'host=0', 'model', 'normalized residual'] elif len(image_host) > 0: host = np.zeros_like(image_host[0]) for i in range(len(image_host)): host += image_host[i] label = [ 'data', 'QSO', '{0}objs'.format(i), 'model', 'normalized residual' ] #Print the numbers of objects flux_list = [data, QSO, host, error_map] import glob mask_list = glob.glob(QSO_msk_list) # Read *.reg files in a list. # print "mask_list,muhahah", mask_list fig = total_compare(label_list=label, flux_list=flux_list, target_ID=ID, pix_sz=pix_sz, data_mask_list=mask_list, data_cut=cut, zp=zp, plot_compare=plot_compare, msk_image=QSO_mask) if tag is not None: fig.savefig("{0}_SB_profile.pdf".format(tag), bbox_inches='tight') # ============================================================================= # Calculate reduced Chisq and save to result # ============================================================================= chiq_map = ((data - image_ps - host) / (error_map))**2 * QSO_mask pixels = len(error_map)**2 - (1 - QSO_mask).sum() reduced_Chisq = chiq_map.sum() / pixels result = roundme(result) result['redu_Chisq'] = round(reduced_Chisq, 6) return result
for i in range(len(chain_list)): f, axes = chain_plot.plot_chain_list(chain_list,i) plt.show() agn_image = pyfits.getdata('./allscience/l{0}_{1}_cutout.fits'.format(ID,fr)) if len(image_host) == 1: host = image_host[0] label = ['data', 'QSO', 'host', 'model', 'normalized residual'] elif len(image_host) >1: host = np.zeros_like(image_host[0]) for i in range(len(image_host)): host += image_host[i] label = ['data', 'QSO', 'host as {0} components'.format(i+1), 'model', 'normalized residual'] #Print the numbers flux_list = [agn_image, image_ps[0], host, error_map] fig = total_compare(label_list = label, flux_list = flux_list, target_ID = ID, pix_sz=pix_sz, zp = zp, plot_compare = False, msk_image = QSO_msk) from IPython.display import display display(fig) #%% Recover the plot from lenstronomy.Plots.model_plot import ModelPlot modelPlot = ModelPlot(multi_band_list, kwargs_model, kwargs_result, arrow_size=0.02, cmap_string="gist_heat", likelihood_mask_list=[QSO_msk]) f, axes = plt.subplots(3, 3, figsize=(16, 16), sharex=False, sharey=False) modelPlot.data_plot(ax=axes[0,0], text="Data") modelPlot.model_plot(ax=axes[0,1]) modelPlot.normalized_residual_plot(ax=axes[0,2], v_min=-6, v_max=6) modelPlot.decomposition_plot(ax=axes[1,0], text='Host galaxy', source_add=True, unconvolved=True) modelPlot.decomposition_plot(ax=axes[1,1], text='Host galaxy convolved', source_add=True) modelPlot.decomposition_plot(ax=axes[1,2], text='All components convolved', source_add=True, lens_light_add=True, point_source_add=True)
def transfer_to_result(data, source_result, ps_result, image_ps, image_host, error_map, zp, fixcenter, ID, cut=0, plot_compare=True, QSO_msk_list="", pix_sz=0.168, QSO_msk=None, tag=None): #============================================================================== # Translate the e1, e2 to phi_G and q #============================================================================== import lenstronomy.Util.param_util as param_util source_result[0]['phi_G'], source_result[0][ 'q'] = param_util.ellipticity2phi_q(source_result[0]['e1'], source_result[0]['e2']) #============================================================================== # Save the result #============================================================================== from roundme import roundme import copy result = copy.deepcopy(source_result[0]) del result['e1'] del result['e2'] result['QSO_amp'] = ps_result[0]['point_amp'][0] result['host_amp'] = image_host[0].sum() result['host_flux_ratio_percent'] = result['host_amp'] / ( result['QSO_amp'] + result['host_amp']) * 100 zp = zp result['host_mag'] = -2.5 * np.log10(result['host_amp']) + zp #print "The host flux is ~:", image_host.sum()/(image_ps.sum() + image_host.sum()) # ============================================================================= # Save QSO position to result if not fix center # ============================================================================= if fixcenter == False: result['qso_x'] = ps_result[0]['ra_image'][0] result['qso_y'] = ps_result[0]['dec_image'][0] ##============================================================================== ##Plot the images for adopting in the paper ##============================================================================== from flux_profile import total_compare data = data QSO = image_ps if QSO_msk is None: QSO_mask = data * 0 + 1 else: QSO_mask = QSO_msk if len(image_host) == 1: host = image_host[0] label = ['data', 'QSO', 'host', 'model', 'normalized residual'] elif len(image_host) > 1: host = np.zeros_like(image_host[0]) for i in range(len(image_host)): host += image_host[i] label = [ 'data', 'QSO', 'host+{0}objs'.format(i), 'model', 'normalized residual' ] #Print the numbers of objects flux_list = [data, QSO, host, error_map] import glob mask_list = glob.glob(QSO_msk_list) # Read *.reg files in a list. # print "mask_list,muhahah", mask_list fig = total_compare(label_list=label, flux_list=flux_list, target_ID=ID, pix_sz=pix_sz, data_mask_list=mask_list, data_cut=cut, zp=zp, plot_compare=plot_compare, msk_image=QSO_mask) if tag is not None: fig.savefig("{0}_SB_profile.pdf".format(tag), bbox_inches='tight') fig1 = total_compare(label_list=label, flux_list=flux_list, target_ID=ID, pix_sz=pix_sz, data_mask_list=mask_list, data_cut=cut, zp=zp, plot_compare=plot_compare, msk_image=QSO_mask, if_annuli=True) if tag is not None: fig1.savefig("{0}_SB_profile_annuli.pdf".format(tag), bbox_inches='tight') # ============================================================================= # Calculate reduced Chisq and save to result # ============================================================================= chiq_map = ((data - image_ps - host) / (error_map))**2 * QSO_mask pixels = len(error_map)**2 - (1 - QSO_mask).sum() reduced_Chisq = chiq_map.sum() / pixels result = roundme(result) result['redu_Chisq'] = round(reduced_Chisq, 6) return result
from flux_profile import total_compare QSO_im, err_map, QSO_bkg, PSF, pix_scale, zp, qso_fr_center, fr_c_RA_DEC = gen_fit_id( image_folder, QSO_RA, QSO_DEC, filename, cut_frame=120, subbkl=sub_bkg) ct = (len(QSO_im) - len(image_host[0])) / 2 # If want to cut to 61, QSO_im[ct:-ct,ct:-ct] if len(image_host) == 1: host = image_host[0] label = ['data', 'QSO', 'host', 'model', 'normalized residual'] elif len(image_host) > 1: host = np.zeros_like(image_host[0]) for i in range(len(image_host)): host += image_host[i] label = [ 'data', 'QSO', 'host as {0} components'.format(i + 1), 'model', 'normalized residual' ] #Print the numbers of objects agn_image = QSO_im[ct:-ct, ct:-ct] error_map = err_map[ct:-ct, ct:-ct] flux_list = [agn_image, image_ps, host, error_map] total_compare(label_list=label, flux_list=flux_list, target_ID=QSO_id + '-' + band, pix_sz=pix_scale, zp=zp, plot_compare=False, msk_image=np.ones_like(agn_image)) #fig.savefig("{0}_SB_profile.pdf".format(name_save), bbox_inches = 'tight')