Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyfeeds-tests
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
FSL
pyfeeds-tests
Commits
40457d8a
Commit
40457d8a
authored
2 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
avscale unit test
parent
171b3e88
No related branches found
No related tags found
1 merge request
!49
avscale unit test
Pipeline
#15682
passed
2 years ago
Stage: fsl-ci-build
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unit_tests/avwutils/avscale/feedsRun
+116
-0
116 additions, 0 deletions
unit_tests/avwutils/avscale/feedsRun
with
116 additions
and
0 deletions
unit_tests/avwutils/avscale/feedsRun
0 → 100755
+
116
−
0
View file @
40457d8a
#!/usr/bin/env fslpython
# test avscale with different input affines
import sys
import os
import fsl.utils.run as run
import numpy as np
PI = np.pi
PION2 = np.pi / 2
# Each test has the form (input-affine, expected-output)
# where expected-output comprises:
# - scales
# - translations
# - rotations
# - skews
# - L/R orientation (preserved or swapped)
tests = [
([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]], [(1, 1, 1), (0, 0, 0), (0, 0, 0), (0, 0, 0), 'preserved']),
([[2, 0, 0, 0],
[0, 2, 0, 0],
[0, 0, 2, 0],
[0, 0, 0, 1]], [(2, 2, 2), (0, 0, 0), (0, 0, 0), (0, 0, 0), 'preserved']),
([[-2, 0, 0, 0],
[ 0, 2, 0, 0],
[ 0, 0, 2, 0],
[ 0, 0, 0, 1]], [(2, 2, 2), (0, 0, 0), (0, 0, PI), (0, 0, 0), 'swapped']),
([[0, 0, 1, 0],
[0, 1, 0, 0],
[1, 0, 0, 0],
[0, 0, 0, 1]], [(1, 1, 1), (0, 0, 0), (0, -PION2, 0), (0, 0, 0), 'swapped']),
([[ 0, 0, -1, 0],
[ 0, -1, 0, 0],
[-1, 0, 0, 0],
[ 0, 0, 0, 1]], [(1, 1, 1), (0, 0, 0), (-PI, PION2, 0), (0, 0, 0), 'preserved']),
([[0, 1, 0, 0],
[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]], [(1, 1, 1), (0, 0, 0), (0, 0, PION2), (0, 0, 0), 'swapped']),
([[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, 1]], [(1, 1, 1), (0, 0, 0), (PION2, 0, 0), (0, 0, 0), 'swapped']),
([[-2, 0, 0, 90],
[ 0, 2, 0, -126],
[ 0, 0, 2, -72],
[ 0, 0, 0, 1]], [(2, 2, 2), (90, -126, -72), (0, 0, PI), (0, 0, 0), 'swapped']),
]
def read_avscale_output(output):
lines = output.split('\n')
# scales
# translations
# rotations
# skews
# l/r orientation (preserved or swapped)
scales = [l for l in lines if l.startswith('Scales ')] [0]
translations = [l for l in lines if l.startswith('Translations ')] [0]
rotations = [l for l in lines if l.startswith('Rotation Angles')][0]
skews = [l for l in lines if l.startswith('Skews ')] [0]
orient = [l for l in lines if l.startswith('Left-Right ')] [0]
scales = [float(s) for s in scales .split()[-3:]]
translations = [float(s) for s in translations.split()[-3:]]
rotations = [float(s) for s in rotations .split()[-3:]]
skews = [float(s) for s in skews .split()[-3:]]
orient = orient.split()[-1]
return {
'scales' : np.array(scales),
'translations' : np.array(translations),
'rotations' : np.array(rotations),
'skews' : np.array(skews),
'orient' : orient.lower(),
}
def test_avscale():
for affine, expected in tests:
affine = np.array(affine)
np.savetxt('affine.mat', affine, '%0.6f')
print(affine)
output = run.runfsl('avscale --allparams affine.mat')
output = read_avscale_output(output)
scales, translations, rotations, skews, orient = expected
try:
assert np.all(np.isclose(scales, output['scales']))
assert np.all(np.isclose(translations, output['translations']))
assert np.all(np.isclose(rotations, output['rotations']))
assert np.all(np.isclose(skews, output['skews']))
assert orient == output['orient']
except AssertionError:
print(affine)
print(output)
raise
if __name__ == '__main__':
if len(sys.argv) > 1:
os.chdir(sys.argv[1])
test_avscale()
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