import os if os.path.exists(sim_folder_name)==True: import shutil shutil.rmtree(sim_folder_name) os.mkdir(sim_folder_name) ##============================================================================== ## #Bin the image res. from high to low. ##============================================================================== sys.path.insert(0, '../share_tools') import rebin factor=4 pattern_x=[0,2,0,2,1,3,1,3] pattern_y=[0,0,2,2,3,3,1,1] #from the info. given by observation ################Bin the lensed image################ exp_grid=rebin.expend_grid(image_highres) cut_out=np.zeros([len(pattern_x),image_highres.shape[0]-5,image_highres.shape[1]-5]) image_bin =np.zeros([len(pattern_x),int(image_highres.shape[0]/factor)-1,int(image_highres.shape[1]/factor)-1]) for i in range(len(pattern_x)): cut_out[i]=exp_grid[pattern_x[i]:(numPix-5)+pattern_x[i],pattern_y[i]:(numPix-5)+pattern_y[i]] #the size before bin image_bin[i]=rebin.block(cut_out[i],(int(numPix/factor)-1,int(numPix/factor)-1),factor=factor) plt.imshow(image_bin[0], origin='lower',cmap='gist_heat', norm=LogNorm()) plt.colorbar() plt.show() ################Bin the PSF and save it################ #exp_psf=rebin.expend_grid(psf_pixel_high_res) cut_fd=int((len(psf_data)-((int(len(psf_data)/8*2)-1)*4+3))/2) exp_psf_o=psf_data[1+cut_fd:-cut_fd,1+cut_fd:-cut_fd]+ 0 # To change it from 251 to 247. exp_psf=rebin.expend_grid(exp_psf_o) cut_len=int(round(len(exp_psf_o)/factor)*factor) cut_out_psf=np.zeros([len(pattern_x),cut_len,cut_len])
# plt.colorbar() # plt.show() # print("Point image:") # plt.imshow(point_highres, origin='lower',cmap='gist_heat', norm=LogNorm()) # plt.colorbar() # plt.show() #%% ##============================================================================== ## #Bin the image res. from high to low. ##============================================================================== factor = oversample pattern_x = [0, 2, 0, 2, 1, 3, 1, 3] pattern_y = [0, 0, 2, 2, 3, 3, 1, 1] #from the info. given by observation ################Bin the lensed image################ total_exp_grid = rebin.expend_grid(total_highres) total_cut_out = np.zeros([ len(pattern_x), total_highres.shape[0] - 5, total_highres.shape[1] - 5 ]) total_image_bin = np.zeros([ len(pattern_x), int(total_highres.shape[0] / factor) - 1, int(total_highres.shape[1] / factor) - 1 ]) host_exp_grid = rebin.expend_grid(host_highres) host_cut_out = np.zeros([ len(pattern_x), host_highres.shape[0] - 5, host_highres.shape[1] - 5 ])
psf_data = psf_data[1:, 1:] psf_data /= psf_data.sum() ##============================================================================== ## #Bin the image res. from high to low. ##============================================================================== import rebin #From my share_tools factor = 4 pattern_x = [0, 2, 0, 2, 1, 3, 1, 3] pattern_y = [0, 0, 2, 2, 3, 3, 1, 1] #from the info. given by observation ################Bin the PSF and save it################ #exp_psf=rebin.expend_grid(psf_pixel_high_res) cut_fd = int( (len(psf_data) - ((int(len(psf_data) / 8 * 2) - 1) * 4 + 3)) / 2) exp_psf_o = psf_data[1 + cut_fd:-cut_fd, 1 + cut_fd:-cut_fd] + 0 # To change it from 251 to 247. exp_psf = rebin.expend_grid(exp_psf_o) cut_len = int(round(len(exp_psf_o) / factor) * factor) cut_out_psf = np.zeros([len(pattern_x), cut_len, cut_len]) image_bin_psf = np.zeros( [len(pattern_x), int(cut_len / factor), int(cut_len / factor)]) for i in range(len(pattern_x)): cut_out_psf[i] = exp_psf[pattern_x[i]:cut_len + pattern_x[i], pattern_y[i]:cut_len + pattern_y[i]] #the size before bin image_bin_psf[i] = rebin.block( cut_out_psf[i], (int(cut_len / factor), int(cut_len / factor)), factor=factor) image_bin_psf[i] /= np.sum(image_bin_psf[i]) #unify the psf value pyfits.PrimaryHDU(image_bin_psf[i]).writeto(
# plt.imshow(host_highres, origin='lower',cmap='gist_heat', norm=LogNorm()) # plt.colorbar() # plt.show() # print("Point image:") # plt.imshow(point_highres, origin='lower',cmap='gist_heat', norm=LogNorm()) # plt.colorbar() # plt.show() #%% ##============================================================================== ## #Bin the image res. from high to low. ##============================================================================== factor = oversample pattern_x = [0] pattern_y = [0] #from the info. given by observation ################Bin the lensed image################ point_exp_grid = rebin.expend_grid(point_highres) point_cut_out = np.zeros([ len(pattern_x), point_highres.shape[0] - 5, point_highres.shape[1] - 5 ]) point_image_bin = np.zeros([ len(pattern_x), int(point_highres.shape[0] / factor) - 1, int(point_highres.shape[1] / factor) - 1 ]) for i in range(len(pattern_x)): point_cut_out[i] = point_exp_grid[pattern_x[i]:(numPix - 5) + pattern_x[i], pattern_y[i]:(numPix - 5) + pattern_y[i]] #the size before bin point_image_bin[i] = rebin.block(