-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Add all_burst_number #367
Closed
Closed
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3803cf2
Feat: Add all_burst_number
arnaudon 952103b
fix
arnaudon 2f5fbc4
bypass warning by default
arnaudon 40a7708
more
arnaudon 2c83183
more
arnaudon adc8b64
relax ISI percentile
arnaudon 397cd46
15
arnaudon 2480c7c
4000
arnaudon 9028c09
voltage_std
arnaudon 09c2339
remove perc
arnaudon db242cf
fix
arnaudon f05cc23
tmp
arnaudon 9490bb1
better tonic
arnaudon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -55,6 +55,7 @@ | |
'impedance', | ||
'burst_number', | ||
'strict_burst_number', | ||
'all_burst_number', | ||
'trace_check', | ||
'phaseslope_max', | ||
] | ||
|
@@ -140,6 +141,45 @@ def strict_burst_number() -> np.ndarray: | |
return np.array([burst_mean_freq.size]) | ||
|
||
|
||
def all_burst_number(): | ||
"""The number of all the bursts, even if they have a single AP. | ||
|
||
Instead of relying on burst_mean_freq, we split the ISIs into two groups, | ||
and count the number of large ISIs. If there are no distinct two groups, | ||
there are no bursts. The groups may not be even, which would correspond to | ||
bursts with equal number of APs. | ||
""" | ||
stim_start = _get_cpp_data("stim_start") | ||
stim_end = _get_cpp_data("stim_end") | ||
peak_times = get_cpp_feature("peak_time") | ||
if peak_times is None: | ||
return np.array([0]) | ||
|
||
peak_times = peak_times[(peak_times > stim_start) & (peak_times < stim_end)] | ||
isis = np.diff(peak_times) | ||
|
||
from sklearn.cluster import KMeans | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you put it at the top of the file and then add |
||
|
||
if len(isis) <= 1: | ||
return np.array([0]) | ||
|
||
# find a split of isis for inter and intra bursts | ||
kmeans = KMeans(n_clusters=2).fit(isis.reshape(len(isis), 1)) | ||
thresh = kmeans.cluster_centers_.mean(axis=0)[0] | ||
|
||
# here we check is the gap between the two group of ISIs is big enough | ||
# to be considered a burst behaviour, the 1.2 and 0.8 are fairly arbitrary | ||
if len(isis[(isis < 1.2 * thresh) & (isis > 0.8 * thresh)]) > 0: | ||
warnings.warn( | ||
"""While calculating all_burst_number, | ||
there are spike around the threshold, we return 0 bursts""", | ||
RuntimeWarning | ||
) | ||
|
||
return np.array([0]) | ||
return np.array([len(isis[isis > thresh])]) | ||
|
||
|
||
def impedance(): | ||
from scipy.ndimage.filters import gaussian_filter1d | ||
|
||
|
@@ -187,7 +227,6 @@ def ISIs(): | |
else: | ||
return np.diff(peak_times) | ||
|
||
|
||
def initburst_sahp_vb(): | ||
"""SlowAHP voltage from voltage base after initial burst""" | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be more descriptive to call it something like
count_burst_events_by_isi_clustering
?