Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ImageAxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export # types
timeaxis,
timedim

ImageCore.HasDimNames(::Type{A}) where {A<:AxisArray} = HasDimNames{true}()
ImageCore.namedaxes(a::AxisArray) = NamedTuple{axisnames(a)}(axisvalues(a))
Base.names(a::AxisArray) = axisnames(a)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of iffy but it is necessary to really fulfill the intended meaning of HasDimNames.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remind me why the name of this function needs to be names? (Link to other package, for example?) The reason I ask:

julia> t = (x = 1, y = 2)
(x = 1, y = 2)

julia> typeof(t)
NamedTuple{(:x, :y),Tuple{Int64,Int64}}

julia> names(t)
ERROR: MethodError: no method matching names(::NamedTuple{(:x, :y),Tuple{Int64,Int64}})
Closest candidates are:
  names(::Module; all, imported) at reflection.jl:98
Stacktrace:
 [1] top-level scope at REPL[3]:1

struct, for example, uses fieldnames rather than just names. axisnames seems like a really good name for this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's what NamedDims uses to access the axis names https://github.com/invenia/NamedDims.jl/blob/master/src/wrapper_array.jl#L77.

But hadn't even considered using a different name. axisnames would certainly be more descriptive.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see what happens in invenia/NamedDims.jl#22


"""
TimeAxis{Ax}

Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ end
@test @inferred(size_spatial(M)) == (5, 4)
assert_timedim_last(P)
@test_throws ErrorException assert_timedim_last(M)
@test @inferred(HasDimNames(A)) == HasDimNames{true}()
@test @inferred(namedaxes(A)) == NamedTuple{axisnames(A)}(axisvalues(A))
end

# Possibly-ambiguous functions
Expand Down