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

Convenience function for setting axis units #72

Open Cody-G opened 7 years ago

Cody-G commented 7 years ago

Is there any interest in having a convenience function for setting units for an existing Axis or AxisArray that is currently unitless? I found this useful when loading someone else's NRRD image using NRRD.jl. With this format it seems common to save images with meaningful spacings but without units, and units are basically communicated by word of mouth since the format doesn't standardize them anyway. I've been manually re-creating the axes after I load the images and am looking for something more convenient. Am I missing something in the API? What if we overload arithmetic like this?

using AxisArrays, Unitful
ax = Axis{:x}(linspace(0,10,11))
ax *= Unitful.μm
mdavezac commented 7 years ago

Isn't Axis{:x}(linspace(0u"m",10u"m",11)) what you are looking for?

timholy commented 7 years ago

Looking at this again, one can't do this in-place because the Axis object's type includes the type of the range. So you'd have to create a new "wrapper." I think it could be something like

A = AxisArray(A.data, map(*, axes(A), (u"m", u"s"))

except that we don't currently define ::Axis * ::Units. If that seems reasonable to you, perhaps a pull request?