changes
This commit is contained in:
parent
65fe9db570
commit
efc79f9d07
@ -3,7 +3,7 @@ import nixio as nix
|
|||||||
import os
|
import os
|
||||||
from numpy.core.fromnumeric import repeat
|
from numpy.core.fromnumeric import repeat
|
||||||
from traitlets.traitlets import Instance
|
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 model import simulate, load_models
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@ -21,8 +21,7 @@ def append_settings(section, sec_name, sec_type, settings):
|
|||||||
section[k] = settings[k]
|
section[k] = settings[k]
|
||||||
|
|
||||||
|
|
||||||
def save(filename, name, stimulus_settings, model_settings, stimulus, responses, overwrite=False):
|
def save(filename, name, stimulus_settings, model_settings, self_signal, other_signal, self_freq, other_freq, complete_stimulus, responses, overwrite=False):
|
||||||
print("saving! ", filename, name)
|
|
||||||
if os.path.exists(filename) and not overwrite:
|
if os.path.exists(filename) and not overwrite:
|
||||||
nf = nix.File.open(filename, nix.FileMode.ReadWrite)
|
nf = nix.File.open(filename, nix.FileMode.ReadWrite)
|
||||||
else:
|
else:
|
||||||
@ -40,8 +39,8 @@ def save(filename, name, stimulus_settings, model_settings, stimulus, responses,
|
|||||||
b.metadata = mdata
|
b.metadata = mdata
|
||||||
|
|
||||||
# save stimulus
|
# save stimulus
|
||||||
stim_da = b.create_data_array("stimulus", "nix.timeseries.sampled", dtype=nix.DataType.Float,
|
stim_da = b.create_data_array("complete_stimulus", "nix.timeseries.sampled", dtype=nix.DataType.Float,
|
||||||
data=stimulus)
|
data=complete_stimulus)
|
||||||
stim_da.label = "voltage"
|
stim_da.label = "voltage"
|
||||||
stim_da.label = "mv/cm"
|
stim_da.label = "mv/cm"
|
||||||
dim = stim_da.append_sampled_dimension(model_settings["deltat"])
|
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"
|
da.unit = "s"
|
||||||
dim = da.append_range_dimension()
|
dim = da.append_range_dimension()
|
||||||
dim.link_data_array(da, [-1])
|
dim.link_data_array(da, [-1])
|
||||||
nf.close()
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def plot_responses():
|
nf.close()
|
||||||
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_params = model_params.copy()
|
||||||
cell = cell_params["cell"]
|
cell = cell_params["cell"]
|
||||||
del cell_params["cell"]
|
del cell_params["cell"]
|
||||||
del cell_params["EODf"]
|
del cell_params["EODf"]
|
||||||
for c in stimulus_params["contrasts"]:
|
for c in stimulus_params["contrasts"]:
|
||||||
print("creating stimuli\n\tcontrast: ", str(c), "\t condition: ",
|
print("\t\tcreating stimuli ... ")
|
||||||
stimulus_params["condition"])
|
|
||||||
params = stimulus_params.copy()
|
params = stimulus_params.copy()
|
||||||
del params["contrasts"]
|
del params["contrasts"]
|
||||||
del params["chirp_frequency"]
|
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)
|
time, self_signal, self_freq, other_signal, other_freq = get_signals(**params)
|
||||||
signal = (self_signal + other_signal)
|
signal = (self_signal + other_signal)
|
||||||
signal /= np.max(signal)
|
signal /= np.max(signal)
|
||||||
print("create p-unit responses for cell: ", cell)
|
print("\t\tcreating p-unit responses ...")
|
||||||
|
|
||||||
spikes = []
|
spikes = []
|
||||||
|
no_other_spikes = []
|
||||||
for r in range(repeats):
|
for r in range(repeats):
|
||||||
spikes.append(simulate(signal, **cell_params))
|
spikes.append(simulate(signal, **cell_params))
|
||||||
save("test.nix", "contrast_%.3f_condition_%s" %(c, stimulus_params["condition"]), params,
|
no_other_spikes.append(simulate, self_signal))
|
||||||
cell_params, signal, spikes)
|
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():
|
def main():
|
||||||
cell_id = 20
|
|
||||||
models = load_models("models.csv")
|
models = load_models("models.csv")
|
||||||
deltaf = 20. # Hz, difference frequency between self and other
|
deltafs = [-200, -100, -20, 20, 100, 200] # Hz, difference frequency between self and other
|
||||||
model_params = models[cell_id]
|
|
||||||
stimulus_params = {"eodfs": {"self": model_params["EODf"],
|
for cell_id in range(len(models)):
|
||||||
"other": model_params["EODf"] + deltaf},
|
model_params = models[cell_id]
|
||||||
"contrasts": [20, 10, 5, 2.5, 1.25, 0.625, 0.3125],
|
print("Cell: %s" % model_params["cell"])
|
||||||
"chirp_size": 100, # Hz, frequency excursion
|
for deltaf in deltafs:
|
||||||
"chirp_duration": 0.015, # s, chirp duration
|
print("\t Deltaf: %i" % deltaf)
|
||||||
"chirp_amplitude_dip": 0.05, # %, amplitude drop during chirp
|
stimulus_params = {"eodfs": {"self": model_params["EODf"],
|
||||||
"chirp_frequency": 5, # Hz, how often does the fish chirp
|
"other": model_params["EODf"] + deltaf},
|
||||||
"duration": 5., # s, total duration of simulation
|
"contrasts": [20, 10, 5, 2.5, 1.25, 0.625, 0.3125],
|
||||||
"dt": model_params["deltat"], # s, stepsize of the simulation
|
"chirp_size": 100, # Hz, frequency excursion
|
||||||
}
|
"chirp_duration": 0.015, # s, chirp duration
|
||||||
chirp_times = np.arange(stimulus_params["chirp_duration"],
|
"chirp_amplitude_dip": 0.05, # %, amplitude drop during chirp
|
||||||
stimulus_params["duration"] - stimulus_params["chirp_duration"],
|
"chirp_frequency": 5, # Hz, how often does the fish chirp
|
||||||
1./stimulus_params["chirp_frequency"])
|
"duration": 5., # s, total duration of simulation
|
||||||
stimulus_params["chirp_times"] = chirp_times
|
"dt": model_params["deltat"], # s, stepsize of the simulation
|
||||||
conditions = ["other", "self"]
|
}
|
||||||
|
chirp_times = np.arange(stimulus_params["chirp_duration"],
|
||||||
for c in conditions:
|
stimulus_params["duration"] - stimulus_params["chirp_duration"],
|
||||||
stimulus_params["condition"] = c
|
1./stimulus_params["chirp_frequency"])
|
||||||
simulate_responses(stimulus_params, model_params, repeats=25)
|
stimulus_params["chirp_times"] = chirp_times
|
||||||
pass
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
9
response_discriminability.py
Normal file
9
response_discriminability.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import nixio as nix
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user