You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: allow passing source-detector distances to beer_lambert_law()` #13862
beer_lambert_law() currently gets source-detector distances from raw.info["chs"]. Many public fNIRS datasets do not include optode locations in the raw data file, but their corresponding papers report a fixed separation such as 3 cm. Could beer_lambert_law() accept an optional sd_distances=None argument so these datasets can still be converted from fnirs_od to hbo/hbr?
I can implement this if it gets accepted.
Describe your proposed implementation
Add an optional sd_distances argument to mne/preprocessing/nirs/_beer_lambert_law.py:17.
Many public fNIRS datasets do not include optode locations in the raw data file, but their corresponding papers report a fixed separation such as 3 cm.
Hmm... do they at least include nominal positions, like for each source/detector pair where the midpoint is? Are those encoded properly in the files?
If that's the case, I wonder if we could instead create a function that uses these midpoints and adds nominal source/detector locations based on those. Like mne.preprocessing.fnirs.add_source_detector_locations(raw.info, distance=0.03) (or something in mne-nirs) that sets info["chs"] locations properly. We would have to choose how to place those sources and detectors, (e.g., just put them on lines of latitude / XY planes in the head coord frame).
The reason for doing this is that, instead of fixing a single function, something like this would allow many other functions (e.g., plot_alignment) to work properly as well. At least in the sense that they will put sourced and detectors on the plot...
Looking into this now, I think warning would be better in case 1 above. If locations are faulty we should allow override somehow.
Case 2: This would also be a breaking change, currently warns and sets distances to 0 if dist calculation fails and proceeds with the calculation. @mne/preprocessing/nirs/_beer_lambert_law.py#L77-L85
distances=_get_sd_distances(raw, sd_distances)
bad=~np.isfinite(distances[picks])
bad|=distances[picks] <=0ifbad.any():
warn(
"Source-detector distances are zero or NaN, some resulting ""concentrations will be zero. Consider setting a montage ""with raw.set_montage."
)
distances[picks[bad]] =0.0
Activity
larsoner commentedon Apr 23, 2026
Hmm... do they at least include nominal positions, like for each source/detector pair where the midpoint is? Are those encoded properly in the files?
If that's the case, I wonder if we could instead create a function that uses these midpoints and adds nominal source/detector locations based on those. Like
mne.preprocessing.fnirs.add_source_detector_locations(raw.info, distance=0.03)(or something inmne-nirs) that setsinfo["chs"]locations properly. We would have to choose how to place those sources and detectors, (e.g., just put them on lines of latitude / XY planes in the head coord frame).The reason for doing this is that, instead of fixing a single function, something like this would allow many other functions (e.g.,
plot_alignment) to work properly as well. At least in the sense that they will put sourced and detectors on the plot...kalomak commentedon Apr 24, 2026
Usually not. They either have no locations or full sensor-detector locations most of the time.
In the rare case that there is only midpoint locations, it is pretty easy to manually make a proper montage with a hacky scipy.optim script, e.g.:
But in my opinion not worth it to add this functionality to mne as the use case is so rare.
sd_distances=Nonewould be very useful though.larsoner commentedon Apr 24, 2026
Okay yeah if it's generally all-or-nothing then agreed adding a
sd_distances=Nonemakes sense.And I am inclined to think it should error if the user:
sd_distances=<scalar>when it can be computed from the actual positions (to be safe, we can always relax this later), orsd_distances=Noneand there are no positions to calculate the distances fromkalomak commentedon Apr 28, 2026
Looking into this now, I think warning would be better in case 1 above. If locations are faulty we should allow override somehow.
Case 2: This would also be a breaking change, currently warns and sets distances to 0 if dist calculation fails and proceeds with the calculation.
@mne/preprocessing/nirs/_beer_lambert_law.py#L77-L85