def test_getMeanPowerSpectrum(self): fr, pw = func.getMeanPowerSpectrum(self.model.rates_exc, dt=self.model.params["dt"])
def evaluateSimulation(traj): model = search.getModelFromTraj(traj) # initiate the model with random initial contitions model.randomICs() if hasattr(model, "model.j_values_list"): jei = model.params["Jei_max"] jie = model.params["Jie_max"] jii = model.params["Jii_max"] if [jie, jei, jii] not in model.j_values_list: result = { "max_output": np.nan, "max_amp_output": np.nan, "domfr": np.nan, "up_down_difference": np.nan, "normalized_down_lengths": np.nan, "normalized_down_lengths_mean": np.nan, "normalized_up_lengths_mean": np.nan, "n_local_waves": np.nan, "perc_local_waves": np.nan, "n_global_waves": np.nan, "all_SWS": np.nan, "SWS_per_min": np.nan, "local_waves_isi": np.nan, "global_waves_isi": np.nan, "frontal_normalized_down_lengths": np.nan, "frontal_normalized_down_lengths_mean": np.nan, "frontalnormalized_up_lengths_mean": np.nan, "frontal_n_local_waves": np.nan, "frontal_perc_local_waves": np.nan, "frontal_all_SWS": np.nan, "frontal_SWS_per_min": np.nan, "frontal_n_global_waves": np.nan, "frontal_local_waves_isi": np.nan, "frontal_global_waves_isi": np.nan } search.saveToPypet(result, traj) return defaultDuration = model.params['duration'] # -------- stage wise simulation -------- # Stage 3: full and final simulation # --------------------------------------- model.params['duration'] = defaultDuration rect_stimulus = construct_stimulus(stim="rect", duration=model.params.duration, dt=model.params.dt) model.params['ext_exc_current'] = rect_stimulus * 5.0 model.run() # up down difference state_length = 2000 # last_state = (model.t > defaultDuration - state_length) # time period in ms where we expect the down-state down_window = ((defaultDuration / 2 - state_length < model.t) & (model.t < defaultDuration / 2)) # and up state up_window = ((defaultDuration - state_length < model.t) & (model.t < defaultDuration)) up_state_rate = np.mean(model.output[:, up_window], axis=1) down_state_rate = np.mean(model.output[:, down_window], axis=1) up_down_difference = np.max(up_state_rate - down_state_rate) # check rates! max_amp_output = np.max( np.max(model.output[:, up_window], axis=1) - np.min(model.output[:, up_window], axis=1)) max_output = np.max(model.output[:, up_window]) model_frs, model_pwrs = func.getMeanPowerSpectrum( model.output, dt=model.params.dt, maxfr=40, spectrum_windowsize=10) model_frs, model_pwrs = func.getMeanPowerSpectrum( model.output[:, up_window], dt=model.params.dt, maxfr=40, spectrum_windowsize=5) domfr = model_frs[np.argmax(model_pwrs)] # -------- SWS analysis all nodes -------- (normalized_down_lengths, n_local_waves, n_global_waves, loca_waves_isi, global_waves_isi) = sws_analysis(model.output, model) # -------- SWS analysis frontal nodes -------- frontal_lobe_nodes = [i - 1 for i in CORTICAL_REGIONS["frontal_lobe"]] (frontal_normalized_down_lengths, frontal_n_local_waves, frontal_n_global_waves, frontal_loca_waves_isi, frontal_global_waves_isi) = sws_analysis( model.output[frontal_lobe_nodes, :], model) result = { "max_output": max_output, "max_amp_output": max_amp_output, "domfr": domfr, "up_down_difference": up_down_difference, "normalized_down_lengths": normalized_down_lengths, "normalized_down_lengths_mean": np.mean(normalized_down_lengths), "normalized_up_lengths_mean": 100 - np.mean(normalized_down_lengths), "n_local_waves": n_local_waves, "perc_local_waves": (n_local_waves * 100 / (n_local_waves + n_global_waves + 1)), "n_global_waves": n_global_waves, "all_SWS": n_local_waves + n_global_waves, "SWS_per_min": (n_local_waves + n_global_waves) * 3, "local_waves_isi": np.mean(loca_waves_isi), "global_waves_isi": np.mean(global_waves_isi), "frontal_normalized_down_lengths": frontal_normalized_down_lengths, "frontal_normalized_down_lengths_mean": np.mean(frontal_normalized_down_lengths), "frontalnormalized_up_lengths_mean": 100 - np.mean(frontal_normalized_down_lengths), "frontal_n_local_waves": frontal_n_local_waves, "frontal_perc_local_waves": (frontal_n_local_waves * 100 / (frontal_n_local_waves + frontal_n_global_waves + 1)), "frontal_all_SWS": frontal_n_local_waves + frontal_n_global_waves, "frontal_SWS_per_min": (frontal_n_local_waves + frontal_n_global_waves) * 3, "frontal_n_global_waves": frontal_n_global_waves, "frontal_local_waves_isi": np.mean(frontal_loca_waves_isi), "frontal_global_waves_isi": np.mean(frontal_global_waves_isi) } search.saveToPypet(result, traj) return