Skip to content

Commit

Permalink
Disambiguate call to axes() because both Compat and AxisArrays export…
Browse files Browse the repository at this point in the history
… it now.
  • Loading branch information
Cody-G committed Dec 29, 2017
1 parent 3e9d83e commit d30a726
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
48 changes: 24 additions & 24 deletions src/ImageAxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ end

# Specializations to preserve the AxisArray wrapper
function ImageCore.permuteddimsview(A::AxisArray, perm)
axs = axes(A)
axs = AxisArrays.axes(A)
AxisArray(permuteddimsview(A.data, perm), axs[[perm...]]...)
end
function ImageCore.channelview(A::AxisArray)
Ac = channelview(A.data)
_channelview(A, Ac)
end
# without extra dimension:
_channelview{C,T,N}(A::AxisArray{C,N}, Ac::AbstractArray{T,N}) = AxisArray(Ac, axes(A)...)
_channelview{C,T,N}(A::AxisArray{C,N}, Ac::AbstractArray{T,N}) = AxisArray(Ac, AxisArrays.axes(A)...)
# with extra dimension: (bug: the type parameters shouldn't be necessary, but julia 0.5 dispatches incorrectly without them)
_channelview{C,T,M,N}(A::AxisArray{C,M}, Ac::AbstractArray{T,N}) = AxisArray(Ac, Axis{:color}(indices(Ac,1)), axes(A)...)
_channelview{C,T,M,N}(A::AxisArray{C,M}, Ac::AbstractArray{T,N}) = AxisArray(Ac, Axis{:color}(indices(Ac,1)), AxisArrays.axes(A)...)


### Image properties based on traits ###
Expand All @@ -133,7 +133,7 @@ using an axis for this purpose.
Note: if you want to recover information about the time axis, it is
generally better to use `timeaxis`.
"""
timedim{T,N}(img::AxisArray{T,N}) = _timedim(filter_time_axis(axes(img), ntuple(identity, Val{N})))
timedim{T,N}(img::AxisArray{T,N}) = _timedim(filter_time_axis(AxisArrays.axes(img), ntuple(identity, Val{N})))
_timedim(dim::Tuple{Int}) = dim[1]
_timedim(::Tuple{}) = 0

Expand All @@ -142,31 +142,31 @@ _nimages(::Void) = 1
_nimages(ax::Axis) = length(ax)

function colordim(img::AxisArray)
d = _colordim(1, axes(img))
d = _colordim(1, AxisArrays.axes(img))
d > ndims(img) ? 0 : d
end
_colordim{Ax<:Axis{:color}}(d, ax::Tuple{Ax,Vararg{Any}}) = d
_colordim(d, ax::Tuple{Any,Vararg{Any}}) = _colordim(d+1, tail(ax))
_colordim(d, ax::Tuple{}) = d+1

ImageCore.pixelspacing(img::AxisArray) = map(step, filter_space_axes(axes(img), axisvalues(img)))
ImageCore.pixelspacing(img::AxisArray) = map(step, filter_space_axes(AxisArrays.axes(img), axisvalues(img)))

ImageCore.spacedirections(img::AxisArray) = ImageCore._spacedirections(pixelspacing(img))

ImageCore.coords_spatial{T,N}(img::AxisArray{T,N}) = filter_space_axes(axes(img), ntuple(identity, Val{N}))
ImageCore.coords_spatial{T,N}(img::AxisArray{T,N}) = filter_space_axes(AxisArrays.axes(img), ntuple(identity, Val{N}))

ImageCore.spatialorder(img::AxisArray) = filter_space_axes(axes(img), axisnames(img))
ImageCore.spatialorder(img::AxisArray) = filter_space_axes(AxisArrays.axes(img), axisnames(img))

ImageCore.size_spatial(img::AxisArray) = filter_space_axes(axes(img), size(img))
ImageCore.indices_spatial(img::AxisArray) = filter_space_axes(axes(img), indices(img))
ImageCore.size_spatial(img::AxisArray) = filter_space_axes(AxisArrays.axes(img), size(img))
ImageCore.indices_spatial(img::AxisArray) = filter_space_axes(AxisArrays.axes(img), indices(img))

data(img::AxisArray) = img.data

### Utilities for writing "simple algorithms" safely ###

# Check that the time dimension, if present, is last
@traitfn function ImageCore.assert_timedim_last{AA<:AxisArray; HasTimeAxis{AA}}(img::AA)
ax = axes(img)[end]
ax = AxisArrays.axes(img)[end]
istimeaxis(ax) || error("time dimension is not last")
nothing
end
Expand Down Expand Up @@ -241,9 +241,9 @@ Base.size(S::StreamingContainer) = size(S.parent)
Base.indices(S::StreamingContainer, d) = indices(S.parent, d)
Base.size(S::StreamingContainer, d) = size(S.parent, d)

AxisArrays.axes(S::StreamingContainer) = axes(parent(S))
AxisArrays.axisnames(S::StreamingContainer) = axisnames(axes(S)...)
AxisArrays.axisvalues(S::StreamingContainer) = axisvalues(axes(S)...)
AxisArrays.axes(S::StreamingContainer) = AxisArrays.axes(parent(S))
AxisArrays.axisnames(S::StreamingContainer) = axisnames(AxisArrays.axes(S)...)
AxisArrays.axisvalues(S::StreamingContainer) = axisvalues(AxisArrays.axes(S)...)
function AxisArrays.axisdim{name}(S::StreamingContainer, ::Type{Axis{name}})
isa(name, Int) && return name <= ndims(S) ? name : error("axis $name greater than array dimensionality $(ndims(S))")
names = axisnames(S)
Expand All @@ -256,12 +256,12 @@ AxisArrays.axisdim{name,T}(S::StreamingContainer, ::Type{Axis{name,T}}) = axisdi

ImageCore.nimages(S::StreamingContainer) = _nimages(timeaxis(S))
ImageCore.coords_spatial{T,N}(S::StreamingContainer{T,N}) =
filter_space_axes(axes(S), ntuple(identity, Val{N}))
ImageCore.spatialorder(S::StreamingContainer) = filter_space_axes(axes(S), axisnames(S))
ImageCore.size_spatial(img::StreamingContainer) = filter_space_axes(axes(img), size(img))
ImageCore.indices_spatial(img::StreamingContainer) = filter_space_axes(axes(img), indices(img))
filter_space_axes(AxisArrays.axes(S), ntuple(identity, Val{N}))
ImageCore.spatialorder(S::StreamingContainer) = filter_space_axes(AxisArrays.axes(S), axisnames(S))
ImageCore.size_spatial(img::StreamingContainer) = filter_space_axes(AxisArrays.axes(img), size(img))
ImageCore.indices_spatial(img::StreamingContainer) = filter_space_axes(AxisArrays.axes(img), indices(img))
function ImageCore.assert_timedim_last(S::StreamingContainer)
istimeaxis(axes(S)[end]) || error("time dimension is not last")
istimeaxis(AxisArrays.axes(S)[end]) || error("time dimension is not last")
nothing
end

Expand All @@ -275,7 +275,7 @@ streamingaxisnames{T,N,names,P,GetIndex}(::Type{StreamingContainer{T,N,names,P,G
names
streamingaxisnames(S::StreamingContainer) = streamingaxisnames(typeof(S))

timeaxis(S::StreamingContainer) = _timeaxis(axes(S)...)
timeaxis(S::StreamingContainer) = _timeaxis(AxisArrays.axes(S)...)

@inline function getindex!(dest, S::StreamingContainer, axs::Axis...)
all(ax->isstreamedaxis(ax,S), axs) || throw(ArgumentError("$axs do not coincide with the streaming axes $(streamingaxisnames(S))"))
Expand All @@ -300,11 +300,11 @@ function isstreamedaxis{name,T,N,saxnames}(ax::Axis{name},
end

sliceindices(S::StreamingContainer) = filter_notstreamed(indices(S), S)
sliceaxes(S::StreamingContainer) = filter_notstreamed(axes(S), S)
getslicedindices(S::StreamingContainer, I) = filter_streamed(map((ax, i) -> ax(i), axes(S), I), S)
sliceaxes(S::StreamingContainer) = filter_notstreamed(AxisArrays.axes(S), S)
getslicedindices(S::StreamingContainer, I) = filter_streamed(map((ax, i) -> ax(i), AxisArrays.axes(S), I), S)

filter_streamed(inds, S) = _filter_streamed(inds, axes(S), S)
filter_notstreamed(inds, S) = _filter_notstreamed(inds, axes(S), S)
filter_streamed(inds, S) = _filter_streamed(inds, AxisArrays.axes(S), S)
filter_notstreamed(inds, S) = _filter_notstreamed(inds, AxisArrays.axes(S), S)
filter_streamed(inds::Tuple{Axis,Vararg{Axis}}, S) = _filter_streamed(inds, inds, S)
filter_notstreamed(inds::Tuple{Axis,Vararg{Axis}}, S) = _filter_notstreamed(inds, inds, S)

Expand Down
14 changes: 7 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using SimpleTraits, Unitful
@test @inferred(size_spatial(A)) === (3,4)
@test @inferred(indices_spatial(A)) === (Base.OneTo(3), Base.OneTo(4))
assert_timedim_last(A)
@test map(istimeaxis, axes(A)) == (false,false)
@test map(istimeaxis, AxisArrays.axes(A)) == (false,false)

@test @inferred(timeaxis(rand(3,5))) == nothing
end
Expand All @@ -60,7 +60,7 @@ end
@test @inferred(size_spatial(A)) === (3,4)
@test @inferred(indices_spatial(A)) === (Base.OneTo(3),Base.OneTo(4))
assert_timedim_last(A)
@test map(istimeaxis, axes(A)) == (false,false)
@test map(istimeaxis, AxisArrays.axes(A)) == (false,false)
end

@testset "units, time" begin
Expand All @@ -78,7 +78,7 @@ end
@test @inferred(size_spatial(A)) === (3,)
@test @inferred(indices_spatial(A)) === (Base.OneTo(3),)
assert_timedim_last(A)
@test map(istimeaxis, axes(A)) == (false,true)
@test map(istimeaxis, AxisArrays.axes(A)) == (false,true)
end

@testset "units, time first" begin
Expand All @@ -96,26 +96,26 @@ end
@test @inferred(size_spatial(A)) === (3,)
@test @inferred(indices_spatial(A)) === (Base.OneTo(3),)
@test_throws ErrorException assert_timedim_last(A)
@test map(istimeaxis, axes(A)) == (true,false)
@test map(istimeaxis, AxisArrays.axes(A)) == (true,false)
end

@testset "grayscale" begin
A = AxisArray(rand(Gray{N0f8}, 4, 5), :y, :x)
@test summary(A) == "2-dimensional AxisArray{Gray{N0f8},2,...} with axes:\n :y, Base.OneTo(4)\n :x, Base.OneTo(5)\nAnd data, a 4×5 Array{Gray{N0f8},2}"
cv = channelview(A)
@test axes(cv) == (Axis{:y}(1:4), Axis{:x}(1:5))
@test AxisArrays.axes(cv) == (Axis{:y}(1:4), Axis{:x}(1:5))
@test spatialorder(cv) == (:y, :x)
@test colordim(cv) == 0
end

@testset "color" begin
A = AxisArray(rand(RGB{N0f8}, 4, 5), :y, :x)
cv = channelview(A)
@test axes(cv) == (Axis{:color}(1:3), Axis{:y}(1:4), Axis{:x}(1:5))
@test AxisArrays.axes(cv) == (Axis{:color}(1:3), Axis{:y}(1:4), Axis{:x}(1:5))
@test spatialorder(cv) == (:y, :x)
@test colordim(cv) == 1
p = permuteddimsview(cv, (2,3,1))
@test axes(p) == (Axis{:y}(1:4), Axis{:x}(1:5), Axis{:color}(1:3))
@test AxisArrays.axes(p) == (Axis{:y}(1:4), Axis{:x}(1:5), Axis{:color}(1:3))
@test colordim(p) == 3
end

Expand Down

0 comments on commit d30a726

Please sign in to comment.