예제 #1
0
    def test_mesh_gaussian_value(self):
        """Check reference values and empty cases for mesh_gaussian"""
        # Numerical values were not checked against an external reference
        # so they are only useful for detecting if the results have _changed_.

        self.assertEqual(
            Broadening.mesh_gaussian(sigma=5, points=[], center=1).shape,
            (0, ))

        zero_result = Broadening.mesh_gaussian(sigma=np.array([[5]]),
                                               points=np.array([
                                                   0,
                                               ]),
                                               center=np.array([[3]]))
        self.assertEqual(zero_result.shape, (1, 1))
        self.assertFalse(zero_result.any())

        assert_array_almost_equal(
            Broadening.mesh_gaussian(sigma=2,
                                     points=np.array([0, 1]),
                                     center=0), np.array([0.199471, 0.176033]))
        assert_array_almost_equal(
            Broadening.mesh_gaussian(sigma=np.array([[2], [2]]),
                                     points=np.array([0, 1, 2]),
                                     center=np.array([[0], [1]])),
            np.array([[0.199471, 0.176033, 0.120985],
                      [0.176033, 0.199471, 0.176033]]))
예제 #2
0
    def test_mesh_gaussian_sum(self):
        """Check sum of mesh_gaussian is correctly adapted to bin width"""
        # Note that larger bin widths will not sum to 1 with this theoretical normalisation factor; this is a
        # consequence of directly evaluating the Gaussian function. For coarse bins, consider using the "normal" kernel
        # which does not have this error.
        for bin_width in 0.1, 0.35:
            points = np.arange(-20, 20, bin_width)
            curve = Broadening.mesh_gaussian(sigma=0.4, points=points)

            self.assertAlmostEqual(sum(curve), 1)