Merge branch 'mbm-redesign'
Merge branch 'mbm-redesign'
Merge branch 'mbm-redesign'
Updated MAGeT.py and HierarchicalMinctracc so that if masking is done, all files related to masking will go in a separate subdirectory.

This is to deal with the sometimes unwieldy amount of output generated when masking is done prior to MAGeT.

It is possible this will be modified or changed somewhat in the future, but for now it at least addresses the problem.
Changes to address Issue #27, #30 and #36.

Major changes:
* Additional logic and try/except/finally logic in launchServer function to handle case when clients are not properly de-registered.
* Added a mutex in the clientExecutor() class so that while executor.continueLoop() and serverShutdownCall no longer have race condition.
* Raised errors in runStage and multiple places in launchExecutor so threads and pool.apply_async will join() properly in calling threads.
* Generally cleaned up exception handling in pipelineExecutor.launchExecutor() function.
* Added try/except/finally logic to pipelineDaemon in cases when it launches its own executors.

Minor changes:
* executors are no longer launched if pipeline.runnable.qsize() = 0.
* Updated some comments and logging messages for clarity.
* renamed launchPipeline() to launchExecutor() in pipelineExecutor class (also for clarity)
Added mincANTS with MI as option for MAGeT

Changes also include some re-organizing of code into functions. (Pulled out from main MAGeT logic)
Moved file resampling/labeling out of HierarchicalMinctracc and into its own function.
Re-write of mincresample classes:
* updated mincresample and mincresample labels to fit more easily into MBM redesign
* added mincresampleMask to simplify
* added required targetFile (separate from likeFile) to all of these classes
* classes now use **kwargs

Other smaller changes:
* setResolution class now uses a range (not related to above)
* registerVolume now includes minctracc or mincANTS when xfms are named
* created MAGeT_modules.py for methods used by MAGeT to simplify reading of code
* moved LabelAndFileResampling from minc_modules.py since it is very specific to MAGeT label propagation.
Further updates to how masks are handled, motivated by how we'll use them in MBM redesign.

NOTE: THIS CODE IS NOT FULLY TESTED AND MAY BE BUGGY.

Changes to File Handlers:
* Added mask as part of __init__ in RegistrationFHBase and RegistrationPipeFH. Optional argument
* self.lastbasevol removed from class. We have inputFileName to keep track of file we start with. Others handled in RegistrationGroupedFiles
* cleaned up get/set functions for lastbasevol accordingly
* Added self.mask to class in addition to having it in RegistrationGroupedFiles. This means it is possible to have self.mask = None, but have a mask created and added to the current group.

Updated setupInitModel and atlas initialization in MAGeT.py as a result of this restructuring.
Smaller check-in/set of changes prior to larger RegistrationChain check-in:
1. Fixed typo in MAGeT_modules so that mincANTS call uses default of Syn[0.1] for MI registration
2. Several smaller bug fixes in minc_atoms.py:
   a. Added rotations, scales, shears to minctracc call. Not sure why they were missing before.
   b. Updated mincresample so default directory no longer must be specified.
   c. Fixed errors with **kwargs implementation.
   d. Fized small error in blur class.
3. Fixed bug in argument specification in initializeInputFiles in registration_functions.py
First major check-in of RegistrationChain code for longitudinal registrations

*** THIS CODE IS STILL BUGGY. FIXES TO COME. ***

Major changes:
1. Addition of RegistrationChain class and associated functions.
2. Addition of stats_tools.py, necessary for RegistrationChain, but later will be used in MBM 2.0
3. Beginning stages (NOT COMPLETE) of additional HierarchicalMinctracc classes, including RotationalMinctracc.

Minor Changes:
1. Small update to how file handlers deal with masks, change in indexing (registration_file_handling.py)
2. Modified mincresample so a tranform can be specified with file handlers, in instances where you might not want lastXfm
3. Fixed setup.py to accommodate new classes.
Bug fixing in registration_chain.py. (Likely the first check-in of many.)

1. In getLsq6AndXfms, fixed syntax error for walking through directories and getting files.
2. Changed option name from --native-or-lsq6 to --lsq6-space and made it a boolean.
3. Fixed code so that ChainAlignLSQ6 is only called if --lsq6-space is True.
4. Fixed error where results of HierarchicalMinctracc were not added to main pipeline. Whoops!
A few minor changes related to masking and resampling.

*Changed default in mincresampleMask so that mask is NOT automatically set for FH in outputLocation.
*The above change fixes an error in MAGeT, which was using improperly set source masks, and requires that masks be set explicitly for a given file handler.
*Added a comment in LabelAndFileResampling in MAGeT_modules to make it clear why input and template orders are switched from prior function calls.
*Fixed small typo.
Various small changes and bug fixes:
1. pipeline.py: Updated how number of skipped_stages is calculated. Previously, addPipeline() did not consider skipped stages from previous pipelines when considering total. Current version may have some redundancy in count, but number will be closer. May want to create github issue for this.
2. minc_atoms.py: Fixed errors in previous get/setLastXfm that used file names instead of file handlers. These should always use file handlers for indexing
                  Error fixed in mincresample that caused issues when not using file handling classes.
3. registration_chain.py: Various syntax errors fixed.
4. stats_tools.py: -mask is currently optional in lin_from_nlin, though testing required since -mask may need to be required for stats to make sense.
5. registration_file_handling.py: newGroup index now set to current + 1. May need to update this, but previous definition didn't work properly/skipped index = 1.
                                  getLastXfm now takes optional groupIndex, in case you want to retrieve transforms from a previous group.
Fixed default w_translations, w_scales, w_shear in minctracc atom to match MBM defaults.
Removed comment from stats_tools.py regarding masks for lin_from_nlin: they will remain optional. (So says JPL and I agree.)
Fixed bug in MAGeT algorithm introduced in commit 7e7c1e6cbf by making sure get/setLastXfm uses FH only, not file names.
If both masking and label propagation chosen, lastXfm needs to be cleared (via addition of newGroup) after images are masked, otherwise, improper lastXfms used.
Updated mincANTS atom defaults to use new CC protocol that is doing a better job of eliminating cortex bumps/cerebellum issues.
Updated MAGeTRegister to use this new default.
Various misc changes that still need additional testing. (This commit might be reverted pending additional testing and development in another branch.)
1. Updated registerVolume naming scheme so file names are a bit less unwieldy. Related: updated groupName/Index ordering in registrationFH classes.
2. Added RotationalMinctracc ot minc_modules. (Needs additional testing.)
3. Updated how directories are set in various places in the registration_chain.py code and stats_tools.py code.
4. Commented out one section of code in registration_chain.py
Merge branch 'master'; commit 'b4fa2eaf43' into mbm-redesign
Revert "Various misc changes that still need additional testing. (This commit might be reverted pending additional testing and development in another branch.)"

This reverts commit d097b0a8d243845b636521bbbdac8aa978735176.

Reverting in MBM-redesign branch only because I did not merge properly.
Added masking option to code. Specify a directory for masks that must contain either a single mask for all scans, or a mask for each scan, with the appropriate naming convention. (To be described in documentation.)
Incorporated lsq6-space flag into retrieval of xfms--so if you are in lsq6 space, the appropriate xfms are now retrieved.