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
Merge requests
!49
avscale unit test
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
avscale unit test
test/avscale
into
master
Overview
0
Commits
1
Pipelines
1
Changes
1
Merged
Paul McCarthy
requested to merge
test/avscale
into
master
2 years ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
Includes regression tests for
miscmaths!16 (merged)
Edited
2 years ago
by
Paul McCarthy
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
40457d8a
1 commit,
2 years ago
1 file
+
116
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
unit_tests/avwutils/avscale/feedsRun
0 → 100755
+
116
−
0
Options
#!/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()
Loading