Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tom Nichols
TNutils
Commits
44bac96f
Commit
44bac96f
authored
Feb 24, 2018
by
nicholst
Browse files
Now works (without decorators)
parent
61ebfa09
Changes
1
Hide whitespace changes
Inline
Side-by-side
TNutils/imstats.py
View file @
44bac96f
...
@@ -15,11 +15,12 @@ def immax(Fns):
...
@@ -15,11 +15,12 @@ def immax(Fns):
fn
=
Fns
[
i
]
fn
=
Fns
[
i
]
try
:
try
:
# np.asarray() not required for newer versions of nibabel
# np.asarray() not required for newer versions of nibabel
# vvvvvvvvvv
Max
.
append
(
np
.
nanmax
(
np
.
asarray
((
nib
.
load
(
fn
).
get_data
()))))
Max
.
append
(
np
.
nanmax
(
np
.
asarray
((
nib
.
load
(
fn
).
get_data
()))))
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"ERROR: "
+
str
(
e
))
print
(
"ERROR: "
+
str
(
e
))
exit
()
exit
()
print
(
'Max {}'
.
format
(
Max
))
return
(
Max
)
return
(
Max
)
...
@@ -34,57 +35,52 @@ def immean(Fns):
...
@@ -34,57 +35,52 @@ def immean(Fns):
fn
=
Fns
[
i
]
fn
=
Fns
[
i
]
try
:
try
:
# np.asarray() not required for newer versions of nibabel
# np.asarray() not required for newer versions of nibabel
# vvvvvvvvvv
Mean
.
append
(
np
.
nanmean
(
np
.
asarray
((
nib
.
load
(
fn
).
get_data
()))))
Mean
.
append
(
np
.
nanmean
(
np
.
asarray
((
nib
.
load
(
fn
).
get_data
()))))
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"ERROR: "
+
str
(
e
))
print
(
"ERROR: "
+
str
(
e
))
exit
()
exit
()
print
(
'Mean {}'
.
format
(
Mean
))
return
(
Mean
)
return
(
Mean
)
def
PrintResults
(
Fns
,
Vals
):
def
PrintResults
(
Fns
,
Vals
):
print
(
'
\n
'
.
join
([
'{:40s} : {:8
.4
f}'
.
format
(
nm
,
mx
)
for
(
nm
,
mx
)
in
zip
(
Fns
,
Vals
)]))
print
(
'
\n
'
.
join
([
'{:40s} : {:
0
8f}'
.
format
(
nm
,
mx
)
for
(
nm
,
mx
)
in
zip
(
Fns
,
Vals
)]))
def
main_ShowRes
(
Usage
):
def
ScriptUtil
(
Usage
):
def
Decorator
(
func
):
if
len
(
sys
.
argv
)
==
1
:
print
(
Usage
)
sys
.
exit
(
1
)
else
:
Imgs
=
sys
.
argv
[
1
:]
def
Wrapper
(
*
args
):
return
(
Imgs
)
if
len
(
sys
.
argv
)
==
1
:
print
(
Usage
)
sys
.
exit
(
1
)
else
:
retval
=
func
(
sys
.
argv
[
1
:])
print
(
retval
)
PrintResults
(
sys
.
argv
[
1
:],
retval
)
return
(
retval
)
return
(
Wrapper
)
return
(
Decorator
)
@
main_ShowRes
(
"""
def
main_immax
():
"""Script wrapper for immax."""
Usage
=
"""
Usage: immax.py img1 [img2 ...]
Usage: immax.py img1 [img2 ...]
Print the maximum of one or more images.
Print the maximum of one or more images.
_________________________________________________________________________
_________________________________________________________________________
T. Nichols
T. Nichols
"""
)
"""
def
main_immax
(
Imgs
):
Imgs
=
ScriptUtil
(
Usage
)
"""Script wrapper for immax."""
mx
=
immax
(
Imgs
)
mx
=
immax
(
Imgs
)
PrintResults
(
Imgs
,
mx
)
@
main_ShowRes
(
"""
def
main_immean
():
"""Script wrapper for immean."""
Usage
=
"""
Usage: immean.py img1 [img2 ...]
Usage: immean.py img1 [img2 ...]
Print the mean of one or more images.
Print the mean of one or more images.
_________________________________________________________________________
_________________________________________________________________________
T. Nichols
T. Nichols
"""
)
"""
def
main_immean
(
Imgs
):
Imgs
=
ScriptUtil
(
Usage
)
"""Script wrapper for immean."""
mn
=
immean
(
Imgs
)
mn
=
immean
(
Imgs
)
PrintResults
(
Imgs
,
mn
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment