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
5086ffd7
Commit
5086ffd7
authored
1 year ago
by
Thomas Kluyver
Browse files
Options
Downloads
Plain Diff
Merge branch 'feat/reorder-axes' into 'master'
Add reorder_axes function See merge request
!853
parents
4c950e6c
74d9cb86
No related branches found
No related tags found
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
+14
-0
14 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
25 additions
and
0 deletions
src/cal_tools/tools.py
+
14
−
0
View file @
5086ffd7
...
...
@@ -1030,3 +1030,17 @@ def write_compressed_frames(
dataset
.
id
.
write_direct_chunk
(
chunk_start
,
compressed
)
return
dataset
def
reorder_axes
(
a
,
from_order
,
to_order
):
"""
Rearrange axes of array a from from_order to to_order
This does the same as np.transpose(), but making the before & after axes
more explicit. from_order is a sequence of strings labelling the axes of a,
and to_order is a similar sequence for the axes of the result.
"""
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 @
5086ffd7
...
...
@@ -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