def get_psf_errors(self, kernel, sigma_bkg, star_list): """ returns a error map of sigma prop Intensity for a stacked psf estimation :param psf_kwargs: :param star_list: :return: """ psf_size = len(kernel) kernel_mean = util.image2array(kernel) weights = np.zeros(len(star_list)) cov_i = np.zeros((psf_size**2, psf_size**2)) num_stars = len(star_list) for i in range(0, num_stars): star_list_i = star_list[i].copy() star = util.cut_edges(star_list_i, psf_size) weights[i] = np.sum(star) rel_array = np.array( [util.image2array(star) / weights[i] - kernel_mean]) a = (rel_array.T).dot(rel_array) cov_i += a factor = 1. / (num_stars) #weights_sum = sum(weights) sigma2_stack = factor * util.array2image(np.diag(cov_i)) psf_stack = copy.deepcopy(kernel) sigma2_stack_new = sigma2_stack # - (data_kwargs['sigma_background']**2/weights_sum) sigma2_stack_new[np.where(sigma2_stack_new < 0)] = 0 psf_stack[np.where(psf_stack < sigma_bkg)] = sigma_bkg error_map = sigma2_stack_new / (psf_stack)**2 #error_map[np.where(error_map < psf_stack**2/data_kwargs['reduced_noise'])] = 0 # n = len(error_map) #error_map[(n-1)/2-1:(n-1)/2+2,(n-1)/2-1:(n-1)/2+2] += 0 #error_map = filters.gaussian_filter(error_map, sigma=0.5) return error_map
def __init__(self, image, sigma, poisson, sampling_option, deltaPix=1, mask=None, subgrid_res=1, x_grid=None, y_grid=None): """ initializes all the classes needed for the chain """ self.image = util.image2array(image) self.numPix = len(image) self.deltaPix = deltaPix self.subgrid_res = subgrid_res self.background = sigma self.poisson = poisson if x_grid is None or y_grid is None: self.x_grid, self.y_grid = util.make_grid(self.numPix, deltaPix, subgrid_res) else: self.x_grid, self.y_grid = util.make_subgrid( x_grid, y_grid, subgrid_res) self.gaussian = Gaussian() self.moffat = Moffat() self.sampling_option = sampling_option if not mask is None: self.mask = util.image2array(mask) else: self.mask = np.ones((self.numPix, self.numPix))
def plot_pixel_histogram(self, image): imgh = util.image2array(image) # print some statistics about the image print('Image minimum = ', min(imgh)) print('Image maximum = ', max(imgh)) print('Image mean = ', np.mean(imgh)) print('Image standard deviation = ', np.std(imgh)) # now plot a histogram of the image values plt.figure(2) plt.hist(imgh, bins=100, histtype='stepfilled') plt.show() # display the plots plow = -1. phi = 1. q = np.where((imgh >= plow) & (imgh <= phi)) imghcut = imgh[q] print('Image minimum = ', min(imghcut)) print('Image maximum = ', max(imghcut)) print('Image mean = ', np.mean(imghcut)) print('Image standard deviation = ', np.std(imghcut)) return 0
def get_coordinates(self, x_min, x_max, y_min, y_max, wcs): """ :param xc: center in ra :param yc: center in dec :param x_min: min pixel x-axis :param x_max: max pixel x-axis :param y_min: min pixel y-axis :param y_max: max pixel y-axis :param wcs: coordinate class initialized with the fits file of the original image :return: ra_coord, dec_coord in units of arc seconds centered to the cutout position """ x_coords = np.linspace(x_min, x_max - 1, x_max - x_min) y_coords = np.linspace(y_min, y_max - 1, y_max - y_min) x_coords, y_coords = np.meshgrid(x_coords, y_coords) ra_coords, dec_coords = wcs.all_pix2world(x_coords, y_coords, 0) ra_coords -= self.ra dec_coords -= self.dec ra_coords *= 3600 dec_coords *= 3600 ra_coords = util.image2array(ra_coords) dec_coords = util.image2array(dec_coords) return ra_coords, dec_coords
if len(data) > 300: factor = 2 if len(data) % factor != 0: res = len(data) % factor data_g = data[:-res, :-res] data = rebin.block(data_g, (len(data_g) / factor, len(data_g) / factor), factor=factor) else: data = rebin.block(data, (len(data) / factor, len(data) / factor), factor=factor) x, y = util.make_grid(numPix=len(data), deltapix=1) # make a coordinate grid image_1d = util.image2array(data) # map 2d image in 1d data array n_max = 100 # choice of number of shapelet basis functions, 150 is a high resolution number, but takes long beta = len(data) / 20. # shapelet scale parameter # return the shapelet coefficients param_list = shapeletSet.decomposition(image_1d, x, y, n_max, beta, 1., center_x=0, center_y=0) # reconstruct M31 with the shapelet coefficients image_reconstructed = shapeletSet.function(x, y,