Skip to content

Conversation

@abukaj
Copy link
Member

@abukaj abukaj commented Nov 7, 2019

For particular combination of dipoles and electrodes calculated potentials were NaNs.

I have traced the error to violation of the -1 <= cos(phi) <= 1 constraint, probably due to a numerical error.

For certain dipole locations (and moments) FSM calculates NaN potential
at certain electrodes.  It is probably due to numerical error in
calculating `cos(phi)` value which violates `-1 <= cos(phi) <= 1`, thus
leading to `arccos(cos(phi))` being NaN.
`cos(phi)` fixed if violating `-1 <= cos(phi) <= 1`.

If `abs(cos(phi)) > 1 + 1e-10`, `RuntimeWarning` is triggered.

See also: f78145b
@abukaj abukaj requested a review from ccluri November 7, 2019 21:07
@solveignaess
Copy link
Collaborator

We discovered the same problem in the LFPy-version of the code. This problem occurs when phi is not defined. I.e., when theta= 0 or theta = pi or when the dipole has no tangential component. Here: LFPy/eegmegcalc.py, from line 646, you can see how we solved this by creating a mask to avoid trying to compute phi when not defined.

The way the dipole is decomposed in a radial and tangential component, is prone to round-off errors. We have created a unit vector containing the direction of the dipole location vector (self._z, line 400), and using self._z to decompose the dipole (line 545) will reduce the risk of round-off errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants