JuliaArrays / AxisArrays.jl

Performant arrays where each dimension can have a named axis with values
http://JuliaArrays.github.io/AxisArrays.jl/latest/
Other
200 stars 41 forks source link

Add ability to iterate on axis elements #142

Closed tlnagy closed 5 years ago

tlnagy commented 6 years ago

It would be great to have the ability to do the following:

Main> a = AxisArray(randn(10,10,5), :x, :y, :time);

Main> timeaxis(a)
AxisArrays.Axis{:time,Base.OneTo{Int64}}(Base.OneTo(5))

Main> for timepoint in timeaxis(a)
          println(timepoint)
       end
ERROR: MethodError: no method matching start(::AxisArrays.Axis{:time,Base.OneTo{Int64}})
Closest candidates are:
  start(::SimpleVector) at essentials.jl:258
  start(::Base.MethodList) at reflection.jl:560
  start(::ExponentialBackOff) at error.jl:107
  ...
Stacktrace:
 [1] anonymous at ./<missing>:?
 [2] eval(::Module, ::Any) at ./boot.jl:235

That would be the most intuitive method for me to iterate over slices along an axis.

My current solution is way uglier and more fragile

for timepoint in 1:size(exp_img)[axisdim(exp_img, Axis{:time}())]
    println(timepoint)
end
tlnagy commented 6 years ago

Thoughts @Evizero @timholy?

Evizero commented 6 years ago

Sorry but I am not that involved with AxisArrays

tlnagy commented 5 years ago

I think this was resolved by https://github.com/JuliaArrays/AxisArrays.jl/pull/160