def auto_cut_PSFs(img, radius=100, view=True): PSFx, PSFy = find_loc_max(img) if view == True: for i in range(len(PSFx)): cut_img = cut_image(img, [PSFx[i], PSFy[i]], radius=radius) if True not in np.isnan(cut_img) and np.max(cut_img) == cut_img[ len(cut_img) / 2][len(cut_img) / 2]: print("plot for position: [{0}, {1}]".format(PSFx[i], PSFy[i]), "idx:", i) cut_img[np.isnan(cut_img)] = 0 print("total flux:", cut_img.sum()) plt_fits(cut_img) print("================") return PSFx, PSFy
if dis < (obj[j][1] + obj_temp[i][1]) / 2: count += 1 if count == 0: obj.append(obj_temp[i]) print("the number of nearby objs:", len(obj)) ct = ct + 1 from mask_objects import find_loc_max, measure_FWHM for k in run_list: #['G', 'R', 'I', 'Z', 'Y'] print("Fiting the: " + filename_list[k]) if_dual = False psf, QSO_img, QSO_std = psf_l[k], QSO_img_l[k], QSO_std_l[k] #for a quick glimsp of the number of image's local maximum x, y = find_loc_max(QSO_img, neighborhood_size=3, threshold=1) arr_x, arr_y = np.asarray(x, dtype=float), np.asarray(y, dtype=float) center = len(QSO_img) / 2 bool_x, bool_y = (arr_x > (center - 18)) * (arr_x < (center + 18)), ( arr_y > (center - 18)) * (arr_y < (center + 18)) arr_x = arr_x[bool_x * bool_y] arr_y = arr_y[bool_x * bool_y] qsoid = filename_list[k].split('.fits')[0] if len(arr_x) >= 2: if_dual = True claim = "This {0} is likely to be a {1} system!!!".format( filename_list[k], 'BH' * len(arr_x)) elif len(arr_x) == 1: FWHM_ver, FWHM_hor, FWHM_xy, FWHM_xy_ = measure_FWHM( QSO_img) #Measure FWHM from ver, hor, up_right, up_left
if k in run_list: psf_l.append(PSF_list[k]) QSO_img_l.append(QSO_im_list[k][ct:-ct, ct:-ct]) QSO_std_l.append(err_map_list[k][ct:-ct, ct:-ct]) else: psf_l.append([]) QSO_img_l.append([]) QSO_std_l.append([]) #%% for k in [band_run_list[0]]: #['G', 'R', 'I', 'Z', 'Y'] print("The two point position using I band: ") psf, QSO_img, QSO_std = psf_l[k], QSO_img_l[k], QSO_std_l[k] #for a quick glimsp of the number of image's local maximum x, y = find_loc_max(QSO_img, neighborhood_size=3) arr_x, arr_y = np.asarray(x, dtype=float), np.asarray(y, dtype=float) center = len(QSO_img) / 2 bool_x, bool_y = (arr_x > (center - 18)) * (arr_x < (center + 18)), ( arr_y > (center - 18)) * (arr_y < (center + 18)) arr_x = arr_x[bool_x * bool_y] arr_y = arr_y[bool_x * bool_y] plt.imshow(QSO_img, origin='low', norm=LogNorm()) for i in range(len(arr_x)): plt.text(arr_x[i], arr_y[i], 'BH{0}'.format(i)) plt.plot(arr_x[i], arr_y[i], 'ro') if pltshow == 1: plt.show() else: plt.close()
# result_dic[folder] = [None, None] # continue multi_band_list, kwargs_model, kwargs_result, chain_list, fix_setting, mcmc_new_list = pickle.load( open(read_file, 'rb')) fixed_lens, fixed_source, fixed_lens_light, fixed_ps, fixed_cosmo = fix_setting mcmc_new_list = np.array(mcmc_new_list) H0_list = mcmc_new_list[:, -1] lens_data = pyfits.getdata(sim_folder + 'Drz_QSO_image.fits') lens_mask = cr_mask(lens_data, 'normal_mask.reg') framesize = len(multi_band_list[0][0]['image_data']) #81 ct = int((len(lens_data) - framesize) / 2) lens_data = lens_data[ct:-ct, ct:-ct] lens_mask = (1 - lens_mask)[ct:-ct, ct:-ct] x, y = find_loc_max(lens_data) x_s, y_s = [], [] center = (framesize - 1) / 2 deltaPix = 0.08 for i in range(len(x)): x0, y0 = (float(x[i]) - center) * deltaPix, (float(y[i]) - center) * deltaPix # print(x0, y0) ds = (x0 - kwargs_ps['ra_image'])**2 + (y0 - kwargs_ps['dec_image'])**2 if ds.min() < 0.01: x_s.append(x[i]) y_s.append(y[i]) y_grid, x_grid = np.indices( (framesize, framesize)) #with higher resolution 60*6 # for i in range(len(x_s)): # lens_mask[np.sqrt((y_grid-y_s[i])**2 + (x_grid-x_s[i])**2) <4] = 0