Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fejer1 support [breaking] #65

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests for Fejer1 and CC
  • Loading branch information
xzackli committed Dec 16, 2023
commit 89b9cdaa4acd3b91b50025113f4ff05b71368299
2 changes: 1 addition & 1 deletion src/enmap.jl
Original file line number Diff line number Diff line change
@@ -217,7 +217,7 @@ function read_map(path::String; hdu::Int=1, sel=(), wcs::Union{WCSTransform,Noth
@assert wcs0.ctype[1] == "RA---CAR"
@assert wcs0.ctype[2] == "DEC--CAR"
if isfejer1(wcs0)
wcs = convert(Fejer1{Float64}, wcs0)
wcs = convert(CarFejer1{Float64}, wcs0)
elseif isclenshawcurtis(wcs0)
wcs = convert(CarClenshawCurtis{Float64}, wcs0)
else
21 changes: 15 additions & 6 deletions src/projections/car_proj.jl
Original file line number Diff line number Diff line change
@@ -38,20 +38,29 @@ function Base.convert(::Type{CarFejer1{T}}, w0::WCSTransform) where T
end

function isfejer1(w0::WCSTransform)
cdelt, crpix, crval = getcdelt(w0), getcrpix(w0), getcrval(w0)
Δα, Δδ = getcdelt(w0)
skyloc = pix2sky(ones(Int, w0.naxis), w0, ones(w0.naxis)) # get first pixel
δ = rad2deg(skyloc[2])
# reference DEC is an integer number of pixels from each pole minus half a pixel
half_from_pole = 90 - cdelt[2]/2
half_from_pole = 90 - Δδ/2
npix1, npix2 = (half_from_pole - δ) / Δδ, (-half_from_pole - δ) / Δδ
return isapprox(δ + npix1 * Δδ, 90.0) && isapprox(δ + npix2 * Δδ, -90.0)
return isapprox(npix1, round(npix1)) && isapprox(npix2, round(npix2))
end

function isclenshawcurtis(w0::WCSTransform, tol=1e-6)
Δδ, j, δ = map(x->x[2], (getcdelt(w0), getcrpix(w0), getcrval(w0)))
function isclenshawcurtis(w0::WCSTransform)
Δα, Δδ = getcdelt(w0)
skyloc = pix2sky(ones(Int, w0.naxis), w0, ones(w0.naxis)) # get first pixel
δ = rad2deg(skyloc[2])
# reference DEC is an integer number of pixels from each pole
npix1, npix2 = (90 - δ) / Δδ, (-90 - δ) / Δδ
return isapprox(δ + npix1 * Δδ, 90.0) && isapprox(δ + npix2 * Δδ, -90.0)
return isapprox(npix1, round(npix1)) && isapprox(npix2, round(npix2))
end

isclenshawcurtis(::CarClenshawCurtis) = true
isclenshawcurtis(x) = false
isfejer1(::CarFejer1) = true
isfejer1(x) = false

function Base.convert(::Type{WCSTransform}, w0::AbstractCARWCS)
return WCSTransform(2;
ctype = ["RA---CAR", "DEC--CAR"],
Binary file added test/data/cc.fits
Binary file not shown.
Binary file added test/data/fejer1.fits
Binary file not shown.
11 changes: 10 additions & 1 deletion test/data_gen/gen_sht_test_data.py
Original file line number Diff line number Diff line change
@@ -8,9 +8,18 @@ def gen_simple(imap, powerlaw_exponent):
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)
shape, wcs = enmap.fullsky_geometry(10.0*utils.degree, variant='CC')
imap = enmap.zeros(shape, wcs=wcs)
gen_simple(imap, 2)
enmap.write_map("../data/cc.fits", imap)

shape, wcs = enmap.fullsky_geometry(10.0*utils.degree, variant='fejer1')
imap = enmap.zeros(shape, wcs=wcs)
gen_simple(imap, 2)
enmap.write_map("../data/fejer1.fits", imap)


# %%

alms = curvedsky.map2alm(imap, lmax=18, method="auto")
np.savetxt("data/simple_analytic_sht.txt", np.column_stack([alms.real, alms.imag]), fmt='%.60g')
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -10,4 +10,4 @@ include("test_transforms.jl")
include("test_distance_transform.jl")
include("test_io.jl")
include("test_plot.jl")
include("test_utils.jl")
include("test_utils.jl")
21 changes: 21 additions & 0 deletions test/test_io.jl
Original file line number Diff line number Diff line change
@@ -14,3 +14,24 @@
end
# todo: add tests on IAU conversion w/ and w/o sel
end

##
@testset "Enmap ClenshawCurtis vs Fejer1" begin

imap1 = read_map("data/cc.fits"; trim=false)
@test Pixell.isfejer1(imap1.wcs) == false
@test Pixell.isclenshawcurtis(imap1.wcs)

imap2= read_map("data/fejer1.fits"; trim=false)
@test Pixell.isfejer1(imap2.wcs)
@test Pixell.isclenshawcurtis(imap2.wcs) == false

imap1 = read_map("data/cc.fits"; trim=true)
@test Pixell.isfejer1(imap1.wcs) == false
@test Pixell.isclenshawcurtis(imap1.wcs)

imap2= read_map("data/fejer1.fits"; trim=true)
@test Pixell.isfejer1(imap2.wcs)
@test Pixell.isclenshawcurtis(imap2.wcs) == false

end
Loading