Ejemplo n.º 1
0
 def test_9_postrun_recording_NEURON_voltageclamp(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     sm.prepare_model_NEURON(parameters=self.sec_parameters,
                             chosenmodel=self.chosenmodel)
     # self.chosenmodel.regions ->
     # {"soma": ["v", "i_cap"], "axon": ["v"],
     # "channels": {"soma": {"hh": ["il", "el"], "pas": ["i"]}, "axon": {"pas": ["i"]}}}
     vstimuli = sm.stimulate_model_NEURON(
         stimparameters=self.sec_stimparam,
         modelsite=self.chosenmodel.cell.soma)
     rec_t, recs, rec_v_stim = rm.prepare_recording_NEURON(
         self.chosenmodel,
         stimuli=vstimuli,
         stimtype=self.sec_stimparam["type"])
     sm.engage_NEURON()
     rec_v_stim = rm.postrun_record_NEURON(
         injectedstimuli=rec_v_stim, stimtype=self.sec_stimparam["type"])
     total_iterations = len(
         range(
             -1,
             int(self.sec_parameters["tstop"] / self.sec_parameters["dt"])))
     self.assertEqual(
         len(rec_t) + len(recs["soma"][0]) + len(rec_v_stim),
         3 * total_iterations)
     os.chdir(pwd)  # reset to the location of this managerRecordTest.py
Ejemplo n.º 2
0
 def test_7_postrun_recording_NEURON_without_stimulating(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     sm.prepare_model_NEURON(parameters=self.no_parameters,
                             chosenmodel=self.chosenmodel)
     # self.chosenmodel.regions ->
     # {"soma": ["v", "i_cap"], "axon": ["v"],
     # "channels": {"soma": {"hh": ["il", "el"], "pas": ["i"]}, "axon": {"pas": ["i"]}}}
     stimuli_list = sm.stimulate_model_NEURON()
     rec_t, recs, rec_i_indivs = rm.prepare_recording_NEURON(
         self.chosenmodel, stimuli=stimuli_list)
     sm.engage_NEURON()
     rec_i = rm.postrun_record_NEURON(injectedstimuli=rec_i_indivs)
     self.assertEqual(rm.postrun_record_NEURON(), "Model is not stimulated")
     os.chdir(pwd)  # reset to the location of this managerRecordTest.py
Ejemplo n.º 3
0
 def test_6_prepare_recording_NEURON_voltageclamp(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     sm.prepare_model_NEURON(parameters=self.sec_parameters,
                             chosenmodel=self.chosenmodel)
     # self.chosenmodel.regions ->
     # {"soma": ["v", "i_cap"], "axon": ["v"],
     # "channels": {"soma": {"hh": ["il", "el"], "pas": ["i"]}, "axon": {"pas": ["i"]}}}
     vstimuli = sm.stimulate_model_NEURON(
         stimparameters=self.sec_stimparam,
         modelsite=self.chosenmodel.cell.soma)
     rec_t, recs, rec_v_stim = rm.prepare_recording_NEURON(
         self.chosenmodel,
         stimuli=vstimuli,
         stimtype=self.sec_stimparam["type"])
     sm.engage_NEURON()
     total_iterations = len(
         range(
             -1,
             int(self.sec_parameters["tstop"] / self.sec_parameters["dt"])))
     self.assertEqual([
         len(rec_t) + len(recs["soma"][0]), rec_v_stim.amp1,
         rec_v_stim.dur1, rec_v_stim.amp2, rec_v_stim.dur2
     ], [
         2 * total_iterations, self.sec_stimparam["stimlist"][0]["amp1"],
         self.sec_stimparam["stimlist"][0]["dur1"],
         self.sec_stimparam["stimlist"][1]["amp2"],
         self.sec_stimparam["stimlist"][1]["dur2"]
     ])
     #self.assertEqual( len(rec_t) + len(rec_v["soma"]),#len(rec_v[self.regionslist_str[0]]),
     #                  2*total_iterations )
     os.chdir(pwd)  # reset to the location of this managerRecordTest.py
Ejemplo n.º 4
0
 def test_1_transform_signal_None(self):
     os.chdir("..")  # move up to load the model
     # pick the model
     parameters = {"dt": 0.1, "celsius": 30, "tstop": 10, "v_init": 65}
     sm.prepare_model_NEURON(parameters=parameters,
                             chosenmodel=self.chosenmodel)
     rec_t, rec_v, x = rm.prepare_recording_NEURON(self.chosenmodel)
     sm.engage_NEURON()
     total_iterations = len(
         range(-1, int(parameters["tstop"] / parameters["dt"])))
     self.assertRaises(ValueError,
                       sp.transform_signal,
                       chosenmodel=self.chosenmodel,
                       recordings=rec_v[self.regionslist_str[0]])
     os.chdir(pwd)  # reset to the location of this managerRecordTest.py
Ejemplo n.º 5
0
 def test_2_recordings_of_cellular_componenets_NEURON(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     sm.prepare_model_NEURON(parameters=self.no_parameters,
                             chosenmodel=self.chosenmodel)
     # self.chosenmodel.regions ->
     # {"soma": ["v", "i_cap"], "axon": ["v"],
     # "channels": {"soma": {"hh": ["il", "el"], "pas": ["i"]}, "axon": {"pas": ["i"]}}}
     recs = rm.recordings_of_cellular_components_NEURON(self.chosenmodel)
     sm.engage_NEURON()
     a = (Counter(list(recs["channels"]["soma"]["hh"][0])) != Counter(
         list(recs["channels"]["soma"]["hh"][1])))
     b = (Counter(list(recs["channels"]["soma"]["pas"][0])) != Counter(
         list(recs["channels"]["axon"]["pas"][0])))
     self.assertEqual([a, b], [True, True])
     os.chdir(pwd)  # reset to the location of this managerRecordTest.py
Ejemplo n.º 6
0
 def test_1_recordings_of_cellular_regionbodies_NEURON(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     sm.prepare_model_NEURON(parameters=self.no_parameters,
                             chosenmodel=self.chosenmodel)
     # self.chosenmodel.regions ->
     # {"soma": ["v", "i_cap"], "axon": ["v"],
     # "channels": {"soma": {"hh": ["il", "el"], "pas": ["i"]}, "axon": {"pas": ["i"]}}}
     recs = rm.recordings_of_cellular_regionbodies_NEURON(self.chosenmodel)
     sm.engage_NEURON()
     total_iterations = len(
         range(-1,
               int(self.no_parameters["tstop"] / self.no_parameters["dt"])))
     a = (Counter(list(recs["soma"][0])) != Counter(list(recs["axon"][0])))
     self.assertEqual([len(recs["soma"][0]), a], [total_iterations, True])
     os.chdir(pwd)  # reset to the location of this managerRecordTest.py
Ejemplo n.º 7
0
 def test_3_voltage_to_spiketrain_without_stimulation(self):
     os.chdir("..") # this moves you up to ~/managers
     os.chdir("..") # you are now in parent /cerebmodels
     parameters = {"dt": 0.1, "celsius": 20, "tstop": 10, "v_init": 65}
     sm.prepare_model_NEURON(parameters=parameters, chosenmodel=self.chosenmodel)
     self.rec["time"], self.rec["response"], self.rec["stimulus"] = \
              rm.prepare_recording_NEURON(self.chosenmodel)
     sm.engage_NEURON()
     spikes = co.voltage_to_spiketrain(self.chosenmodel, self.rec)
     ans = \
     len( range(
          int(spikes[self.regionslist_str[0]].t_start.magnitude),
          int(spikes[self.regionslist_str[0]].t_stop.magnitude/parameters["dt"])
           ) ) + 1 # for the additional dt step
     self.assertEqual( ans, len(self.rec["time"]) )
     os.chdir(pwd) # reset to the location of this converterTest.py
Ejemplo n.º 8
0
 def test_4_prepare_recording_NEURON_without_stimulating_but_evoke_stimulate_model(
         self):
     os.chdir(rootwd)  # move up to load the model
     # pick the modelstimtype = currparameters["type"]
     sm.prepare_model_NEURON(parameters=self.no_parameters,
                             chosenmodel=self.chosenmodel)
     # self.chosenmodel.regions ->
     # {"soma": ["v", "i_cap"], "axon": ["v"],
     # "channels": {"soma": {"hh": ["il", "el"], "pas": ["i"]}, "axon": {"pas": ["i"]}}}
     stimulate_not = sm.stimulate_model_NEURON()
     rec_t, recs, x = rm.prepare_recording_NEURON(self.chosenmodel,
                                                  stimuli=stimulate_not)
     sm.engage_NEURON()
     a = (Counter(list(recs["soma"][0])) != Counter(
         list(recs["channels"]["soma"]["pas"][0])))
     b = (Counter(list(recs["axon"][0])) != Counter(
         list(recs["channels"]["axon"]["pas"][0])))
     total_iterations = len(
         range(-1,
               int(self.no_parameters["tstop"] / self.no_parameters["dt"])))
     self.assertEqual([len(rec_t), a, b], [total_iterations, True, True])
     os.chdir(pwd)  # reset to the location of this managerRecordTest.py
Ejemplo n.º 9
0
 def test_4_voltage_to_spiketrain_with_stimulation(self):
     os.chdir("..") # this moves you up to ~/managers
     os.chdir("..") # you are now in parent /cerebmodels
     parameters = {"dt": 0.1, "celsius": 20, "tstop": 10, "v_init": 65}
     currparameters = {"type": ["current", "IClamp"],
                       "stimlist": [ {'amp': 0.5, 'dur': 10.0, 'delay': 5.0},
                                     {'amp': 1.0, 'dur': 20.0, 'delay': 5.0+10.0} ],
                       "tstop": parameters["tstop"] }
     sm.prepare_model_NEURON(parameters=parameters, chosenmodel=self.chosenmodel)
     stimuli_list = sm.stimulate_model_NEURON(stimparameters = currparameters,
                                            modelsite = self.chosenmodel.cell.soma)
     self.rec["time"], self.rec["response"], self.rec["stimulus"] = \
              rm.prepare_recording_NEURON(self.chosenmodel)
     sm.engage_NEURON()
     spikes = co.voltage_to_spiketrain(self.chosenmodel, self.rec)
     ans = \
     len( range(
          int(spikes[self.regionslist_str[0]].t_start.magnitude),
          int(spikes[self.regionslist_str[0]].t_stop.magnitude/parameters["dt"])
           ) ) + 1 # for the additional dt step
     self.assertEqual( ans, len(self.rec["time"]) )
     os.chdir(pwd) # reset to the location of this converterTest.py
Ejemplo n.º 10
0
 def test_5_prepare_recording_NEURON_currentclamp(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     sm.prepare_model_NEURON(parameters=self.ic_parameters,
                             chosenmodel=self.chosenmodel)
     # self.chosenmodel.regions ->
     # {"soma": ["v", "i_cap"], "axon": ["v"],
     # "channels": {"soma": {"hh": ["il", "el"], "pas": ["i"]}, "axon": {"pas": ["i"]}}}
     stimuli_list = sm.stimulate_model_NEURON(
         stimparameters=self.ic_stimparam,
         modelsite=self.chosenmodel.cell.soma)
     rec_t, recs, rec_i_indivs = rm.prepare_recording_NEURON(
         self.chosenmodel,
         stimuli=stimuli_list,
         stimtype=self.ic_stimparam["type"])
     sm.engage_NEURON()
     total_iterations = len(
         range(-1,
               int(self.ic_parameters["tstop"] / self.ic_parameters["dt"])))
     self.assertEqual(
         len(rec_t) + len(recs["soma"][0]) + len(rec_i_indivs),
         2 * total_iterations + len(self.ic_stimparam["stimlist"]))
     os.chdir(pwd)  # reset to the location of this managerRecordTest.py
Ejemplo n.º 11
0
 def test_2_transform_signal_to_spikes(self):
     os.chdir("..")  # move up to load the model
     # pick the model
     parameters = {"dt": 0.1, "celsius": 30, "tstop": 10, "v_init": 65}
     currparameters = {
         "type": ["current", "IClamp"],
         "stimlist": [{
             'amp': 0.5,
             'dur': 10.0,
             'delay': 5.0
         }, {
             'amp': 1.0,
             'dur': 20.0,
             'delay': 5.0 + 10.0
         }]
     }
     sm.prepare_model_NEURON(parameters=parameters,
                             chosenmodel=self.chosenmodel)
     stimuli_list = sm.stimulate_model_NEURON(
         stimparameters=currparameters,
         modelsite=self.chosenmodel.cell.soma)
     self.rec["time"], self.rec["response"], self.rec["stimulus"] = \
              rm.prepare_recording_NEURON(self.chosenmodel)
     sm.engage_NEURON()
     spikes = sp.transform_signal(chosenmodel=self.chosenmodel,
                                  recordings=self.rec,
                                  tosignal='spikes')
     ans = \
       len( range(
            int(spikes[self.regionslist_str[0]].t_start.magnitude),
            int(spikes[self.regionslist_str[0]].t_stop.magnitude/parameters["dt"])
           ) ) + 1 # for the additional dt step
     self.assertEqual(ans, len(self.rec["time"]))
     os.chdir(
         pwd
     )  # reset to the location of this managerSignalProcessingTest.py
Ejemplo n.º 12
0
    def launch_model(self,
                     parameters=None,
                     onmodel=None,
                     stimparameters=None,
                     stimloc=None,
                     capabilities={
                         'model': None,
                         'vtest': None
                     },
                     mode="raw"):
        """Directs the :ref:`SimulationManager` to launch simulation on an instantiated model.

        **Keyword Arguments:**

        +-------------------------------+----------------------------------------------+
        | Key                           | Value type                                   |
        +===============================+==============================================+
        | ``parameters``                | dictionary                                   |
        +-------------------------------+----------------------------------------------+
        |  ``onmodel``                  | instantiated model                           |
        +-------------------------------+----------------------------------------------+
        | ``stimparameters`` (optional) | dictionary                                   |
        +-------------------------------+----------------------------------------------+
        | ``stimloc`` (optional)        | string; attribute name of instantiated model |
        +-------------------------------+----------------------------------------------+
        | ``capabilities`` (optional)   | dictionary                                   |
        +-------------------------------+----------------------------------------------+
        | ``mode`` (optional)           | string;                                      |
        |                               |- "raw" (default), "capability"               |
        +-------------------------------+----------------------------------------------+

        * ``parameters``- *mandatory* whose value is a dictionary. For example, ``parameters = {"dt": 0.01, "celsius": 30, "tstop": 100, "v_init": 65}``
        * ``onmodel``- *mandatory* whose value is the instantiated model using :py:meth:`.choose_model()`. For example, ``onmodel = <instance>.choose_model(modelscale="a_chosen_scale", modelname="a_chosen_name")``.
        * ``stimparameters``- optional whose value is a dictionary. For example, ``{"type": ["current", "IClamp"], "stimlist": [ {'amp': 0.5, 'dur': 100.0, 'delay': 10.0}, {'amp': 1.0, 'dur': 50.0, 'delay': 10.0+100.0} ] }``.
        * ``stimloc``- optional (mandatory only if ``stimparameters`` argument is provided). Its value is string representing the namse of an attribute of the instantiated model. Note that this instantiated model is the value for the mandatory keyword argument ``onmodel``.
        * ``capabilties``- optional whose value is a dictionary. The dictionary **must** have the keys ``model`` and ``vtest``. The value for ``model`` key is a string representing the models method. For example, ``model: "produce_voltage_response"``. The value for ``vtest`` key is a class imported from the installed ``CerebUnit``.

        *NOTE*: Calling this function returns the model as the attribute ``ExecutiveControl.chosenmodel``.
        """
        # NOTE: although it is convenient to use self.chosenmodel
        # to the user having explicitly choose onmodel as an argument is clearer
        uu.check_not_None_in_arg({
            'parameters': parameters,
            'onmodel': onmodel
        })
        get_stimtype = (lambda stimpar: None
                        if stimpar is None else stimpar["type"])
        self.simtime = datetime.datetime.now()
        if onmodel.modelscale is "cells":
            get_stimloc = (
                lambda stimloc: None
                if stimloc is None else getattr(onmodel.cell, stimloc))
            sm.prepare_model_NEURON(parameters=parameters,
                                    chosenmodel=onmodel,
                                    modelcapability=capabilities['model'],
                                    cerebunitcapability=capabilities['vtest'])
            stimuli_clamp = sm.stimulate_model_NEURON(
                stimparameters=stimparameters, modelsite=get_stimloc(stimloc))
            self.recordings["time"], self.recordings["response"], rec_clamp_indivs = \
                    rm.prepare_recording_NEURON( onmodel,
                                                 stimuli = stimuli_clamp,
                                                 stimtype = get_stimtype(stimparameters) )
            if mode == "raw":
                sm.trigger_NEURON(onmodel)
            elif mode == "capability":
                sm.trigger_NEURON(
                    onmodel,
                    modelcapability=capabilities['model'],
                    # Below are the **kwargs for lock_and_load_capability
                    parameters=parameters,
                    stimparameters=stimparameters,
                    stimloc=stimloc,
                    onmodel=onmodel,
                    mode="capability")
            self.recordings["stimulus"] = \
                    rm.postrun_record_NEURON( injectedstimuli = rec_clamp_indivs,
                                              stimtype = get_stimtype(stimparameters) )
        # save the parameters as attributes
        self.chosenmodel = onmodel
        self.parameters = parameters
        self.stimparameters = stimparameters
        return self.chosenmodel