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

Now works (without decorators)

parent 61ebfa09
...@@ -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.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): 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)
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