Exemple #1
0
def test_grid_centers():
    x = numpy.linspace(-1, 1, 100)
    dx = x[1] - x[0]
    nx, rng = sampling.grid_npix(rng=[x[0], x[-1]], dx=dx)
    centers, _dx = sampling.grid_centers(rng, nx)
    assert dx == _dx, 'Bad linear step size'
    assert numpy.allclose(centers, x), 'Bad linear borders'

    x = numpy.logspace(-1, 1, 100)
    dx = numpy.log10(x[1]) - numpy.log10(x[0])
    nx, rng = sampling.grid_npix(rng=[x[0], x[-1]], dx=dx, log=True)
    centers, _dx = sampling.grid_centers(rng, nx, log=True)
    assert dx == _dx, 'Bad logarithmic step size'
    assert numpy.allclose(centers, x), 'Bad geometric borders'
Exemple #2
0
def test_grid_npix():
    for s in numpy.random.randint(2, high=1000, size=100):
        x = numpy.linspace(-1., 1., s)
        nx, rng = sampling.grid_npix(rng=[x[0], x[-1]], dx=x[1] - x[0])
        assert nx == s, 'Bad number of linear grid points'
        assert numpy.allclose(rng, [-1., 1.]), 'Bad linear grid range'

        x = numpy.logspace(-1., 1., s)
        nx, rng = sampling.grid_npix(rng=[x[0], x[-1]],
                                     dx=numpy.log10(x[1]) - numpy.log10(x[0]),
                                     log=True)
        assert nx == s, 'Bad number of logarithmic grid points'
        assert numpy.allclose(rng, numpy.power(
            10., [-1., 1.])), 'Bad logarithmic grid range'