def __new__(cls, image_data, units=None, dtype=None, copy=True, spatial_scale=None, sampling_period=None, sampling_rate=None, name=None, description=None, file_origin=None, **annotations): """ Constructs new :class:`ImageSequence` from data. This is called whenever a new class:`ImageSequence` is created from the constructor, but not when slicing. __array_finalize__ is called on the new object. """ if spatial_scale is None: raise ValueError('spatial_scale is required') image_data = np.stack(image_data) if len(image_data.shape) != 3: raise ValueError('list doesn\'t have the good number of dimension') obj = pq.Quantity(image_data, units=units, dtype=dtype, copy=copy).view(cls) obj.segment = None # function from analogsignal.py in neo/core directory obj.sampling_rate = _get_sampling_rate(sampling_rate, sampling_period) obj.spatial_scale = spatial_scale return obj
def __new__(cls, signal, units=None, dtype=None, copy=True, t_start=0 * pq.s, sampling_rate=None, sampling_period=None, name=None, file_origin=None, description=None, channel_index=None, **annotations): ''' Constructs new :class:`AnalogSignalArray` from data. This is called whenever a new class:`AnalogSignalArray` is created from the constructor, but not when slicing. ''' if (isinstance(signal, pq.Quantity) and units is not None and units != signal.units): signal = signal.rescale(units) if not units and hasattr(signal, "units"): units = signal.units obj = pq.Quantity.__new__(cls, signal, units=units, dtype=dtype, copy=copy) obj.t_start = t_start obj.sampling_rate = _get_sampling_rate(sampling_rate, sampling_period) obj.channel_index = channel_index obj.segment = None obj.recordingchannelgroup = None return obj
def __new__(cls, signal, units=None, dtype=None, copy=True, t_start=0 * pq.s, sampling_rate=None, sampling_period=None, name=None, file_origin=None, description=None, channel_index=None, **annotations): ''' Constructs new :class:`AnalogSignalArray` from data. This is called whenever a new class:`AnalogSignalArray` is created from the constructor, but not when slicing. ''' if (isinstance(signal, pq.Quantity) and units is not None and units != signal.units): signal = signal.rescale(units) if not units and hasattr(signal, "units"): units = signal.units obj = pq.Quantity.__new__(cls, signal, units=units, dtype=dtype, copy=copy) obj.t_start = t_start obj.sampling_rate = _get_sampling_rate(sampling_rate, sampling_period) obj.channel_index = channel_index obj.segment = None obj.recordingchannelgroup = None return obj
def __new__(cls, signal, units=None, dtype=None, copy=True, t_start=0 * pq.s, sampling_rate=None, sampling_period=None, name=None, file_origin=None, description=None, channel_index=None, **annotations): ''' Constructs new :class:`AnalogSignalArray` from data. This is called whenever a new class:`AnalogSignalArray` is created from the constructor, but not when slicing. ''' if units is None: if not hasattr(signal, "units"): raise ValueError("Units must be specified") elif isinstance(signal, pq.Quantity): # could improve this test, what if units is a string? if units != signal.units: signal = signal.rescale(units) obj = pq.Quantity(signal, units=units, dtype=dtype, copy=copy).view(cls) obj.t_start = t_start obj.sampling_rate = _get_sampling_rate(sampling_rate, sampling_period) obj.channel_index = channel_index obj.segment = None obj.recordingchannelgroup = None return obj
def test___get_sampling_rate__period_rate_equivalent(self): sampling_rate = pq.Quantity(10., units=pq.Hz) sampling_period = pq.Quantity(0.1, units=pq.s) targ_rate = sampling_rate out_rate = _get_sampling_rate(sampling_rate, sampling_period) self.assertEqual(targ_rate, out_rate)
def test___get_sampling_rate__period_none_rate_quant(self): sampling_rate = pq.Quantity(10., units=pq.Hz) sampling_period = None targ_rate = sampling_rate out_rate = _get_sampling_rate(sampling_rate, sampling_period) self.assertEqual(targ_rate, out_rate)
def test___get_sampling_rate__period_quant_rate_none(self): sampling_rate = None sampling_period = pq.Quantity(10., units=pq.s) targ_rate = 1 / sampling_period out_rate = _get_sampling_rate(sampling_rate, sampling_period) self.assertEqual(targ_rate, out_rate)
def test___get_sampling_rate__period_rate_equivalent(self): sampling_rate = pq.Quantity(10., units=pq.Hz) sampling_period = pq.Quantity(0.1, units=pq.s) targ_rate = sampling_rate out_rate = _get_sampling_rate(sampling_rate, sampling_period) self.assertEqual(targ_rate, out_rate)
def test___get_sampling_rate__period_none_rate_quant(self): sampling_rate = pq.Quantity(10., units=pq.Hz) sampling_period = None targ_rate = sampling_rate out_rate = _get_sampling_rate(sampling_rate, sampling_period) self.assertEqual(targ_rate, out_rate)
def test___get_sampling_rate__period_quant_rate_none(self): sampling_rate = None sampling_period = pq.Quantity(10., units=pq.s) targ_rate = 1/sampling_period out_rate = _get_sampling_rate(sampling_rate, sampling_period) self.assertEqual(targ_rate, out_rate)