Skip to content

Runtime warnings in debiasRician() when sigma_diff = b0 / SNR becomes zero (divide-by-zero / invalid value) #217

@Kikubernetes

Description

@Kikubernetes

Hi, thank you for AMICO.

I encountered runtime warnings in amico/preproc.py during doDebiasSignal=True preprocessing, caused by division by zero in the Rician debiasing step.

Context

  • ae.set_config('doDebiasSignal', True)
  • ae.set_config('DWI-SNR', 30.0) (required when debiasing is enabled)

The warnings came from expressions using sig2 = sigma_diff**2 in denominators, where:

  • sigma_diff = b0 / SNR
  • and for some voxels, b0 can be zero or extremely small (e.g., boundary / low-signal voxels)

This leads to sig2 == 0 (or near-zero), then warnings such as:

  • RuntimeWarning: divide by zero encountered in divide
  • RuntimeWarning: invalid value encountered in divide

Minimal patch tested

I tested the following safeguard in debiasRician():

sigma_diff = b0 / SNR
sigma_diff = max(float(sigma_diff), 1e-8)

Result in my test

  • The runtime warnings disappeared.

  • AMICO preprocessing + NODDI fitting completed successfully.

  • Final outputs were unchanged compared with the original doDebiasSignal=True run (voxelwise diff = 0 in-mask for:

    • fit_NDI.nii.gz
    • fit_ODI.nii.gz
    • fit_FWF.nii.gz)

As an additional sanity check, I also compared doDebiasSignal=False vs True outputs and observed clear structured differences in NDI/ODI/FWF maps (not uniform noise), indicating that the debiasing effect itself remains active and meaningful.
NDI maps (same subject, same slice). From left to right: no debiasing, original debiasing, and patched debiasing. The middle and right panels are visually indistinguishable in this example, consistent with the voxelwise comparison (difference = 0 in-mask).

Image

Suggestion

Would you consider adding a small lower bound for sigma_diff (or skipping debiasing for zero/invalid b0 voxels) to avoid numerical instability in low-signal voxels?

If helpful, I can open a PR with the minimal change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions