From 5dbe7f8bac9f76e016c95dfc82438050a255a9ca Mon Sep 17 00:00:00 2001 From: Zack Li Date: Sun, 27 Feb 2022 00:06:48 -0500 Subject: [PATCH 1/4] add naxis and printing to CarClenshawCurtis to close #43 --- src/enmap.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/enmap.jl b/src/enmap.jl index fac6c91..940fb88 100644 --- a/src/enmap.jl +++ b/src/enmap.jl @@ -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 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)) From 4d3cd07472536dd2a9ba9287dcb8aeaedc7455dd Mon Sep 17 00:00:00 2001 From: Zack Li Date: Sun, 27 Feb 2022 00:16:29 -0500 Subject: [PATCH 2/4] test both trim=true and trim=false in io tests --- test/test_io.jl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/test_io.jl b/test/test_io.jl index ab78714..f1b73c3 100644 --- a/test/test_io.jl +++ b/test/test_io.jl @@ -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 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=trim) + @test size(imap) == (10,20,2) + end # todo: add tests on IAU conversion w/ and w/o sel end From 5dd241827e8271af6781c48637fd26489d9e8ba3 Mon Sep 17 00:00:00 2001 From: Zack Li Date: Sun, 27 Feb 2022 00:24:14 -0500 Subject: [PATCH 3/4] collect tuples --- test/test_io.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_io.jl b/test/test_io.jl index f1b73c3..a3c5505 100644 --- a/test/test_io.jl +++ b/test/test_io.jl @@ -5,8 +5,8 @@ imap = read_map("data/test.fits"; trim=trim) @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 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) From d863d835eb9090c42aa1de9a15c32f828ca725fc Mon Sep 17 00:00:00 2001 From: Zack Li Date: Sun, 27 Feb 2022 01:03:56 -0500 Subject: [PATCH 4/4] use Base.getproperty --- src/enmap.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/enmap.jl b/src/enmap.jl index 940fb88..7b3fdcc 100644 --- a/src/enmap.jl +++ b/src/enmap.jl @@ -55,7 +55,7 @@ function Base.convert(::Type{CarClenshawCurtis{T}}, w0::WCSTransform) where T end # this kind of WCS only has two spatial dimensions. this check should be constant-propagated -function getproperty(wcs::CarClenshawCurtis, k::Symbol) +function Base.getproperty(wcs::CarClenshawCurtis, k::Symbol) if k == :naxis return 2 end