Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Commits
5040e702
Commit
5040e702
authored
1 year ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Add reorder_axes function
parent
4c950e6c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!853
Add reorder_axes function
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cal_tools/tools.py
+8
-0
8 additions, 0 deletions
src/cal_tools/tools.py
tests/test_cal_tools.py
+11
-0
11 additions, 0 deletions
tests/test_cal_tools.py
with
19 additions
and
0 deletions
src/cal_tools/tools.py
+
8
−
0
View file @
5040e702
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
tests/test_cal_tools.py
+
11
−
0
View file @
5040e702
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment