Skip to content

Add ability to iterate on axis elements #142

@tlnagy

Description

@tlnagy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions