def produce_inputR(self, roi, **kwargs): """ roi, region of interest is a string, i.e, 1 key in chosenmodel.regions kwargs = { "parameters": dictionary with keys, "stimparameters": dictionary with keys "type" and "stimlist", "onmodel": instantiated model } """ print("Sim produce_" + roi + "_inputR starting ...") ec = ExecutiveControl() # only works when in ~/cerebmodels model = ec.launch_model(parameters=kwargs["parameters"], stimparameters=kwargs["stimparameters"], stimloc=kwargs["stimloc"], onmodel=kwargs["onmodel"], capabilities={ "model": "produce_voltage_response", "vtest": ProducesElectricalResponse }, mode="capability") nwbfile = rm.load_nwbfile(model.fullfilename) orderedepochs = rm.order_all_epochs_for_region(nwbfile=nwbfile, region=roi) timestamps_over_epochs = [ rm.timestamps_for_epoch(orderedepochs[i]) for i in range(len(orderedepochs)) ] data_over_epochs = [ rm.data_for_epoch(orderedepochs[i]) for i in range(len(orderedepochs)) ] baseVms = spm.distill_baseVm_pre_epoch( timestamps=timestamps_over_epochs, datavalues=data_over_epochs) setattr(model, "prediction", self._compute_inputR(baseVms, kwargs["stimparameters"])) print("Simulation produce_" + roi + "_inputR Done.") return model
def produce_restingVm(self, **kwargs): """ kwargs = { "parameters": dictionary with keys, "stimparameters": dictionary with keys "type" and "stimlist", "onmodel": instantiated model } """ print("Sim produce_restingVm starting ...") ec = ExecutiveControl() # only works when in ~/cerebmodels model = ec.launch_model( parameters = kwargs["parameters"], stimparameters = kwargs["stimparameters"], stimloc = kwargs["stimloc"], onmodel = kwargs["onmodel"], capabilities = {"model": "produce_voltage_response", "vtest": ProducesElectricalResponse}, mode="capability") #self.fullfilename # already saved by invoking produce_voltage_response above #print("Signal Processing ...") nwbfile = rm.load_nwbfile(model.fullfilename) orderedepochs = rm.order_all_epochs_for_region(nwbfile=nwbfile, region="soma") timestamps_over_epochs = [ rm.timestamps_for_epoch( orderedepochs[i] ) for i in range(len(orderedepochs)) ] data_over_epochs = [ rm.data_for_epoch( orderedepochs[i] ) for i in range(len(orderedepochs)) ] baseVms = spm.distill_Vm_pre_epoch( timestamps = timestamps_over_epochs, datavalues = data_over_epochs ) #print("Signal Processing Done.") setattr(model, "prediction", baseVms) print("Simulation produce_restingVm Done.") return model
def test_4_order_all_epocs_for_region(self): # <---10---> <----20----> # 0----------10-----------20------------35 # ep0 ep1 ep2 # {"soma": ["v", "i_cap"], "axon": ["v"], # "channels": {"soma": {"hh": ["il", "el"], "pas": ["i"]}, "axon": {"pas": ["i"]}}} # notice 7 measuring regions times three points above = 21 epochs in total nwbfile = rm.load_nwbfile(self.fullname) chosenreg = "soma v" orderedepochs = rm.order_all_epochs_for_region(nwbfile=nwbfile, region=chosenreg) #print(len(orderedepochs)) epoch0 = orderedepochs[0] epoch1 = orderedepochs[1] epoch2 = orderedepochs[2] #print( epoch1[0] ) #print( epoch1[1] ) #print( epoch1[2] ) #print( epoch1[3] ) #print( epoch0[4] ) a = len(orderedepochs) == 3 b = epoch0[1] < epoch1[1] c = epoch1[1] < epoch2[1] #print(a, b, c) #print( epoch0[1], epoch1[1], epoch2[1] ) self.assertEqual([a, b, c], [True, True, True]) #self.assertTrue( a and b and c is True ) os.remove(self.fullname)
def visualize_aio(chosenmodel=None, roi=None): nwbfile = rdm.load_nwbfile(chosenmodel.fullfilename) orderedepochs = rdm.order_all_epochs_for_region(nwbfile=nwbfile, region=roi) # n_epochs = len(orderedepochs) #if n_epochs == 1: # plt.plot( orderedepochs[0][4][0][2].timestamps, orderedepochs[0][4][0][2].data ) #else: timestamps_over_epochs = [ rdm.timestamps_for_epoch(orderedepochs[i]) for i in range(len(orderedepochs)) ] data_over_epochs = [ rdm.data_for_epoch(orderedepochs[i]) for i in range(len(orderedepochs)) ] # t_axis = timestamps_over_epochs[0] y_axis = data_over_epochs[0] for i in range(1, n_epochs): t_axis = t_axis + timestamps_over_epochs[i] y_axis = y_axis + data_over_epochs[i] try: axes = [] stim = nwbfile.get_stimulus() axes.append(plt.subplot(2, 1, 1)) axes[0].plot(stim.timestamps, stim.data) axes.append(plt.subplot(2, 1, 2)) axes[1].plot(t_axis, y_axis) except: plt.plot(t_axis, y_axis)
def visualize_all(chosenmodel=None, roi=None): nwbfile = rdm.load_nwbfile(chosenmodel.fullfilename) orderedepochs = rdm.order_all_epochs_for_region(nwbfile=nwbfile, region=roi) # n_epochs = len(orderedepochs) #if n_epochs == 1: # plt.plot( orderedepochs[0][4][0][2].timestamps, orderedepochs[0][4][0][2].data ) #else: timestamps_over_epochs = [ rdm.timestamps_for_epoch(orderedepochs[i]) for i in range(len(orderedepochs)) ] data_over_epochs = [ rdm.data_for_epoch(orderedepochs[i]) for i in range(len(orderedepochs)) ] # cols = 2 rows = math.ceil(n_epochs / cols) axes = [] try: stim = nwbfile.get_stimulus() axes.append(plt.subplot(rows + 1, 1, 1)) axes[0].plot(stim.timestamps, stim.data) for i in range(n_epochs): axes.append(plt.subplot(rows + 1, cols, i + 3)) axes[i + 1].plot(timestamps_over_epochs[i], data_over_epochs[i]) except: axes = [] for i in range(n_epochs): axes.append(plt.subplot(rows, cols, i + 1)) axes[i].plot(timestamps_over_epochs[i], data_over_epochs[i])
def test_3_get_total_epochIDs(self): # <---10---> <----20----> # 0----------10-----------20------------35 # ep0 ep1 ep2 # {"soma": ["v", "i_cap"], "axon": ["v"], # "channels": {"soma": {"hh": ["il", "el"], "pas": ["i"]}, "axon": {"pas": ["i"]}}} # notice 7 measuring regions times three points above = 21 epochs in total nwbfile = rm.load_nwbfile(self.fullname) self.assertEqual(rm.total_epochIDs(nwbfile), 3) os.remove(self.fullname)
def test_2_timestamps_and_data_for_epoch(self): # <---10---> <----20----> # 0----------10-----------20------------35 # ep0 ep1 ep2 # {"soma": ["v", "i_cap"], "axon": ["v"], # "channels": {"soma": {"hh": ["il", "el"], "pas": ["i"]}, "axon": {"pas": ["i"]}}} # notice 7 measuring regions times three points above = 21 epochs in total nwbfile = rm.load_nwbfile(self.fullname) times = rm.timestamps_for_epoch(nwbfile.epochs[0]) data = rm.data_for_epoch(nwbfile.epochs[0]) #a = all(boolean == True for boolean in times!=data) self.assertEqual(len(times), len(data)) os.remove(self.fullname)
def produce_soma_spikeheight(self, **kwargs): """ kwargs = { "parameters": dictionary with keys, "stimparameters": dictionary with keys "type" and "stimlist", "onmodel": instantiated model } """ print("Sim produce_soma_spikeheight starting ...") ec = ExecutiveControl() # only works when in ~/cerebmodels model = ec.launch_model(parameters=kwargs["parameters"], stimparameters=kwargs["stimparameters"], stimloc=kwargs["stimloc"], onmodel=kwargs["onmodel"], capabilities={ "model": "produce_voltage_response", "vtest": ProducesElectricalResponse }, mode="capability") nwbfile = rm.load_nwbfile(model.fullfilename) orderedepochs = rm.order_all_epochs_for_region(nwbfile=nwbfile, region="soma v") timestamps_over_epochs = [ rm.timestamps_for_epoch(orderedepochs[i]) for i in range(len(orderedepochs)) ] data_over_epochs = [ rm.data_for_epoch(orderedepochs[i]) for i in range(len(orderedepochs)) ] baseVm = spm.distill_baseVm_pre_epoch( timestamps=timestamps_over_epochs, datavalues=data_over_epochs) try: peakVms = spm.distill_peakVm_from_spikes( timestamps=timestamps_over_epochs, datavalues=data_over_epochs) except: peakVms = baseVm setattr(model, "prediction", peakVms[0] - baseVm[0]) print("Simulation produce_soma_spikeheight Done.") return model
def test_1_load_nwbfile(self): nwbfile = rm.load_nwbfile(self.fullname) self.assertTrue( (str(type(nwbfile))[8:-2] == "pynwb.file.NWBFile") is True) os.remove(self.fullname)