Skip to content

Commit

Permalink
add some tests from Pixell for scalar SHTs
Browse files Browse the repository at this point in the history
  • Loading branch information
xzackli committed Feb 20, 2022
1 parent f7f4f13 commit 985f44c
Show file tree
Hide file tree
Showing 8 changed files with 5,601 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[targets]
test = ["Test"]
test = ["Test", "DelimitedFiles"]
6 changes: 3 additions & 3 deletions src/transforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function make_cc_geom_info(shape, wcs₀::AbstractWCSTransform)
Cint(nsubrings),nph, offsets, stride, phi0s, theta, weights, geom_info_ptr
)

GeomInfo(geom_info_ptr[])
return GeomInfo(geom_info_ptr[])
end


Expand Down Expand Up @@ -87,12 +87,12 @@ function map2alm(input_map::Enmap{T,2}; lmax=nothing, mmax=lmax) where T
nalms = alm_count(alm_info)
npix = map_size(geom_info)
alm = Alm(lmax, mmax, zeros(ComplexF64, nalms))
map1d = reshape(band.data, npix)
flat_map = reshape(band.data, npix)

sharp_execute!(
SHARP_MAP2ALM, 0,
[alm.alm],
[map1d],
[flat_map],
geom_info, alm_info, SHARP_DP
)
return alm
Expand Down
190 changes: 190 additions & 0 deletions test/data/simple_analytic_sht.txt

Large diffs are not rendered by default.

190 changes: 190 additions & 0 deletions test/data/simple_analytic_sht_sliced.txt

Large diffs are not rendered by default.

5,151 changes: 5,151 additions & 0 deletions test/data/simple_box_analytic_sht.txt

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions test/gen_sht_test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# %%
from pixell import enmap, utils, curvedsky
import numpy as np

# add some simple analytic stuff to the map
def gen_simple(imap, powerlaw_exponent):
for i in range(imap.shape[0]):
for j in range(imap.shape[1]):
imap[i,j] = (i * imap.shape[1] + j + 1)**powerlaw_exponent

shape, wcs = enmap.fullsky_geometry(10.0*utils.degree)
imap = enmap.zeros(shape, wcs=wcs)
gen_simple(imap, 2)

alms = curvedsky.map2alm(imap, lmax=18, method="auto")
np.savetxt("data/simple_analytic_sht.txt", np.column_stack([alms.real, alms.imag]), fmt='%.60g')

alms = curvedsky.map2alm(imap[4:-3, 5:-2], lmax=18, method="auto")
np.savetxt("data/simple_analytic_sht_sliced.txt", np.column_stack([alms.real, alms.imag]), fmt='%.60g')

box = np.array([[-5,10],[5,-10]]) * utils.degree
shape, wcs = enmap.geometry(pos=box,res=60 * utils.arcmin,proj='car')
imap = enmap.zeros(shape, wcs=wcs)
gen_simple(imap, 2.5)
alms = curvedsky.map2alm(imap, lmax=100, method="auto")
np.savetxt("data/simple_box_analytic_sht.txt", np.column_stack([alms.real, alms.imag]), fmt='%.60g')
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ using Pixell
using Test
import Pixell: degree, arcminute

using DelimitedFiles

include("test_geometry.jl") # creating geometries and sky ↔ pix
include("test_enmap.jl") # enmap features and manipulation
include("test_transforms.jl")
include("test_io.jl")
36 changes: 36 additions & 0 deletions test/test_transforms.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# write some simple stuff to the map
function gen_simple!(m, powerlaw_exponent)
for i in axes(m, 1)
for j in axes(m, 2)
m[i,j] = ( ((j-1) * size(m, 1)) + i )^powerlaw_exponent
end
end
end

@testset "Scalar SHTs" begin
shape, wcs = fullsky_geometry(10.0 * Pixell.degree)
m = Enmap(zeros(shape), wcs)
gen_simple!(m, 2)

alms = map2alm(m; lmax=18)
data = readdlm("data/simple_analytic_sht.txt")
ref_alms = data[:,1] + 1im .* data[:,2]
@test (alms.alm ref_alms)

alms = map2alm(m[6:end-2, 5:end-3]; lmax=18)
data = readdlm("data/simple_analytic_sht_sliced.txt")
ref_alms = data[:,1] + 1im .* data[:,2]
@test (alms.alm ref_alms)


box = [10 -10; # RA
-5 5] * degree # DEC
shape, wcs = geometry(CarClenshawCurtis, box, 1.0 * degree)
m = Enmap(zeros(shape), wcs)
gen_simple!(m, 2.5)
alms = map2alm(m; lmax=100)
data = readdlm("data/simple_box_analytic_sht.txt")
ref_alms = data[:,1] + 1im .* data[:,2]
@test (alms.alm ref_alms)
end

0 comments on commit 985f44c

Please sign in to comment.