Ejemplo n.º 1
0
class NestCurrentSource(BaseCurrentSource):
    """Base class for a nest source of current to be injected into a neuron."""
    def __init__(self, **parameters):
        self._device = nest.Create(self.nest_name)
        self.cell_list = []
        self.parameter_space = ParameterSpace(self.default_parameters,
                                              self.get_schema(),
                                              shape=(1, ))
        if parameters:
            self.parameter_space.update(**parameters)

        self.min_delay = state.min_delay
        self.dt = state.dt

    def inject_into(self, cells):
        for id in cells:
            if id.local and not id.celltype.injectable:
                raise TypeError("Can't inject current into a spike source.")
        if isinstance(cells, (Population, PopulationView, Assembly)):
            self.cell_list = [cell for cell in cells]
        else:
            self.cell_list = cells
        nest.Connect(self._device,
                     self.cell_list,
                     syn_spec={"delay": state.min_delay})

    def _delay_correction(self, value):
        """
        A change in a device requires a min_delay to take effect at the target
        """
        corrected = value - self.min_delay
        # set negative times to zero
        if isinstance(value, numpy.ndarray):
            corrected = numpy.where(corrected > 0, corrected, 0.0)
        else:
            corrected = max(corrected, 0.0)
        return corrected

    def record(self):
        self.i_multimeter = nest.Create('multimeter',
                                        params={
                                            'record_from': ['I'],
                                            'interval': state.dt
                                        })
        nest.Connect(self.i_multimeter, self._device)

    def _get_data(self):
        events = nest.GetStatus(self.i_multimeter)[0]['events']
        # Similar to recording.py: NEST does not record values at
        # the zeroth time step, so we add them here.
        t_arr = numpy.insert(numpy.array(events['times']), 0, 0.0)
        i_arr = numpy.insert(numpy.array(events['I'] / 1000.0), 0, 0.0)
        # NEST and pyNN have different concepts of current initiation times
        # To keep this consistent across simulators, we will have current
        # initiating at the electrode at t_start and effect on cell at next dt
        # This requires padding min_delay equivalent period with 0's
        pad_length = int(self.min_delay / self.dt)
        i_arr = numpy.insert(i_arr[:-pad_length], 0, [0] * pad_length)
        return t_arr, i_arr
Ejemplo n.º 2
0
 def __init__(self, **parameters):
     self._device   = nest.Create(self.nest_name)
     self.cell_list = []
     parameter_space = ParameterSpace(self.default_parameters,
                                      self.get_schema(),
                                      shape=(1,))
     parameter_space.update(**parameters)
     parameter_space = self.translate(parameter_space)
     self.set_native_parameters(parameter_space)
Ejemplo n.º 3
0
class BaseModelType(object):
    """Base class for standard and native cell and synapse model classes."""
    default_parameters = {}
    default_initial_values = {}
    parameter_checks = {}

    def __init__(self, **parameters):
        """
        `parameters` should be a mapping object, e.g. a dict
        """
        self.parameter_space = ParameterSpace(self.default_parameters,
                                              self.get_schema(),
                                              shape=None)
        if parameters:
            self.parameter_space.update(**parameters)

    def __repr__(self):
        # should really include the parameters explicitly, to be unambiguous
        return "%s(<parameters>)" % self.__class__.__name__

    @classmethod
    def has_parameter(cls, name):
        """Does this model have a parameter with the given name?"""
        return name in cls.default_parameters

    @classmethod
    def get_parameter_names(cls):
        """Return the names of the parameters of this model."""
        return list(cls.default_parameters.keys())

    def get_schema(self):
        """
        Returns the model schema: i.e. a mapping of parameter names to allowed
        parameter types.
        """
        return dict((name, type(value))
                    for name, value in self.default_parameters.items())

    def describe(self, template='modeltype_default.txt', engine='default'):
        """
        Returns a human-readable description of the cell or synapse type.

        The output may be customized by specifying a different template
        togther with an associated template engine (see ``pyNN.descriptions``).

        If template is None, then a dictionary containing the template context
        will be returned.
        """
        context = {
            "name": self.__class__.__name__,
            "default_parameters": self.default_parameters,
            "default_initial_values": self.default_initial_values,
            "parameters": self.parameter_space.
            _parameters,  # should add a describe() method to ParameterSpace
        }
        return descriptions.render(engine, template, context)
Ejemplo n.º 4
0
 def parameter_space(self):
     timing_parameters = self.timing_dependence.parameter_space
     weight_parameters = self.weight_dependence.parameter_space
     parameters = ParameterSpace({'weight': self.weight,
                                  'delay': self.delay,
                                  'dendritic_delay_fraction': self.dendritic_delay_fraction},
                                 self.get_schema())
     parameters.update(**timing_parameters)
     parameters.update(**weight_parameters)
     return parameters
Ejemplo n.º 5
0
 def parameter_space(self):
     timing_parameters = self.timing_dependence.parameter_space
     weight_parameters = self.weight_dependence.parameter_space
     parameters = ParameterSpace({'weight': self.weight,
                                  'delay': self.delay,
                                  'dendritic_delay_fraction': self.dendritic_delay_fraction},
                                 self.get_schema())
     parameters.update(**timing_parameters)
     parameters.update(**weight_parameters)
     return parameters
Ejemplo n.º 6
0
 def __init__(self, **parameters):
     super(StandardCurrentSource, self).__init__(**parameters)
     self.cell_list = []
     self.indices = []
     simulator.state.current_sources.append(self)
     parameter_space = ParameterSpace(self.default_parameters,
                                      self.get_schema(),
                                      shape=(1, ))
     parameter_space.update(**parameters)
     parameter_space = self.translate(parameter_space)
     self.set_native_parameters(parameter_space)
Ejemplo n.º 7
0
 def __init__(self, **parameters):
     super(StandardCurrentSource, self).__init__(**parameters)
     self.cell_list = []
     self.indices = []
     simulator.state.current_sources.append(self)
     parameter_space = ParameterSpace(self.default_parameters,
                                      self.get_schema(),
                                      shape=(1,))
     parameter_space.update(**parameters)
     parameter_space = self.translate(parameter_space)
     self.set_native_parameters(parameter_space)
Ejemplo n.º 8
0
class BaseModelType(object):
    """Base class for standard and native cell and synapse model classes."""
    default_parameters = {}
    default_initial_values = {}
    parameter_checks = {}

    def __init__(self, **parameters):
        """
        `parameters` should be a mapping object, e.g. a dict
        """
        self.parameter_space = ParameterSpace(self.default_parameters,
                                              self.get_schema(),
                                              shape=None)
        if parameters:
            self.parameter_space.update(**parameters)

    def __repr__(self):
        return "%s(<parameters>)" % self.__class__.__name__  # should really include the parameters explicitly, to be unambiguous

    @classmethod
    def has_parameter(cls, name):
        """Does this model have a parameter with the given name?"""
        return name in cls.default_parameters

    @classmethod
    def get_parameter_names(cls):
        """Return the names of the parameters of this model."""
        return list(cls.default_parameters.keys())

    def get_schema(self):
        """
        Returns the model schema: i.e. a mapping of parameter names to allowed
        parameter types.
        """
        return dict((name, type(value))
                    for name, value in self.default_parameters.items())

    def describe(self, template='modeltype_default.txt', engine='default'):
        """
        Returns a human-readable description of the cell or synapse type.

        The output may be customized by specifying a different template
        togther with an associated template engine (see ``pyNN.descriptions``).

        If template is None, then a dictionary containing the template context
        will be returned.
        """
        context = {
            "name": self.__class__.__name__,
            "default_parameters": self.default_parameters,
            "default_initial_values": self.default_initial_values,
            "parameters": self.parameter_space._parameters,  # should add a describe() method to ParameterSpace
        }
        return descriptions.render(engine, template, context)
Ejemplo n.º 9
0
class NestCurrentSource(BaseCurrentSource):
    """Base class for a nest source of current to be injected into a neuron."""

    def __init__(self, **parameters):
        self._device = nest.Create(self.nest_name)
        self.cell_list = []
        self.parameter_space = ParameterSpace(self.default_parameters,
                                              self.get_schema(),
                                              shape=(1,))
        if parameters:
            self.parameter_space.update(**parameters)

        self.min_delay = state.min_delay
        self.dt = state.dt

    def inject_into(self, cells):
        for id in cells:
            if id.local and not id.celltype.injectable:
                raise TypeError("Can't inject current into a spike source.")
        if isinstance(cells, (Population, PopulationView, Assembly)):
            self.cell_list = [cell for cell in cells]
        else:
            self.cell_list = cells
        nest.Connect(self._device, self.cell_list, syn_spec={"delay": state.min_delay})

    def _delay_correction(self, value):
        """
        A change in a device requires a min_delay to take effect at the target
        """
        corrected = value - self.min_delay
        # set negative times to zero
        if isinstance(value, numpy.ndarray):
            corrected = numpy.where(corrected > 0, corrected, 0.0)
        else:
            corrected = max(corrected, 0.0)
        return corrected

    def record(self):
        self.i_multimeter = nest.Create('multimeter', params={'record_from': ['I'], 'interval': state.dt})
        nest.Connect(self.i_multimeter, self._device)

    def _get_data(self):
        events = nest.GetStatus(self.i_multimeter)[0]['events']
        # Similar to recording.py: NEST does not record values at
        # the zeroth time step, so we add them here.
        t_arr = numpy.insert(numpy.array(events['times']), 0, 0.0)
        i_arr = numpy.insert(numpy.array(events['I']/1000.0), 0, 0.0)
        # NEST and pyNN have different concepts of current initiation times
        # To keep this consistent across simulators, we will have current
        # initiating at the electrode at t_start and effect on cell at next dt
        # This requires padding min_delay equivalent period with 0's
        pad_length = int(self.min_delay/self.dt)
        i_arr = numpy.insert(i_arr[:-pad_length], 0, [0]*pad_length)
        return t_arr, i_arr
Ejemplo n.º 10
0
 def __init__(self, **parameters):
     self._devices = []
     self.cell_list = []
     self._amplitudes = None
     self._times = None
     self._h_iclamps = {}
     parameter_space = ParameterSpace(self.default_parameters,
                                      self.get_schema(),
                                      shape=(1, ))
     parameter_space.update(**parameters)
     parameter_space = self.translate(parameter_space)
     self.set_native_parameters(parameter_space)
Ejemplo n.º 11
0
 def __init__(self, **parameters):
     self._devices    = []
     self.cell_list   = []
     self._amplitudes = None
     self._times      = None
     self._h_iclamps  = {}
     parameter_space = ParameterSpace(self.default_parameters,
                                      self.get_schema(),
                                      shape=(1,))
     parameter_space.update(**parameters)
     parameter_space = self.translate(parameter_space)
     self.set_native_parameters(parameter_space)
Ejemplo n.º 12
0
 def __init__(self, **parameters):
     super(StandardCurrentSource, self).__init__(**parameters)
     global current_sources
     self.cell_list = []
     self.indices   = []
     self.ind = len(current_sources) # Todo use self.indices instead...
     current_sources.append(self)
     parameter_space = ParameterSpace(self.default_parameters,
                                      self.get_schema(),
                                      shape=(1,))
     parameter_space.update(**parameters)
     parameter_space = self.translate(parameter_space)
     self.set_native_parameters(parameter_space)