From efc79f9d07eb47b47d55c03256d22d632d215c23 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Mon, 14 Sep 2020 11:06:07 +0200 Subject: [PATCH] changes --- punit_responses.py | 84 ++++++++++++++++++------------------ response_discriminability.py | 9 ++++ 2 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 response_discriminability.py diff --git a/punit_responses.py b/punit_responses.py index cb4b311..77202a7 100644 --- a/punit_responses.py +++ b/punit_responses.py @@ -3,7 +3,7 @@ import nixio as nix import os from numpy.core.fromnumeric import repeat from traitlets.traitlets import Instance -from chirp_ams import get_signals +from chirp_ams import get_signals, other_freq, other_signal, self_freq from model import simulate, load_models from IPython import embed import matplotlib.pyplot as plt @@ -21,8 +21,7 @@ def append_settings(section, sec_name, sec_type, settings): section[k] = settings[k] -def save(filename, name, stimulus_settings, model_settings, stimulus, responses, overwrite=False): - print("saving! ", filename, name) +def save(filename, name, stimulus_settings, model_settings, self_signal, other_signal, self_freq, other_freq, complete_stimulus, responses, overwrite=False): if os.path.exists(filename) and not overwrite: nf = nix.File.open(filename, nix.FileMode.ReadWrite) else: @@ -40,8 +39,8 @@ def save(filename, name, stimulus_settings, model_settings, stimulus, responses, b.metadata = mdata # save stimulus - stim_da = b.create_data_array("stimulus", "nix.timeseries.sampled", dtype=nix.DataType.Float, - data=stimulus) + stim_da = b.create_data_array("complete_stimulus", "nix.timeseries.sampled", dtype=nix.DataType.Float, + data=complete_stimulus) stim_da.label = "voltage" stim_da.label = "mv/cm" dim = stim_da.append_sampled_dimension(model_settings["deltat"]) @@ -56,22 +55,18 @@ def save(filename, name, stimulus_settings, model_settings, stimulus, responses, da.unit = "s" dim = da.append_range_dimension() dim.link_data_array(da, [-1]) + + nf.close() - pass - -def plot_responses(): - pass - -def simulate_responses(stimulus_params, model_params, repeats=10): +def simulate_responses(stimulus_params, model_params, repeats=10, deltaf=20): cell_params = model_params.copy() cell = cell_params["cell"] del cell_params["cell"] del cell_params["EODf"] for c in stimulus_params["contrasts"]: - print("creating stimuli\n\tcontrast: ", str(c), "\t condition: ", - stimulus_params["condition"]) + print("\t\tcreating stimuli ... ") params = stimulus_params.copy() del params["contrasts"] del params["chirp_frequency"] @@ -79,41 +74,48 @@ def simulate_responses(stimulus_params, model_params, repeats=10): time, self_signal, self_freq, other_signal, other_freq = get_signals(**params) signal = (self_signal + other_signal) signal /= np.max(signal) - print("create p-unit responses for cell: ", cell) + print("\t\tcreating p-unit responses ...") spikes = [] + no_other_spikes = [] for r in range(repeats): spikes.append(simulate(signal, **cell_params)) - save("test.nix", "contrast_%.3f_condition_%s" %(c, stimulus_params["condition"]), params, - cell_params, signal, spikes) + no_other_spikes.append(simulate, self_signal)) + print("\t\tsaving ...") + save("cell_%s.nix" % cell, "contrast_%.3f_condition_%s_deltaf_%i" %(c, stimulus_params["condition"], deltaf), params, + cell_params, self_signal, other_signal, self_freq, other_freq, signal, spikes) def main(): - cell_id = 20 models = load_models("models.csv") - deltaf = 20. # Hz, difference frequency between self and other - model_params = models[cell_id] - stimulus_params = {"eodfs": {"self": model_params["EODf"], - "other": model_params["EODf"] + deltaf}, - "contrasts": [20, 10, 5, 2.5, 1.25, 0.625, 0.3125], - "chirp_size": 100, # Hz, frequency excursion - "chirp_duration": 0.015, # s, chirp duration - "chirp_amplitude_dip": 0.05, # %, amplitude drop during chirp - "chirp_frequency": 5, # Hz, how often does the fish chirp - "duration": 5., # s, total duration of simulation - "dt": model_params["deltat"], # s, stepsize of the simulation - } - chirp_times = np.arange(stimulus_params["chirp_duration"], - stimulus_params["duration"] - stimulus_params["chirp_duration"], - 1./stimulus_params["chirp_frequency"]) - stimulus_params["chirp_times"] = chirp_times - conditions = ["other", "self"] - - for c in conditions: - stimulus_params["condition"] = c - simulate_responses(stimulus_params, model_params, repeats=25) - pass - - + deltafs = [-200, -100, -20, 20, 100, 200] # Hz, difference frequency between self and other + + for cell_id in range(len(models)): + model_params = models[cell_id] + print("Cell: %s" % model_params["cell"]) + for deltaf in deltafs: + print("\t Deltaf: %i" % deltaf) + stimulus_params = {"eodfs": {"self": model_params["EODf"], + "other": model_params["EODf"] + deltaf}, + "contrasts": [20, 10, 5, 2.5, 1.25, 0.625, 0.3125], + "chirp_size": 100, # Hz, frequency excursion + "chirp_duration": 0.015, # s, chirp duration + "chirp_amplitude_dip": 0.05, # %, amplitude drop during chirp + "chirp_frequency": 5, # Hz, how often does the fish chirp + "duration": 5., # s, total duration of simulation + "dt": model_params["deltat"], # s, stepsize of the simulation + } + chirp_times = np.arange(stimulus_params["chirp_duration"], + stimulus_params["duration"] - stimulus_params["chirp_duration"], + 1./stimulus_params["chirp_frequency"]) + stimulus_params["chirp_times"] = chirp_times + conditions = ["other", "self"] + + for c in conditions: + print("\t\tcondition: %s" % c) + stimulus_params["condition"] = c + simulate_responses(stimulus_params, model_params, repeats=25, + deltaf=deltaf) + if __name__ == "__main__": main() \ No newline at end of file diff --git a/response_discriminability.py b/response_discriminability.py new file mode 100644 index 0000000..5d8070a --- /dev/null +++ b/response_discriminability.py @@ -0,0 +1,9 @@ +import nixio as nix +import matplotlib.pyplot as plt + + +def main(): + pass + +if __name__ == "__main__": + main() \ No newline at end of file