AttributeError: module 'os' has no attribute 'basename'

Hi fMRIPrep experts,

Thank you for your usual support. I recently have encountered the followiing error in preprocessing step of resting-state functional MRI with one T1-weighted MRI image, and fieldmap images, and no T2-weighted MRI image, and fieldmap processing was halted (though other processing steps were going…). In only a few cases (in other many cases, there were no problems), I encountered such error. As fieldmap images, I used two magnitude images derived from our GE MRI scanner and one phase-difference fieldmap (Hz) from the same scanner. Only a phase-difference image for each subject was made from two magnitude images and two real phase images by myself with SPM12 Fieldmap Toolbox. Would you mind providing me some clues to solve this condition? I appreciate your guidance in advance.


Node: fmriprep_23_1_wf.single_subject_023_wf.fmap_preproc_wf.wf_auto_00000.check_register
Working directory: /scratch/fmriprep_23_1_wf/single_subject_023_wf/fmap_preproc_wf/wf_auto_00000/check_register

Node inputs:

fmap_files = <undefined>
mag_files = ['/data/sub-023/fmap/sub-023_magnitude1.nii', '/data/sub-023/fmap/sub-023_magnitude2.nii']
rot_thresh = 0.02
trans_thresh = 1.0

Traceback (most recent call last):
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node check_register.

Traceback:
	Traceback (most recent call last):
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 397, in run
	    runtime = self._run_interface(runtime)
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/sdcflows/interfaces/fmap.py", line 343, in _run_interface
	    out_fmaps = [_conform_img(fmap, mag_imgs[0], runtime.cwd) for fmap in fmap_imgs]
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/sdcflows/interfaces/fmap.py", line 343, in <listcomp>
	    out_fmaps = [_conform_img(fmap, mag_imgs[0], runtime.cwd) for fmap in fmap_imgs]
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/sdcflows/interfaces/fmap.py", line 365, in _conform_img
	    basename = os.basename(img.get_filename())
	AttributeError: module 'os' has no attribute 'basename'

Hi @fmark and welcome to neurostars!

There is information missing here that we usually ask for in software support questions, such as the command you used, how you are running it (Singukarity, Docker, Python), and BIDS validation status. You can see what the post template looks like if you begin opening a new issue in the Software Support category. Please provide that information by editing your post so we can help you better.

For this error, it is possible you’ve uncovered a bug, as basename is part of the Python module os.path, not os.

Best,
Steven

Hi @fmark,

I have opened a PR to fix this change in the SDCFlows repository: [FIX] Change `os.basename` to `os.path.basename` by smeisler Β· Pull Request #419 Β· nipreps/sdcflows Β· GitHub

Appreciate you spotting the bug!

Best,
Steven

Hi Steven,

Many thanks for your immediate and helpful response. My answer in relation to software support questions is as follows. With the information, I would be very grateful if you could give me some guidance.

Summary of what happened:

As I told in my former post, the processing step was stopped partly only in fieldmap part and I could not see β€œfmap” directory emerging that I always found when the all steps worked correctly. First of all, custom installation fMRIPrep v23.1.4 under anaconda & python 3.9 showed the error in a few cases. Then, I tried to use fMRIPrep with Docker after I upgraded python version to 3.10, but the same results emerged.

Command used

fmriprep-docker /data /home/output_sub-023 participant --participant-label sub-023 --task-id rest --fs-license-file /home/license.txt -w /home/work_sub-023 --mem 56000

Version:

23.1.4

Environment (Docker, Singularity, custom installation):

Docker

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

BIDS-validated

Relevant log outputs (up to 20 lines):

(As I already told you, )

Traceback (most recent call last):
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node check_register.

Traceback:
	Traceback (most recent call last):
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 397, in run
	    runtime = self._run_interface(runtime)
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/sdcflows/interfaces/fmap.py", line 343, in _run_interface
	    out_fmaps = [_conform_img(fmap, mag_imgs[0], runtime.cwd) for fmap in fmap_imgs]
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/sdcflows/interfaces/fmap.py", line 343, in <listcomp>
	    out_fmaps = [_conform_img(fmap, mag_imgs[0], runtime.cwd) for fmap in fmap_imgs]
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/sdcflows/interfaces/fmap.py", line 365, in _conform_img
	    basename = os.basename(img.get_filename())
	AttributeError: module 'os' has no attribute 'basename'

Screenshots / relevant information:

Root directory composition is as follows:

data/sub-023
β”œβ”€β”€ anat
β”‚   β”œβ”€β”€ sub-023_T1w.json
β”‚   └── sub-023_T1w.nii
β”œβ”€β”€ fmap
β”‚   β”œβ”€β”€ sub-023_magnitude1.json
β”‚   β”œβ”€β”€ sub-023_magnitude1.nii
β”‚   β”œβ”€β”€ sub-023_magnitude2.json
β”‚   β”œβ”€β”€ sub-023_magnitude2.nii
β”‚   β”œβ”€β”€ sub-023_phasediff.json
β”‚   └── sub-023_phasediff.nii
└── func
    β”œβ”€β”€ sub-023_task-rest_bold.json
    └── sub-023_task-rest_bold.nii

Thanks for the info, @fmark, but I think we will have to wait for this change to be implemented in SDCFlows to proceed, which should fix the bug you are experiencing. Also, for future posts, please format code and terminal outputs so they look nice

like this

by surrounding it in tickmarks or by pressing the </> button in the text editor, which will do it for you.

Best,
Steven

Thanks @Steven, I understood the situation perfectly. I sincerely thank you for submitting the bug fix application, and will wait for experts’ reponse to it. Also, I will take care of formatting code as you told when I post something in the future of course!

Best regards,
@fmark

1 Like

Hi Steven,

Your pull request relating to my consultation seemed approved in github just before, but how could I use the fixed version of fmap.py or fMRIPrep? Or, should I wait until some additional steps will be finished? Thank you in advance.

Kind regards,
@fmark

I would know how to do this for singularity / apptainer:

  1. Build the container with the --sandbox flag e.g., singularity build --sandbox fmriprep_dev.img docker://nipreps/fmriprep:23.2.0a3. This build the container as a folder that you can navigate.
  2. Edit the file fmap.py in the small way I did in the PR
  3. singularity run as you would for any fmriprep command in singularity, pointing to fmriprep_dev.img.

I do not know to do this in Docker though, so otherwise you might just have to wait.

Best,
Steven

I appreciate a lot, and I will try to do as you told about Docker and also wait for the future fixation that can enable me to use the fixed version of fMRIPrep easily. Thank you again.

Best regards,
@fmark