How to use the quantities.ms 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 / PyNN / test / unittests / test_populationview.py View on Github external
# but then need to make sure we get the right initial value
        sim.run(t2)
        sim.reset()
        pv.record('spikes')
        pv.record('w')
        sim.run(t3)
        data = p.get_data(gather=True)
        self.assertEqual(len(data.segments), 2)

        seg0 = data.segments[0]
        self.assertEqual(len(seg0.analogsignals), 1)
        v = seg0.analogsignals[0]
        self.assertEqual(v.name, 'v')
        num_points = int(round((t1 + t2) / sim.get_time_step())) + 1
        self.assertEqual(v.shape, (num_points, pv.size))
        self.assertEqual(v.t_start, 0.0 * pq.ms)
        self.assertEqual(v.units, pq.mV)
        self.assertEqual(v.sampling_period, 0.1 * pq.ms)
        self.assertEqual(len(seg0.spiketrains), 0)

        seg1 = data.segments[1]
        self.assertEqual(len(seg1.analogsignals), 2)
        w = seg1.filter(name='w')[0]
        self.assertEqual(w.name, 'w')
        num_points = int(round(t3 / sim.get_time_step())) + 1
        self.assertEqual(w.shape, (num_points, pv.size))
        self.assertEqual(v.t_start, 0.0)
        self.assertEqual(len(seg1.spiketrains), pv.size)
github NeuralEnsemble / PyNN / test / system / test_neuron.py View on Github external
connector = nrn.AllToAllConnector()
    syn = nrn.StaticSynapse(weight=0.1)
    prj_alpha = nrn.Projection(p2, p1, connector, syn, receptor_type='apical.ampa')

    nrn.run(250.0)

    data = p1.get_data().segments[0].analogsignals
    assert_equal(len(data), 2)  # one array per variable
    assert_equal(data[0].name, 'apical(1.0).v')
    assert_equal(data[1].name, 'soma(0.5).ina')
    assert_equal(data[0].sampling_rate, 10.0 * pq.kHz)
    assert_equal(data[0].units, pq.mV)
    assert_equal(data[1].units, pq.mA / pq.cm**2)
    assert_equal(data[0].t_start, 0.0 * pq.ms)
    assert_equal(data[0].t_stop, 250.1 * pq.ms)  # would prefer if it were 250.0, but this is a fundamental Neo issue
    assert_equal(data[0].shape, (2501, 10))
    return data
github NeuralEnsemble / elephant / elephant / unitary_event_analysis.py View on Github external
def _winpos(t_start, t_stop, winsize, winstep, position='left-edge'):
    """
    Calculates the position of the analysis window
    """
    t_start_dl = t_start.rescale('ms').magnitude
    t_stop_dl = t_stop.rescale('ms').magnitude
    winsize_dl = winsize.rescale('ms').magnitude
    winstep_dl = winstep.rescale('ms').magnitude

    # left side of the window time
    if position == 'left-edge':
        ts_winpos = np.arange(
            t_start_dl, t_stop_dl - winsize_dl + winstep_dl,
            winstep_dl) * pq.ms
    else:
        raise ValueError(
            'the current version only returns left-edge of the window')
    return ts_winpos
github antolikjan / mozaik / mozaik / analysis / analysis.py View on Github external
      @staticmethod
      def _remove_spikes(vm,spike_train,window_length):
          new_vm=vm[:]
          assert (window_length - int((window_length / vm.sampling_period.rescale(qt.ms).magnitude)) * vm.sampling_period.rescale(qt.ms).magnitude) < 0.00000000000001, ("%f" % (window_length % vm.sampling_period.rescale(qt.ms).magnitude))
          for spike_time in spike_train:
              spike_time_in_vm = int(spike_time / vm.sampling_period)
              # we assume spike_time and sampling rates are in ms
              window_end = spike_time_in_vm+int(round(window_length/vm.sampling_period.rescale(qt.ms).magnitude))
              if window_end >= len(vm):
                 window_end = len(vm)-1
              if spike_time_in_vm != 0:
                new_vm[spike_time_in_vm:window_end] = vm[spike_time_in_vm-1] + (vm[window_end]-vm[spike_time_in_vm-1])*numpy.linspace(0,1.0,(window_end-spike_time_in_vm)+2)[1:-1,numpy.newaxis]
              else:
                new_vm[spike_time_in_vm:window_end] = vm[spike_time_in_vm] + (vm[window_end]-vm[spike_time_in_vm])*numpy.linspace(0,1.0,(window_end-spike_time_in_vm)+2)[1:-1,numpy.newaxis]
          return new_vm
github rproepp / spykeviewer / spykeviewer / plugins / Spike Trains / sde.py View on Github external
def __init__(self):
        super(SDEPlugin, self).__init__()
        self.unit = pq.ms
github antolikjan / mozaik / mozaik / analysis / helper_functions.py View on Github external
----
    The spiketrains are assumed to start and stop at the same time!
    """
    t_start = round(spike_list[0].t_start.rescale(qt.ms),5)
    t_stop = round(spike_list[0].t_stop.rescale(qt.ms),5)
    num_bins = int(round((t_stop-t_start)/bin_length))
    r = (float(t_start), float(t_stop))

    for sp in spike_list:
        assert len(numpy.histogram(sp, bins=num_bins, range=r)[0]) == num_bins
        
    normalizer = 1.0
    if normalize:
       normalizer = (bin_length/1000.0)
       
    h = [AnalogSignal(numpy.histogram(sp, bins=num_bins, range=r)[0] /normalizer ,t_start=t_start*qt.ms,sampling_period=bin_length*qt.ms,units=munits.spike_per_sec) for sp in spike_list]
    return  h
github NeuralEnsemble / python-neo / neo / io / pynnio.py View on Github external
Supported: Read/Write

Authors: Andrew Davison, Pierre Yger
"""

from __future__ import with_statement
from .baseio import BaseIO
from ..core import Segment, AnalogSignal, AnalogSignalArray, SpikeTrain
from .tools import create_many_to_one_relationship

import numpy
import quantities as pq

UNITS_MAP = {
    'spikes': pq.ms,
    'v': pq.mV,
    'gsyn': pq.UnitQuantity('microsiemens', 1e-9*pq.S, 'uS', 'µS'), # check
}


class BasePyNNIO(BaseIO):
    """
    Base class for PyNN IO classes
    """
    is_readable = True 
    is_writable = True
    has_header = True
    is_streameable = False # TODO - correct spelling to "is_streamable"
    supported_objects = [Segment, AnalogSignal, AnalogSignalArray, SpikeTrain]
    readable_objects = supported_objects
    writeable_objects = supported_objects
github NeuralEnsemble / PyNN / pyNN / recording / __init__.py View on Github external
def _get_current_segment(self, filter_ids=None, variables='all', clear=False):
        segment = neo.Segment(name="segment%03d" % self._simulator.state.segment_counter,
                              description=self.population.describe(),
                              rec_datetime=datetime.now())  # would be nice to get the time at the start of the recording, not the end
        variables_to_include = set(self.recorded.keys())
        if variables is not 'all':
            variables_to_include = variables_to_include.intersection(set(variables))
        for variable in variables_to_include:
            if variable == 'spikes':
                t_stop = self._simulator.state.t * pq.ms  # must run on all MPI nodes
                sids = sorted(self.filter_recorded('spikes', filter_ids))
                data = self._get_spiketimes(sids)

                segment.spiketrains = []
                for id in sids:
                    times = pq.Quantity(data.get(int(id), []), pq.ms)
                    if times.size > 0 and times.max() > t_stop:
                        warn("Recorded at least one spike after t_stop")
                        times = times[times <= t_stop]
                    segment.spiketrains.append(
                        neo.SpikeTrain(times,
                                       t_start=self._recording_start_time,
                                       t_stop=t_stop,
                                       units='ms',
                                       source_population=self.population.label,
                                       source_id=int(id),source_index=self.population.id_to_index(int(id)))
                    )
            else:
                ids = sorted(self.filter_recorded(variable, filter_ids))
                signal_array = self._get_all_signals(variable, ids, clear=clear)
                t_start = self._recording_start_time
                sampling_period = self.sampling_interval * pq.ms
github NeuralEnsemble / elephant / elephant / spike_train_generation.py View on Github external
def _mother_proc_cpp_stat(A, t_stop, rate, t_start=0 * ms):
    """
    Generate the hidden ("mother") Poisson process for a Compound Poisson
    Process (CPP).


    Parameters
    ----------
    A : numpy.array
        Amplitude distribution. A[j] represents the probability of a
        synchronous event of size j.
        The sum over all entries of a must be equal to one.
    t_stop : quantities.Quantity
        The stopping time of the mother process
    rate : quantities.Quantity
        Homogeneous rate of the n spike trains that will be genereted by the
        CPP function
github NeuralEnsemble / python-neo / neo / io / nestio.py View on Github external
    def read_block(self, gid_list=None, time_unit=pq.ms, t_start=None,
                   t_stop=None, sampling_period=None, id_column_dat=0,
                   time_column_dat=1, value_columns_dat=2,
                   id_column_gdf=0, time_column_gdf=1, value_types=None,
                   value_units=None, lazy=False):
        assert not lazy, 'Do not support lazy'

        seg = self.read_segment(gid_list, time_unit, t_start,
                                t_stop, sampling_period, id_column_dat,
                                time_column_dat, value_columns_dat,
                                id_column_gdf, time_column_gdf, value_types,
                                value_units)
        blk = Block(file_origin=seg.file_origin, file_datetime=seg.file_datetime)
        blk.segments.append(seg)
        seg.block = blk
        return blk