Skip to content

Commit

Permalink
Merge pull request #16 from JuliaImages/teh/traits_nesting
Browse files Browse the repository at this point in the history
Support nesting for `timeaxis` over MappedArrays
  • Loading branch information
timholy authored Mar 21, 2017
2 parents 8bd2356 + acfe252 commit ff917a1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
julia 0.5
ImageCore
ImageCore 0.2
AxisArrays
MappedArrays
SimpleTraits
Reexport
Colors
Expand Down
3 changes: 2 additions & 1 deletion src/ImageAxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __precompile__()
module ImageAxes

using Base: @pure, tail
using Reexport, Colors, SimpleTraits
using Reexport, Colors, SimpleTraits, MappedArrays

@reexport using AxisArrays
@reexport using ImageCore
Expand Down Expand Up @@ -38,6 +38,7 @@ new names as well.
Return the time axis, if present, of the array `A`, and `nothing` otherwise.
"""
@inline timeaxis(A::AxisArray) = _timeaxis(A.axes...)
timeaxis(A::AbstractMappedArray) = timeaxis(parent(A))
@traitfn _timeaxis{Ax<:Axis; !TimeAxis{Ax}}(ax::Ax, axes...) = _timeaxis(axes...)
@traitfn _timeaxis{Ax<:Axis; TimeAxis{Ax}}(ax::Ax, axes...) = ax
_timeaxis() = nothing
Expand Down
40 changes: 39 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Colors, FixedPointNumbers, ImageAxes, Base.Test
using Colors, FixedPointNumbers, ImageAxes, MappedArrays, Base.Test

if VERSION < v"0.6.0-dev"
ambs = detect_ambiguities(ImageAxes,ImageCore,Base,Core)
Expand Down Expand Up @@ -106,6 +106,44 @@ end
@test colordim(p) == 3
end

@testset "nested" begin
A = AxisArray(rand(RGB{N0f8}, 4, 5), (:y, :x), (2, 1))
P = permuteddimsview(A, (2, 1))
@test @inferred(pixelspacing(P)) == (1, 2)
M = mappedarray(identity, A)
@test @inferred(pixelspacing(M)) == (2, 1)
const s = u"s"
const μm = u"μm"
tax = Axis{:time}(range(0.0s, 0.1s, 11))
A = AxisArray(rand(N0f16, 4, 5, 11), (:y, :x, :time), (2μm, 1μm, 0.1s))
P = permuteddimsview(A, (3, 1, 2))
M = mappedarray(identity, A)
@test @inferred(pixelspacing(P)) == @inferred(pixelspacing(M)) == (2μm, 1μm)
@test @inferred(timeaxis(P)) == @inferred(timeaxis(M)) == tax
@test has_time_axis(P)
@test coords_spatial(P) == (2, 3)
@test coords_spatial(M) == (1, 2)
@test spatialorder(P) == spatialorder(M) == (:y, :x)
@test @inferred(size_spatial(P)) == @inferred(size_spatial(M)) == (4, 5)
@test_throws ErrorException assert_timedim_last(P)
assert_timedim_last(M)
A = AxisArray(rand(N0f16, 11, 5, 4), (:time, :x, :y), (0.1s, 1μm, 2μm))
P = permuteddimsview(A, (3, 2, 1))
M = mappedarray(identity, A)
@test @inferred(pixelspacing(P)) == (2μm, 1μm)
@test @inferred(pixelspacing(M)) == (1μm, 2μm)
@test @inferred(timeaxis(P)) == @inferred(timeaxis(M)) == tax
@test has_time_axis(P)
@test coords_spatial(P) == (1, 2)
@test coords_spatial(M) == (2, 3)
@test spatialorder(P) == (:y, :x)
@test spatialorder(M) == (:x, :y)
@test @inferred(size_spatial(P)) == (4, 5)
@test @inferred(size_spatial(M)) == (5, 4)
assert_timedim_last(P)
@test_throws ErrorException assert_timedim_last(M)
end

# Possibly-ambiguous functions
@testset "ambig" begin
A = AxisArray(rand(RGB{N0f8},3,5), :x, :y)
Expand Down

0 comments on commit ff917a1

Please # to comment.