Пример #1
0
    def __init__(self,
                 data,
                 clock=None,
                 timeunit=1 * usecond,
                 relative_time=True):
        if isinstance(data, str):
            l = data.split('.')
            ext = l[-1].strip('\n')
            if ext == 'aeidx':
                raise ValueError(
                    'Cannot create a single AERSpikeGeneratorGroup with aeidx files. Consider using load_AER first and manually create multiple AERSpikeGeneratorGroups.'
                )
            else:
                data = load_AER(data,
                                relative_time=relative_time,
                                check_sorted=True)
        if isinstance(data, SpikeMonitor):
            addr, time = zip(*data.spikes)
            addr = np.array(list(addr))
            timestamps = np.array(list(time))
        elif isinstance(data, tuple):
            addr, timestamps = data

        self.tmax = max(timestamps) * timeunit
        self._nspikes = len(addr)
        N = max(addr) + 1
        clock = guess_clock(clock)
        threshold = FastDCThreshold(addr, timestamps * timeunit, dt=clock.dt)
        NeuronGroup.__init__(self,
                             N,
                             model=LazyStateUpdater(),
                             threshold=threshold,
                             clock=clock)
Пример #2
0
 def __init__(self, threshold=1 * mvolt, refractory=1 * msecond, state=0, clock=None):
     self.threshold = threshold # Threshold value
     self.state = state
     clock = guess_clock(clock)
     self.refractory = int(refractory / clock.dt)
     # this assumes that if the state stays over the threshold, and say
     # refractory=5ms the user wants spiking at 0ms 5ms 10ms 15ms etc.
     if is_approx_equal(self.refractory * clock.dt, refractory) and self.refractory > 0:
         self.refractory -= 1
Пример #3
0
 def __init__(self, threshold=1 * mvolt, refractory=1 * msecond, state=0, clock=None):
     self.threshold = threshold # Threshold value
     self.state = state
     clock = guess_clock(clock)
     self.refractory = int(refractory / clock.dt)
     # this assumes that if the state stays over the threshold, and say
     # refractory=5ms the user wants spiking at 0ms 5ms 10ms 15ms etc.
     if is_approx_equal(self.refractory * clock.dt, refractory) and self.refractory > 0:
         self.refractory -= 1
Пример #4
0
 def set_clock(self):
     '''
     Sets the clock and checks that clocks of all groups are synchronized.
     '''
     if self.same_clocks():
         groups_and_operations=self.groups + self.operations
         if len(groups_and_operations)>0:
             self.clock = groups_and_operations[0].clock
         else:
             self.clock = guess_clock()
     else:
         raise TypeError, 'Clocks are not synchronized!' # other error type?
Пример #5
0
 def reinit(self, states=True):
     '''
     Resets the objects and clocks. If ``states=False`` it will not reinit
     the state variables.
     '''
     objs = self.groups + self.connections + self.operations
     if self.clock is not None:
         objs.append(self.clock)
     else:
         guess_clock(None).reinit()
     if hasattr(self, 'clocks'):
         objs.extend(self.clocks)
     for P in objs:
         if hasattr(P, 'reinit'):
             if isinstance(P, NeuronGroup):
                 try:
                     P.reinit(states=states)
                 except TypeError:
                     P.reinit()
             else:
                 P.reinit()
Пример #6
0
 def set_clock(self):
     '''
     Sets the clock and checks that clocks of all groups are synchronized.
     '''
     if self.same_clocks():
         groups_and_operations = self.groups + self.operations
         if len(groups_and_operations) > 0:
             self.clock = groups_and_operations[0].clock
         else:
             self.clock = guess_clock()
     else:
         raise TypeError, 'Clocks are not synchronized!'  # other error type?
Пример #7
0
 def reinit(self, states=True):
     '''
     Resets the objects and clocks. If ``states=False`` it will not reinit
     the state variables.
     '''
     objs = self.groups + self.connections + self.operations
     if self.clock is not None:
         objs.append(self.clock)
     else:
         guess_clock(None).reinit()
     if hasattr(self, 'clocks'):
         objs.extend(self.clocks)
     for P in objs:
         if hasattr(P, 'reinit'):
             if isinstance(P, NeuronGroup):
                 try:
                     P.reinit(states=states)
                 except TypeError:
                     P.reinit()
             else:
                 P.reinit()
Пример #8
0
 def __init__(self, data, clock = None, timeunit = 1*usecond, relative_time = True):
     if isinstance(data, str):
         l = data.split('.')
         ext = l[-1].strip('\n')
         if ext == 'aeidx':
             raise ValueError('Cannot create a single AERSpikeGeneratorGroup with aeidx files. Consider using load_AER first and manually create multiple AERSpikeGeneratorGroups.')
         else:
             data = load_AER(data, relative_time = relative_time, check_sorted = True)
     if isinstance(data, SpikeMonitor):
         addr, time = zip(*data.spikes)
         addr = np.array(list(addr))
         timestamps = np.array(list(time))
     elif isinstance(data, tuple):
         addr, timestamps = data
         
     self.tmax = max(timestamps)*timeunit
     self._nspikes = len(addr)
     N = max(addr) + 1
     clock = guess_clock(clock)
     threshold = FastDCThreshold(addr, timestamps*timeunit, dt = clock.dt)
     NeuronGroup.__init__(self, N, model = LazyStateUpdater(), threshold = threshold, clock = clock)
Пример #9
0
    def __init__(self,
                 morphology=None,
                 model=None,
                 threshold=None,
                 reset=NoReset(),
                 refractory=0 * ms,
                 level=0,
                 clock=None,
                 unit_checking=True,
                 compile=False,
                 freeze=False,
                 implicit=True,
                 Cm=0.9 * uF / cm**2,
                 Ri=150 * ohm * cm,
                 bc_type=2,
                 diffeq_nonzero=True):
        clock = guess_clock(clock)
        N = len(morphology)  # number of compartments

        if isinstance(model, str):
            model = Equations(model, level=level + 1)

        model += Equations('''
		v:volt # membrane potential
		''')

        # Process model equations (Im) to extract total conductance and the remaining current
        if use_sympy:
            try:
                membrane_eq = model._string['Im']  # the membrane equation
            except:
                raise TypeError, "The transmembrane current Im must be defined"
            # Check conditional linearity
            ids = get_identifiers(membrane_eq)
            _namespace = dict.fromkeys(
                ids, 1.
            )  # there is a possibility of problems here (division by zero)
            _namespace['v'] = AffineFunction()
            eval(membrane_eq, model._namespace['v'], _namespace)
            try:
                eval(membrane_eq, model._namespace['v'], _namespace)
            except:  # not linear
                raise TypeError, "The membrane current must be linear with respect to v"
            # Extracts the total conductance from Im, and the remaining current
            z = symbolic_eval(membrane_eq)
            symbol_v = sympy.Symbol('v')
            b = z.subs(symbol_v, 0)
            a = -sympy.simplify(z.subs(symbol_v, 1) - b)
            gtot_str = "_gtot=" + str(a) + ": siemens/cm**2"
            I0_str = "_I0=" + str(b) + ": amp/cm**2"
            model += Equations(
                gtot_str + "\n" + I0_str, level=level +
                1)  # better: explicit insertion with namespace of v
        else:
            raise TypeError, "The Sympy package must be installed for SpatialNeuron"

        # Equations for morphology (isn't it a duplicate??)
        eqs_morphology = Equations("""
		diameter : um
		length : um
		x : um
		y : um
		z : um
		area : um**2
		""")

        full_model = model + eqs_morphology

        NeuronGroup.__init__(self,
                             N,
                             model=full_model,
                             threshold=threshold,
                             reset=reset,
                             refractory=refractory,
                             level=level + 1,
                             clock=clock,
                             unit_checking=unit_checking,
                             implicit=implicit)
        self.model_with_diffeq_nonzero = diffeq_nonzero
        self._state_updater = SpatialStateUpdater(self, clock)
        self.Cm = ones(len(self)) * Cm
        self.Ri = Ri
        self.bc_type = bc_type  #default boundary condition on leaves
        self.bc = ones(len(self))  # boundary conditions on branch points
        self.changed = True

        # Insert morphology
        self.morphology = morphology
        self.morphology.compress(diameter=self.diameter,
                                 length=self.length,
                                 x=self.x,
                                 y=self.y,
                                 z=self.z,
                                 area=self.area)
Пример #10
0
 def __init__(self, function=None, clock=None, when='end'):
     self.clock = guess_clock(clock)
     self.when = when
     self.function = function
     if hasattr(function, 'func_code'):
         self._has_arg = (self.function.func_code.co_argcount==1)
Пример #11
0
	def __init__(self, morphology=None, model=None, threshold=None, reset=NoReset(),
				refractory=0 * ms, level=0,
				clock=None, unit_checking=True,
				compile=False, freeze=False, implicit=True, Cm=0.9 * uF / cm ** 2, Ri=150 * ohm * cm,
				bc_type = 2, diffeq_nonzero=True):
		clock = guess_clock(clock)
		N = len(morphology) # number of compartments
		
		if isinstance(model, str):
			model = Equations(model, level=level + 1)
		
		model += Equations('''
		v:volt # membrane potential
		''')

		# Process model equations (Im) to extract total conductance and the remaining current
		if use_sympy:
			try:
				membrane_eq=model._string['Im'] # the membrane equation
			except:
				raise TypeError,"The transmembrane current Im must be defined"
			# Check conditional linearity
			ids=get_identifiers(membrane_eq)
			_namespace=dict.fromkeys(ids,1.) # there is a possibility of problems here (division by zero)
			_namespace['v']=AffineFunction()
			eval(membrane_eq,model._namespace['v'],_namespace)
			try:
				eval(membrane_eq,model._namespace['v'],_namespace)
			except: # not linear
				raise TypeError,"The membrane current must be linear with respect to v"
			# Extracts the total conductance from Im, and the remaining current
			z=symbolic_eval(membrane_eq)
			symbol_v=sympy.Symbol('v')
			b=z.subs(symbol_v,0)
			a=-sympy.simplify(z.subs(symbol_v,1)-b)
			gtot_str="_gtot="+str(a)+": siemens/cm**2"
			I0_str="_I0="+str(b)+": amp/cm**2"
			model+=Equations(gtot_str+"\n"+I0_str,level=level+1) # better: explicit insertion with namespace of v
		else:
			raise TypeError,"The Sympy package must be installed for SpatialNeuron"
		
		# Equations for morphology (isn't it a duplicate??)
		eqs_morphology = Equations("""
		diameter : um
		length : um
		x : um
		y : um
		z : um
		area : um**2
		""")
		
		full_model = model + eqs_morphology
		
		NeuronGroup.__init__(self, N, model=full_model, threshold=threshold, reset=reset, refractory=refractory,
							level=level + 1, clock=clock, unit_checking=unit_checking, implicit=implicit)
		self.model_with_diffeq_nonzero = diffeq_nonzero
		self._state_updater = SpatialStateUpdater(self, clock)
		self.Cm = ones(len(self))*Cm
		self.Ri = Ri
		self.bc_type = bc_type #default boundary condition on leaves
		self.bc = ones(len(self)) # boundary conditions on branch points
		self.changed = True
		
		# Insert morphology
		self.morphology = morphology
		self.morphology.compress(diameter=self.diameter, length=self.length, x=self.x, y=self.y, z=self.z, area=self.area)
Пример #12
0
    def __init__(self, morphology=None, model=None, threshold=None, reset=NoReset(),
                 refractory=0 * ms, level=0,
                 clock=None, unit_checking=True,
                 compile=False, freeze=False, Cm=0.9 * uF / cm ** 2, Ri=150 * ohm * cm):
        clock = guess_clock(clock)
        N = len(morphology) # number of compartments

        if isinstance(model, str):
            model = Equations(model, level=level + 1)

        model += Equations('''
        v:volt # membrane potential
        ''')

        # Process model equations (Im) to extract total conductance and the remaining current
        if use_sympy:
            try:
                membrane_eq=model._string['Im'] # the membrane equation
            except:
                raise TypeError,"The transmembrane current Im must be defined"
            # Check conditional linearity
            ids=get_identifiers(membrane_eq)
            _namespace=dict.fromkeys(ids,1.) # there is a possibility of problems here (division by zero)
            _namespace['v']=AffineFunction()
            eval(membrane_eq,model._namespace['v'],_namespace)
            try:
                eval(membrane_eq,model._namespace['v'],_namespace)
            except: # not linear
                raise TypeError,"The membrane current must be linear with respect to v"
            # Extracts the total conductance from Im, and the remaining current
            z=symbolic_eval(membrane_eq)
            symbol_v=sympy.Symbol('v')
            b=z.subs(symbol_v,0)
            a=-sympy.simplify(z.subs(symbol_v,1)-b)
            gtot_str="_gtot="+str(a)+": siemens/cm**2"
            I0_str="_I0="+str(b)+": amp/cm**2"
            model+=Equations(gtot_str+"\n"+I0_str,level=level+1) # better: explicit insertion with namespace of v
        else:
            raise TypeError,"The Sympy package must be installed for SpatialNeuron"

        # Equations for morphology (isn't it a duplicate??)
        eqs_morphology = Equations("""
        diameter : um
        length : um
        x : um
        y : um
        z : um
        area : um**2
        """)

        full_model = model + eqs_morphology

        # Create the state updater
        NeuronGroup.__init__(self, N, model=full_model, threshold=threshold, reset=reset, refractory=refractory,
                             level=level + 1, clock=clock, unit_checking=unit_checking, implicit=True)

        #Group.__init__(self, full_model, N, unit_checking=unit_checking, level=level+1)
        #self._eqs = model
        #var_names = full_model._diffeq_names
        self.Cm = Cm # could be a vector?
        self.Ri = Ri
        self._state_updater = SpatialStateUpdater(self, clock)
        #S0 = {}
        # Fill missing units
        #for key, value in full_model._units.iteritems():
        #    if not key in S0:
        #        S0[key] = 0 * value
        #self._S0 = [0] * len(var_names)
        #for var, i in zip(var_names, count()):
        #    self._S0[i] = S0[var]

        # Insert morphology
        self.morphology = morphology
        self.morphology.compress(diameter=self.diameter, length=self.length, x=self.x, y=self.y, z=self.z, area=self.area)
Пример #13
0
    def __init__(self,
                 morphology=None,
                 model=None,
                 threshold=None,
                 reset=NoReset(),
                 refractory=0 * ms,
                 level=0,
                 clock=None,
                 unit_checking=True,
                 compile=False,
                 freeze=False,
                 Cm=0.9 * uF / cm**2,
                 Ri=150 * ohm * cm):
        clock = guess_clock(clock)
        N = len(morphology)  # number of compartments

        if isinstance(model, str):
            model = Equations(model, level=level + 1)

        model += Equations('''
        v:volt # membrane potential
        ''')

        # Process model equations (Im) to extract total conductance and the remaining current
        if use_sympy:
            try:
                membrane_eq = model._string['Im']  # the membrane equation
            except:
                raise TypeError, "The transmembrane current Im must be defined"
            # Check conditional linearity
            ids = get_identifiers(membrane_eq)
            _namespace = dict.fromkeys(
                ids, 1.
            )  # there is a possibility of problems here (division by zero)
            _namespace['v'] = AffineFunction()
            eval(membrane_eq, model._namespace['v'], _namespace)
            try:
                eval(membrane_eq, model._namespace['v'], _namespace)
            except:  # not linear
                raise TypeError, "The membrane current must be linear with respect to v"
            # Extracts the total conductance from Im, and the remaining current
            z = symbolic_eval(membrane_eq)
            symbol_v = sympy.Symbol('v')
            b = z.subs(symbol_v, 0)
            a = -sympy.simplify(z.subs(symbol_v, 1) - b)
            gtot_str = "_gtot=" + str(a) + ": siemens/cm**2"
            I0_str = "_I0=" + str(b) + ": amp/cm**2"
            model += Equations(
                gtot_str + "\n" + I0_str, level=level +
                1)  # better: explicit insertion with namespace of v
        else:
            raise TypeError, "The Sympy package must be installed for SpatialNeuron"

        # Equations for morphology (isn't it a duplicate??)
        eqs_morphology = Equations("""
        diameter : um
        length : um
        x : um
        y : um
        z : um
        area : um**2
        """)

        full_model = model + eqs_morphology

        # Create the state updater
        NeuronGroup.__init__(self,
                             N,
                             model=full_model,
                             threshold=threshold,
                             reset=reset,
                             refractory=refractory,
                             level=level + 1,
                             clock=clock,
                             unit_checking=unit_checking,
                             implicit=True)

        #Group.__init__(self, full_model, N, unit_checking=unit_checking, level=level+1)
        #self._eqs = model
        #var_names = full_model._diffeq_names
        self.Cm = Cm  # could be a vector?
        self.Ri = Ri
        self._state_updater = SpatialStateUpdater(self, clock)
        #S0 = {}
        # Fill missing units
        #for key, value in full_model._units.iteritems():
        #    if not key in S0:
        #        S0[key] = 0 * value
        #self._S0 = [0] * len(var_names)
        #for var, i in zip(var_names, count()):
        #    self._S0[i] = S0[var]

        # Insert morphology
        self.morphology = morphology
        self.morphology.compress(diameter=self.diameter,
                                 length=self.length,
                                 x=self.x,
                                 y=self.y,
                                 z=self.z,
                                 area=self.area)
Пример #14
0
 def __init__(self, function=None, clock=None, when='end'):
     self.clock = guess_clock(clock)
     self.when = when
     self.function = function
     if hasattr(function, 'func_code'):
         self._has_arg = (self.function.func_code.co_argcount == 1)