Each cube file content is reshaped and then swapped axes.
It is unclear why this swapping is necessary, given that knossos never does it and
presents a coherent supercube.
Anyway, as the strides of the resulting matrix are incompatible with the large output matrix,
assignment is voxel-wise rather than block-wise, i.e. extremely inefficient.
As proof of concept I simply cancelled the swapaxes (which by itself took nothing
much), then the assignment dropped from something to practically nothing.
If you remove the swap simply, it won't work. But the swap becoms unnecessary if in this line the order of current coordinates is changed from 0,1,2 to 2,1,0. Then the resulting array has axis order z,y,x and the sub-arrays are assembled in a consistent manner.
Each cube file content is reshaped and then swapped axes. It is unclear why this swapping is necessary, given that knossos never does it and presents a coherent supercube. Anyway, as the strides of the resulting matrix are incompatible with the large output matrix, assignment is voxel-wise rather than block-wise, i.e. extremely inefficient.
As proof of concept I simply cancelled the swapaxes (which by itself took nothing much), then the assignment dropped from something to practically nothing.