From 6309e850dcc4e74d237af9186fb26ebd023676b4 Mon Sep 17 00:00:00 2001 From: Zack Li Date: Sat, 16 Dec 2023 09:12:19 -0800 Subject: [PATCH 1/3] car projection checking functions --- src/enmap.jl | 8 +++++++- src/projections/car_proj.jl | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/enmap.jl b/src/enmap.jl index e40ca42..e344a4d 100644 --- a/src/enmap.jl +++ b/src/enmap.jl @@ -216,7 +216,13 @@ function read_map(path::String; hdu::Int=1, sel=(), wcs::Union{WCSTransform,Noth wcs0 = WCS.from_header(header_str)[1] @assert wcs0.ctype[1] == "RA---CAR" @assert wcs0.ctype[2] == "DEC--CAR" - wcs = convert(CarClenshawCurtis{Float64}, wcs0) # FIXME select between CC or Fejer1 + if isfejer1(wcs0) + wcs = convert(Fejer1{Float64}, wcs0) + elseif isclenshawcurtis(wcs0) + wcs = convert(CarClenshawCurtis{Float64}, wcs0) + else + wcs = sub(WCS.from_header(header_str)[1], 2) + end end end Enmap(data, wcs) diff --git a/src/projections/car_proj.jl b/src/projections/car_proj.jl index c0c42ff..d588af7 100644 --- a/src/projections/car_proj.jl +++ b/src/projections/car_proj.jl @@ -37,6 +37,21 @@ function Base.convert(::Type{CarFejer1{T}}, w0::WCSTransform) where T T.(getcdelt(w0)), T.(getcrpix(w0)), T.(getcrval(w0)), getunit(T, w0)) end +function isfejer1(w0::WCSTransform) + cdelt, crpix, crval = getcdelt(w0), getcrpix(w0), getcrval(w0) + # reference DEC is an integer number of pixels from each pole minus half a pixel + half_from_pole = 90 - cdelt[2]/2 + npix1, npix2 = (half_from_pole - δ) / Δδ, (-half_from_pole - δ) / Δδ + return isapprox(δ + npix1 * Δδ, 90.0) && isapprox(δ + npix2 * Δδ, -90.0) +end + +function isclenshawcurtis(w0::WCSTransform, tol=1e-6) + Δδ, j, δ = map(x->x[2], (getcdelt(w0), getcrpix(w0), getcrval(w0))) + # reference DEC is an integer number of pixels from each pole + npix1, npix2 = (90 - δ) / Δδ, (-90 - δ) / Δδ + return isapprox(δ + npix1 * Δδ, 90.0) && isapprox(δ + npix2 * Δδ, -90.0) +end + function Base.convert(::Type{WCSTransform}, w0::AbstractCARWCS) return WCSTransform(2; ctype = ["RA---CAR", "DEC--CAR"], From 89b9cdaa4acd3b91b50025113f4ff05b71368299 Mon Sep 17 00:00:00 2001 From: xzackli Date: Sat, 16 Dec 2023 11:11:08 -0800 Subject: [PATCH 2/3] add tests for Fejer1 and CC --- src/enmap.jl | 2 +- src/projections/car_proj.jl | 21 +++++++++++++++------ test/data/cc.fits | Bin 0 -> 8640 bytes test/data/fejer1.fits | Bin 0 -> 8640 bytes test/data_gen/gen_sht_test_data.py | 11 ++++++++++- test/runtests.jl | 2 +- test/test_io.jl | 21 +++++++++++++++++++++ 7 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 test/data/cc.fits create mode 100644 test/data/fejer1.fits diff --git a/src/enmap.jl b/src/enmap.jl index e344a4d..8162ccf 100644 --- a/src/enmap.jl +++ b/src/enmap.jl @@ -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 diff --git a/src/projections/car_proj.jl b/src/projections/car_proj.jl index d588af7..59ad825 100644 --- a/src/projections/car_proj.jl +++ b/src/projections/car_proj.jl @@ -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"], diff --git a/test/data/cc.fits b/test/data/cc.fits new file mode 100644 index 0000000000000000000000000000000000000000..2ae642fae4d4f50f7be0109bb511d6985cc0a9d7 GIT binary patch literal 8640 zcmeH}e{fXQ6~`}ONfro@YO9+MSBElSTMBCBhp|;u3R*ELC=II(ib@~|s36LUpi#&V2;oQQyZ3v*jILHY{j0&feChWEeKI(Ib|89{&qoVsYC(yuQSWb@U9Wm>Rau}` z*339pxuPmiT~|?4UH5sBexFRevC-@OxlY&$6kKv1pE0FRm=-i+Hd)ME&EB<24)0m z1J&gLIlHE!I@s^_P%rBD9h-A$&VNzQlRvpM+Wn2@dcW`oX5K9GKEJ<;>hjuv{f>ju z7yR;_=IMH0cYoiu-t~nAxW8=sMzZ@q3jKMEyuP|3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*+u%m{5p7QVi1dI;fzua)ydNA{$==NI{m5^3=`^9*FJYgE zc>7G`xAT6{{un#&8||MWzr#SNjxp@Kk95={zhepNci z`6m!R_HFnv-nWj;LjEx`EYz`e?7WY4ry;+a_p|OP?DeSM{U_vi$5FrgWB73|;>X7$ z|2Xe=$7AekIKB({n4VB4zQh@Tk>KXWDGXF|w7 zvxwvC*?HgX$wq#UNf)Z8nw|IIo;dP*+HwEcZ^6%Ai~478L;l%Dj<>L*Ac>rW4v-jO zgM|SQ`!HhfzE#D+`# z`n!$ylNy5hUCEAfi28+*-!En(zA6E3kl@Z3*r6e)e+Ili&ME3o$nSrXjreT=5a$;4 zf6@&%Y0mxo*>R3h`Y`0DkH!7zQ%oYI<6NWkyJP15^i>*y(l@a0mhdj*yFIpX_lN+9 zbC2AX8*aja+{@UTB*t4g|Ak_J4(`K>nM?E%Aq zI5%nF58QAwENEbe9p@+wT+aFHasR;G3FPBkr9s&-lz()M> z0Ely&1|M=8A7UVA$Z&R?<1{3M{2>iC@*YlrnK zIQMDjKDTj?{_EWD@wh9g5Pbz@&hx|3Ur^?fI2?TjWj=4g(Qi=Z9v>Wi z2W6gh8TaA=koRJC^daOeM7|gO2zf&m^3j)&_cw9)5)DD#$NV7r6!LCK!uKlhaHC-s z`WDLaHo$!vg0jZ3qmQAishmGcA%1%jL|;Q$%l+`R8qWRAaS(kDWgW2K=yxc4pwDJ?EnzqU;AP=)wj77geA{eBRA66K^PjptmXz!8lg z`X-_&=+3e^8Y1mcBA6B9ew=58SAq`s)hoe8#pD$b&p1{|A0{;f Date: Sat, 16 Dec 2023 11:55:19 -0800 Subject: [PATCH 3/3] enforce CAR tests --- src/enmap_geom.jl | 18 ++-- test/test_distance_transform.jl | 4 +- test/test_enmap.jl | 59 +++++++------ test/test_geometry.jl | 145 ++++++++++++++++---------------- test/test_transforms.jl | 8 +- 5 files changed, 117 insertions(+), 117 deletions(-) diff --git a/src/enmap_geom.jl b/src/enmap_geom.jl index e81816f..6128eb6 100644 --- a/src/enmap_geom.jl +++ b/src/enmap_geom.jl @@ -10,8 +10,8 @@ function create_car_wcs(::Type{WCSTransform}, cdelt, crpix, crval) end # try to follow WCS.WCSTransform with degree units -function create_car_wcs(::Type{CarClenshawCurtis{T}}, cdelt, crpix, crval) where T - return CarClenshawCurtis{T}( +function create_car_wcs(W::Type{<:AbstractCARWCS{T}}, cdelt, crpix, crval) where T + return W( (cdelt[1], cdelt[2]), (crpix[1], crpix[2]), (crval[1], crval[2]), @@ -19,6 +19,8 @@ function create_car_wcs(::Type{CarClenshawCurtis{T}}, cdelt, crpix, crval) where end create_car_wcs(::Type{CarClenshawCurtis}, cdelt, crpix, crval) = create_car_wcs(CarClenshawCurtis{Float64}, cdelt, crpix, crval) +create_car_wcs(::Type{CarFejer1}, cdelt, crpix, crval) = + create_car_wcs(CarClenshawCurtis{Float64}, cdelt, crpix, crval) """ fullsky_geometry([W=CarClenshawCurtis], res; shape = nothing, dims = ()) @@ -44,7 +46,7 @@ julia> shape, wcs = fullsky_geometry(deg2rad(30/60)) # 30 arcmin pixel ((720, 361), WCSTransform(naxis=2,cdelt=[-0.5, 0.5],crval=[0.25, 0.0],crpix=[360.5, 181.0])) ``` """ -function fullsky_geometry(W::Type{<:AbstractWCSTransform}, res; shape = nothing, dims = ()) +function fullsky_geometry(W::Type{<:CarClenshawCurtis{T}}, res; shape = nothing, dims = ()) where T if isnothing(shape) shape = (round.(Int, (2π, π) ./ res .+ (0, 1))) # CAR has pixels on poles end @@ -66,15 +68,15 @@ function fullsky_geometry(W::Type{<:AbstractWCSTransform}, res; shape = nothing, return (nx, ny, dims...), wcs end -fullsky_geometry(W::Type{<:AbstractWCSTransform}, res::Number; shape = nothing, dims = ()) = +fullsky_geometry(W::Type{<:CarClenshawCurtis{T}}, res::Number; shape = nothing, dims = ()) where T = fullsky_geometry(W, (res, res); shape = shape, dims = dims) -fullsky_geometry(res; shape = nothing, dims = ()) = - fullsky_geometry(CarClenshawCurtis{Float64}, res; shape = shape, dims = dims) +# fullsky_geometry(res; shape = nothing, dims = ()) = +# fullsky_geometry(Fejer1{Float64}, res; shape = shape, dims = dims) # ONLY DOES CAR FOR NOW -function geometry(W::Type{<:AbstractWCSTransform}, bbox_coords, res) +function geometry(W::Type{<:CarClenshawCurtis{T}}, bbox_coords, res) where T # get everything into radians res_in_radians = ustrip.(uconvert.(radian, res)) @@ -104,5 +106,5 @@ function geometry(W::Type{<:AbstractWCSTransform}, bbox_coords, res) return shape, wcs end -geometry(W::Type{<:AbstractWCSTransform}, bbox_coords, res::Number) = +geometry(W::Type{<:CarClenshawCurtis{T}}, bbox_coords, res::Number) where T = geometry(W, bbox_coords, (res, res)) diff --git a/test/test_distance_transform.jl b/test/test_distance_transform.jl index 29e203d..8baabce 100644 --- a/test/test_distance_transform.jl +++ b/test/test_distance_transform.jl @@ -3,7 +3,7 @@ box = [20 -20; # RA -10 10] * degree # DEC - shape, wcs = geometry(Pixell.WCS.WCSTransform, box, (1/2) * degree) + shape, wcs = geometry(CarClenshawCurtis{Float64}, box, (1/2) * degree) for kk in 1:300 m = Enmap(ones(shape), wcs) @@ -26,7 +26,7 @@ end @testset "distance transform metric" begin box = [20 -20; # RA 0 10] * degree # DEC - shape, wcs = geometry(Pixell.WCS.WCSTransform, box, (1/2) * degree) + shape, wcs = geometry(CarClenshawCurtis{Float64}, box, (1/2) * degree) m = Enmap(ones(shape), wcs) m[1,1] = 0.0 diff --git a/test/test_enmap.jl b/test/test_enmap.jl index c9cba95..f783d6f 100644 --- a/test/test_enmap.jl +++ b/test/test_enmap.jl @@ -1,6 +1,6 @@ @testset "Enmap slicing" begin - shape0, wcs0 = fullsky_geometry(π/180) + shape0, wcs0 = fullsky_geometry(CarClenshawCurtis{Float64}, π/180) m = Enmap(rand(shape0...), wcs0) # regular slicing @@ -36,7 +36,7 @@ end ## @testset "Enmap view slicing" begin - shape0, wcs0 = fullsky_geometry(π/180) + shape0, wcs0 = fullsky_geometry(CarClenshawCurtis{Float64}, π/180) m = Enmap(rand(shape0...), wcs0) # regular slicing @@ -65,34 +65,34 @@ end end ## WCS should be not be shared under deepcopy, broadcasting, or broadcasted assignment -@testset "Enmap copying behavior" begin - for copy_op in (copy, deepcopy, similar) # these should all do the same thing: NEVER keep the same WCS - shape0, wcs0 = fullsky_geometry(Pixell.WCS.WCSTransform, π/180) - m = Enmap(rand(shape0...), wcs0) - m2 = copy_op(m) - @test !(m.wcs === m2.wcs) - m2.wcs.cdelt = collect([99., 99.]) - @test !(m.wcs.cdelt ≈ collect([99., 99.])) - - m = Enmap(rand(shape0...), wcs0) - m2 = m.^2 - @test !(m.wcs === m2.wcs) - m2.wcs.cdelt = collect([99., 99.]) - @test !(m.wcs.cdelt ≈ collect([99., 99.])) - - m = Enmap(rand(shape0...), wcs0) - m2 = copy_op(m) - m2 .= m - @test !(m.wcs === m2.wcs) - m2.wcs.cdelt = collect([99., 99.]) # also make sure sub-arrays aren't shared - @test !(m.wcs.cdelt ≈ collect([99., 99.])) - end -end +# @testset "Enmap copying behavior" begin + # for copy_op in (copy, deepcopy, similar) # these should all do the same thing: NEVER keep the same WCS + # shape0, wcs0 = fullsky_geometry(Pixell.WCS.WCSTransform, π/180) + # m = Enmap(rand(shape0...), wcs0) + # m2 = copy_op(m) + # @test !(m.wcs === m2.wcs) + # m2.wcs.cdelt = collect([99., 99.]) + # @test !(m.wcs.cdelt ≈ collect([99., 99.])) + + # m = Enmap(rand(shape0...), wcs0) + # m2 = m.^2 + # @test !(m.wcs === m2.wcs) + # m2.wcs.cdelt = collect([99., 99.]) + # @test !(m.wcs.cdelt ≈ collect([99., 99.])) + + # m = Enmap(rand(shape0...), wcs0) + # m2 = copy_op(m) + # m2 .= m + # @test !(m.wcs === m2.wcs) + # m2.wcs.cdelt = collect([99., 99.]) # also make sure sub-arrays aren't shared + # @test !(m.wcs.cdelt ≈ collect([99., 99.])) + # end +# end ## @testset "Enmap broadcasting" begin - shape, wcs = fullsky_geometry(deg2rad(1); dims=(3,)) + shape, wcs = fullsky_geometry(CarClenshawCurtis{Float64}, deg2rad(1); dims=(3,)) A, B = rand(shape...), rand(shape...) ma = Enmap(A, wcs) mb = Enmap(B, wcs) @@ -135,7 +135,7 @@ end end @testset "Enmap WCS props" begin - shape, wcs = fullsky_geometry(π/180) + shape, wcs = fullsky_geometry(CarClenshawCurtis{Float64}, π/180) m = Enmap(zeros(shape), wcs) @test stride(m,1) == 1 @test stride(m,2) == stride(m.data, 2) @@ -165,7 +165,7 @@ end ## @testset "Enmap pad" begin - shape0, wcs0 = fullsky_geometry(π/180) + shape0, wcs0 = fullsky_geometry(CarClenshawCurtis{Float64}, π/180) m = Enmap(rand(shape0...), wcs0) NPAD = 5 @@ -179,11 +179,10 @@ end end @testset "collapse to parent array for enmap view when slicing ra or dec" begin - shape0, wcs0 = fullsky_geometry(π/180) + shape0, wcs0 = fullsky_geometry(CarClenshawCurtis{Float64}, π/180) m = Enmap(rand(shape0...), wcs0) m[1,5:10] .= 1 - shape0, wcs0 = fullsky_geometry(π/180) m = Enmap(rand(shape0...,2), wcs0) mv = @view m[1,:,1] @test typeof(mv) == SubArray{Float64, 1, Array{Float64, 3}, diff --git a/test/test_geometry.jl b/test/test_geometry.jl index ce08997..40c0dc0 100644 --- a/test/test_geometry.jl +++ b/test/test_geometry.jl @@ -3,7 +3,7 @@ using Test, DelimitedFiles import Pixell: degree, arcminute @testset "Enmap geometry" begin - for W in (Pixell.WCS.WCSTransform, CarClenshawCurtis{Float64}) + for W in (CarClenshawCurtis{Float64},) #(Pixell.WCS.WCSTransform, CarClenshawCurtis{Float64}) shape, wcs = fullsky_geometry(W, deg2rad(1 / 60)) @test collect(wcs.cdelt) ≈ [-0.016666666666666666, 0.016666666666666666] @test collect(wcs.crpix) ≈ [10800.5, 5401.0] @@ -45,7 +45,7 @@ end ## wrap(ra_dec_vec) = [mod(ra_dec_vec[1], 2π), mod(ra_dec_vec[2], π)] @testset "Enmap sky2pix and pix2sky" begin - for W in (Pixell.WCS.WCSTransform, CarClenshawCurtis{Float64}) + for W in (CarClenshawCurtis{Float64},) #(Pixell.WCS.WCSTransform, CarClenshawCurtis{Float64}) shape, wcs = fullsky_geometry(W, deg2rad(1)) m = Enmap(rand(shape...), wcs) # in this test, wrap to angles in [0, 2π] and [0, π] for RA and DEC @@ -66,18 +66,18 @@ wrap(ra_dec_vec) = [mod(ra_dec_vec[1], 2π), mod(ra_dec_vec[2], π)] # check our custom implementations pixcoords = π .* rand(2, 1024) skycoords = pix2sky(m, pixcoords; safe=false) - shape, wcs_generic = fullsky_geometry(Pixell.WCS.WCSTransform, deg2rad(1)) - @test skycoords ≈ Pixell.WCS.pix_to_world(wcs_generic, pixcoords) .* (π/180) - skycoords .= 0.0 - pix2sky!(m, pixcoords, skycoords; safe=false) - @test skycoords ≈ Pixell.WCS.pix_to_world(wcs_generic, pixcoords) .* (π/180) + # shape, wcs_generic = fullsky_geometry(Pixell.WCS.WCSTransform, deg2rad(1)) + # @test skycoords ≈ Pixell.WCS.pix_to_world(wcs_generic, pixcoords) .* (π/180) + # skycoords .= 0.0 + # pix2sky!(m, pixcoords, skycoords; safe=false) + # @test skycoords ≈ Pixell.WCS.pix_to_world(wcs_generic, pixcoords) .* (π/180) - skycoords = π .* rand(2, 1024) - pixcoords = sky2pix(m, skycoords; safe=false) - @test pixcoords ≈ Pixell.WCS.world_to_pix(wcs_generic, skycoords .* (180/π)) - pixcoords .= 0.0 - sky2pix!(m, skycoords, pixcoords; safe=false) - @test pixcoords ≈ Pixell.WCS.world_to_pix(wcs_generic, skycoords .* (180/π)) + # skycoords = π .* rand(2, 1024) + # pixcoords = sky2pix(m, skycoords; safe=false) + # @test pixcoords ≈ Pixell.WCS.world_to_pix(wcs_generic, skycoords .* (180/π)) + # pixcoords .= 0.0 + # sky2pix!(m, skycoords, pixcoords; safe=false) + # @test pixcoords ≈ Pixell.WCS.world_to_pix(wcs_generic, skycoords .* (180/π)) box = [10 -10; # RA -5 5] * degree # DEC @@ -120,50 +120,49 @@ end end ## -@testset "Enmap sky2pix and pix2sky WCSlib fallbacks" begin - shape, wcs = fullsky_geometry(Pixell.WCS.WCSTransform, deg2rad(1)) - m = Enmap(rand(shape...), wcs) - # in this test, wrap to angles in [0, 2π] and [0, π] for RA and DEC - @test [3.12413936, -1.55334303] ≈ collect(pix2sky(m, [2.0, 2.0])) - @test [2.96705973, -1.79768913] ≈ collect(pix2sky(m, [11.0, -12.0])) - @test [2.44346095, -2.0943951] ≈ collect(pix2sky(m, [41.0, -29.0])) - @test [1.0, 0.0] ≈ collect(sky2pix(m, pix2sky(m, [1.0, 0.0]))) - @test [13., 7.] ≈ collect(sky2pix(m, pix2sky(m, [13., 7.]))) +# @testset "Enmap sky2pix and pix2sky WCSlib fallbacks" begin +# shape, wcs = fullsky_geometry(Pixell.WCS.WCSTransform, deg2rad(1)) +# m = Enmap(rand(shape...), wcs) +# # in this test, wrap to angles in [0, 2π] and [0, π] for RA and DEC +# @test [3.12413936, -1.55334303] ≈ collect(pix2sky(m, [2.0, 2.0])) +# @test [2.96705973, -1.79768913] ≈ collect(pix2sky(m, [11.0, -12.0])) +# @test [2.44346095, -2.0943951] ≈ collect(pix2sky(m, [41.0, -29.0])) +# @test [1.0, 0.0] ≈ collect(sky2pix(m, pix2sky(m, [1.0, 0.0]))) +# @test [13., 7.] ≈ collect(sky2pix(m, pix2sky(m, [13., 7.]))) - @test [1.0, 0.0] ≈ collect(sky2pix(m, pix2sky(m, [1.0, 0.0]) .+ (2π, 6π))) - @test [13., 7.] ≈ collect(sky2pix(m, pix2sky(m, [13., 7.]) .+ (12π, 16π))) - - # check our custom implementations - pixcoords = π .* rand(2, 1024) - skycoords = pix2sky(m, pixcoords; safe=false) - shape, wcs_generic = fullsky_geometry(Pixell.WCS.WCSTransform, deg2rad(1)) - @test skycoords ≈ Pixell.WCS.pix_to_world(wcs_generic, pixcoords) .* (π/180) - skycoords .= 0.0 - pix2sky!(m, pixcoords, skycoords; safe=false) - @test skycoords ≈ Pixell.WCS.pix_to_world(wcs_generic, pixcoords) .* (π/180) +# @test [1.0, 0.0] ≈ collect(sky2pix(m, pix2sky(m, [1.0, 0.0]) .+ (2π, 6π))) +# @test [13., 7.] ≈ collect(sky2pix(m, pix2sky(m, [13., 7.]) .+ (12π, 16π))) + +# # check our custom implementations +# pixcoords = π .* rand(2, 1024) +# skycoords = pix2sky(m, pixcoords; safe=false) +# shape, wcs_generic = fullsky_geometry(Pixell.WCS.WCSTransform, deg2rad(1)) +# @test skycoords ≈ Pixell.WCS.pix_to_world(wcs_generic, pixcoords) .* (π/180) +# skycoords .= 0.0 +# pix2sky!(m, pixcoords, skycoords; safe=false) +# @test skycoords ≈ Pixell.WCS.pix_to_world(wcs_generic, pixcoords) .* (π/180) - skycoords = π .* rand(2, 1024) - pixcoords = sky2pix(m, skycoords; safe=false) - @test pixcoords ≈ Pixell.WCS.world_to_pix(wcs_generic, skycoords .* (180/π)) - pixcoords .= 0.0 - sky2pix!(m, skycoords, pixcoords; safe=false) - @test pixcoords ≈ Pixell.WCS.world_to_pix(wcs_generic, skycoords .* (180/π)) - - box = [10 -10; # RA - -5 5] * degree # DEC - shape, wcs = geometry(CarClenshawCurtis, box, 1 * degree) - m = Enmap(ones(shape), wcs) - @test [sky2pix(m, deg2rad(ra), 0.0; safe=true)[1] - for ra in 178:182] ≈ [-167., -168., -169., 190., 189.] - -end +# skycoords = π .* rand(2, 1024) +# pixcoords = sky2pix(m, skycoords; safe=false) +# @test pixcoords ≈ Pixell.WCS.world_to_pix(wcs_generic, skycoords .* (180/π)) +# pixcoords .= 0.0 +# sky2pix!(m, skycoords, pixcoords; safe=false) +# @test pixcoords ≈ Pixell.WCS.world_to_pix(wcs_generic, skycoords .* (180/π)) + +# box = [10 -10; # RA +# -5 5] * degree # DEC +# shape, wcs = geometry(CarClenshawCurtis, box, 1 * degree) +# m = Enmap(ones(shape), wcs) +# @test [sky2pix(m, deg2rad(ra), 0.0; safe=true)[1] +# for ra in 178:182] ≈ [-167., -168., -169., 190., 189.] +# end ## @testset "sky2pix every single pixel" begin box = [10 -10; # RA -5 5] * degree # DEC - shape, wcs = geometry(CarClenshawCurtis, box, 1 * degree) + shape, wcs = geometry(CarClenshawCurtis{Float64}, box, 1 * degree) m = Enmap(ones(shape), wcs) for i in 1:shape[1] for j in 1:shape[2] @@ -182,7 +181,7 @@ end box = [179 -179; # RA -89 89] * degree # DEC - shape, wcs = geometry(CarClenshawCurtis, box, 1 * degree) + shape, wcs = geometry(CarClenshawCurtis{Float64}, box, 1 * degree) m = Enmap(ones(shape), wcs) for i in 1:shape[1] for j in 1:shape[2] @@ -203,30 +202,30 @@ end end end - # determine if safe angles are on the sky - shape, wcs = fullsky_geometry(deg2rad(1)) - m = Enmap(ones(shape), wcs) - for i in 1:shape[1] - for j in 1:shape[2] - ra, dec = pix2sky(m, i, j) - ra_unsafe, dec_unsafe = pix2sky(m, i, j; safe=false) - @test -π ≤ ra ≤ π - @test -π/2 ≤ dec ≤ π/2 - - ra_pix, dec_pix = sky2pix(m, ra, dec) - @test 1 ≤ ra_pix ≤ shape[1] - @test 1 ≤ dec_pix ≤ shape[2] - ra_pix, dec_pix = sky2pix(m, ra_unsafe, dec_unsafe) - @test 1 ≤ ra_pix ≤ shape[1] - @test 1 ≤ dec_pix ≤ shape[2] - end - end + # # determine if safe angles are on the sky + # shape, wcs = fullsky_geometry(deg2rad(1)) + # m = Enmap(ones(shape), wcs) + # for i in 1:shape[1] + # for j in 1:shape[2] + # ra, dec = pix2sky(m, i, j) + # ra_unsafe, dec_unsafe = pix2sky(m, i, j; safe=false) + # @test -π ≤ ra ≤ π + # @test -π/2 ≤ dec ≤ π/2 + + # ra_pix, dec_pix = sky2pix(m, ra, dec) + # @test 1 ≤ ra_pix ≤ shape[1] + # @test 1 ≤ dec_pix ≤ shape[2] + # ra_pix, dec_pix = sky2pix(m, ra_unsafe, dec_unsafe) + # @test 1 ≤ ra_pix ≤ shape[1] + # @test 1 ≤ dec_pix ≤ shape[2] + # end + # end end ## @testset "nonallocating WCS info utilities" begin - shape, wcs = fullsky_geometry(deg2rad(1)) + shape, wcs = fullsky_geometry(CarClenshawCurtis{Float64}, deg2rad(1)) @test all(Pixell.getcrpix(wcs) .== collect(wcs.crpix)) @test all(Pixell.getcrval(wcs) .== collect(wcs.crval)) @test all(Pixell.getcdelt(wcs) .== collect(wcs.cdelt)) @@ -234,7 +233,7 @@ end ## @testset "slice_geometry" begin - for W in (Pixell.WCS.WCSTransform, CarClenshawCurtis{Float64}) + for W in (CarClenshawCurtis{Float64},) #(Pixell.WCS.WCSTransform, CarClenshawCurtis{Float64}) shape0, wcs0 = fullsky_geometry(W, deg2rad(1)) shape, wcs = slice_geometry(shape0, wcs0, 1:3, 11:-1:3) @test (3, 9) == shape @@ -270,7 +269,7 @@ end ## @testset "pixel skyareas" begin - for W in (Pixell.WCS.WCSTransform, CarClenshawCurtis{Float64}) + for W in (CarClenshawCurtis{Float64},)#(Pixell.WCS.WCSTransform, CarClenshawCurtis{Float64}) shape, wcs = fullsky_geometry(W, deg2rad(1)) @test skyarea(shape, wcs) ≈ 4π @@ -279,7 +278,7 @@ end box = [10 -10; # RA -5 5] * degree # DEC - shape, wcs = geometry(CarClenshawCurtis, box, (1/60) * degree) + shape, wcs = geometry(W, box, (1/60) * degree) @test skyarea(shape, wcs) ≈ 0.06084618627514243 end end @@ -289,7 +288,7 @@ end -5 5] * Pixell.degree # DEC boxgeom = geometry(CarClenshawCurtis{Float64}, box, 5. * Pixell.arcminute) - fullgeom = fullsky_geometry(π/180) + fullgeom = fullsky_geometry(CarClenshawCurtis{Float64}, π/180) pm_py_full = readdlm("data/fullsky_pixareas.dat") pm_py_box = readdlm("data/box_pixareas.dat") diff --git a/test/test_transforms.jl b/test/test_transforms.jl index 6a0fbea..8031789 100644 --- a/test/test_transforms.jl +++ b/test/test_transforms.jl @@ -9,7 +9,7 @@ function gen_spin0!(m, powerlaw_exponent=2) end @testset "spin-0 SHTs" begin - shape, wcs = fullsky_geometry(10.0 * Pixell.degree) + shape, wcs = fullsky_geometry(CarClenshawCurtis{Float64}, 10.0 * Pixell.degree) m = Enmap(zeros(shape), wcs) gen_spin0!(m) @@ -27,7 +27,7 @@ end box = [10 -10; # RA -5 5] * Pixell.degree # DEC - shape, wcs = geometry(CarClenshawCurtis, box, 1.0 * Pixell.degree) + shape, wcs = geometry(CarClenshawCurtis{Float64}, box, 1.0 * Pixell.degree) m = Enmap(zeros(shape), wcs) gen_spin0!(m, 2.5) alms = map2alm(m; lmax=100) @@ -47,7 +47,7 @@ function gen_spin2!(m) end @testset "spin-2 SHTs" begin - shape, wcs = fullsky_geometry(10.0 * Pixell.degree; dims=(2,)) + shape, wcs = fullsky_geometry(CarClenshawCurtis{Float64}, 10.0 * Pixell.degree; dims=(2,)) m_QU = Enmap(zeros(shape), wcs) gen_spin2!(m_QU) alm_e, alm_b = map2alm(m_QU; lmax=3 * 36) @@ -61,7 +61,7 @@ end @test (ref_alm_e ≈ alm_e.alm) @test (ref_alm_b ≈ alm_b.alm) - shape, wcs = fullsky_geometry(10.0 * Pixell.degree; dims=(3,)) + shape, wcs = fullsky_geometry(CarClenshawCurtis{Float64}, 10.0 * Pixell.degree; dims=(3,)) m_IQU = Enmap(zeros(shape), wcs) gen_spin0!(@view(m_IQU[:,:,1])) gen_spin2!(@view(m_IQU[:,:,2:3]))