QSIPrep "AttributeError: Can only use .str accessor with string values!"

Summary of what happened:

I am using QSIPrep to preprocess my diffusion-weighted imaging (DWI) data. However, I encountered the following error.

I consulted an AI assistant, which suggested that the error might be caused by a missing PhaseEncodingDirection field in the JSON sidecar file associated with my DWI data. My JSON is:

{
“Modality”: “MR”,
“MagneticFieldStrength”: 3,
“ImagingFrequency”: 127.773,
“Manufacturer”: “Philips”,
“ManufacturersModelName”: “Ingenia CX”,
“InstitutionName”: “SHX People Hospital”,
“InstitutionalDepartmentName”: “MR”,
“DeviceSerialNumber”: “78281”,
“StationName”: “PHILIPS-5E2PNDK”,
“BodyPartExamined”: “ANKLE”,
“PatientPosition”: “HFS”,
“ProcedureStepDescription”: “TEST”,
“SoftwareVersions”: “6.1.571\\6.1.571.0”,
“MRAcquisitionType”: “2D”,
“SeriesDescription”: “DKI_B1000_B2000”,
“ProtocolName”: “WIP DKI_B1000_B2000”,
“ScanningSequence”: “SE”,
“SequenceVariant”: “SK”,
“ScanOptions”: “FS”,
“ImageType”: \[“ORIGINAL”, “PRIMARY”, “M”, “SE”, “M”, “SE”\],
“SeriesNumber”: 701,
“AcquisitionTime”: “09:30:23.450000”,
“AcquisitionNumber”: 7,
“PhilipsRescaleSlope”: 2.00684,
“PhilipsRescaleIntercept”: 0,
“PhilipsScaleSlope”: 0.0236278,
“UsePhilipsFloatNotDisplayScaling”: 1,
“SliceThickness”: 2,
“SpacingBetweenSlices”: 2,
“SAR”: 0.0837028,
“EchoTime”: 0.086302,
“RepetitionTime”: 5,
“MTState”: false,
“FlipAngle”: 90,
“CoilString”: “MULTI COIL”,
“PercentPhaseFOV”: 100,
“PercentSampling”: 100,
“EchoTrainLength”: 51,
“PartialFourierDirection”: “PHASE”,
“PartialFourierEnabled”: “YES”,
“PhaseEncodingStepsNoPartialFourier”: 126,
“AcquisitionMatrixPE”: 126,
“ReconMatrixPE”: 128,
“ParallelReductionFactorInPlane”: 2.5,
“ParallelAcquisitionTechnique”: “MBSENSE”,
“ParallelReductionOutOfPlane”: 2,
“WaterFatShift”: 18.6392,
“EstimatedEffectiveEchoSpacing”: 0.000331339,
“EstimatedTotalReadoutTime”: 0.0420801,
“PixelBandwidth”: 1778,
“PhaseEncodingAxis”: “j”,
“ImageOrientationPatientDICOM”: \[
0.999204,
-0.00134204,
0.0398811,
0.00712224,
0.989384,
-0.145151	\],
“InPlanePhaseEncodingDirectionDICOM”: “COL”,
“ConversionSoftware”: “dcm2niix”,
“ConversionSoftwareVersion”: “v1.0.20211006”
}

Could you help me determine whether the missing PhaseEncodingDirection field is responsible for this error and suggest how to resolve it?

In particular, I would like to know how to correctly specify the PhaseEncodingDirection parameter and whether any additional BIDS metadata are required for QSIPrep to preprocess my DWI data successfully.

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

docker run --rm ^
  -v "F:\LDM_FP\test\DTI:/data:ro" ^
  -v "F:\LDM_FP\test\qsiprep_out:/out" ^
  -v "F:\LDM_FP\freesurfer_license:/fs_license:ro" ^
  -v "F:\LDM_FP\test\qsiprep_work:/work" ^
  pennbbl/qsiprep:0.22.0 /data /out participant ^
  --fs-license-file /fs_license/license.txt ^
  -w /work ^
  --output-resolution 1 ^
  --skip-bids-validation

Version:

0.22.0

Environment (Docker, Singularity / Apptainer, custom installation):

Docker

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

PASTE VALIDATOR OUTPUT HERE

Relevant log outputs (up to 20 lines):

261021-13:44:09,295 nipype.workflow IMPORTANT:
         Running QSIPrep version 0.22.1.dev0+gd9279db.d20240719

         License NOTICE ##################################################
         QSIPrep 0.22.1.dev0+gd9279db.d20240719
         Copyright The PennLINC Developers.

         This product includes software developed by
         the NiPreps Community (https://nipreps.org/).

         Portions of this software were developed at the Department of
         Psychology at Stanford University, Stanford, CA, US.

         This software is also distributed as a Docker container image.
         The bootstrapping file for the image ("Dockerfile") is licensed
         under the MIT License.

         This software may be distributed through an add-on package called
         "Docker Wrapper" that is under the BSD 3-clause License.
         #################################################################
261021-13:44:09,331 nipype.workflow IMPORTANT:
         Building QSIPrep's workflow:
           * BIDS dataset path: /data.
           * Participant list: ['01'].
           * Run identifier: 20261021-134344_c02a4b20-f1d3-4a9b-b151-51122e4035e2.
261021-13:44:09,441 nipype.workflow INFO:
         Running nonlinear normalization to template
261021-13:44:09,481 nipype.workflow INFO:
         Combining all 1 dwis within the single available session
261021-13:44:09,503 nipype.workflow INFO:
         [{'dwi_series': ['/data/sub-01/dwi/sub-01_dwi.nii.gz'], 'fieldmap_info': {'suffix': None}, 'dwi_series_pedir': '', 'concatenated_bids_name': 'sub-01'}]
Process Process-2:
Traceback (most recent call last):
  File "/opt/conda/envs/qsiprep/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/opt/conda/envs/qsiprep/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/qsiprep/cli/workflow.py", line 160, in build_workflow
    retval["workflow"] = workflow_builder()
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/qsiprep/workflows/base.py", line 82, in init_qsiprep_wf
    single_subject_wf = init_single_subject_wf(subject_id)
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/qsiprep/workflows/base.py", line 352, in init_single_subject_wf
    dwi_preproc_wf = init_dwi_preproc_wf(
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/qsiprep/workflows/dwi/base.py", line 246, in init_dwi_preproc_wf
    pre_hmc_wf = init_dwi_pre_hmc_wf(
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/qsiprep/workflows/dwi/pre_hmc.py", line 238, in init_dwi_pre_hmc_wf
    merge_dwis = init_merge_and_denoise_wf(
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/qsiprep/workflows/dwi/merge.py", line 151, in init_merge_and_denoise_wf
    dwi_df = get_acq_parameters_df(raw_dwi_files, layout=layout)
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/qsiprep/workflows/dwi/merge.py", line 704, in get_acq_parameters_df
    ].str.replace("-", "")
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/pandas/core/generic.py", line 5902, in __getattr__
    return object.__getattribute__(self, name)
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/pandas/core/accessor.py", line 182, in __get__
    accessor_obj = self._accessor(obj)
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/pandas/core/strings/accessor.py", line 181, in __init__
    self._inferred_dtype = self._validate(data)
  File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/pandas/core/strings/accessor.py", line 235, in _validate
    raise AttributeError("Can only use .str accessor with string values!")
AttributeError: Can only use .str accessor with string values!. Did you mean: 'std'?

What's next:
    Debug this container error with Gordon → docker ai "help me fix this container error"

Screenshots / relevant information:


Hi @Meimei_Liu and welcome to neurostars!

In the future please use the Software Support post category and template. You can see I have edited it in for you this time.

This is a very old version, and coming from the wrong repository. The most recent version is pennlinc/qsiprep:26.1.1.

Indeed, you would need a field like that to run susceptibility distortion correction. But if you don’t have a fieldmap, and you are using something like the Synb0 option to correct your data, it doesn’t matter if your direction has the right sign. E.g. I see you PhaseEncodingAxis is j, so if you are using Synb0, then setting your PhaseEncodingDirection to j or j- should be fine.

Best,
Steven

Thank you for your answer. I have updated the toolkit again. I also reran another batch of data, and the other batch ran successfully. This proves that it was indeed a missing field issue. I want to avoid manually setting a certain parameter value as much as possible. Is there any way to run successfully without manually setting parameters?

Hi @Meimei_Liu,

You can update the jsons with a script, for example using the json library in Python.

Best,
Steven

Could another method be used to generate a JSON file containing PhaseEncodingDirection when converting the format and generating the JSON?

Hi @Meimei_Liu,

Other tools such as scripting in Bash can add that field in as well. But if the field is not present in the scanner metadata (which is often the case with Philips scanners), you will need to add that data in somehow.

Best,
Steven

Thank you for your answer.