Skip to content

Commit

Permalink
Merge pull request #46 from simonsobs/add_nicewcs_prop
Browse files Browse the repository at this point in the history
add naxis and printing to CarClenshawCurtis to close #43
  • Loading branch information
xzackli authored Feb 27, 2022
2 parents 0d414bc + d863d83 commit 77075bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
14 changes: 14 additions & 0 deletions src/enmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ function Base.convert(::Type{CarClenshawCurtis{T}}, w0::WCSTransform) where T
return CarClenshawCurtis{T}(T.(getcdelt(w0)), T.(getcrpix(w0)), T.(getcrval(w0)), getunit(T, w0))
end

# this kind of WCS only has two spatial dimensions. this check should be constant-propagated
function Base.getproperty(wcs::CarClenshawCurtis, k::Symbol)
if k == :naxis
return 2
end
return getfield(wcs, k)
end

function Base.show(io::IO, wcs::CarClenshawCurtis{T}) where T
expr = join(["$k=$(getproperty(wcs, Symbol(k)))"
for k in ["naxis","cdelt","crval","crpix"]], ",")
print(io, "CarClenshawCurtis{$(T)}($expr)")
end


# forward all array traits to parent. based on MetaArrays
Base.size(x::Enmap) = size(parent(x))
Expand Down
22 changes: 11 additions & 11 deletions test/test_io.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@


@testset "Enmap I/O" begin
imap = read_map("data/test.fits"; trim=false)
@test size(imap) == (100, 100, 3)
@test imap.wcs.naxis == 2
@test imap.wcs.cdelt == [-1, 1]
@test imap.wcs.crval == [0.5, 0.0]
@test sum(imap) 14967.2985
# read with sel
imap = read_map("data/test.fits", sel=(11:20,21:40,1:2); trim=false)
@test size(imap) == (10,20,2)
imap = read_map("data/test.fits", sel=(11:20,21:40,1:2); trim=true)
@test size(imap) == (10,20,2)
for trim in (true, false)
imap = read_map("data/test.fits"; trim=trim)
@test size(imap) == (100, 100, 3)
@test imap.wcs.naxis == 2
@test collect(imap.wcs.cdelt) == [-1, 1]
@test collect(imap.wcs.crval) == [0.5, 0.0]
@test sum(imap) 14967.2985
# read with sel
imap = read_map("data/test.fits", sel=(11:20,21:40,1:2); trim=trim)
@test size(imap) == (10,20,2)
end
# todo: add tests on IAU conversion w/ and w/o sel
end

0 comments on commit 77075bf

Please sign in to comment.