For !852 (merged), I needed to understand the axis order from calls to np.transpose
, with arguments like (2, 0, 1, 3)
. It might just be me, but understanding what this meant in terms of which axis is which required:
np.transpose()
to see how it worked
(2, ...)
mean input axis 0 moves to position 2, or input axis 2 moves to position 0? (It's the latter)reorder_axes
provides a far more verbose way to do this, but which makes the input and output order explicit, so it's easier to understand and check what's going on.
saved_axes = ('slow_scan', 'fast_scan', 'memory_cells', 'gain')
target_axes = ('memory_cells', 'slow_scan', 'fast_scan', 'gain')
const = reorder_axes(const, saved_axes, target_axes)
This will also simplify using a saved axis order from the file, when we get to that.
This is a tiny subset of what Xarray can do, but I think it's worth having this without bringing in all the complexity of wrapping arrays in Xarray objects. We may end up copying this function to use in other places, but that's OK.
Test added to the codebase.