Commit 44bac96f authored by nicholst's avatar nicholst
Browse files

Now works (without decorators)

parent 61ebfa09
......@@ -15,11 +15,12 @@ def immax(Fns):
fn = Fns[i]
try:
# np.asarray() not required for newer versions of nibabel
# vvvvvvvvvv
Max.append(np.nanmax(np.asarray((nib.load(fn).get_data()))))
except Exception as e:
print("ERROR: "+str(e))
exit()
print('Max {}'.format(Max))
return(Max)
......@@ -34,57 +35,52 @@ def immean(Fns):
fn = Fns[i]
try:
# np.asarray() not required for newer versions of nibabel
# vvvvvvvvvv
Mean.append(np.nanmean(np.asarray((nib.load(fn).get_data()))))
except Exception as e:
print("ERROR: "+str(e))
exit()
print('Mean {}'.format(Mean))
return(Mean)
def PrintResults(Fns,Vals):
print('\n'.join(['{:40s} : {:8.4f}'.format(nm,mx) for (nm,mx) in zip(Fns,Vals)]))
print('\n'.join(['{:40s} : {:08f}'.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):
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)
return(Imgs)
@main_ShowRes("""
def main_immax():
"""Script wrapper for immax."""
Usage="""
Usage: immax.py img1 [img2 ...]
Print the maximum of one or more images.
_________________________________________________________________________
T. Nichols
""")
def main_immax(Imgs):
"""Script wrapper for immax."""
"""
Imgs=ScriptUtil(Usage)
mx=immax(Imgs)
PrintResults(Imgs,mx)
@main_ShowRes("""
def main_immean():
"""Script wrapper for immean."""
Usage="""
Usage: immean.py img1 [img2 ...]
Print the mean of one or more images.
_________________________________________________________________________
T. Nichols
""")
def main_immean(Imgs):
"""Script wrapper for immean."""
"""
Imgs=ScriptUtil(Usage)
mn=immean(Imgs)
PrintResults(Imgs,mn)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment