Switch NDArrayImage
dimension order to (band, y, x)
#32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #29 by making
NDArrayImage
use shape(band, y, x)
, which is consistent with multi-band images loaded byrasterio
orrioxarray
. Dataset loading and tests were updated to work with the new dimension order.It's worth noting that internally,
_ImageChunk
still handles images in(y, x, band)
order becausexr.apply_ufunc
always moves the core dimension (band) to the last axis. This means thatNDArrayImage
also has to transpose arrays before they go into the ufunc, and both image types need to transpose the ufunc outputs back to(band, y, x)
.To reduce some duplication introduced by that change, I refactored
apply_ufunc_across_bands
from theImage
subclasses into the base class, with the type-specific functionality now handled by preprocessing and postprocessing functions. This means that both image types are now handled identically byxr.apply_ufunc
, which further simplifies things. It does feel a little weird callingxr.apply_ufunc
with Numpy arrays, but it's a documented feature and I'm sure the overhead of passing it through is negligible.