Fmriprep TOPUP Issue Not Finding Files

Summary of what happened:

I seem to be running into a problem with fmriprep and (I believe) the fieldmaps that are being applied. I have received the following error:

nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node topup.

Cmdline:
        topup --config=/opt/conda/lib/python3.9/site-packages/sdcflows/data/flirtsch/b02b0.cnf --datain=/scratch/fmriprep_23_0_wf/single_subject_0005_wf/fmap_preproc_wf/wf_auto_00000/topup/sub-0005_acq-smallFOVcor_dir-FH_epi_average_merged_sliced_volregLAS_encfile.txt --imain=/scratch/fmriprep_23_0_wf/single_subject_0005_wf/fmap_preproc_wf/wf_auto_00000/to_las/sub-0005_acq-smallFOVcor_dir-FH_epi_average_merged_sliced_volregLAS.nii.gz --out=sub-0005_acq-smallFOVcor_dir-FH_epi_average_merged_sliced_volregLAS_base --iout=sub-0005_acq-smallFOVcor_dir-FH_epi_average_merged_sliced_volregLAS_corrected.nii.gz --fout=sub-0005_acq-smallFOVcor_dir-FH_epi_average_merged_sliced_volregLAS_field.nii.gz --jacout=jac --logout=sub-0005_acq-smallFOVcor_dir-FH_epi_average_merged_sliced_volregLAS_topup.log --rbmout=xfm --dfout=warpfield
Stdout:

Stderr:
        Error occurred when preparing to run topup
        Exception thrown with message: Topup: msg=TopupScan::TopupScan: third element of pevec must be zero
Traceback:
        Traceback (most recent call last):
          File "/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 453, in aggregate_outputs
            setattr(outputs, key, val)
          File "/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/traits_extension.py", line 330, in validate
            value = super(File, self).validate(objekt, name, value, return_pathlike=True)
          File "/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/traits_extension.py", line 135, in validate
            self.error(objekt, name, str(value))
          File "/opt/conda/lib/python3.9/site-packages/traits/base_trait_handler.py", line 74, in error
            raise TraitError(
        traits.trait_errors.TraitError: The 'out_movpar' trait of a TOPUPOutputSpec instance must be a pathlike object or string representing an existing file, but a value of '/scratch/fmriprep_23_0_wf/single_subject_0005_wf/fmap_preproc_wf/wf_auto_00000/topup/sub-0005_acq-smallFOVcor_dir-FH_epi_average_merged_sliced_volregLAS_base_movpar.txt' <class 'str'> was specified.

        During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
          File "/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 400, in run
            outputs = self.aggregate_outputs(runtime)
          File "/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 460, in aggregate_outputs
            raise FileNotFoundError(msg)
        FileNotFoundError: No such file or directory '/scratch/fmriprep_23_0_wf/single_subject_0005_wf/fmap_preproc_wf/wf_auto_00000/topup/sub-0005_acq-smallFOVcor_dir-FH_epi_average_merged_sliced_volregLAS_base_movpar.txt' for output 'out_movpar' of a TOPUP interface

Command used (and if a helper script was used, a link to the helper script or the command generated):

The command I have input is the following:
fmriprep-docker /lbc/lbc1/derivatives/brainstem_funk/BIDS /lbc/lbc1/derivatives/brainstem_funk/fmriprep participant -w work/ --fs-license-file /lbc/lbc1/derivatives/brainstem_funk/license.txt --fs-no-reconall --skip-bids-validation --output-spaces MNI152NLin2009cAsym:res-native MNI152NLin2009cAsym

The BIDS folder is set up as follows:


**(I’m new to bash so I don’t know why ‘anat’ looks like a file in the tree; It’s definitely a folder in the BIDS file)

Version:

  • fmriprep v. 23.0.2
  • docker v. 20.10.21

Environment (Docker, Singularity, custom installation):

Installed using docker.

Data formatted according to a validatable standard? Please provide the output of the validator:

It is listed as valid according to bids.validator.

Screenshots / relevant information:

I have included the “IntendedFor” with the file path in the .json files.

Hi @ejdavid,

  1. Your func files do not look to be BIDS valid, as there is no acq label before smallFOVcor.
  2. What does HF and FH stand for in the dir label? Usually dir labels are AP, PA, RL, LR, SI, IS (anterior, posterior, left, right, superior inferior).
  3. Can you show us an example fmap JSON file?
  4. What is the output from the BIDS validator if you do not skip it?

Best,
Steven

Hi Steven,

  1. Apologies. I pasted the tree from before I changed the file names. I updated them and ran it again with the same error. The file names under this next run look like this:

  2. HF and FH stand for head and feet (instead of anterior/posterior). Could this error be the result of this?

  3. An example JSON file is the following:

{
	"Modality": "MR",
	"MagneticFieldStrength": 7,
	"ImagingFrequency": 297.2,
	"Manufacturer": "Siemens",
	"ManufacturersModelName": "Investigational_Device_7T",
	"InstitutionName": "BIC",
	"InstitutionalDepartmentName": "Department",
	"InstitutionAddress": "Street StreetNo,City,District,CA,ZIP",
	"DeviceSerialNumber": "79017",
	"StationName": "AWP79017",
	"BodyPartExamined": "BRAIN",
	"PatientPosition": "HFS",
	"ProcedureStepDescription": "Development^Dr. Spreng",
	"SoftwareVersions": "syngo MR E12",
	"MRAcquisitionType": "2D",
	"SeriesDescription": "fmap-fmri_acq-mbep2d_SE_0.8mm_dir-H-F",
	"ProtocolName": "fmap-fmri_acq-mbep2d_SE_0.8mm_dir-H-F",
	"ScanningSequence": "EP",
	"SequenceVariant": "SK\\OSP",
	"ScanOptions": "PFP\\SAT1\\FS",
	"SequenceName": "epse2d1_148",
	"ImageType": ["ORIGINAL", "PRIMARY", "M", "MB", "ND", "MOSAIC"],
	"SeriesNumber": 34,
	"AcquisitionTime": "13:19:22.237500",
	"AcquisitionNumber": 1,
	"ImageComments": "Unaliased MB3/PE4/LB",
	"SliceThickness": 0.8,
	"SpacingBetweenSlices": 0.8,
	"SAR": 0.22484,
	"EchoTime": 0.0352,
	"RepetitionTime": 5.531,
	"FlipAngle": 90,
	"PartialFourier": 0.75,
	"BaseResolution": 176,
	"ShimSetting": [
		123,
		21,
		678,
		316,
		-117,
		-7,
		154,
		-221	],
	"TxRefAmp": 251.978,
	"PhaseResolution": 1,
	"ReceiveCoilName": "8Tx32Rx_Head",
	"CoilString": "AC",
	"PulseSequenceDetails": "%CustomerSeq%\\cmrr_mbep2d_se",
	"WipMemBlock": "419413ee-fcf3-45fb-8f70-1afaa244c4ec||Sequence: R016 ve12u/SP01_R016a r/af3652dd; Apr  1 2021 14:29:52 by eja",
	"RefLinesPE": 54,
	"ConsistencyInfo": "N4_VE12U_LATEST_20181126",
	"MultibandAccelerationFactor": 3,
	"PercentPhaseFOV": 84.0909,
	"PercentSampling": 100,
	"EchoTrainLength": 37,
	"PhaseEncodingSteps": 110,
	"AcquisitionMatrixPE": 148,
	"ReconMatrixPE": 148,
	"BandwidthPerPixelPhaseEncode": 17.938,
	"ParallelReductionFactorInPlane": 3,
	"EffectiveEchoSpacing": 0.000376673,
	"DerivedVendorReportedEchoSpacing": 0.00113002,
	"TotalReadoutTime": 0.0553709,
	"PixelBandwidth": 1015,
	"DwellTime": 2.8e-06,
	"PhaseEncodingDirection": "j-",
	"SliceTiming": [
		0,
		1.29,
		2.58,
		3.87,
		5.16,
		0.92,
		2.2125,
		3.5025,
		4.7925,
		0.5525,
		1.8425,
		3.1325,
		4.4225,
		0.1825,
		1.475,
		2.765,
		4.055,
		5.345,
		1.105,
		2.395,
		3.685,
		4.9775,
		0.7375,
		2.0275,
		3.3175,
		4.6075,
		0.3675,
		1.6575,
		2.95,
		4.24,
		0,
		1.29,
		2.58,
		3.87,
		5.16,
		0.92,
		2.2125,
		3.5025,
		4.7925,
		0.5525,
		1.8425,
		3.1325,
		4.4225,
		0.1825,
		1.475,
		2.765,
		4.055,
		5.345,
		1.105,
		2.395,
		3.685,
		4.9775,
		0.7375,
		2.0275,
		3.3175,
		4.6075,
		0.3675,
		1.6575,
		2.95,
		4.24,
		0,
		1.29,
		2.58,
		3.87,
		5.16,
		0.92,
		2.2125,
		3.5025,
		4.7925,
		0.5525,
		1.8425,
		3.1325,
		4.4225,
		0.1825,
		1.475,
		2.765,
		4.055,
		5.345,
		1.105,
		2.395,
		3.685,
		4.9775,
		0.7375,
		2.0275,
		3.3175,
		4.6075,
		0.3675,
		1.6575,
		2.95,
		4.24	],
	"ImageOrientationPatientDICOM": [
		1,
		0,
		0,
		0,
		0.345298,
		-0.938493	],
	"InPlanePhaseEncodingDirectionDICOM": "COL",
	"ConversionSoftware": "dcm2niix",
	"ConversionSoftwareVersion": "v1.0.20210317",
	"IntendedFor": [
		"bids::sub-0005/func/sub-0005_task-rest_acq-smallFOVcor_bold.nii"
	]

}

Hope this helps!! Thanks again!

Cheers,
Emily

I don’t think fMRIPrep currently is compatible with the BIDS URI (the bids:: thing you have upfront). Also, your file path is missing the .gz file extension. So try this:

"IntendedFor": [
		"func/sub-0005_task-rest_acq-smallFOVcor_bold.nii.gz"
	]

Also, just to be safe, use a fresh working directory too.

Best,
Steven

Thanks again for your reply!

I tried making this adjustment and also turning off the bid validation skip. There are no errors for the bids validation step (just a warning about a lack of README). The same error listed above persists even with the adjustment of the IntendedFor parameter.

Did you use a fresh working directory?

I did. No luck, unfortunately.

The error is here:

 Error occurred when preparing to run topup
Exception thrown with message: Topup: msg=TopupScan::TopupScan: third element of pevec must be zero

TOPUP only allows the phase-encoding directions to be L/R or A/P. So this is exactly it:

HF and FH stand for head and feet (instead of anterior/posterior). Could this error be the result of this?

SDCFlows will eventually support reorienting images pre/post-TOPUP, as it’s needed for rodents. In the meantime, I’m curious how you even acquired these data. How were the subjects positioned?

This is good to know. I’m incredibly new to all of this so apologies for my ignorance in advance. I’m hoping there’s a way to use these field maps somehow so maybe the following information might be useful?

The parameters for the field map are the following:
image

The parameters for the functional scan are the following:
image

Is there any modifications I can make in order to use the field maps on this dataset? We’re getting a little experimental with our scanning parameters because we’re trying to look at brainstem in very high resolution on a 7T scanner. Because of this, the field maps are a must. We’re still toying around with different scanning parameters; is there anything we might be able to do to preprocess these data with field maps?

Okay, so it looks like you had an A/P phase encoding direction, but the rotation of the field of view causes the affine to be read as rotated (e.g., if you collected in LPS, your affine will be reading as LSA, or if you collected in LAS, your affine would show RSP).

So when fMRIPrep rotates to LAS, which makes working with the outputs of TOPUP cleaner, the PhaseEncodingDirection is getting flipped from j to k.

It’s unfortunate that you have a partial FoV and won’t be able to register your EPI/fieldmaps reliably. Updating the affine to be cardinal at the expense of anatomical fidelity would allow us to work with this just fine.

We should be able to adapt to this, and it may help with a related issue we’re having for rodents (the slice-encoding axis is A/P, so an I/S PE-dir is common). Is there any chance you’d be willing to share a single subject that I could test things on?

As a thing you can try, and I can’t be sure it will work, you could rotate the fieldmaps 90 degrees forward. These functions would do the trick:

from nibabel.orientations import axcodes2ornt, inv_ornt_aff

def rotate_affine(aff):
    RSPtoRAS = inv_ornt_aff(axcodes2ornt("RSP"), (1, 1, 1))
    return RPStoRAS @ aff

def update_image_affine(img):
    rotated_affine = rotate_affine(img.affine)
    return img.__class__(img.dataobj, rotated_affine, img.header)

def update_file_affine(in_fname, out_fname):
    img = nb.load(in_fname)
    update_image_affine(img).to_filename(out_fname)

This would preserve the data shape and voxel sizes, it would just relabel the axes, so RSP would become RAS. You can verify that it will work for other orientations as well.

You will then be relying on registration to identify the orientation mismatch and correct for it. You can also think about eliminating rotation so you get a non-oblique image. I can’t generate that code off the top of my head, right now, but I believe AFNI has a deobliquing tool.

Sure, I’d be happy to share a single subject. Let me know your email and I’ll send one over.

As to the code you’ve put forward here as a solution, I’ll be happy to try it out. Again, sorry for my newbie ignorance, but where should these be incorporated? Is this something I’m running before or after fmriprep? Thanks again!!

This username at gmail will find me. If you prefer an academic email, my last name @ stanford.edu will also find me.

For using that code, this would be before running fMRIPrep. I would first try modifying only the fieldmaps. If that works but the fieldmap-to-BOLD registration is bad, you could then try also modifying the BOLD files. Hopefully obvious, but just be careful not to overwrite your old files. I would try it in a new test dataset. The JSON metadata should all stay the same.