test_pysharp.py 2.18 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import pysharp
import numpy as np
import math
import pytest
from numpy.testing import assert_equal, assert_allclose

pmp = pytest.mark.parametrize

@pmp('params', [(511, 511, 512, 1024),
                (511, 2, 512, 5),
                (511, 0, 512, 1)])
def test_GL(params):
    lmax, mmax, nlat, nlon = params
    job = pysharp.sharpjob_d()
    nalm = ((mmax+1)*(mmax+2))//2 + (mmax+1)*(lmax-mmax)
    nalm_r = nalm*2-lmax-1
17
18
    rng = np.random.default_rng(np.random.SeedSequence(42))
    alm_r = rng.uniform(-1., 1., nalm_r)
Martin Reinecke's avatar
Martin Reinecke committed
19
20
21
22
23
    alm = np.empty(nalm, dtype=np.complex128)
    alm[0:lmax+1] = alm_r[0:lmax+1]
    alm[lmax+1:] = np.sqrt(0.5)*(alm_r[lmax+1::2] + 1j*alm_r[lmax+2::2])

    job.set_triangular_alm_info(lmax, mmax)
24
    job.set_gauss_geometry(nlat, nlon)
Martin Reinecke's avatar
Martin Reinecke committed
25
26
27
28
29
30
    alm2 = job.map2alm(job.alm2map(alm))
    assert_allclose(alm, alm2)

@pmp('params', [(511, 511, 1024, 1024),
                (511, 2, 1024, 5),
                (511, 0, 1024, 1)])
31
def test_fejer1(params):
Martin Reinecke's avatar
Martin Reinecke committed
32
33
34
35
    lmax, mmax, nlat, nlon = params
    job = pysharp.sharpjob_d()
    nalm = ((mmax+1)*(mmax+2))//2 + (mmax+1)*(lmax-mmax)
    nalm_r = nalm*2-lmax-1
36
37
    rng = np.random.default_rng(np.random.SeedSequence(42))
    alm_r = rng.uniform(-1., 1., nalm_r)
Martin Reinecke's avatar
Martin Reinecke committed
38
39
40
41
42
    alm = np.empty(nalm, dtype=np.complex128)
    alm[0:lmax+1] = alm_r[0:lmax+1]
    alm[lmax+1:] = np.sqrt(0.5)*(alm_r[lmax+1::2] + 1j*alm_r[lmax+2::2])

    job.set_triangular_alm_info(lmax, mmax)
43
44
45
46
47
48
49
50
51
52
53
54
    job.set_fejer1_geometry(nlat, nlon)
    alm2 = job.map2alm(job.alm2map(alm))
    assert_allclose(alm, alm2)

@pmp('params', [(511, 511, 1024, 1024),
                (511, 2, 1024, 5),
                (511, 0, 1024, 1)])
def test_dh(params):
    lmax, mmax, nlat, nlon = params
    job = pysharp.sharpjob_d()
    nalm = ((mmax+1)*(mmax+2))//2 + (mmax+1)*(lmax-mmax)
    nalm_r = nalm*2-lmax-1
55
56
    rng = np.random.default_rng(np.random.SeedSequence(42))
    alm_r = rng.uniform(-1., 1., nalm_r)
57
58
59
60
61
62
    alm = np.empty(nalm, dtype=np.complex128)
    alm[0:lmax+1] = alm_r[0:lmax+1]
    alm[lmax+1:] = np.sqrt(0.5)*(alm_r[lmax+1::2] + 1j*alm_r[lmax+2::2])

    job.set_triangular_alm_info(lmax, mmax)
    job.set_dh_geometry(nlat, nlon)
Martin Reinecke's avatar
Martin Reinecke committed
63
64
    alm2 = job.map2alm(job.alm2map(alm))
    assert_allclose(alm, alm2)