Skip to content
Snippets Groups Projects
Commit 5040e702 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Add reorder_axes function

parent 4c950e6c
No related branches found
No related tags found
1 merge request!853Add reorder_axes function
......@@ -1030,3 +1030,11 @@ def write_compressed_frames(
dataset.id.write_direct_chunk(chunk_start, compressed)
return dataset
def reorder_axes(a, from_order, to_order):
assert len(from_order) == a.ndim
assert sorted(from_order) == sorted(to_order)
from_order = list(from_order)
order = tuple([from_order.index(lbl) for lbl in to_order])
return a.transpose(order)
......@@ -22,6 +22,7 @@ from cal_tools.tools import (
recursive_update,
send_to_db,
write_constants_fragment,
reorder_axes,
)
# AGIPD operating conditions.
......@@ -614,3 +615,13 @@ def test_write_constants_fragment(tmp_path: Path):
},
}
}
def test_reorder_axes():
a = np.zeros((10, 32, 256, 3))
from_order = ('cells', 'slow_scan', 'fast_scan', 'gain')
to_order = ('slow_scan', 'fast_scan', 'cells', 'gain')
assert reorder_axes(a, from_order, to_order).shape == (32, 256, 10, 3)
to_order = ('gain', 'fast_scan', 'slow_scan', 'cells')
assert reorder_axes(a, from_order, to_order).shape == (3, 256, 32, 10)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment