-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50c8a11
commit 77fb198
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import nelpy as nel | ||
import numpy as np | ||
|
||
from neuro_py.detectors.up_down_state import detect_up_down_states | ||
|
||
|
||
def test_detect_up_down_states_detection(): | ||
|
||
# Mock data generation | ||
down_state_times = [4, 7, 15] | ||
|
||
spikes_upstate = [] | ||
for i in range(10): | ||
up_spikes = np.random.poisson(0.25, 20_000) | ||
spikes = np.where(up_spikes > 0)[0] * 0.001 | ||
# silence around down states | ||
for down_state_time in down_state_times: | ||
spikes = spikes[ | ||
~((spikes > down_state_time - 0.1) & (spikes < down_state_time + 0.1)) | ||
] | ||
spikes_upstate.append(spikes) | ||
|
||
nrem_epochs = nel.EpochArray([np.array([[0, 20]])]) | ||
st = nel.SpikeTrainArray(timestamps=spikes_upstate, fs=1000, support=nrem_epochs) | ||
|
||
# Run the function with mock data | ||
down_state_epochs, up_state_epochs = detect_up_down_states( | ||
st=st, | ||
nrem_epochs=nrem_epochs, | ||
save_mat=False, # Disable saving | ||
) | ||
|
||
# Assertions to check detection accuracy | ||
assert down_state_epochs is not None, "Expected detected DOWN states, got None." | ||
assert up_state_epochs is not None, "Expected detected UP states, got None." | ||
|
||
# Check DOWN states detected in low activity periods | ||
down_state_intervals = down_state_epochs.time | ||
for down_state_time in down_state_times: | ||
assert any( | ||
(down_state_time >= down_state_intervals[:, 0]) | ||
& (down_state_time <= down_state_intervals[:, 1]) | ||
), f"DOWN state at {down_state_time} not detected." |