AxisArrays.jl icon indicating copy to clipboard operation
AxisArrays.jl copied to clipboard

Convenience function for setting axis units

Open Cody-G opened this issue 8 years ago • 2 comments

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

Cody-G avatar Mar 22 '17 17:03 Cody-G

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

mdavezac avatar Aug 08 '17 08:08 mdavezac

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?

timholy avatar Aug 08 '17 09:08 timholy