[RESOLVED] Error running hcp_fMRIVolume with Siemens field maps

Description
I am trying to run subjects (from the NAPLS3 dataset) through fMRIVolume, but it seems to be looking for parameters that are used for TOPUP distortion correction even though I specified other options for _hcp_bold_dcmethod.

Some options I have tried:
_hcp_bold_dcmethod : NONE and _hcp_processing_mode : LegacyStyleData (for NAPLS subjects with GE field maps)

_hcp_bold_dcmethod : GeneralElectricFieldMap and _hcp_processing_mode : HCPStyleData (for NAPLS subjects with GE field maps)

_hcp_bold_dcmethod : SiemensFieldMap and _hcp_processing_mode : HCPStyleData (for NAPLS subjects with Siemens field maps)

This error occurs when I run hcp_fMRIVolume both on Grace and in the container qunex_0_49_10.sif and 0.51.2.

Call:

qunexContainer hcp_fMRIVolume \
     --sessions="/gpfs/project/fas/n3/Studies/NAPLS3/processing/batchfiles/batch.4.Hillside.GE_Test2.txt" \
     --subjectsfolder="/gpfs/project/fas/n3/Studies/NAPLS3/subjects" \
     --parsessions="10" \
     --overwrite="no" \
     --container="/gpfs/project/fas/n3/software/Singularity/qunex_0_49_10.sif"

Logs:
Example log:
/gpfs/project/fas/n3/Studies/NAPLS3/processing/logs/runlogs/Log-hcp_fMRIVolume-2020-05-12_16.26.1589315176.log

Excerpt below:

============================= LOG ================================



=================================================================
gmri hcp_fMRIVolume \
  --parsessions="10" \
  --subjectsfolder="/gpfs/project/fas/n3/Studies/NAPLS3/subjects" \
  --overwrite="no" \
  --sessions="/gpfs/project/fas/n3/Studies/NAPLS3/processing/batchfiles/batch.4.Hillside.GE_Test2.txt" \
=================================================================

Starting multiprocessing sessions in /gpfs/project/fas/n3/Studies/NAPLS3/processing/batchfiles/batch.4.Hillside.GE_Test2.txt with a pool of 1 concurrent processes


---------------------------------------------------------
Session id: 04-S0300_BL 
[started on Tuesday, 12. May 2020 16:26:16]
Running HCP fMRI Volume registration [LegacyStyleData] ... 
---> PreFS results present.
---> FS results present.
---> PostFS results present.

---> Preprocessing settings (unwarpdir, refimage, moveref, seimage) for BOLD 1
ERROR: Unknown error occured: 
...................................
Traceback (most recent call last):
  File "/opt/qunex/niutilities/niutilities/gp_HCP.py", line 2965, in hcpfMRIVolume
    unwarpdir = unwarpdirs.get('default')
UnboundLocalError: local variable 'unwarpdirs' referenced before assignment
...................................


HCP fMRIVolume completed on Tuesday, 12. May 2020 16:26:16
---------------------------------------------------------


===> Final report for command hcp_fMRIVolume
... 04-S0300_BL ---> HCP fMRI Volume failed
===> Not all tasks completed fully!

Suspected cause:
I suspect the issue occurs in gp_HCP.py. The block starting line 2923, which defines unwarpdirs, is part of the if options['hcp_bold_dcmethod'].lower() == 'topup': statement:

                # --- Process unwarp direction

                unwarpdirs = [[f.strip() for f in e.strip().split("=")] for e in options['hcp_bold_unwarpdir'].split("|")]
                unwarpdirs = [['default', e[0]] if len(e) == 1 else e for e in unwarpdirs]
                unwarpdirs = dict(unwarpdirs)

However, the next section (starting line 2929), has one fewer indent and therefore lies outside the if statement. Hence it is called even if hcp_bold_dcmethod is NOT topup. This leads to an error because this section references unwarpdirs, which (if hcp_bold_dcmethod is not topup) has at this point not been defined.

        # --- Get sorted bold numbers

        bolds, bskip, report['boldskipped'], r = useOrSkipBOLD(sinfo, options, r)
        if report['boldskipped']:
            if options['hcp_filename'] == 'original':
                report['skipped'] = [bi.get('filename', str(bn)) for bn, bnm, bt, bi in bskip]
            else:
                report['skipped'] = [str(bn) for bn, bnm, bt, bi in bskip]
#...etc.

            # --- set unwarpdir

            if "o" in boldinfo:
                orient    = "_" + boldinfo['o']
                unwarpdir = unwarpdirs.get(boldinfo['o']) # Code fails here when trying to reference unwarpdirs
                if unwarpdir is None:
                    r += '\n     ... ERROR: No unwarpdir is defined for %s! Please check hcp_bold_unwarpdir parameter!' % (boldinfo['o'])
                    boldok = False
            elif 'phenc' in boldinfo:
                orient    = "_" + boldinfo['phenc']
                unwarpdir = unwarpdirs.get(boldinfo['phenc'])
                if unwarpdir is None:
                    r += '\n     ... ERROR: No unwarpdir is defined for %s! Please check hcp_bold_unwarpdir parameter!' % (boldinfo['phenc'])
                    boldok = False
            else:
                orient = ""
                unwarpdir = unwarpdirs.get('default')
                if unwarpdir is None:
                    r += '\n     ... ERROR: No default unwarpdir is set! Please check hcp_bold_unwarpdir parameter!'
                    boldok = False

Proposed solution:
I am 60% certain that removing one level of indent from the line 2923 # --- Process unwarp direction section will allow the script to run but would appreciate having an experienced developer check this.

This issue was resolved in the feature/multiplefieldmaps branch. I ran into the exact same problem when running hcp_fMRIVolume step on the data collected with Philips Achieva 3.0T, where we also used gradient-echo fieldmaps.

Yes, you are precisely right. The issue was resolved by removing one indentation level and including a simple if statement in case hcp_bold_dcmethod is set to NONE.

Thank you Aleksij! I will mark this as resolved once the testing with NAPLS3 subject is completed.

Testing was completed with Qu|Nex v0.61.15.