def test_kernel_normalization_mode(self): """ Test that an error is raised if mode is invalid. """ with pytest.raises(ValueError): kernel = CustomKernel(np.ones(3)) kernel.normalize(mode='invalid')
def test_normalize_peak(self): """ Check if normalize works with peak mode. """ custom = CustomKernel([1, 2, 3, 2, 1]) custom.normalize(mode='peak') assert custom.array.max() == 1
def test_custom_2D_kernel(self): """ Check CustomKernel against Box2DKernel. """ # Define one dimensional array: array = np.ones((5, 5)) custom = CustomKernel(array) custom.normalize() box = Box2DKernel(5) c2 = convolve(delta_pulse_2D, custom, boundary='fill') c1 = convolve(delta_pulse_2D, box, boundary='fill') assert_almost_equal(c1, c2, decimal=12)
def test_custom_2D_kernel_zerosum(self): """ Check if CustomKernel works when the input array/list sums to zero. """ array = [[0, -1, 0], [-1, 4, -1], [0, -1, 0]] custom = CustomKernel(array) with pytest.warns(AstropyUserWarning, match=r'kernel cannot be ' r'normalized because it sums to zero'): custom.normalize() assert custom.truncation == 0. assert custom._kernel_sum == 0.
def test_custom_2D_kernel_list(self): """ Check if CustomKernel works with lists. """ custom = CustomKernel([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) assert custom.is_bool is True
def test_kernel_normalization(self): """ Test that repeated normalizations do not change the kernel [#3747]. """ kernel = CustomKernel(np.ones(5)) kernel.normalize() data = np.copy(kernel.array) kernel.normalize() assert_allclose(data, kernel.array) kernel.normalize() assert_allclose(data, kernel.array)
def use_custom_lsf(self,FWHM='6.5',grating='G130M',life_position='1',cen_wave='1300A'): if FWHM=='COS': instr_config=dict(name='COS',grating=grating,life_position=life_position,cen_wave=cen_wave) coslsf=LSF(instr_config) s,data=coslsf.load_COS_data() #if 1150A 1200A 1250A 1300A 1350A 1400A 1450A kernel = CustomKernel(data[cen_wave].data) else: COS_kernel=np.double(FWHM)/2.355 #6.5 pixels #window_size_number_of_points=np.round(FWHM /(2.355*np.abs(velgrid[2]-velgrid[1]))) # Create kernel kernel = Gaussian1DKernel(stddev=COS_kernel) self.kernel=kernel
Paso 3: Convolucionar la imagen modelo con el PSF, para obtener la imagen vista por el instrumento ''' # Leer imagen modelo image = io.imread('PDS70c.jpg', as_gray=True) #Cargar como escala de grises, no como RGB image = resize(image, (image.shape[0] // 2, image.shape[1] // 2), anti_aliasing=True) print('Tamaño de la matriz de la imagen: {}'.format(image.shape)) #Límites para truncar el kernel de convolución zoom = 1 # zoom factor to truncate and display kernel kern_min = int((dom_size - 1) / 2 - (dom_size - 1) / (2 * zoom)) kern_max = int((dom_size - 1) / 2 + (dom_size - 1) / (2 * zoom)) kernel = CustomKernel(beam[kern_min:kern_max + 1, kern_min:kern_max + 1]) print('Tamaño de la matriz del kernel de convolución: {}'.format(kernel.shape)) #Ejecutar la convolución: #im_conv = convolve(image, kernel) im_conv = convolve_fft(image, kernel) ''' Paso 4: Crear, desplegar y guardar las figuras. ''' fig = plt.figure(figsize=(10, 10)) ax1 = plt.subplot(2, 2, 1) ax2 = plt.subplot(2, 2, 2) ax3 = plt.subplot(2, 2, 3) ax4 = plt.subplot(2, 2, 4)
def test_custom_kernel_odd_error(self): """ Check if CustomKernel raises if the array size is odd. """ with pytest.raises(KernelSizeError): CustomKernel([1, 1, 1, 1])