Exemple #1
0
    def test_x1_surrounds_x2_with_constant_distribution(self):
        """
        x1 domain surrounds x2
        """
        # old size
        m = 20

        # new size
        n = 30

        # bin edges
        x_old = np.linspace(0., 1., m + 1)
        x_new = np.linspace(0.05, 0.26, n + 1)

        # constant spline
        mms_spline = BoundedUnivariateSpline([0, .1, .2, 1],
                                             [1, 1, 1, 1], s=0.)

        y_old = np.array([mms_spline.integral(x_old[i],
                                               x_old[i + 1])
                          for i in range(m)])

        y_new_mms = np.array([mms_spline.integral(x_new[i],
                                                  x_new[i + 1])
                              for i in range(n)])

        # rebin
        y_new = rebin.rebin(x_old, y_old, x_new, interp_kind=3)

        assert_allclose(y_new, y_new_mms)
Exemple #2
0
    def test_x2_right_overlap_x1_with_constant_distribution(self):
        """
        x2 domain overlaps x1 domain from the right
        """
        # old size
        m = 20

        # new size
        n = 30

        # bin edges
        x_old = np.linspace(0., 1., m + 1)
        x_new = np.linspace(0.95, 1.05, n + 1)

        # constant spline
        mms_spline = BoundedUnivariateSpline([0, .1, .2, 1],
                                             [1, 1, 1, 1], s=0.)

        y_old = np.array([mms_spline.integral(x_old[i],
                                              x_old[i + 1])
                          for i in range(m)])

        y_new_mms = np.array([mms_spline.integral(x_new[i],
                                                  x_new[i + 1])
                              for i in range(n)])

        # rebin
        y_new = rebin.rebin(x_old, y_old, x_new, interp_kind=3)
        assert_allclose(y_new, y_new_mms, rtol=1e-6, atol=1e-4)