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).
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.
Hi, thank you for AMICO.
I encountered runtime warnings in
amico/preproc.pyduringdoDebiasSignal=Truepreprocessing, 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**2in denominators, where:sigma_diff = b0 / SNRb0can 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 divideRuntimeWarning: invalid value encountered in divideMinimal patch tested
I tested the following safeguard in
debiasRician():Result in my test
The runtime warnings disappeared.
AMICO preprocessing + NODDI fitting completed successfully.
Final outputs were unchanged compared with the original
doDebiasSignal=Truerun (voxelwise diff = 0 in-mask for:fit_NDI.nii.gzfit_ODI.nii.gzfit_FWF.nii.gz)As an additional sanity check, I also compared
doDebiasSignal=FalsevsTrueoutputs and observed clear structured differences inNDI/ODI/FWFmaps (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).
Suggestion
Would you consider adding a small lower bound for
sigma_diff(or skipping debiasing for zero/invalidb0voxels) to avoid numerical instability in low-signal voxels?If helpful, I can open a PR with the minimal change.