Skip to content

Commit 1af517c

Browse files
Merge pull request #1171 from apdavison/epoch-duration-float
Allow epoch duration to be a float
2 parents 714c9c2 + ff1efbf commit 1af517c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

neo/core/epoch.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'''
77

88
from copy import deepcopy, copy
9+
from numbers import Number
910

1011
import numpy as np
1112
import quantities as pq
@@ -53,10 +54,12 @@ class Epoch(DataObject):
5354
*Required attributes/properties*:
5455
:times: (quantity array 1D, numpy array 1D or list) The start times
5556
of each time period.
56-
:durations: (quantity array 1D, numpy array 1D, list, or quantity scalar)
57+
:durations: (quantity array 1D, numpy array 1D, list, quantity scalar or float)
5758
The length(s) of each time period.
58-
If a scalar, the same value is used for all time periods.
59+
If a scalar/float, the same value is used for all time periods.
5960
:labels: (numpy.array 1D dtype='U' or list) Names or labels for the time periods.
61+
:units: (quantity units or str) Required if the times is a list or NumPy
62+
array, not if it is a :class:`Quantity`
6063
6164
*Recommended attributes/properties*:
6265
:name: (str) A label for the dataset,
@@ -88,8 +91,10 @@ def __new__(cls, times=None, durations=None, labels=None, units=None, name=None,
8891
raise ValueError("Times array has more than 1 dimension")
8992
if isinstance(durations, (list, tuple)):
9093
durations = np.array(durations)
91-
if durations is None:
94+
elif durations is None:
9295
durations = np.array([]) * pq.s
96+
elif isinstance(durations, Number):
97+
durations = durations * np.ones(times.shape)
9398
elif durations.size != times.size:
9499
if durations.size == 1:
95100
durations = durations * np.ones_like(times.magnitude)

0 commit comments

Comments
 (0)