-
Notifications
You must be signed in to change notification settings - Fork 95
[ENH] time_histogram handles single neo.SpikeTrain
#650
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
Open
Moritz-Alexander-Kern
wants to merge
21
commits into
NeuralEnsemble:master
Choose a base branch
from
INM-6:fix/time_histogram_648
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6c0e8d4
remove copy statement
Moritz-Alexander-Kern a3fdbaa
add regression test for issue #648
Moritz-Alexander-Kern 0635878
fix time_histogram for single spike_train
Moritz-Alexander-Kern 710a993
update docstring
Moritz-Alexander-Kern 64b50cb
fix neo. spike trains to neo.spiketrain objects
Moritz-Alexander-Kern a965d30
fix bullet point list
Moritz-Alexander-Kern 9c06d0d
fix bullet points
Moritz-Alexander-Kern 7fee5ad
Update elephant/test/test_statistics.py
Moritz-Alexander-Kern f6580e0
check if result is correct
Moritz-Alexander-Kern a406a79
add comments
Moritz-Alexander-Kern a0ebaf4
Merge branch 'master' into fix/time_histogram_648
Moritz-Alexander-Kern 409e69e
Merge branch 'master' into fix/time_histogram_648
Moritz-Alexander-Kern aeb3603
Update elephant/test/test_statistics.py
Moritz-Alexander-Kern 37387af
Merge branch 'master' into fix/time_histogram_648
CozySocksAlways 7e2e019
fix docstring issues in time_histogram based on PR review
CozySocksAlways bdaec17
Merge branch 'master' into fix/time_histogram_648
CozySocksAlways ec77fa2
Added all output cases to time_histogram regression test
CozySocksAlways e826beb
Merge commit for remote branch onto local
CozySocksAlways 5f42436
Modified docstring to fix false bold emphasis on text
CozySocksAlways dfab4dd
character case fix
CozySocksAlways 959f79a
removed a '
CozySocksAlways 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 hidden or 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 |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ | |
| import scipy.signal | ||
| from numpy import ndarray | ||
| from scipy.special import erf | ||
| from typing import Union | ||
| from typing import List, Optional, Union | ||
|
|
||
| import elephant.conversion as conv | ||
| import elephant.kernels as kernels | ||
|
|
@@ -1062,46 +1062,51 @@ def optimal_kernel(st): | |
|
|
||
|
|
||
| @deprecated_alias(binsize='bin_size') | ||
| def time_histogram(spiketrains, bin_size, t_start=None, t_stop=None, | ||
| output='counts', binary=False): | ||
| def time_histogram(spiketrains: Union[List[neo.SpikeTrain], neo.SpikeTrain], | ||
| bin_size: pq.Quantity, | ||
| t_start: Optional[pq.Quantity] = None, | ||
| t_stop: Optional[pq.Quantity] = None, | ||
| output: str = 'counts', | ||
| binary: bool = False) -> neo.AnalogSignal: | ||
| """ | ||
| Time Histogram of a list of `neo.SpikeTrain` objects. | ||
| Time Histogram of a list of :class:`neo.core.SpikeTrain` objects. | ||
|
|
||
| Visualization of this function is covered in Viziphant: | ||
| :func:`viziphant.statistics.plot_time_histogram`. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| spiketrains : list of neo.SpikeTrain | ||
| `neo.SpikeTrain`s with a common time axis (same `t_start` and `t_stop`) | ||
| spiketrains : list of :class:`neo.core.SpikeTrain` or :class:`neo.core.SpikeTrain` | ||
| `neo.SpikeTrain` objects with a common time axis (same `t_start` and `t_stop`) | ||
| bin_size : pq.Quantity | ||
| Width of the histogram's time bins. | ||
| t_start : pq.Quantity, optional | ||
| Start time of the histogram. Only events in `spiketrains` falling | ||
| between `t_start` and `t_stop` (both included) are considered in the | ||
| histogram. | ||
| If None, the maximum `t_start` of all `neo.SpikeTrain`s is used as | ||
| If None, the maximum `t_start` of all :class:`neo.core.SpikeTrain`s is used as | ||
| `t_start`. | ||
| Default: None | ||
| t_stop : pq.Quantity, optional | ||
| Stop time of the histogram. Only events in `spiketrains` falling | ||
| between `t_start` and `t_stop` (both included) are considered in the | ||
| histogram. | ||
| If None, the minimum `t_stop` of all `neo.SpikeTrain`s is used as | ||
| If None, the minimum `t_stop` of all :class:`neo.core.SpikeTrain` s is used as | ||
CozySocksAlways marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| `t_stop`. | ||
| Default: None | ||
| output : {'counts', 'mean', 'rate'}, optional | ||
| Normalization of the histogram. Can be one of: | ||
| * 'counts': spike counts at each bin (as integer numbers). | ||
| * 'mean': mean spike counts per spike train. | ||
| * 'rate': mean spike rate per spike train. Like 'mean', but the | ||
| counts are additionally normalized by the bin width. | ||
|
|
||
| - 'counts': spike counts at each bin (as integer numbers). | ||
| - 'mean': mean spike counts per spike train. | ||
| - 'rate': mean spike rate per spike train. Like 'mean', but the counts are additionally normalized | ||
| by the bin width. | ||
|
|
||
| Default: 'counts' | ||
| binary : bool, optional | ||
| If True, indicates whether all `neo.SpikeTrain` objects should first | ||
| If True, indicates whether all :class:`neo.core.SpikeTrain` objects should first | ||
| be binned to a binary representation (using the | ||
| `conversion.BinnedSpikeTrain` class) and the calculation of the | ||
| [:class:`elephant.conversion.BinnedSpikeTrain` class] and the calculation of the | ||
|
||
| histogram is based on this representation. | ||
| Note that the output is not binary, but a histogram of the converted, | ||
| binary representation. | ||
|
|
@@ -1110,8 +1115,8 @@ def time_histogram(spiketrains, bin_size, t_start=None, t_stop=None, | |
| Returns | ||
| ------- | ||
| neo.AnalogSignal | ||
| A `neo.AnalogSignal` object containing the histogram values. | ||
| `neo.AnalogSignal[j]` is the histogram computed between | ||
| A :class:`neo.core.SpikeTrain` object containing the histogram values. | ||
CozySocksAlways marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| :class:`neo.core.SpikeTrain `[j]` is the histogram computed between | ||
| `t_start + j * bin_size` and `t_start + (j + 1) * bin_size`. | ||
|
|
||
| Raises | ||
|
|
@@ -1129,7 +1134,7 @@ def time_histogram(spiketrains, bin_size, t_start=None, t_stop=None, | |
|
|
||
| See also | ||
| -------- | ||
| elephant.conversion.BinnedSpikeTrain | ||
| :func:`elephant.conversion.BinnedSpikeTrain` | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
@@ -1178,17 +1183,17 @@ def time_histogram(spiketrains, bin_size, t_start=None, t_stop=None, | |
|
|
||
| def _counts() -> pq.Quantity: | ||
| # 'counts': spike counts at each bin (as integer numbers). | ||
| return pq.Quantity(bin_hist, units=pq.dimensionless, copy=False) | ||
| return pq.Quantity(bin_hist, units=pq.dimensionless) | ||
|
|
||
| def _mean() -> pq.Quantity: | ||
| # 'mean': mean spike counts per spike train. | ||
| return pq.Quantity(bin_hist / len(spiketrains), | ||
| units=pq.dimensionless, copy=False) | ||
| return pq.Quantity(bin_hist / binned_spiketrain.shape[0], | ||
CozySocksAlways marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| units=pq.dimensionless) | ||
|
|
||
| def _rate() -> pq.Quantity: | ||
| # 'rate': mean spike rate per spike train. Like 'mean', but the | ||
| # counts are additionally normalized by the bin width. | ||
| return bin_hist / (len(spiketrains) * bin_size) | ||
| return bin_hist / (binned_spiketrain.shape[0] * bin_size) | ||
|
|
||
| output_mapping = {"counts": _counts, "mean": _mean, "rate": _rate} | ||
| try: | ||
|
|
||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.