Exemple #1
0
 def test_model_1D_kernel(self):
     """
     Check Model1DKernel against Gaussian1Dkernel
     """
     stddev = 5.
     gauss = Gaussian1D(1. / np.sqrt(2 * np.pi * stddev**2), 0, stddev)
     model_gauss_kernel = Model1DKernel(gauss, x_size=21)
     gauss_kernel = Gaussian1DKernel(stddev, x_size=21)
     assert_almost_equal(model_gauss_kernel.array, gauss_kernel.array,
                         decimal=12)
Exemple #2
0
 def test_array_keyword_not_allowed(self):
     """
     Regression test for issue #10439
     """
     x = np.ones([10, 10])
     with pytest.raises(TypeError, match=r".* allowed .*"):
         AiryDisk2DKernel(2, array=x)
         Box1DKernel(2, array=x)
         Box2DKernel(2, array=x)
         Gaussian1DKernel(2, array=x)
         Gaussian2DKernel(2, array=x)
         RickerWavelet1DKernel(2, array=x)
         RickerWavelet2DKernel(2, array=x)
         Model1DKernel(Gaussian1D(1, 0, 2), array=x)
         Model2DKernel(Gaussian2D(1, 0, 0, 2, 2), array=x)
         Ring2DKernel(9, 8, array=x)
         Tophat2DKernel(2, array=x)
         Trapezoid1DKernel(2, array=x)
         Trapezoid1DKernel(2, array=x)
Exemple #3
0
    def set_smoothing_kernel(self,
                             kernel=None,
                             kernel_width=None,
                             custom_array_kernel=None,
                             custom_kernel_function=None,
                             function_array_size=21):
        #if custom_kernel_array is None and custom_kernel_function is None:

        if custom_array_kernel is not None:
            custom_kernel_array = np.array([i for i in custom_array_kernel])
            self.kernel_func = CustomKernel(custom_kernel_array)
            self.kernel_func_type = SmoothingKernels.CUSTOM

        elif custom_kernel_function is not None:
            if isinstance(custom_kernel_function, Fittable1DModel):
                self.kernel_func = Model1DKernel(custom_kernel_function,
                                                 x_size=function_array_size)
            else:
                self.kernel_func = custom_kernel_function

            self.kernel_func_type = SmoothingKernels.CUSTOM

        elif kernel in default_smoothing_kernels:
            width = int(kernel_width)
            if kernel == SmoothingKernels.GAUSSIAN1D:
                self.kernel_func = Gaussian1DKernel(width)
            elif kernel == SmoothingKernels.Box1D:
                self.kernel_func = Box1DKernel(width)
            elif kernel == SmoothingKernels.MEDIAN:
                self.kernel_func = ndimage.median_filter
            else:
                raise Exception("Unsupported smoothing kernel " + str(kernel))
            self.kernel_func_type = kernel
            self.kernel_width = width
        else:
            raise Exception("Problem while setting the smoothing kernel")