ZeroDivisionError with combine.py for multi-echo fMRI

I have multi-echo data that I’m working with (new to fmriprep and tedana). It seems like I’m having an issue with the combination step of tedana, getting this error:

Standard error:
/usr/local/miniconda/lib/python3.7/site-packages/sklearn/utils/init.py:4: DeprecationWarning: Using or importing the ABCs from ‘collections’ instead of from ‘collections.abc’ is deprecated, and in 3.8 it will stop working
from collections import Sequence
INFO:tedana.workflows.t2smap:Using output directory: /tmp/work/fmriprep_wf/single_subject_01_wf/func_preproc_ses_1_task_rest_echo_1_wf/bold_t2smap_wf/t2smap_node
INFO:tedana.workflows.t2smap:Loading input data: [’/tmp/work/fmriprep_wf/single_subject_01_wf/func_preproc_ses_1_task_rest_echo_1_wf/skullstrip_bold_wf/bold_file…data…sub-01…ses-1…func…sub-01_ses-1_task-rest_echo-1_bold.nii.gz/apply_mask/vol0000_xform-00000_merged_masked.nii.gz’, ‘/tmp/work/fmriprep_wf/single_subject_01_wf/func_preproc_ses_1_task_rest_echo_1_wf/skullstrip_bold_wf/bold_file…data…sub-01…ses-1…func…sub-01_ses-1_task-rest_echo-2_bold.nii.gz/apply_mask/vol0000_xform-00000_merged_masked.nii.gz’, ‘/tmp/work/fmriprep_wf/single_subject_01_wf/func_preproc_ses_1_task_rest_echo_1_wf/skullstrip_bold_wf/bold_file…data…sub-01…ses-1…func…sub-01_ses-1_task-rest_echo-3_bold.nii.gz/apply_mask/vol0000_xform-00000_merged_masked.nii.gz’]
INFO:tedana.workflows.t2smap:Computing adaptive mask
INFO:REPORT:An adaptive mask was then generated, in which each voxel’s value reflects the number of echoes with ‘good’ data.
INFO:tedana.workflows.t2smap:Computing adaptive T2* map
INFO:REPORT:A monoexponential model was fit to the data at each voxel using nonlinear model fitting in order to estimate T2* and S0 maps, using T2*/S0 estimates from a log-linear fit as initial values. For each voxel, the value from the adaptive mask was used to determine which echoes would be used to estimate T2* and S0. In cases of model fit failure, T2*/S0 estimates from the log-linear fit were retained instead.
INFO:tedana.workflows.t2smap:Computing optimal combination
INFO:tedana.combine:Optimally combining data with voxel-wise T2* estimates
INFO:REPORT:Multi-echo data were then optimally combined using the T2* combination method (Posse et al., 1999).
INFO:REFERENCES:Posse, S., Wiese, S., Gembris, D., Mathiak, K., Kessler, C., Grosse‐Ruyken, M. L., … & Kiselev, V. G. (1999). Enhancement of BOLD‐contrast sensitivity by single‐shot multi‐echo functional MR imaging. Magnetic Resonance in Medicine: An Official Journal of the International Society for Magnetic Resonance in Medicine, 42(1), 87-97.
Traceback (most recent call last):
File “/usr/local/miniconda/bin/t2smap”, line 10, in
sys.exit(_main())
File “/usr/local/miniconda/lib/python3.7/site-packages/tedana/workflows/t2smap.py”, line 256, in main
t2smap_workflow(**kwargs)
File “/usr/local/miniconda/lib/python3.7/site-packages/tedana/workflows/t2smap.py”, line 231, in t2smap_workflow
combmode=combmode)
File “/usr/local/miniconda/lib/python3.7/site-packages/tedana/combine.py”, line 190, in make_optcom
data[echo_idx, :echo, :], tes[:, :echo], t2s
[echo_idx, …])
File “/usr/local/miniconda/lib/python3.7/site-packages/tedana/combine.py”, line 58, in _combine_t2s
combined = np.average(data, axis=1, weights=alpha)
File “/usr/local/miniconda/lib/python3.7/site-packages/numpy/lib/function_base.py”, line 386, in average
“Weights sum to zero, can’t be normalized”)
ZeroDivisionError: Weights sum to zero, can’t be normalized
Return code: 1

Hi @QuintinFrerichsWUSTL,

The ZeroDivisionError is a known issue in tedana (see ME-ICA/tedana#513). It seems to happen fairly randomly due to estimated T2* values very close to zero. We have solved it in our current version on GitHub, but we haven’t made a release since then. We will try to make a release soon, after which we can update fMRIPrep’s requirements to use that version.

I hope that helps.

Best,
Taylor

1 Like

Thanks, this makes sense. I’ll just wait on that until the new update is pushed. Appreciate the help!

@QuintinFrerichsWUSTL an update to tedana has been release, version 0.0.9, which contains that fix in addition to quite a few others. Details here Releases · ME-ICA/tedana · GitHub
Installation details (available on pip) and other docs here: Installation — tedana 0.0.9+0.g3897363.dirty documentation

Thanks for letting me know @dowdlelt! I installed the new version of tedana, but am still getting this issue. I’m not sure what it is, but it appears to be fmriprep-related again?

Traceback (most recent call last):
File “/usr/local/miniconda/bin/fmriprep”, line 10, in
sys.exit(main())
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/cli/run.py”, line 159, in main
packagename=“fmriprep”,
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/reports/core.py”, line 92, in generate_reports
for subject_label in subject_list
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/reports/core.py”, line 92, in
for subject_label in subject_list
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/reports/core.py”, line 72, in run_reports
reportlets_dir=reportlets_dir,
File “/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/reports/core.py”, line 271, in init
self._load_config(Path(config or pkgrf(“niworkflows”, “reports/default.yml”)))
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/reports/core.py”, line 25, in _load_config
self.index(settings[“sections”])
File “/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/reports/core.py”, line 358, in index
self.errors = [read_crashfile(str(f)) for f in error_dir.glob(“crash*.")]
File “/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/reports/core.py”, line 358, in
self.errors = [read_crashfile(str(f)) for f in error_dir.glob("crash
.*”)]
File “/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/utils/misc.py”, line 118, in read_crashfile
return _read_txt(path)
File “/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/utils/misc.py”, line 175, in _read_txt
cur_key, cur_val = tuple(line.split(" = ", 1))

@QuintinFrerichsWUSTL - is this indeed the same error? I’m looking through the text you pasted and it is unclear what is going on, maybe something got cut off.

I’m not as much an expert on fmriprep so I’m going to ping @tsalo here.

I don’t think so? It seems like an issue with niworkflows rather than tedana. Or at least, it doesn’t seem that this issue is driven by tedana, I’m not sure what the cause is.

And I suppose I’m unclear on if the fmriprep version pulled from docker is using my local version of tedana? I’m certain my local tedana has been updated to v0.0.9, so if it is a tedana issue, that would be my other go-to explanation.

To me this seems to be a different error, unrelated to tedana. Looking at the text you copied, it is also not clear what the error actually is- what actually made things break. May be worth closing this thread, and opening a new one if tedana is no longer the source of the problem so that you get some more fmriprep eyes on it.

I can confirm that I’m still getting the same ZeroDivisionError in fact. It seems like the currently latest available Docker version of fmriprep doesn’t include tedana 0.0.9. @tsalo, is that requires a re-release of fmriprep? Can I build a version of the docker image locally that uses tedana 0.0.9?

I have a pull request open to pin the tedana version in fMRIPrep to 0.0.9 (nipreps/fmriprep#2366), but there are issues with some of the dependencies’ dependencies that seem to have broken CI in fMRIPrep and blocked PRs. Unfortunately, I’m not sure when those blockers will be dealt with.

Once that PR is merged, you could use fMRIPrep’s latest Docker/Singularity image, but until then I think your best bet is to build your own image. I’m definitely not the best person to help with Docker (or even Singularity, thought I definitely use it more than Docker), but perhaps @dowdlelt might be able to help you there?

Afraid I have even less experience with Docker/Singularity. Sorry folks

1 Like

This guide should still be up-to-date (I hope !) for updating dependencies and building an fMRIPrep docker image:

https://fmriprep.org/en/stable/contributors.html#adding-dependencies

If you encounter any issues, it’d be great to open a new issue on fMRIPrep so we can patch the docs !

HTH,

Elizabeth

1 Like

Thanks @emdpure! I went through those docs and I noticed two issues:

  1. There’s a broken link in the documentation: https://github.com/nipreps/fmriprep/blob/master/requirements.txt (looks like the repo no longer has a requirements.txt) and
  2. Rebuilding the docker image gives an error: E: Version ‘5.0.9-4~nd16.04+1’ for ‘fsl-core’ was not found (might be the branch referenced by the documentation hasn’t been maintained?)

I’ll open an issue on fMRIPrep with this info.

1 Like