From 7c4b156848e58ae585b67aa2a57c99e673a61175 Mon Sep 17 00:00:00 2001 From: ru57y34nn Date: Mon, 12 Apr 2021 11:26:31 -0700 Subject: [PATCH] GH #508 - Remove np.nan values from np.diff array np.nan values were not being dropped from the end of the np.diff array before calling np.flatnonzero to remove non-zero values in get_stim_epoch. This was causing get_stim_epoch to incorrectly identify the end of the stimulus epoch as the same as the end of the sweep epoch, which was also causing the end of the experiment epoch to be incorrect as well since it relys on the stimulus epoch. By dropping the np.nan values from the end of the difference array (di) in get_stim_epoch, the correct indices for end of the stimulus epoch as well as for the experiment epoch are now being returned. This should fix the issue with sweeps being incorrectly tagged with 'Recording stopped before completing the experiment epoch'. --- CHANGELOG.md | 7 ++++++- ipfx/epochs.py | 1 + tests/test_epochs.py | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11e2b385..36ed26e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,12 @@ All notable changes to this project will be documented in this file. ## Unreleased - +This pull request adds a line of code to the get_stim_epoch function in epochs.py to +remove np.nan values from the array of differences between data points before removing +all non-zero values. This change allows get_stim_epoch to find the correct ending index +of the stimlus epoch and the correct ending index of the experiment epoch as well since +it relys on the stimulus epoch, which should fix the issue of sweeps being incorrectly +tagged with "Recording stopped before completing the experiment epoch". ### Added ### Changed diff --git a/ipfx/epochs.py b/ipfx/epochs.py index f15e3b93..584dca06 100644 --- a/ipfx/epochs.py +++ b/ipfx/epochs.py @@ -108,6 +108,7 @@ def get_stim_epoch(i, test_pulse=True): """ di = np.diff(i) + di = di[~np.isnan(di)] # != NaN di_idx = np.flatnonzero(di) # != 0 if test_pulse: diff --git a/tests/test_epochs.py b/tests/test_epochs.py index 6364f0dc..d0bed253 100644 --- a/tests/test_epochs.py +++ b/tests/test_epochs.py @@ -109,6 +109,11 @@ def test_get_test_epoch(i, sampling_rate, test_epoch): [0, 0, 0, 0, 0, 0, 0], None ), + # array containing np.nan + ( + [0, 0, 1, 1, 0, 0, 2, 2, 2, 0, 0, np.nan, np.nan], + (6, 8) + ), ] )