Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
if sampling_period is None:
if time_column is not None:
data_sampling = np.unique(
np.diff(sorted(np.unique(data[:, 1]))))
if len(data_sampling) > 1:
raise ValueError('Different sampling distances found in '
'data set (%s)' % data_sampling)
else:
dt = data_sampling[0]
else:
raise ValueError('Can not estimate sampling rate without time '
'column id provided.')
sampling_period = pq.CompoundUnit(str(dt) + '*'
+ time_unit.units.u_symbol)
elif not isinstance(sampling_period, pq.UnitQuantity):
raise ValueError("sampling_period is not specified as a unit.")
return sampling_period
__docformat__ = "restructuredtext en"
__all__ = ['a0', 'bohr_radius', 'h', 'planck', 'h_bar', 'reduced_planck',
'electronic_mass', 'Ry', 'rydberg', 'Kb', 'boltzmann']
import quantities as pq
h = pq.UnitQuantity("planck", 4.1356673310e-15 * pq.eV * pq.s)
""" Planck's constant. """
planck = h
""" Planck's constant. """
h_bar = pq.UnitQuantity("h_bar", h / 2e0 / pq.pi, symbol='h_bar')
""" Reduced Planck's constant. """
reduced_plank = h_bar
""" Reduced Planck's constant. """
Ry = pq.UnitQuantity('Rydberg', 0.5 * pq.hartree, symbol='Ry')
""" Rydberg energy units. """
rydberg = Ry
""" Rydberg energy units. """
a0 = pq.UnitQuantity('bohr_radius', 0.529177249 * pq.angstrom, symbol='a0')
""" Bohr radius, unit of length of atomic units. """
bohr_radius = a0
""" Bohr radius, unit of length of atomic units. """
emass = pq.UnitQuantity("electronic_mass", h_bar**2 / (2e0 * Ry * a0**2),
symbol='m_e')
""" Mass of the electron at rest.
The value is obtained from a formula. It comes close enough and makes the
Rydberg units consistent.
"""
import scipy.integrate as si
import scipy.signal as ss
import quantities as pq
import neo
#patch quantities with the SI unit Siemens if it does not exist
for symbol, prefix, definition, u_symbol in zip(
['siemens', 'S', 'mS', 'uS', 'nS', 'pS'],
['', '', 'milli', 'micro', 'nano', 'pico'],
[pq.A/pq.V, pq.A/pq.V, 'S', 'mS', 'uS', 'nS'],
[None, None, None, None, u'µS', None]):
if type(definition) is str:
definition = lastdefinition / 1000
if not hasattr(pq, symbol):
setattr(pq, symbol, pq.UnitQuantity(
prefix + 'siemens',
definition,
symbol=symbol,
u_symbol=u_symbol))
lastdefinition = definition
class CSD(object):
'''Base iCSD class'''
def __init__(self, lfp, f_type='gaussian', f_order=(3, 1)):
'''Initialize parent class iCSD
Parameters
----------
lfp : np.ndarray * quantity.Quantity
LFP signal of shape (# channels, # time steps)
import quantities as pq
import warnings
from neo.io.baseio import BaseIO
from neo.core import Segment, AnalogSignal, SpikeTrain
try:
unicode
PY2 = True
except NameError:
PY2 = False
UNITS_MAP = {
'spikes': pq.ms,
'v': pq.mV,
'gsyn': pq.UnitQuantity('microsiemens', 1e-6 * pq.S, 'uS', 'µS'), # checked
}
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, SpikeTrain]
readable_objects = supported_objects
writeable_objects = supported_objects
mode = 'file'
a0 = pq.UnitQuantity('bohr_radius', 0.529177249 * pq.angstrom, symbol='a0')
""" Bohr radius, unit of length of atomic units. """
bohr_radius = a0
""" Bohr radius, unit of length of atomic units. """
emass = pq.UnitQuantity("electronic_mass", h_bar**2 / (2e0 * Ry * a0**2),
symbol='m_e')
""" Mass of the electron at rest.
The value is obtained from a formula. It comes close enough and makes the
Rydberg units consistent.
"""
Kb = pq.UnitQuantity("boltzmann", 8.617 * pq.eV / pq.K, symbol='Kb')
""" Boltzmann's constant. """
boltzmann = Kb
""" Boltzmann's constant. """
reduced_reciprocal_au = pq.UnitQuantity("reduced_reciprocal_au",
2e0 * pq.pi / a0, symbol='2pi/a0')
if 'planck' not in pq.__dict__:
pq.planck = planck
if 'h_bar' not in pq.__dict__:
pq.h_bar = h_bar
if 'Ry' not in pq.__dict__:
pq.Ry = Ry
if 'a0' not in pq.__dict__:
pq.a0 = a0
if 'bohr_radius' not in pq.__dict__:
# .
###############################
""" Physical quantities.
Holds things related to physical quantities, eg atomic units using the
*quantities* package.
"""
__docformat__ = "restructuredtext en"
__all__ = ['a0', 'bohr_radius', 'h', 'planck', 'h_bar', 'reduced_planck',
'electronic_mass', 'Ry', 'rydberg', 'Kb', 'boltzmann']
import quantities as pq
h = pq.UnitQuantity("planck", 4.1356673310e-15 * pq.eV * pq.s)
""" Planck's constant. """
planck = h
""" Planck's constant. """
h_bar = pq.UnitQuantity("h_bar", h / 2e0 / pq.pi, symbol='h_bar')
""" Reduced Planck's constant. """
reduced_plank = h_bar
""" Reduced Planck's constant. """
Ry = pq.UnitQuantity('Rydberg', 0.5 * pq.hartree, symbol='Ry')
""" Rydberg energy units. """
rydberg = Ry
""" Rydberg energy units. """
a0 = pq.UnitQuantity('bohr_radius', 0.529177249 * pq.angstrom, symbol='a0')
""" Bohr radius, unit of length of atomic units. """
bohr_radius = a0
:copyright: Copyright 2006-2016 by the PyNN team, see AUTHORS.
:license: CeCILL, see LICENSE for details.
"""
import logging
import numpy
import quantities as pq
import brian2
from pyNN.core import is_listlike
from pyNN import recording
from . import simulator
mV = brian2.mV
ms = brian2.ms
uS = brian2.uS
pq.uS = pq.UnitQuantity('microsiemens', 1e-6 * pq.S, 'uS')
pq.nS = pq.UnitQuantity('nanosiemens', 1e-9 * pq.S, 'nS')
logger = logging.getLogger("PyNN")
class Recorder(recording.Recorder):
"""Encapsulates data and functions related to recording model variables."""
_simulator = simulator
def __init__(self, population=None, file=None):
__doc__ = recording.Recorder.__doc__
recording.Recorder.__init__(self, population, file)
self._devices = {} # defer creation until first call of record()
def _create_device(self, group, variable):
"""Create a Brian2 recording device."""
def patch_quantities():
"""patch quantities with the SI unit Siemens if it does not exist"""
for symbol, prefix, definition, u_symbol in zip(
['siemens', 'S', 'mS', 'uS', 'nS', 'pS'],
['', '', 'milli', 'micro', 'nano', 'pico'],
[pq.A / pq.V, pq.A / pq.V, 'S', 'mS', 'uS', 'nS'],
[None, None, None, None, u'µS', None]):
if type(definition) is str:
definition = lastdefinition / 1000
if not hasattr(pq, symbol):
setattr(pq, symbol, pq.UnitQuantity(
prefix + 'siemens',
definition,
symbol=symbol,
u_symbol=u_symbol))
lastdefinition = definition
return