How to use the quantities.s function in quantities

To help you get started, we’ve selected a few quantities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NeuralEnsemble / python-neo / neo / io / asciispiketrainio.py View on Github external
def read_segment(self,
                     lazy=False,
                     delimiter='\t',
                     t_start=0. * pq.s,
                     unit=pq.s,
                     ):
        """
        Arguments:
            delimiter  :  columns delimiter in file  '\t' or one space or two space or ',' or ';'
            t_start : time start of all spiketrain 0 by default
            unit : unit of spike times, can be a str or directly a Quantities
        """
        assert not lazy, 'Do not support lazy'

        unit = pq.Quantity(1, unit)

        seg = Segment(file_origin=os.path.basename(self.filename))

        f = open(self.filename, 'Ur')
        for i, line in enumerate(f):
            alldata = line[:-1].split(delimiter)
github NeuralEnsemble / python-neo / neo / core / spike.py View on Github external
    def __init__(self, time=0 * pq.s, waveform=None, sampling_rate=None,
                 left_sweep=None, name=None, description=None,
                 file_origin=None, **annotations):
        '''
        Initialize a new :class:`Spike` instance.
        '''
        BaseNeo.__init__(self, name=name, file_origin=file_origin,
                         description=description, **annotations)

        self.time = time

        self.waveform = waveform
        self.left_sweep = left_sweep
        self.sampling_rate = sampling_rate

        self.segment = None
        self.unit = None
github NeuralEnsemble / python-neo / examples / generated_data.py View on Github external
for rc in chx.recordingchannels:
            sig = np.random.randn(data_samples)
            sig[feature_pos:feature_pos + feature_samples] += wave

            signal = neo.AnalogSignal(sig * pq.mV, sampling_rate=1 * pq.kHz)
            seg.analogsignals.append(signal)
            rc.analogsignals.append(signal)

        # Spike trains: Random spike times with elevated rate in short period
        feature_time = feature_pos / data_samples
        for u in units:
            random_spikes = np.random.rand(20)
            feature_spikes = np.random.rand(5) * feature_len + feature_time
            spikes = np.hstack([random_spikes, feature_spikes])

            train = neo.SpikeTrain(spikes * pq.s, 1 * pq.s)
            seg.spiketrains.append(train)
            u.spiketrains.append(train)

    block.create_many_to_one_relationship()
    return block
github NeuralEnsemble / python-neo / neo / core / epoch.py View on Github external
def __new__(cls, times=None, durations=None, labels=None, units=None, name=None,
                description=None, file_origin=None, array_annotations=None, **annotations):
        if times is None:
            times = np.array([]) * pq.s
        if durations is None:
            durations = np.array([]) * pq.s
        elif durations.size != times.size:
            if durations.size == 1:
                durations = durations * np.ones_like(times.magnitude)
            else:
                raise ValueError("Durations array has different length to times")
        if labels is None:
            labels = np.array([], dtype='S')
        elif len(labels) != times.size:
            raise ValueError("Labels array has different length to times")
        if units is None:
            # No keyword units, so get from `times`
            try:
                units = times.units
                dim = units.dimensionality
github antolikjan / mozaik / mozaik / visualization / simple_plot.py View on Github external
def plot(self):
        if self.parameters["colors"] == None:
            colors = ['#000000' for i in xrange(0, len(self.sps))]
        else:
            colors = self.colors

        neurons = [i for i in xrange(0, len(self.sps[0][0]))]
        
        t_start = float(self.sps[0][0][0].t_start.rescale(pq.s))
        t_stop = float(self.sps[0][0][0].t_stop.rescale(pq.s))
        
        
        num_n = len(neurons)  # number of neurons
        num_t = len(self.sps[0])  # number of trials

        for k, sp in enumerate(self.sps):
            for j, n in enumerate(neurons):
                if self.group_trials:
                   train = []
                   for i, spike_list in enumerate(sp):
                       train.extend(spike_list[n].rescale(pq.s))
                   self.axis.plot(train,[j for x in xrange(0, len(train))],'|',color=colors[k],mew=1)
                else:
                    for i, spike_list in enumerate(sp):
                        spike_train = spike_list[n].rescale(pq.s)
                        self.axis.plot(spike_train,
github antolikjan / mozaik / mozaik / storage / neo_neurotools_wrapper.py View on Github external
def mean_rates(self,start=None,end=None):
            """
            Returns the mean rates of the spiketrains in spikes/s.
            """
            if start != None:
                start = start.rescale(qt.s)
                end = end.rescale(qt.s)
                return [len(s.time_slice(start,end))/(end.magnitude-start.magnitude) for s in self.spiketrains]
            else:
               return [len(s)/(s.t_stop.rescale(qt.s).magnitude-s.t_start.rescale(qt.s).magnitude) for s in self.spiketrains]
github antolikjan / mozaik / mozaik / storage / neo_neurotools_wrapper.py View on Github external
def mean_rates(self,start=None,end=None):
            """
            Returns the mean rates of the spiketrains in spikes/s.
            """
            if start != None:
                start = start.rescale(qt.s)
                end = end.rescale(qt.s)
                return [len(s.time_slice(start,end))/(end.magnitude-start.magnitude) for s in self.spiketrains]
            else:
               return [len(s)/(s.t_stop.rescale(qt.s).magnitude-s.t_start.rescale(qt.s).magnitude) for s in self.spiketrains]
github NeuralEnsemble / python-neo / neo / io / brainwaresrcio.py View on Github external
times = []
        labels = []
        senders = []
        for event in events:
            times.append(event.times.magnitude)
            if event.labels.shape == (1,):
                labels.append(event.labels[0])
            else:
                raise AssertionError("This single event has multiple labels in an array with "
                                     "shape {} instead of a single label.".
                                     format(event.labels.shape))
            senders.append(event.annotations['sender'])

        times = np.array(times, dtype=np.float32)
        t_start = times.min()
        times = pq.Quantity(times - t_start, units=pq.d).rescale(pq.s)

        labels = np.array(labels)
        senders = np.array(senders)

        event = Event(times=times, labels=labels,
                      t_start=t_start.tolist(), senders=senders)

        return event
github NeuralEnsemble / python-neo / neo / io / brainwaredamio.py View on Github external
# float32 * numelements -- the values for the stimulus parameters
        paramvalues = np.fromfile(fobject, dtype=np.float32, count=numelements)

        # combine parameter names and the parameters as a dict
        params = dict(zip(paramnames, paramvalues))

        # int32 -- the number elements in the AnalogSignal
        numpts = np.fromfile(fobject, dtype=np.int32, count=1)[0]

        # int16 * numpts -- the AnalogSignal itself
        signal = np.fromfile(fobject, dtype=np.int16, count=numpts)

        sig = AnalogSignal(signal.astype(np.float)*pq.mV,
                           t_start=t_start*pq.d,
                           file_origin=self._filename,
                           sampling_period=1.*pq.s,
                           copy=False)
        # Note: setting the sampling_period to 1 s is arbitrary

        # load the AnalogSignal and parameters into a new Segment
        seg = Segment(file_origin=self._filename,
                      index=seg_index,
                      **params)
        seg.analogsignals = [sig]

        return seg
github jkitchin / pycse / pycse / qmath.py View on Github external
else:
        uY = y * y0.units

    y = uY

    if full_output:
        return y, infodict
    else:
        return y


if __name__ == '__main__':
    # Problem 1
    CA0 = 1 * u.mol / u.L
    CA = 0.01 * u.mol / u.L
    k = 1.0 / u.s

    def func(t):
        return CA - CA0 * np.exp(-k * t)

    tguess = 4 * u.s
    sol1, = fsolve(func, tguess)
    print('sol1 = ', sol1)

    # Problem 2
    def func2(X):
        a, b = X
        return [a**2 - 4 * u.kg**2,
                b**2 - 25 * u.J**2]

    Xguess = [2.2*u.kg, 5.2*u.J]
    sol, infodict, ier, mesg = fsolve(func2, Xguess, full_output=1)