|
6 | 6 | ''' |
7 | 7 |
|
8 | 8 | from copy import deepcopy, copy |
| 9 | +from numbers import Number |
9 | 10 |
|
10 | 11 | import numpy as np |
11 | 12 | import quantities as pq |
@@ -53,10 +54,12 @@ class Epoch(DataObject): |
53 | 54 | *Required attributes/properties*: |
54 | 55 | :times: (quantity array 1D, numpy array 1D or list) The start times |
55 | 56 | 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) |
57 | 58 | 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. |
59 | 60 | :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` |
60 | 63 |
|
61 | 64 | *Recommended attributes/properties*: |
62 | 65 | :name: (str) A label for the dataset, |
@@ -88,8 +91,10 @@ def __new__(cls, times=None, durations=None, labels=None, units=None, name=None, |
88 | 91 | raise ValueError("Times array has more than 1 dimension") |
89 | 92 | if isinstance(durations, (list, tuple)): |
90 | 93 | durations = np.array(durations) |
91 | | - if durations is None: |
| 94 | + elif durations is None: |
92 | 95 | durations = np.array([]) * pq.s |
| 96 | + elif isinstance(durations, Number): |
| 97 | + durations = durations * np.ones(times.shape) |
93 | 98 | elif durations.size != times.size: |
94 | 99 | if durations.size == 1: |
95 | 100 | durations = durations * np.ones_like(times.magnitude) |
|
0 commit comments