Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
aquatiko committed Aug 18, 2019
1 parent d02ea78 commit 8caf0a4
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/AstroImages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ for n in (8, 16, 32, 64)
end
end

mutable struct Properties{T <: Real}
rgb_image::MappedArrays.MultiMappedArray{RGB{T},2,Tuple{Array{T,2},Array{Float64,2},Array{T,2}},Type{RGB{T}},typeof(ImageCore.extractchannels)}
function Properties{T}(;kvs...) where T
obj = new{T}()
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)}
function Properties{P}(;kvs...) where P
obj = new{P}()
for (k,v) in kvs
setproperty!(obj, k, v)
end
return obj
end
end

struct AstroImage{T<:Real,C<:Color, N}
struct AstroImage{T<:Real,C<:Color, N, P}
data::NTuple{N, Matrix{T}}
wcs::NTuple{N, WCSTransform}
property::Properties{T}
property::Properties{P}
end

"""
Expand All @@ -109,19 +109,23 @@ end
Construct an `AstroImage` object of `data`, using `color` as color map, `Gray` by default.
"""
AstroImage(color::Type{<:Color}, data::Matrix{T}, wcs::WCSTransform) where {T<:Real} =
AstroImage{T,color, 1}((data,), (wcs,), Properties{T}())
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
if N == 3 && color == RGB && T <: Union{AbstractFloat, FixedPoint}
img = ccd2rgb((data[1], wcs[1]),(data[2], wcs[2]),(data[3], wcs[3]))
return AstroImage{T,color,N}(data, wcs, Properties{T}(rgb_image = img))
print(eltype(img))
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))
else
return AstroImage{T,color, N}(data, wcs, Properties{T}())
return AstroImage{T,color, N, AbstractFloat}(data, wcs, Properties{AbstractFloat}())
end
end
AstroImage(data::Matrix{T}) where {T<:Real} = AstroImage{T,Gray,1}((data,), (WCSTransform(2),), Properties{T}())
AstroImage(data::NTuple{N, Matrix{T}}) where {T<:Real, N} = AstroImage{T,Gray,N}(data, ntuple(i-> WCSTransform(2), N), Properties{T}())
AstroImage(data::Matrix{T}, wcs::WCSTransform) where {T<:Real} = AstroImage{T,Gray,1}((data,), (wcs,), Properties{T}())
AstroImage(data::NTuple{N, Matrix{T}}, wcs::NTuple{N, WCSTransform}) where {T<:Real, N} = AstroImage{T,Gray,N}(data, wcs, Properties{T}())
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}())

"""
AstroImage([color=Gray,] filename::String, n::Int=1)
Expand Down

0 comments on commit 8caf0a4

Please sign in to comment.