From d5454bd7f2884978f5e4888d62b3d95f8f2abde4 Mon Sep 17 00:00:00 2001 From: Ben Darwin Date: Fri, 29 May 2015 17:23:46 -0400 Subject: [PATCH 1/4] pmincaverage: improve usage messages via argparse upgrade; fix option parsing for and implement --clobber --- python/pmincaverage | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/python/pmincaverage b/python/pmincaverage index 9ae7b86..4a99684 100755 --- a/python/pmincaverage +++ b/python/pmincaverage @@ -2,8 +2,9 @@ from pyminc.volumes.factory import * from numpy import * -#from scipy.stats import * -from optparse import OptionParser +from argparse import ArgumentParser +import os.path +import sys import multiprocessing as mp def getslice(volhandle, slice, q,nslices): @@ -31,31 +32,30 @@ def getfile(q, filename): if __name__ == "__main__": - usage = "Usage text" - description = "Description text" - - parser = OptionParser(usage=usage, description=description) - parser.add_option("--clobber", dest="clobber", - help="clobber output file", - type="string") + parser = ArgumentParser() + parser.add_argument("--clobber", + action="store_true", + default=False, + help="clobber output file") + parser.add_argument("infile", nargs="+", type=str, help="files to average") + parser.add_argument("outfile", type=str, help="name of file to output") + + args = parser.parse_args() - (options, args) = parser.parse_args() + infiles = args.infile + nfiles = len(infiles) + outfilename = args.outfile - if len(args) < 4: + if len(infiles) < 2: parser.error("Incorrect number of arguments") - outfilename = args[-1] - # clobber check should go here + if not(args.clobber) and os.path.exists(outfilename): + sys.exit("Output file already exists; use --clobber to overwrite.") - volhandles = [] - # open all the file handles - nfiles = len(args)-1 - for i in range( nfiles ): - print("VOLHANDLES: %d" % i) - volhandles.append(volumeFromFile(args[i], dtype='double')) + volhandles = [volumeFromFile(f, dtype='double') for f in infiles] - outfile = volumeLikeFile(args[0], outfilename, volumeType='short') + outfile = volumeLikeFile(infiles[0], outfilename, volumeType='short') # create the slice array nslices = 10 @@ -122,5 +122,3 @@ if __name__ == "__main__": outfile.writeFile() outfile.closeVolume() - - From 5703ad2f7ea2512c175d58d3af36958a01098f54 Mon Sep 17 00:00:00 2001 From: Ben Darwin Date: Tue, 2 Jun 2015 15:51:00 -0400 Subject: [PATCH 2/4] pmincaverage: add '--noclobber' --- python/pmincaverage | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/pmincaverage b/python/pmincaverage index 4a99684..94efd3a 100755 --- a/python/pmincaverage +++ b/python/pmincaverage @@ -33,10 +33,14 @@ def getfile(q, filename): if __name__ == "__main__": parser = ArgumentParser() - parser.add_argument("--clobber", + g = parser.add_mutually_exclusive_group() + g.add_argument("--clobber", dest="clobber", action="store_true", - default=False, help="clobber output file") + g.add_argument("--noclobber", dest="clobber", + action="store_false", + help="don't clobber output file (default)") + g.set_defaults(clobber=False) parser.add_argument("infile", nargs="+", type=str, help="files to average") parser.add_argument("outfile", type=str, help="name of file to output") From 3cf00ef2ca693d46a4a37115f0634ff7a9ac0f33 Mon Sep 17 00:00:00 2001 From: Matthijs van Eede Date: Wed, 10 Jun 2015 15:28:46 -0400 Subject: [PATCH 3/4] updated README and fixed an autotools related issue that was caused by us having a README.md, instead of a README file which is the standard. --- Makefile.am | 4 ++++ README.md | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/Makefile.am b/Makefile.am index 6221803..7b7ce74 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,9 @@ ACLOCAL_AMFLAGS = -I m4 +# we are not conforming to gnu standards: +# we have README.md instead of README +AUTOMAKE_OPTIONS = foreign + SUBDIRS = src perl data m4_files = m4/mni_REQUIRE_LIB.m4 m4/mni_REQUIRE_MNILIBS.m4 \ diff --git a/README.md b/README.md index 7007b69..5fa7a63 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,20 @@ git submodule update --init --recursive To build and install the perl and src code: ------------------------------------------ +

 ./autogen.sh
 ./configure
 make
 make install
+
+ To build and install the python scripts: --------------------------------------- +

 python setup.py install
+
+ Installation Notes: ------------------- From e6e25384f70216e97556a521c39901a08c45cfd6 Mon Sep 17 00:00:00 2001 From: Matthijs van Eede Date: Wed, 10 Jun 2015 15:45:02 -0400 Subject: [PATCH 4/4] Bumped version and updated NEWS --- NEWS | 4 ++++ setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 098e9fa..6cd9377 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +New in Version 0.1.8 +==================== +* clobber option in pmincaverage is activated + New in Version 0.1.7 ==================== * added vtk_meshconvert.py a program that can be used to convert between BIC obj, stl and vtk meshes diff --git a/setup.py b/setup.py index 74c8b38..3ff163d 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ m.Extension.__dict__ = m._Extension.__dict__ setup(name="python-stuffs", - version='0.1.7', + version='0.1.8', scripts=["python/TFCE", "python/smooth_vector", "python/measure_xcorr",