def test_psg_fixed(): psg = PoissonSpikeGenerator(population='test', seed=100) psg.add(node_ids=range(10), firing_rate=5.0, times=(0.0, 3.0)) assert (psg.populations == ['test']) assert (np.all(psg.node_ids() == list(range(10)))) assert (psg.n_spikes() == 143) assert (psg.n_spikes(population='test') == 143) assert (np.allclose(psg.time_range(), (5.380662350673328, 2986.5205688893295))) df = psg.to_dataframe() assert (df.shape == (143, 3)) assert (np.allclose(psg.get_times(node_id=0), [ 156.7916, 222.0400, 332.5493, 705.1267, 706.0727, 731.9963, 954.1834, 1303.7542, 1333.1543, 1504.3314, 1948.2045, 1995.1471, 2036.1411, 2059.0835, 2108.6982, 2877.7935 ], atol=1.0e-3)) assert (np.allclose(psg.get_times(node_id=9, population='test'), [ 23.3176, 241.7332, 390.1951, 428.2215, 1001.0229, 1056.4003, 2424.8442, 2599.6312, 2640.1228, 2737.9504, 2780.0140, 2885.8020 ], atol=1.0e-3))
def _activate_hln(self, sim, block_interval, firing_rate): next_block_tstart = (block_interval[1] + 1) * sim.dt # The next time-step next_block_tstop = next_block_tstart + sim.nsteps_block*sim.dt # The time-step when the next block ends # This is where you can use the firing-rate of the low-level neurons to generate a set of spike times for the # next block if firing_rate != 0.0: psg = PoissonSpikeGenerator() psg.add(node_ids=[0], firing_rate=firing_rate, times=(next_block_tstart/1000.0, next_block_tstop/1000.0)) if psg.n_spikes() <= 0: io.log_info(' _activate_hln: firing rate {} did not produce any spikes'.format(firing_rate)) else: self._spike_events = psg.get_times(0) # Update firing rate of bladder afferent neurons for gid in self._high_level_neurons: nc = self._netcons[gid] for t in self._spike_events: nc.event(t) else: io.log_info(' _activate_hln: firing rate 0') # If pressure is maxxed, update firing rate of EUS motor neurons # Guarding reflex # press_change = self._prev_glob_press - self._glob_press # if self._glob_press > press_thres or press_change > change_thres: # psg = PoissonSpikeGenerator() # eus_fr = self._glob_press*10 + press_change*10 # Assumption: guarding reflex # # depends on current pressure # # and change from last pressure # psg.add(node_ids=[0], firing_rate=eus_fr, times=(next_block_tstart, next_block_tstop)) # self._spike_events = psg.get_times(0) # for gid in self._eus_neurons: # nc = self._netcons[gid] # for t in self._spike_events: # nc.event(t) ################ Activate higher order based on pressure threshold ############################## # if block_interval[1] % 2000 == 1000: # For fast testing, only add events to every other block # if False: # For testing if self._glob_press > self.press_thres: io.log_info(' updating pag input') psg = PoissonSpikeGenerator() print(self.press_thres) pag_fr = self.press_thres #change psg.add(node_ids=[0], firing_rate=pag_fr, times=(next_block_tstart/1000.0, next_block_tstop/1000.0)) if psg.n_spikes() <= 0: io.log_info(' no psg spikes generated by Poisson distritubtion') self._spike_events = psg.get_times(0) for gid in self._pag_neurons: nc = self._netcons[gid] for t in self._spike_events: nc.event(t)
def test_psg_fixed(): psg = PoissonSpikeGenerator(population='test', seed=100) psg.add(node_ids=range(10), firing_rate=5.0, times=(0.0, 3.0)) assert (psg.populations == ['test']) assert (np.all(psg.node_ids() == list(range(10)))) assert (psg.n_spikes() == 143) assert (psg.n_spikes(population='test') == 143) assert (np.allclose(psg.time_range(), (0.005380662350673328, 2.9865205688893295))) df = psg.to_dataframe() assert (df.shape == (143, 3)) assert (np.allclose(psg.get_times(node_id=0), [ 0.156, 0.222, 0.332, 0.705, 0.706, 0.731, 0.954, 1.303, 1.333, 1.504, 1.948, 1.995, 2.036, 2.059, 2.108, 2.877 ], atol=1.0e-3)) assert (np.allclose(psg.get_times(node_id=9, population='test'), [ 0.0233, 0.241, 0.390, 0.428, 1.001, 1.056, 2.424, 2.599, 2.640, 2.737, 2.780, 2.885 ], atol=1.0e-3))
def test_psg_variable(): times = np.linspace(0.0, 3.0, 1000) fr = np.exp(-np.power(times - 1.0, 2) / (2 * np.power(.5, 2))) * 5 psg = PoissonSpikeGenerator(population='test', seed=0.0) psg.add(node_ids=range(10), firing_rate=fr, times=times) assert (psg.populations == ['test']) assert (np.all(psg.node_ids() == list(range(10)))) assert (psg.n_spikes() == 59) assert (np.allclose(psg.time_range(), (0.13932107933711294, 2.9013003727909172))) assert (psg.to_dataframe().shape == (59, 3)) assert (np.allclose(psg.get_times(node_id=0), [0.442, 0.520, 0.640, 1.099, 1.393, 1.725], atol=1.0e-3)) assert (np.allclose(psg.get_times(node_id=9), [0.729, 0.885, 1.047, 1.276, 1.543, 1.669, 1.881], atol=1.0e-3))
def test_psg_variable(): times = np.linspace(0.0, 3.0, 1000) fr = np.exp(-np.power(times - 1.0, 2) / (2 * np.power(.5, 2))) * 5 psg = PoissonSpikeGenerator(population='test', seed=0.0) psg.add(node_ids=range(10), firing_rate=fr, times=times) assert (psg.populations == ['test']) assert (np.all(psg.node_ids() == list(range(10)))) assert (psg.n_spikes() == 59) assert (np.allclose(psg.time_range(), (139.32107933711294, 2901.3003727909172))) assert (psg.to_dataframe().shape == (59, 3)) assert (np.allclose( psg.get_times(node_id=0), [442.8378, 520.3624, 640.3880, 1099.0661, 1393.0794, 1725.6109], atol=1.0e-3)) assert (np.allclose(psg.get_times(node_id=9), [ 729.6267, 885.2469, 1047.7728, 1276.3554, 1543.6557, 1669.9070, 1881.3605 ], atol=1.0e-3))
# ('shock', './12_cell_inputs/shock_spikes.csv'), # ('bg_pn', '12_cell_inputs/bg_pn_spikes.h5'), # ('bg_pv', '12_cell_inputs/bg_pv_spikes.h5'), # ('bg_olm', '12_cell_inputs/bg_olm_spikes.h5')], # components_dir='biophys_components', # config_file='config.json', # compile_mechanisms=False) psg = PoissonSpikeGenerator(population='bg_pn') psg.add( node_ids=range(8), # need same number as cells firing_rate=1, # 1 spike every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('12_cell_inputs/bg_pn_spikes.h5') print('Number of background spikes for pn: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_pv') psg.add( node_ids=range(2), # need same number as cells firing_rate=8, # 8 spikes every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('12_cell_inputs/bg_pv_spikes.h5') print('Number of background spikes for pv: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_olm') psg.add( node_ids=range(2), # need same number as cells firing_rate=2, # 8 spikes every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason
# SPIKE TRAINS t_sim = 40000 #build_env_bionet(base_dir='./', # network_dir='./network', # tstop=t_sim, dt=0.1, # report_vars=['v'], # components_dir='biophys_components', # config_file='config.json', # spikes_inputs=[('bg_pn_c', '2_cell_inputs/bg_pn_c_spikes.h5'), # ('bg_pv', '2_cell_inputs/bg_pv_spikes.h5')], # compile_mechanisms=False) psg = PoissonSpikeGenerator(population='bg_pn_c') psg.add( node_ids=range(1), # need same number as cells firing_rate=6, # 1 spike every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('2_cell_inputs/bg_pn_c_spikes.h5') print('Number of background spikes for PN_C: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_pv') psg.add( node_ids=range(1), # need same number as cells firing_rate=7.7, # 8 spikes every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('2_cell_inputs/bg_pv_spikes.h5') print('Number of background spikes for PV: {}'.format(psg.n_spikes()))
distance_range=[0.0, 150.0], dynamics_params='AMPA_ExcToExc.json', model_template='exp2syn') net.build() net.save(output_dir='network') thalamus.build() thalamus.save(output_dir='network') psg = PoissonSpikeGenerator(population='mthalamus') psg.add( node_ids=1, # Have 5 nodes to match mthalamus firing_rate=8, # 2 Hz times=(0.0, 1)) # time is in seconds for some reason psg.to_sonata('virtual_spikes.h5') print('Number of background spikes: {}'.format(psg.n_spikes())) from bmtk.utils.sim_setup import build_env_bionet build_env_bionet( base_dir='../', network_dir='./network', tstop=1000.0, dt=0.1, report_vars=['v'], spikes_inputs=[('mthalamus', 'virtual_spikes.h5')], #current_clamp={ # 'amp': -0.100, # 'delay': 250.0, # 'duration': 200 #200 for bask 600 for pyr #}, components_dir='../biophys_components',
def build_model(): if os.path.isdir('network'): shutil.rmtree('network') if os.path.isdir('2_cell_inputs'): shutil.rmtree('2_cell_inputs') seed = 967 random.seed(seed) np.random.seed(seed) load() syn = syn_params_dicts() # Initialize our network net = NetworkBuilder("biophysical") num_inh = [1] num_exc = [1] ################################################################################## ###################################BIOPHY######################################### # PN net.add_nodes(N=1, pop_name='PyrC', mem_potential='e', model_type='biophysical', model_template='hoc:Cell_C', morphology=None) # PV net.add_nodes(N=1, pop_name="PV", mem_potential='e', model_type='biophysical', model_template='hoc:basket', morphology=None) backgroundPN_C = NetworkBuilder('bg_pn_c') backgroundPN_C.add_nodes(N=1, pop_name='tON', potential='exc', model_type='virtual') backgroundPV = NetworkBuilder('bg_pv') backgroundPV.add_nodes(N=2, pop_name='tON', potential='exc', model_type='virtual') # if neuron is sufficiently depolorized enough post synaptic calcium then synaptiic weight goes up # pyr->pyr & pyr->PV # PV->pyr PV->PV def one_to_all(source, target): sid = source.node_id tid = target.node_id print("connecting bio cell {} to bio cell {}".format(sid, tid)) return 1 def BG_to_PN_C(source, target): sid = source.node_id tid = target.node_id if sid == tid: print("connecting BG {} to PN_C{}".format(sid, tid)) return 1 else: return 0 def BG_to_PV(source, target): sid = source.node_id tid = target.node_id sid = sid + 1 if sid == tid: print("connecting BG {} to PV{}".format(sid, tid)) return 1 else: return 0 conn = net.add_edges(source=net.nodes(pop_name='PyrC'), target=net.nodes(pop_name="PV"), connection_rule=one_to_all, syn_weight=1.0, delay=0.1, distance_range=[-10000, 10000], dynamics_params='PN2PV.json', model_template=syn['PN2PV.json']['level_of_detail']) conn.add_properties(['sec_id', 'sec_x'], rule=(1, 0.9), dtypes=[np.int32, np.float]) conn = net.add_edges(source=net.nodes(pop_name='PV'), target=net.nodes(pop_name="PyrC"), connection_rule=one_to_all, syn_weight=1.0, delay=0.1, distance_range=[-10000, 10000], dynamics_params='PV2PN.json', model_template=syn['PV2PN.json']['level_of_detail']) conn.add_properties(['sec_id', 'sec_x'], rule=(1, 0.9), dtypes=[np.int32, np.float]) conn = net.add_edges(source=backgroundPN_C.nodes(), target=net.nodes(pop_name='PyrC'), connection_rule=BG_to_PN_C, syn_weight=1.0, delay=0.1, distance_range=[-10000, 10000], dynamics_params='BG2PNC.json', model_template=syn['BG2PNC.json']['level_of_detail']) conn.add_properties(['sec_id', 'sec_x'], rule=(2, 0.9), dtypes=[np.int32, np.float]) # places syn on apic at 0.9 conn = net.add_edges(source=backgroundPV.nodes(), target=net.nodes(pop_name='PV'), connection_rule=BG_to_PV, syn_weight=1.0, delay=0.1, distance_range=[-10000, 10000], dynamics_params='BG2PV.json', model_template=syn['BG2PV.json']['level_of_detail']) conn.add_properties(['sec_id', 'sec_x'], rule=(1, 0.9), dtypes=[np.int32, np.float]) backgroundPN_C.build() backgroundPN_C.save_nodes(output_dir='network') backgroundPV.build() backgroundPV.save_nodes(output_dir='network') net.build() net.save(output_dir='network') # SPIKE TRAINS t_sim = 40000 # build_env_bionet(base_dir='./', # network_dir='./network', # tstop=t_sim, dt=0.1, # report_vars=['v'], # components_dir='biophys_components', # config_file='config.json', # spikes_inputs=[('bg_pn_c', '2_cell_inputs/bg_pn_c_spikes.h5'), # ('bg_pv', '2_cell_inputs/bg_pv_spikes.h5')], # compile_mechanisms=False) psg = PoissonSpikeGenerator(population='bg_pn_c') psg.add( node_ids=range(1), # need same number as cells firing_rate=6, # 1 spike every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('2_cell_inputs/bg_pn_c_spikes.h5') print('Number of background spikes for PN_C: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_pv') psg.add( node_ids=range(1), # need same number as cells firing_rate=7.7, # 8 spikes every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('2_cell_inputs/bg_pv_spikes.h5') print('Number of background spikes for PV: {}'.format(psg.n_spikes()))