def __init__(self, data): self.x = data self.x2 = self.x ** 2 self.i = self.x.cumsum(axis=0).cumsum(axis=1) self.i2 = self.x2.cumsum(axis=0).cumsum(axis=1) self.i_pad = pad2d(self.i, 1) self.i2_pad = pad2d(self.i2, 1)
def __init__(self, data): self.x = data self.x2 = self.x**2 self.i = self.x.cumsum(axis=0).cumsum(axis=1) self.i2 = self.x2.cumsum(axis=0).cumsum(axis=1) self.i_pad = pad2d(self.i, 1) self.i2_pad = pad2d(self.i2, 1)
def window(data, pos, pixel_rad): # Check that the input array has two dimensions. data = np.array(data) if data.ndim != 2: raise ValueError('The input array must be 2D.') # If the pixel radius size is one repat the value for the 2nd dimension. pixel_rad = np.array(pixel_rad) if pixel_rad.size == 1: pixel_rad = np.repeat(pixel_rad, 2) if pixel_rad.size not in (1, 2): raise ValueError('The pixel radius must have a size of 1 or 2.') # Check that the array position has a size of two. pos = np.array(pos) % np.array(data.shape) if pos.size != 2: raise ValueError('The array position must have a size of 2.') # Check if the pixel radius is within the bounds of the input array. if (np.any(pixel_rad < 1) or np.any(np.array(data.shape) / 2 - pixel_rad < 0)): raise ValueError('The pixel radius values must have a value of at ' 'least 1 and at most half the size of the input ' 'array. Array size: ' + str(data.shape)) # Return window selection. return pad2d(data, pixel_rad)[[ slice(a, a + 2 * b + 1) for a, b in zip(pos, pixel_rad) ]]
def psf_var_convolve(image, psf): # Function to select slices of an image. def select_slices(image_shape, sub_shape): ranges = np.array([np.arange(i) for i in image_shape]) limits = np.array([ranges.T + sub_shape / 2 + 1, ranges.T + 1.5 * sub_shape + 1]).T return np.array([np.array([slice(*i), slice(*j)]) for i in limits[0] for j in limits[1]]) # Function to convolve a PSF with a sub-image. def get_convolve(sub_image, psf): return np.multiply(sub_image, np.rot90(psf, 2)).sum() # Pad image borders by PSF size. image_pad = pad2d(image, psf.shape[1:]) # Get sub-image slices of the padded image. slices = select_slices(image.shape, data2np(psf.shape[1:])) # Convolve sub-images with PSFs. image_conv = np.array([[get_convolve(image_pad[list(x)], y)] for x, y in zip(slices, psf)]) return np.reshape(image_conv, image.shape)
def window(data, pos, pixel_rad): # Check that the input array has two dimensions. data = np.array(data) if data.ndim != 2: raise ValueError('The input array must be 2D.') # If the pixel radius size is one repat the value for the 2nd dimension. pixel_rad = np.array(pixel_rad) if pixel_rad.size == 1: pixel_rad = np.repeat(pixel_rad, 2) if pixel_rad.size not in (1, 2): raise ValueError('The pixel radius must have a size of 1 or 2.') # Check that the array position has a size of two. pos = np.array(pos) % np.array(data.shape) if pos.size != 2: raise ValueError('The array position must have a size of 2.') # Check if the pixel radius is within the bounds of the input array. if (np.any(pixel_rad < 1) or np.any(np.array(data.shape) / 2 - pixel_rad < 0)): raise ValueError('The pixel radius values must have a value of at ' 'least 1 and at most half the size of the input ' 'array. Array size: ' + str(data.shape)) # Return window selection. return pad2d(data, pixel_rad)[[slice(a, a + 2 * b + 1) for a, b in zip(pos, pixel_rad)]]
def get_l2norm(data, layout, pixel_rad=9): radius = data.shape[0] / layout[0] / 2 centres = image.image_centres(data.shape, layout) cube = image_file_io.gen_data_cube(data, centres, pixel_rad) cube = transform.cube2map(np.array([np_adjust.pad2d(x, radius - pixel_rad) for x in cube]), layout) diff = data - cube l2norm = np.linalg.norm(diff) / np.sum(diff > 0) * np.prod(data.shape) print ' - L2 Norm of noise from data:', l2norm return l2norm
def _pad_data(self): self.pad_data = pad2d(self.data, self.pixel_rad)