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

Support for RGB #22

Merged
merged 5 commits into from
Aug 20, 2019
Merged

Support for RGB #22

merged 5 commits into from
Aug 20, 2019

Conversation

aquatiko
Copy link
Member

@aquatiko aquatiko commented Aug 8, 2019

I plan to add many data fields which will hold the results of operations performed on AstroImage. All those fields will be added to mutable struct properties.

@aquatiko
Copy link
Member Author

aquatiko commented Aug 8, 2019

If CI passes and there aren't any changes required regarding this approach, then it can be merged.

Copy link
Member

@giordano giordano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate on what you want to achieve here? It's not clear to me at all and doesn't look like it's particularly efficient

src/AstroImages.jl Outdated Show resolved Hide resolved
src/AstroImages.jl Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Aug 9, 2019

Codecov Report

Merging #22 into master will decrease coverage by 2.18%.
The diff coverage is 81.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #22      +/-   ##
==========================================
- Coverage   99.18%   96.99%   -2.19%     
==========================================
  Files           4        4              
  Lines         122      133      +11     
==========================================
+ Hits          121      129       +8     
- Misses          1        4       +3
Impacted Files Coverage Δ
src/AstroImages.jl 95.94% <81.25%> (-4.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a3483d...4b2a7e6. Read the comment docs.

@aquatiko
Copy link
Member Author

aquatiko commented Aug 13, 2019

@giordano Appvyeor needs a re-run.

src/AstroImages.jl Outdated Show resolved Hide resolved
src/AstroImages.jl Outdated Show resolved Hide resolved
src/AstroImages.jl Outdated Show resolved Hide resolved
AstroImage(data::NTuple{N, Matrix{T}}, wcs::NTuple{N, WCSTransform}) where {T<:Real, N} = AstroImage{T,Gray,N}(data, wcs)
AstroImage{T,color, 1, AbstractFloat}((data,), (wcs,), Properties{AbstractFloat}())
function AstroImage(color::Type{<:Color}, data::NTuple{N, Matrix{T}}, wcs::NTuple{N, WCSTransform}) where {T<:Real, N}
if N == 3 && color == RGB && T <: Union{AbstractFloat, FixedPoint}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not

if N == 3 && color == RGB
    if T <: Union{AbstractFloat, FixedPoint}
        ...
    else
        ...
    end

instead of repeating conditions multiple times?

Actually, why not using multiple method instead of having runtime checks on parameters?

return AstroImage{T,color,N, widen(T)}(data, wcs, Properties{widen(T)}(rgb_image = img))
elseif N == 3 && color == RGB
img = ccd2rgb((data[1], wcs[1]),(data[2], wcs[2]),(data[3], wcs[3]))
return AstroImage{T,color,N, AbstractFloat}(data, wcs, Properties{AbstractFloat}(rgb_image = img))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the parameter is abstract here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giordano The parameter is Abstract here for the following reasons:

  • When we fixed the MappedArrays type for rgb_image, the RGB subtype in it can only have P as an AbstractFloat or FixedPoint numbers.
  • Also, note that we are not filling rgb_image in all cases. So, when I simply passed T as a parameter (as done in the previous commit), it generated errors when T was not AbstractFloat or FixedPoint.
  • A solution for this was to pass a valid parameter just for the sake of passing it (when rgb_image is not getting filled). That's what is done except in one case where rgb_image is filled and the type isn't a valid one. The type needs to be in the above-mentioned domain as per Images.jl.

return AstroImage{T,color, N, AbstractFloat}(data, wcs, Properties{AbstractFloat}())
end
end
AstroImage(data::Matrix{T}) where {T<:Real} = AstroImage{T,Gray,1, AbstractFloat}((data,), (WCSTransform(2),), Properties{AbstractFloat}())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why the last parameter of the returned object is abstract?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same reason as above.

end
end
AstroImage(data::Matrix{T}) where {T<:Real} = AstroImage{T,Gray,1, AbstractFloat}((data,), (WCSTransform(2),), Properties{AbstractFloat}())
AstroImage(data::NTuple{N, Matrix{T}}) where {T<:Real, N} = AstroImage{T,Gray,N, AbstractFloat}(data, ntuple(i-> WCSTransform(2), N), Properties{AbstractFloat}())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same reason as above.

end
AstroImage(data::Matrix{T}) where {T<:Real} = AstroImage{T,Gray,1, AbstractFloat}((data,), (WCSTransform(2),), Properties{AbstractFloat}())
AstroImage(data::NTuple{N, Matrix{T}}) where {T<:Real, N} = AstroImage{T,Gray,N, AbstractFloat}(data, ntuple(i-> WCSTransform(2), N), Properties{AbstractFloat}())
AstroImage(data::Matrix{T}, wcs::WCSTransform) where {T<:Real} = AstroImage{T,Gray,1, AbstractFloat}((data,), (wcs,), Properties{AbstractFloat}())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstract parameter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same reason as above.

AstroImage(data::Matrix{T}) where {T<:Real} = AstroImage{T,Gray,1, AbstractFloat}((data,), (WCSTransform(2),), Properties{AbstractFloat}())
AstroImage(data::NTuple{N, Matrix{T}}) where {T<:Real, N} = AstroImage{T,Gray,N, AbstractFloat}(data, ntuple(i-> WCSTransform(2), N), Properties{AbstractFloat}())
AstroImage(data::Matrix{T}, wcs::WCSTransform) where {T<:Real} = AstroImage{T,Gray,1, AbstractFloat}((data,), (wcs,), Properties{AbstractFloat}())
AstroImage(data::NTuple{N, Matrix{T}}, wcs::NTuple{N, WCSTransform}) where {T<:Real, N} = AstroImage{T,Gray,N, AbstractFloat}(data, wcs, Properties{AbstractFloat}())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstract parameter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same reason as above.

@@ -44,4 +44,11 @@ end
@test isapprox(red.(asinh_res), red.(asinh_ans), nans = true, rtol = 3e-5)
@test isapprox(blue.(asinh_res), blue.(asinh_ans), nans = true, rtol = 3e-5)
@test isapprox(green.(asinh_res), green.(asinh_ans), nans = true, rtol = 3e-5)

@testset "AstroImage using ccd2rgb" begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably test coverage can be improved for this new feature

Copy link
Member Author

@aquatiko aquatiko Aug 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part takes relatively large time compared to other tests. So, I wanted to keep non-redundant tests only (as AstroImage is tested very comprehensively through other tests). Also, in the next PR, I'm adding more fields and already written more tests in this very @testset.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worried by the fact this takes a lot of time. Does it mean that performance is that bad?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproject is the bottleneck where it takes around 20 seconds to reproject an image of size 1024*1024.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't sound like a good news

@@ -85,9 +85,21 @@ for n in (8, 16, 32, 64)
end
end

struct AstroImage{T<:Real,C<:Color, N}
mutable struct Properties{P <: Union{AbstractFloat, FixedPoint}}
rgb_image::MappedArrays.MultiMappedArray{RGB{P},2,Tuple{Array{P,2},Array{Float64,2},Array{P,2}},Type{RGB{P}},typeof(ImageCore.extractchannels)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That Float64 should probably be P?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, missed that

@giordano giordano merged commit 98bc20d into JuliaAstro:master Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants