Skip to content

Commit

Permalink
add new flag ignore_shared_time to BinnedSpiketrain
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz-Alexander-Kern committed Aug 9, 2024
1 parent a2d2a93 commit a02a0d8
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions elephant/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ class BinnedSpikeTrain(object):
The sparse matrix format. By default, CSR format is used to perform
slicing and computations efficiently.
Default: 'csr'
ignore_shared_time : bool, optional
If True, check for binning outside of common interval is possible.
Raises
------
Expand Down Expand Up @@ -335,7 +337,8 @@ class BinnedSpikeTrain(object):
"""

def __init__(self, spiketrains, bin_size=None, n_bins=None, t_start=None,
t_stop=None, tolerance=1e-8, sparse_format="csr"):
t_stop=None, tolerance=1e-8, sparse_format="csr",
ignore_shared_time=False):
if sparse_format not in ("csr", "csc"):
raise ValueError(f"Invalid 'sparse_format': {sparse_format}. "
"Available: 'csr' and 'csc'")
Expand All @@ -352,6 +355,7 @@ def __init__(self, spiketrains, bin_size=None, n_bins=None, t_start=None,
self.n_bins = n_bins
self._bin_size = bin_size
self.units = None # will be set later
self.ignore_shared_time = ignore_shared_time
# Check all parameter, set also missing values
self._resolve_input_parameters(spiketrains)
# Now create the sparse matrix
Expand Down Expand Up @@ -531,14 +535,15 @@ def check_consistency():
tolerance = self.tolerance
if tolerance is None:
tolerance = 0
if self._t_start < start_shared - tolerance \
or self._t_stop > stop_shared + tolerance:
raise ValueError("'t_start' ({t_start}) or 't_stop' ({t_stop}) is "
"outside of the shared [{start_shared}, "
"{stop_shared}] interval".format(
t_start=self.t_start, t_stop=self.t_stop,
start_shared=start_shared,
stop_shared=stop_shared))
if not self.ignore_shared_time:
if self._t_start < start_shared - tolerance \
or self._t_stop > stop_shared + tolerance:
raise ValueError("'t_start' ({t_start}) or 't_stop' ({t_stop}) is "
"outside of the shared [{start_shared}, "
"{stop_shared}] interval".format(
t_start=self.t_start, t_stop=self.t_stop,
start_shared=start_shared,
stop_shared=stop_shared))

if self.n_bins is None:
# bin_size is provided
Expand Down

0 comments on commit a02a0d8

Please sign in to comment.