From cde8ac9895a8aa2e7a29f344800469e8cbe7a225 Mon Sep 17 00:00:00 2001 From: Keith Jamison Date: Mon, 15 Mar 2021 16:38:54 -0400 Subject: [PATCH 1/2] Add CLI for transforming files (and tweak mapdata to bypass nsdpath and accept transform file) --- nsdcode/nsd_mapdata.py | 3 +++ nsdmapcli.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 nsdmapcli.py diff --git a/nsdcode/nsd_mapdata.py b/nsdcode/nsd_mapdata.py index 10df283..f7b4247 100644 --- a/nsdcode/nsd_mapdata.py +++ b/nsdcode/nsd_mapdata.py @@ -29,6 +29,7 @@ def fit(self, outputfile=None, outputclass=None, fsdir=None, + transformfile=None, ): """nsa_mapdata is used to map functional data between coordinate systems @@ -211,6 +212,8 @@ def fit(self, res = None # load transform + if transformfile is not None: + tfile=transformfile a1_data = load_transform(casenum, tfile) # load sourcedata diff --git a/nsdmapcli.py b/nsdmapcli.py new file mode 100644 index 0000000..f0c578f --- /dev/null +++ b/nsdmapcli.py @@ -0,0 +1,43 @@ +import os +import sys +import argparse +from nsdcode.nsd_mapdata import NSDmapdata +from nsdcode.nsd_datalocation import nsd_datalocation + +def argument_parse(): + parser=argparse.ArgumentParser(description='Transform NSD data from the command line') + + parser.add_argument('--nsdlocation',action='store',dest='basedir',default=None) + parser.add_argument('--subjix',action='store',dest='subjix',type=int) + parser.add_argument('--sourcespace',action='store',dest='sourcespace') + parser.add_argument('--targetspace',action='store',dest='targetspace') + parser.add_argument('--sourcedata',action='store',dest='sourcedata') + parser.add_argument('--interptype',action='store',dest='interptype',default=None) + parser.add_argument('--badval',action='store',dest='badval',default=None) + parser.add_argument('--outputfile',action='store',dest='outputfile') + parser.add_argument('--outputclass',action='store',dest='outputclass',default=None) + parser.add_argument('--fsdir',action='store',dest='fsdir',default=None) + parser.add_argument('--transformfile',action='store',dest='transformfile',default=None) + + return parser.parse_args() + +if __name__ == "__main__": + args=argument_parse() + #if transform file was provided, we can ignore the basedir and subjix and just set defaults + if args.transformfile is not None: + if args.basedir is None: + args.basedir=nsd_datalocation(".") + if args.subjix is None: + args.subjix=1 + NSD=NSDmapdata(args.basedir) + NSD.fit(args.subjix, + args.sourcespace, + args.targetspace, + args.sourcedata, + args.interptype, + args.badval, + args.outputfile, + args.outputclass, + args.fsdir, + args.transformfile, + ) \ No newline at end of file From 05ae43f4b48dc096b4993837bd69375c410a464b Mon Sep 17 00:00:00 2001 From: Keith Jamison Date: Tue, 16 Mar 2021 10:24:53 -0400 Subject: [PATCH 2/2] Update to CLI for pip entry-point compatibility --- nsdcode/nsdmapcli.py | 55 ++++++++++++++++++++++++++++++++++++++++++++ nsdmapcli.py | 43 ---------------------------------- setup.py | 7 +++++- 3 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 nsdcode/nsdmapcli.py delete mode 100644 nsdmapcli.py diff --git a/nsdcode/nsdmapcli.py b/nsdcode/nsdmapcli.py new file mode 100644 index 0000000..9e1b138 --- /dev/null +++ b/nsdcode/nsdmapcli.py @@ -0,0 +1,55 @@ +import os +import sys +import argparse +import textwrap +from nsdcode.nsd_mapdata import NSDmapdata +from nsdcode.nsd_datalocation import nsd_datalocation + +def argument_parse(): + parser=argparse.ArgumentParser(description='Transform NSD data from the command line', + epilog=textwrap.dedent('''\ + --sourcespace and --targetspace options include: + anat0pt5, anat0pt8, anat1pt0, func1pt0, func1pt8, MNI, + [lh,rh].white, [lh,rh].pial, [lh,rh].layerB1, [lh,rh].layerB2, [lh,rh].layerB3, fsaverage''')) + + parser.add_argument('--sourcespace',action='store',dest='sourcespace',help="One of the volume/surface space options below",required=True) + parser.add_argument('--targetspace',action='store',dest='targetspace',help="One of the volume/surface space options below",required=True) + parser.add_argument('--inputfile',action='store',dest='inputfile',help="Input file in ",required=True) + parser.add_argument('--outputfile',action='store',dest='outputfile',help="Output file in ",required=True) + parser.add_argument('--nsdlocation',action='store',dest='basedir',default=None,help='Directory containing ppdata/, etc') + parser.add_argument('--subjix',action='store',dest='subjix',type=int,help="NSD subject index 1-8") + parser.add_argument('--interptype',action='store',dest='interptype',default='cubic', + choices=['nearest','linear','cubic','wta','surfacewta'], + help="default: 'cubic'. See nsd_mapdata.py for wta details") + parser.add_argument('--badval',action='store',dest='badval',default=None) + parser.add_argument('--outputclass',action='store',dest='outputclass',default=None) + parser.add_argument('--fsdir',action='store',dest='fsdir',default=None) + parser.add_argument('--transformfile',action='store',dest='transformfile',default=None, + help="Manually-specified transformation file (ignores --nsdlocation and --subjix)") + + return parser.parse_args() + +def main(): + args=argument_parse() + #if transform file was provided, we can ignore the basedir and subjix and just set defaults + if args.transformfile is not None: + if args.basedir is None: + args.basedir=nsd_datalocation(".") + if args.subjix is None: + args.subjix=1 + NSD=NSDmapdata(args.basedir) + NSD.fit(subjix=args.subjix, + sourcespace=args.sourcespace, + targetspace=args.targetspace, + sourcedata=args.inputfile, + interptype=args.interptype, + badval=args.badval, + outputfile=args.outputfile, + outputclass=args.outputclass, + fsdir=args.fsdir, + transformfile=args.transformfile, + ) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/nsdmapcli.py b/nsdmapcli.py deleted file mode 100644 index f0c578f..0000000 --- a/nsdmapcli.py +++ /dev/null @@ -1,43 +0,0 @@ -import os -import sys -import argparse -from nsdcode.nsd_mapdata import NSDmapdata -from nsdcode.nsd_datalocation import nsd_datalocation - -def argument_parse(): - parser=argparse.ArgumentParser(description='Transform NSD data from the command line') - - parser.add_argument('--nsdlocation',action='store',dest='basedir',default=None) - parser.add_argument('--subjix',action='store',dest='subjix',type=int) - parser.add_argument('--sourcespace',action='store',dest='sourcespace') - parser.add_argument('--targetspace',action='store',dest='targetspace') - parser.add_argument('--sourcedata',action='store',dest='sourcedata') - parser.add_argument('--interptype',action='store',dest='interptype',default=None) - parser.add_argument('--badval',action='store',dest='badval',default=None) - parser.add_argument('--outputfile',action='store',dest='outputfile') - parser.add_argument('--outputclass',action='store',dest='outputclass',default=None) - parser.add_argument('--fsdir',action='store',dest='fsdir',default=None) - parser.add_argument('--transformfile',action='store',dest='transformfile',default=None) - - return parser.parse_args() - -if __name__ == "__main__": - args=argument_parse() - #if transform file was provided, we can ignore the basedir and subjix and just set defaults - if args.transformfile is not None: - if args.basedir is None: - args.basedir=nsd_datalocation(".") - if args.subjix is None: - args.subjix=1 - NSD=NSDmapdata(args.basedir) - NSD.fit(args.subjix, - args.sourcespace, - args.targetspace, - args.sourcedata, - args.interptype, - args.badval, - args.outputfile, - args.outputclass, - args.fsdir, - args.transformfile, - ) \ No newline at end of file diff --git a/setup.py b/setup.py index d519046..2e693e0 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,12 @@ def local_version(version): opts = dict( use_scm_version={"root": ".", "relative_to": __file__, "write_to": op.join("nsdcode", "version.py"), - "local_scheme": local_version} + "local_scheme": local_version}, + entry_points={ + 'console_scripts': [ + 'nsdmapdata = nsdcode.nsdmapcli:main', + ], + }, )