Skip to content

Commit

Permalink
GH AllenInstitute#508 - Remove np.nan values from np.diff array
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
ru57y34nn committed Apr 12, 2021
1 parent 95d7f00 commit 7c4b156
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ipfx/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
),
]
)
Expand Down

0 comments on commit 7c4b156

Please sign in to comment.