Skip to content

Commit

Permalink
Ensure times at which chpi are fitted are valid samples (#8827)
Browse files Browse the repository at this point in the history
* Ensure times at which chpi are fitted are valid samples

* SKip zero-length annotation
  • Loading branch information
wmvanvliet authored Feb 26, 2021
1 parent 8e3bcef commit 8178cca
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mne/chpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,8 @@ def compute_chpi_amplitudes(raw, t_step_min=0.01, t_window='auto',
% (len(hpi['freqs']), len(fit_idxs), tmax - tmin))
del tmin, tmax
sin_fits = dict()
sin_fits['times'] = (fit_idxs + raw.first_samp -
hpi['n_window'] / 2.) / raw.info['sfreq']
sin_fits['times'] = np.round(fit_idxs + raw.first_samp -
hpi['n_window'] / 2.) / raw.info['sfreq']
sin_fits['proj'] = hpi['proj']
sin_fits['slopes'] = np.empty(
(len(sin_fits['times']),
Expand Down
2 changes: 2 additions & 0 deletions mne/preprocessing/maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ def _run_maxwell_filter(
logger.info(
' Processing %s data chunk%s' % (len(starts), _pl(starts)))
for ii, (start, stop) in enumerate(zip(starts, stops)):
if start == stop:
continue # Skip zero-length annotations
tsss_valid = (stop - start) >= st_duration
rel_times = raw_sss.times[start:stop]
t_str = '%8.3f - %8.3f sec' % tuple(rel_times[[0, -1]])
Expand Down
1 change: 1 addition & 0 deletions mne/tests/test_chpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ def test_calculate_chpi_coil_locs_artemis():
raw = read_raw_artemis123(art_fname, preload=True)
times, cHPI_digs = _calculate_chpi_coil_locs(raw, verbose='debug')

assert len(np.setdiff1d(times, raw.times + raw.first_time)) == 0
assert_allclose(times[5], 1.5, atol=1e-3)
assert_allclose(cHPI_digs[5][0]['gof'], 0.995, atol=5e-3)
assert_allclose(cHPI_digs[5][0]['r'],
Expand Down

0 comments on commit 8178cca

Please sign in to comment.