def plot_power_spectrum(rec, fs, fr_low): img_path = str(get_project_root()) + "/img" f, Pxx_den = periodogram(rec, fs) fig = plt.figure(figsize=(20,5)) inds = np.where(f > fr_low) plt.plot(f[inds], Pxx_den[inds]) plt.xlabel('frequency [Hz]') plt.ylabel('PSD [V**2/Hz]') plt.show(block=True) fig.savefig(img_path + f"/periodogram.png") return None
def nice_error_bar_scatter(x,y,error, title, xlabel,ylabel, save_to = None): img_path = str(get_project_root()) + "/img" fig = plt.figure(figsize = (40,20)) plt.errorbar(x, y, yerr = error , color = 'red', ls='', marker='o', ecolor = 'gray', capsize = 3, linewidth = 3, alpha = 0.8) plt.title(title, fontsize = 20) plt.xlabel(xlabel, fontsize = 15) plt.ylabel(ylabel, fontsize = 15) plt.ylim(min(y-error)-0.2*abs(min(y-error)),1.2*max(y+error)) plt.grid(True) plt.show() if save_to is not None: fig.savefig(img_path + '/' + save_to)
def construct_and_run_model(dt, t_start, duration, amp, stoptime): data_folder = str(get_project_root()) + "/data" img_folder = f"{get_project_root()}/img" default_neural_params = json.load( open(f'{data_folder}/params/default_neural_params.json', 'r+')) population_names = [ 'PreI', 'EarlyI', "PostI", "AugE", "KF_t", "KF_p", "KF_relay", "NTS_drive", "Sw1", "Sw2", "Relay", "RampI" ] W, drives = set_weights_and_drives(1, 1, population_names) Network_model = construct_model(population_names, W, drives, dt, default_neural_params) run_model(Network_model, t_start, stoptime, amp, duration) V_array = Network_model.v_history t = np.array(Network_model.t) signals = Network_model.firing_rate(V_array, Network_model.V_half, Network_model.slope).T return signals, t
def generate_params(inh_NTS, inh_KF): params = dict() num_nrns = 18 num_drives = 3 x = [0.1, 1.0, 10][inh_NTS] # Disinh-inh of NTS y = [0.1, 1.0, 10][inh_KF] # Disinh-inh of KF # 0- PreI # 1 - EarlyI # 2 - PostI # 3 - AugE # 4 - RampI # 5 - Relay # 6 - Sw 1 # 7 - Sw2 # 8 - Sw3 # 9 - KF_t # 10 - KF_p # 11 - KF_r # 12 - M_HN # 13- M_PN # 14 - M_VN # 15 - KF_inh # 16 - NTS_inh # 17 - SI b = np.zeros((num_nrns, num_nrns)) # # positive weights b[0, 1] = 0.3 #PreI -> EarlyI # Rubins (2009): (0.4) Rubins (2011): (0.35) b[0, 4] = 0.6 #PreI -> RampI b[0, 12] = 0.4 # PreI -> M_HN b[2, 14] = 0.25 # PostI -> M_VN b[4, 13] = 0.6 # RampI -> M_HN b[4, 13] = 0.5 # RampI -> M_PN b[4, 14] = 0.3 # RampI -> M_VN b[5, 2] = 0.4 # Relay -> PostI b[5, 6] = 0.84 # Relay -> Sw1 b[5, 7] = 0.77 # Relay -> Sw2 b[5, 8] = 0.65 # Relay -> Sw3 b[5, 9] = 0.4 # Relay -> KF_t b[5, 10] = 0.4 # Relay -> KF_p b[6, 12] = 0.5 # Sw1 -> M_HN b[6, 14] = 0.6 # Sw1 -> M_VN b[8, 1] = 0.2 # Sw3 -> EarlyI b[8, 2] = 0.5 # Sw3 -> PostI b[8, 3] = 0.6 # Sw3 -> AugE b[10, 2] = 0.75 # KF_p -> PostI b[10, 3] = 0.85 # KF_p -> AugE b[10, 8] = 0.5 # KF_p -> Sw3 b[10, 14] = 0.38 # KF_p -> M_VN b[9, 11] = 1.4 # KF_t -> KF_relay b[17, 5] = 0.75 # SI -> Relay # negative weights b[1, 0] = -0.02 # EarlyI -> PreI #in Rubins: (0) Rubins (2011): (0) b[1, 2] = -0.3 # EarlyI -> PostI #in Rubins: (0.25) Rubins (2011): (0.2) b[1, 3] = -0.4 # EarlyI -> AugE #in Rubins: (0.35) Rubins (2011): (0.25) # b[1,6] = -0.05 # EarlyI -> Sw1 b[1, 4] = -0.15 # EarlyI1 -> RampI b[1, 10] = -0.3 # EarlyI1 -> KF_p b[2, 0] = -0.16 # PostI -> PreI #in Rubins: (0.3) Rubins (2011): (0.8) b[2, 1] = -0.35 # PostI -> EarlyI #in Rubins: (0.05) Rubins (2011): (0.15) b[2, 3] = -0.35 # PostI -> AugE #in Rubins: (0.35) Rubins (2011): (0.4) b[2, 4] = -0.67 # PostI -> RampI b[2, 6] = -0.06 # PostI -> Sw1 b[2, 7] = -0.07 # PostI -> Sw2 b[3, 0] = -0.55 # 0.55 AugE -> PreI #in Rubins: (0.2) Rubins (2011): (0.22) b[3, 1] = -0.44 # AugE -> EarlyI #in Rubins: (0.35) Rubins (2011): (0.08) b[3, 2] = -0.04 # AugE -> PostI #in Rubins: (0.1) Rubins (2011): (0.0) b[3, 4] = -0.67 # AugE -> RampI b[3, 6] = -0.01 # AugE -> Sw1 b[3, 7] = -0.02 # AugE -> Sw2 b[5, 0] = -0.2 # Relay -> PreI b[5, 1] = -0.2 # Relay -> EarlyI b[6, 7] = -0.3 * x # Sw1 -> Sw2 b[7, 6] = -0.35 * x # Sw2 -> Sw1 b[11, 0] = -0.07 # KF_relay -> PreI b[11, 1] = -0.06 # KF_relay -> EarlyI b[11, 6] = -0.08 # KF_relay -> Sw1 b[11, 7] = -0.08 # KF_relay -> Sw2 b[15, 9] = -0.3 * y # KF_inh -> KF_t b[15, 10] = -0.3 * y # KF_inh -> KF_p b[16, 5] = -0.3 * x # NTS_inh -> Relay b[16, 6] = -0.2 * x # NTS_inh -> Sw1 b[16, 7] = -0.2 * x # NTS_inh -> Sw2 b[16, 8] = -0.2 * x # NTS_inh -> Sw3 c = np.zeros((num_drives, num_nrns)) # other c[0, 0] = 0.265 # To PreI c[0, 1] = 0.38 # To EarlyI c[0, 2] = 0.03 # To PostI c[0, 3] = 0.03 # To AugE c[0, 4] = 0.53 # To RampI c[0, 6] = 0.63 # To Sw1 c[0, 7] = 0.74 # To Sw2 c[0, 8] = 0.8 # To Sw3 c[0, 9] = 0.8 # To KF_t c[0, 10] = 0.8 # To KF_p c[0, 15] = 0.3 # To KF_inh c[0, 16] = 0.3 # To NTS_inh b = b.tolist() c = c.tolist() params["description"] = "" params["b"] = b params["c"] = c data_path = str(get_project_root()) + "/data" json.dump(params, open(f'{data_path}/rCPG_swCPG.json', 'w', encoding='utf-8'), separators=(',', ':'), sort_keys=True, indent=4) return None
t = np.array(Network_model.t) signals = Network_model.firing_rate(V_array, Network_model.V_half, Network_model.slope).T return signals, t def run_the_model_with_Relay_const(net, Relay_activity): for i in range(T_steps): # set activity of a relay neuron net.step() if __name__ == '__main__': # sorting out folders data_folder = str(get_project_root()) + "/data" img_folder = str(get_project_root()) + "/img" save_img_folder = f"{img_folder}/num_experiments/varying_Relay" save_data_folder = f"{data_folder}/num_exp_runs/varying_Relay" create_dir_if_not_exist(save_img_folder) create_dir_if_not_exist(save_data_folder) # Specifying parameters of tre simulation dt = 0.75 T_steps = int(30000 / dt) T_transient = int(10000 / dt) #Constructing a model default_neural_params = json.load( open(f'{data_folder}/params/default_neural_params.json', 'r+')) population_names = [
params = json.load(file) W = np.array(params["b"]) drives = np.array(params["c"]) dt = 0.75 net = Network(populations, W, drives, dt, history_len=int(40000 / dt)) # get rid of all transients net.run(int(15000 / dt)) # runs for 15 seconds # run for 15 more seconds net.run(int(15000 / dt)) # set input to Relay neurons inp = np.zeros(net.N) inp[5] = 150 net.set_input_current(inp) # run for 10 more seconds net.run(int(10000 / dt)) net.set_input_current(np.zeros(net.N)) # run for 15 more seconds net.run(int(15000 / dt)) img_path = str(get_project_root()) + "/img" folder = "Model_02042020" create_dir_if_not_exist(f"{img_path}/{folder}") net.plot( show=False, save_to=f"{img_path}/{folder}/{get_postfix(inh_NTS, inh_KF)}.png") fig = plot_num_exp_traces(signals) folder_save_img_to = img_path + "/" + f"other_plots" fig.savefig(folder_save_img_to + "/" + f"num_exp_{amp}_{stim_duration}" + ".png") plt.close(fig) generate_params(1, 1)
def run_simulations(W, d, dt, amp, stim_start, durations, stoptime): data_folder = str(get_project_root()) + "/data" img_folder = f"{get_project_root()}/img" default_neural_params = json.load( open(f'{data_folder}/params/default_neural_params.json', 'r+')) population_names = ['Sw1', 'Sw2', 'Relay'] Relay = NeuralPopulation("Relay", default_neural_params) Sw1 = NeuralPopulation("Sw1", default_neural_params) Sw2 = NeuralPopulation("Sw2", default_neural_params) Relay.tau_ad = 15000.0 Sw1.tau_ad = 1000.0 Sw2.tau_ad = 1000.0 # populations dictionary populations = dict() for name in population_names: populations[name] = eval(name) N = len(population_names) drives = d for i in range(len(durations)): net = Network(populations, W, drives, dt, history_len=int(stoptime / dt)) net.v = -100 + 100 * np.random.rand(len(population_names)) inp = np.zeros(net.N) inp[population_names.index("Relay")] = amp net.run(int(stim_start / dt)) # set an impuls input to "three" neuron net.set_input_current(inp) net.run(int((durations[i]) / dt)) # run the network further net.set_input_current(np.zeros(net.N)) net.run(int((stoptime - (stim_start + durations[i])) / dt)) v = np.array(net.v_history) fr = net.firing_rate(v, v_half=-30, slope=4) fig, axes = plt.subplots(N, 1, figsize=(20, 10), sharex=True) colors = ['r', 'g', 'k', 'k'] for j in range(N): axes[j].plot(net.t, fr[:, j], color=colors[j], label=population_names[j], linewidth=3) axes[j].grid(True) axes[j].legend(fontsize=24) axes[j].set_ylim([0, 1]) plt.subplots_adjust(wspace=None, hspace=None) img_path = str(get_project_root()) + "/img" folder_save_img_to = img_path + "/" + f"other_plots/trigger" # fig.savefig(folder_save_img_to + "/" + f"trigger_{stim_start}_{amp}_{durations[i]}" + ".png") plt.show() return None
def run_model(dt, t_start, t_end, amp, stoptime): default_neural_params = { 'C': 20, 'g_NaP': 0.0, 'g_K': 5.0, 'g_ad': 10.0, 'g_l': 2.8, 'g_synE': 10, 'g_synI': 60, 'g_synE_slow': 0, 'E_Na': 50, 'E_K': -85, 'E_ad': -85, 'E_l': -60, 'E_synE': 0, 'E_synI': -75, 'V_half': -30, 'slope': 4, 'tau_ad': 2000, 'K_ad': 0.9, 'tau_NaP_max': 6000} population_names = ["PreI", "EarlyI", "PostI", "AugE", "RampI", "Relay", "Sw1", "Sw2", "Sw3", "KF_t", "KF_p", "KF_r", "HN", "PN", "VN", "KF_inh", "NTS_inh", "SI"] # create populations # for name in population_names: # exec(f"{name} = NeuralPopulation(\'{name}\', default_neural_params)") PreI = NeuralPopulation("PreI", default_neural_params) EarlyI = NeuralPopulation("EarlyI", default_neural_params) PostI = NeuralPopulation("PostI", default_neural_params) AugE = NeuralPopulation("AugE", default_neural_params) RampI = NeuralPopulation("RampI", default_neural_params) Relay = NeuralPopulation("Relay", default_neural_params) Sw1 = NeuralPopulation("Sw1", default_neural_params) Sw2 = NeuralPopulation("Sw2", default_neural_params) Sw3 = NeuralPopulation("Sw3", default_neural_params) KF_t = NeuralPopulation("KF_t", default_neural_params) KF_p = NeuralPopulation("KF_p", default_neural_params) KF_r= NeuralPopulation("KF_r", default_neural_params) HN = NeuralPopulation("HN", default_neural_params) PN = NeuralPopulation("PN", default_neural_params) VN = NeuralPopulation("VN", default_neural_params) KF_inh = NeuralPopulation("KF_inh", default_neural_params) NTS_inh = NeuralPopulation("NTS_inh", default_neural_params) SI = NeuralPopulation("SI", default_neural_params) # # modifications: # PreI.g_NaP = 5.0 # PreI.g_ad = HN.g_ad = PN.g_ad = VN.g_ad = 0.0 # HN.g_NaP = PN.g_NaP = VN.g_NaP = 0.0 # Relay.tau_ad = 15000.0 # PostI.tau_ad = 10000.0 #modifications: PreI.g_NaP = 5.0 PreI.g_ad = HN.g_ad = PN.g_ad = VN.g_ad = SI.g_ad = 0.0 HN.g_NaP = PN.g_NaP = VN.g_NaP = SI.g_NaP = 0.0 PostI.tau_ad = 15000.0 Relay.tau_ad = 10000.0 Sw1.tau_ad = 1000.0 Sw2.tau_ad = 1000.0 # populations dictionary populations = dict() for name in population_names: populations[name] = eval(name) data_path = str(get_project_root()) + "/data" file = open(f"{data_path}/rCPG_swCPG.json", "rb+") params = json.load(file) W = np.array(params["b"]) drives = np.array(params["c"]) net = Network(populations, W, drives, dt, history_len=int(stoptime / dt)) # if for some reason the running has failed try once again net.run(int(t_start / dt)) # set input to Relay neurons inp = np.zeros(net.N) inp[17] = amp # SI neurons net.set_input_current(inp) # run for 10 more seconds net.run(int((t_end - t_start) / dt)) net.set_input_current(np.zeros(net.N)) # run til stoptime net.run(int((stoptime - (t_end - t_start) - t_start) / dt)) # img_path = str(get_project_root()) + "/img" # net.plot(show=False, save_to=f"{img_path}/{folder_save_img_to}/single_trial_{amp}.png") V_array = net.v_history t = np.array(net.t) signals = net.firing_rate(V_array, net.V_half, net.slope).T return signals, t