def test_plf_integration(self):
        import numpy as num

        x = num.array([1., 1., 3., 3.])
        y = num.array([0., 1., 1., 0.])
        x_edges = num.array([0.5, 1.5, 2.5, 3.5])
        yy = util.plf_integrate_piecewise(x_edges, x, y)
        assert num.all(num.abs(yy - num.array([0.5, 1.0, 0.5])) < 1e-6)

        x = num.array([0., 1., 2., 3.])
        y = num.array([0., 1., 1., 0.])
        x_edges = num.array([0., 1., 2., 3.])
        yy = util.plf_integrate_piecewise(x_edges, x, y)
        assert num.all(num.abs(yy - num.array([0.5, 1.0, 0.5])) < 1e-6)
Example #2
0
    def test_plf_integration(self):
        import numpy as num

        x = num.array([1., 1., 3., 3.])
        y = num.array([0., 1., 1., 0.])
        x_edges = num.array([0.5, 1.5, 2.5, 3.5])
        yy = util.plf_integrate_piecewise(x_edges, x, y)
        assert num.all(num.abs(yy - num.array([0.5, 1.0, 0.5])) < 1e-6)

        x = num.array([0., 1., 2., 3.])
        y = num.array([0., 1., 1., 0.])
        x_edges = num.array([0., 1., 2., 3.])
        yy = util.plf_integrate_piecewise(x_edges, x, y)
        assert num.all(num.abs(yy - num.array([0.5, 1.0, 0.5])) < 1e-6)
    def discretize_t(self, deltat, tref):
        tmin_stf = tref - self.duration * (self.anchor + 1.) * 0.5
        tmax_stf = tref + self.duration * (1. - self.anchor) * 0.5
        tmin = np.round(tmin_stf / deltat) * deltat
        tmax = np.round(tmax_stf / deltat) * deltat
        nt = int(np.round((tmax - tmin) / deltat)) + 1
        times = np.linspace(tmin, tmax, nt)
        amplitudes = np.ones_like(times)
        if times.size > 1:
            t_edges = np.linspace(tmin - 0.5 * deltat, tmax + 0.5 * deltat,
                                  nt + 1)
            t = tmin_stf + self.duration * np.array([0.0, 0.0, 1.0, 1.0],
                                                    dtype=np.float)
            f = np.array([0., 1., 1., 0.], dtype=np.float)
            amplitudes = util.plf_integrate_piecewise(t_edges, t, f)
            amplitudes /= np.sum(amplitudes)

        amplitudes *= self.noise_func(nt)
        tshift = (np.sum(amplitudes * times) - self.centroid_time(tref))

        return sshift(times, amplitudes, -tshift, deltat)