Merge branch 'release-1.2' into develop
First check-in to update twolevel_model_building code: updates to directory structure.

Created a new function setupFirstLevelDirectories so we now have the following directory structure:

outputDir/pipeline_name_firstlevel/
outputDir/pipeline_name_secondlevel/

In firstlevel directory is a _lsq6/_lsq12/_nlin/_processed for each subject. (With subfolders for every scan)
In secondlevel directory is a single _lsq6/_lsq12/_nlin/_processed directory for second level reg.

This function might get cleaned up/merged with setupSubjectHash (which was modified to handle both this and reg_chain cases).

Overall, I think this makes the directory structure more intuitive than previously.
Changed setupFirstLevelDirectories to setupTwoLevelDirectories.

Function now returns a tuple with both the first and second level directories. Eliminates a bit of code in the main twolevel code.
A number of fixes, initially conceived to make the two level code less cluttered. These fixes touch a number of other modules as well.

1. Creation of initializeAndRunNLIN class (which expands upon and replaces initNLINModule function.) Based on parameters this function also calls mincAverage, if necessary. This elminiated a lot of repeated code in both the NLIN module and twolevel_model_building code.
2. Moved --input-space command line option to general registration options, as it will be used in both the registration_chain and twolevel code, and potentially MBM as well. (Future check-in.)

Note that 1. above hits MBM.py, registration_chain.py, twolevel_model_building.py, NLIN.py and minc_modules.py.

Kind of vaguely touches upon Issue #99, but does not fully resolve it, because the crap code I don't like is still there.
First check-in of several, I'm sure. Main goal of this commit: add LSQ12 to second level of two level registration code.

This involved replacing initializeAndRunNLIN in the second level loop of twolevel_model_building.py with FullIterativeLSQ12Nlin. All fine and good, but this resulted in an error (since pyminc cannnot find the resolution of a file that does not yet exist) so I had to change a fair amount of underlying code. There is a discussion of this in Issue #76. Per discussion today with Jason, we should only try to get the file resolution using pyminc if we need it, which is often not the case.

1. Created returnFinestResolution function. This removes a lot of duplicate code, and returns a more sensible error when getting the file resolution fails. All error handling happens in this function.
2. In several functions, returnFinestResolution is only called if a registration protocol does not exist, since file resolution is usually used to set default protocols. In cases like LSQ6, it is always called, since right now, it is needed throughout the class.
3. Error handling in minc_parameters classes so a message is given if we try to set default protocols and file resolution does not exist.
4. minc_parameters now only set defaults if a protocol is NOT specified, so protocols now must specify all parameters instead of a subset.
5. small changes to FullIterativeLSQ12Nlin: changed order of arguments since initModel is optional and set lsq12_likeFile more sensibly.

Next step, which will set the stage for resolving Issue #94 and #76:
1. Ability to pass protocols from one module to another. E.g. We get a protocol from the command line and if a second protocol is not specified, we can pass the params (already parsed) to another module.
2. Add LSQ6 and LSQ12 into the first level of the two level code.
For every module where parameters are set using one of the minc_parameters classes, the result is now included as an attribute.

This is intended to make it easier to pass parameters classes between modules.

Next step: Allowing modules to correctly handle parameters files, whether they are of the parameters class or a csv.

This is related to the previous check-in: 6d1bc4fa7983ad55f2 and issues #76 and #94.
Parameters can now be passed as either csv files (for parsing) or as parameter class objects with the appropriate parameters already set.

This is the next step identified in commit: 8115d5f4656e84...Done!
Fixed directory structure for twolevel code. Now, second_level_processed contains a sub-directory for each level one non-linear average, and all subsequent output files are placed here.

This necessitated an additional fix: adding a new parameter, avgPrefix, to all classes that call iterative non-linear registrations. This means that the default naming is no longer nlin-1.mnc, nlin-2.mnc, etc for non-linear averages, but prefix-nlin-1.mnc, prefix-nlin-2.mnc, etc. None may also be passed. For many registrations, the prefix is the pipeline name. For the first level of two level model building, it is subj-name-nlin-1.mnc, etc.

Also fixed an error with resampling first level determinants into common space. Was previously asking for the wrong (and non-existent!) transform.
For first level of two level code, added the ability to start in native space (LSQ6/12/NLIN), lsq6 space (LSQ12/NLIN) or lsq12 space (NLIN only)

Note that in the second level of the code, we always do LSQ12/NLIN (assume LSQ6 starting space), but this will change in the future, after I handle options customization.

Change to FullIterativeLSQ12NLIN: Added avgPrefix, so you can override the default of pipelineName

Misc small changes (renamed resetFirstlevelNlins, addPrefix="second_level" for second level registration, fixed initialTarget for second level stats, initModel now specified for LSQ12/NLIn call in first level, so initModel mask will be used if input space is native.)
Updated how parameters are set in __init__. Now a separate setupProtocol() method is called in the __init__, which is overwritten in the LSQ12 child class. This fixes an error where protocols were not being set correctly when an lsq12-subject-matter is specified. This will likely get further updated/modified as we move forward to address issue #94.

Fixed small bug with avgPrefix being set to the wrong value when NLIN module is initialized in MBM.
Fixed error in when to get resolution for LSQ12ANTSNlin and HierarchicalMinctracc.

Changed default avgPrefix to common space name for iterative model building in registration chain.
Merge branch 'twolevel-updates' into develop
Moved LSQ6, LSQ12 and NLIN protocol options to their corresponding option groups within the appropriate modules (e.g. LSQ6, LSQ12, NLIN). This resulted in minor changes to all four applications.

This will make it easier to implement the code necessary to address Issue #90.

As a result, I have deleted the paramsOptions class and all of its subclasses.

Updated help for --lsq12-max-pairs option, to indicate that it is not yet implemented. (Captured in Issue #93)
Moved registration method option to NLIN module options. Changed default from minctracc to mincANTS.
Merge branch 'opts-params-refactor' into develop
* Overall code clean up: wrapped pipelineExecutor and clientExecutor in one
* bug fix: the server only launched executors if they were able to shut themselves down. However, the server should always launch the initial executors, regardless of whether they can die
* added keyboardinterrupt handler. Now when ctrl+c is provided to the server, this will be propagated to the executors.
* the client now explicitly unregisters with the server when shutting down or when it's killed.
* removed all semaphores and locks from the code; does not seem to be necessary
* in runStage in the pipeline_executor, replaced subprocess.call with subprocess.Popen. This was done in order to properly shutdown executors. The processes in the Pool (multiprocessing) turned out to be difficult to kill on a keyboard interrupt. To get around this, now all process IDs (pid) are stored in the executors. When a shut down call is made to the executor (through a caught keyboard interrupt), all processes currently running are killed through their pid.
* the server now keeps track of running stages. That way, the server can shut itself down when no stages are running, no stages are runnable and not all stages have finished. (this fixes #101)
* command line output of failed stages (this fixes #103)
Merge branch 'feedback-to-user-from-server' into develop
Merge branch 'develop' of github.com:mfriedel/pydpiper into develop
Bumped version to 1.3