Ejemplo n.º 1
0
 def session_info(self):
     """method displaying the session of loaded nwbfile as table
     """
     Row = namedtuple('Row', ['metadata_background', 'metadata'])
     data1 = Row("Where is the data from?", self.nwbfile.source)
     data2 = Row("How was the data generated?",
                 self.nwbfile.session_description)
     data3 = Row("When did the simulation start?",
                 self.nwbfile.session_start_time)
     data4 = Row("What is the session id?", self.nwbfile.session_id)
     uu.pprinttable([data1, data2, data3, data4])
Ejemplo n.º 2
0
 def test_11_stimulate_model_NEURON_voltage(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     modelmodule = importlib.import_module("models.cells.modelDummyTest")
     pickedmodel = getattr(modelmodule,
                           uu.classesinmodule(modelmodule)[0].__name__)
     chosenmodel = pickedmodel()
     #
     parameters = {"dt": 0.01, "celsius": 30, "tstop": 100, "v_init": 65}
     voltparameters = {
         "type": ["voltage", "SEClamp"],
         "stimlist": [{
             'amp1': 0.,
             'dur1': 100.0
         }, {
             'amp2': 20.,
             'dur2': 150.0
         }]
     }
     sm.prepare_model_NEURON(parameters=parameters, chosenmodel=chosenmodel)
     stimuli = sm.stimulate_model_NEURON(stimparameters=voltparameters,
                                         modelsite=chosenmodel.cell.soma)
     self.assertEqual([stimuli.amp1, stimuli.amp2, stimuli.dur2], [
         voltparameters["stimlist"][0]["amp1"],
         voltparameters["stimlist"][1]["amp2"],
         voltparameters["stimlist"][1]["dur2"]
     ])
     os.chdir(pwd)  # return to the location of this test file
Ejemplo n.º 3
0
 def test_10_stimulate_model_NEURON_current(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     modelmodule = importlib.import_module("models.cells.modelDummyTest")
     pickedmodel = getattr(modelmodule,
                           uu.classesinmodule(modelmodule)[0].__name__)
     chosenmodel = pickedmodel()
     #
     parameters = {"dt": 0.01, "celsius": 30, "tstop": 100, "v_init": 65}
     currparameters = {
         "type": ["current", "IClamp"],
         "stimlist": [{
             'amp': 0.5,
             'dur': 100.0,
             'delay': 10.0
         }, {
             'amp': 1.0,
             'dur': 50.0,
             'delay': 10.0 + 100.0
         }]
     }
     sm.prepare_model_NEURON(parameters=parameters, chosenmodel=chosenmodel)
     self.assertEqual(
         len(
             sm.stimulate_model_NEURON(stimparameters=currparameters,
                                       modelsite=chosenmodel.cell.soma)),
         len(currparameters["stimlist"]))
     os.chdir(pwd)  # return to the location of this test file
Ejemplo n.º 4
0
 def load_model(self):
     """method called by __init__
     """
     modelmodule = importlib.import_module("models." + self.modelscale +
                                           ".model" + self.modelname)
     pickedmodel = getattr(modelmodule,
                           uu.classesinmodule(modelmodule)[0].__name__)
     self.chosenmodel = pickedmodel()
Ejemplo n.º 5
0
 def test_8_stimulate_model_NEURON_parameter_None(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     modelmodule = importlib.import_module("models.cells.modelDummyTest")
     pickedmodel = getattr(modelmodule,
                           uu.classesinmodule(modelmodule)[0].__name__)
     chosenmodel = pickedmodel()
     #
     parameters = {"dt": 0.01, "celsius": 30, "tstop": 100, "v_init": 65}
     sm.prepare_model_NEURON(parameters=parameters, chosenmodel=chosenmodel)
     self.assertEqual(sm.stimulate_model_NEURON(),
                      "Model is not stimulated")
     os.chdir(pwd)  # return to the location of this test file
Ejemplo n.º 6
0
 def test_7_trigger_NEURON_raw(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     modelmodule = importlib.import_module("models.cells.modelDummyTest")
     pickedmodel = getattr(modelmodule,
                           uu.classesinmodule(modelmodule)[0].__name__)
     chosenmodel = pickedmodel()
     #
     parameters = {"dt": 0.01, "celsius": 30, "tstop": 100, "v_init": 65}
     sm.prepare_model_NEURON(parameters=parameters, chosenmodel=chosenmodel)
     self.assertEqual(sm.trigger_NEURON(chosenmodel),
                      "model was successfully triggered via NEURON")
     os.chdir(pwd)  # return to the location of this test file
Ejemplo n.º 7
0
 def test_5_lock_and_load_capability(self):
     os.chdir(rootwd)  # move up to load the model
     #from utilities import UsefulUtils as uu
     # pick the model
     modelmodule = importlib.import_module("models.cells.modelDummyTest")
     pickedmodel = getattr(modelmodule,
                           uu.classesinmodule(modelmodule)[0].__name__)
     chosenmodel = pickedmodel()
     #
     self.assertEqual(
         sm.lock_and_load_capability(chosenmodel,
                                     modelcapability="produce_spike_train"),
         "DummyTest model just finished run for produce_spike_train")
     os.chdir(pwd)  # return to the location of this test file
Ejemplo n.º 8
0
 def test_4_prepare_model_NEURON(self):
     os.chdir(rootwd)  # move up to load the model
     #from utilities import UsefulUtils as uu
     # pick the model
     modelmodule = importlib.import_module("models.cells.modelDummyTest")
     pickedmodel = getattr(modelmodule,
                           uu.classesinmodule(modelmodule)[0].__name__)
     chosenmodel = pickedmodel()
     #
     parameters = {"dt": 0.01, "celsius": 30, "tstop": 100, "v_init": 65}
     self.assertEqual(
         sm.prepare_model_NEURON(parameters=parameters,
                                 chosenmodel=chosenmodel),
         "NEURON model is ready")
     os.chdir(pwd)  # return to the location of this test file
Ejemplo n.º 9
0
 def test_9_stimulate_model_NEURON_parameter_error(self):
     os.chdir(rootwd)  # move up to load the model
     # pick the model
     modelmodule = importlib.import_module("models.cells.modelDummyTest")
     pickedmodel = getattr(modelmodule,
                           uu.classesinmodule(modelmodule)[0].__name__)
     chosenmodel = pickedmodel()
     #
     parameters = {"dt": 0.01, "celsius": 30, "tstop": 100, "v_init": 65}
     #currparameters = {"type": ["current", "IClamp"]} # default
     currparameters = {"type": "current"}  # alternative
     sm.prepare_model_NEURON(parameters=parameters, chosenmodel=chosenmodel)
     self.assertRaises(ValueError,
                       sm.stimulate_model_NEURON,
                       stimparameters=currparameters,
                       modelsite=chosenmodel.cell.soma)
     os.chdir(pwd)  # return to the location of this test file
Ejemplo n.º 10
0
    def choose_model(modelscale=None, modelname=None):
        """Returns instantiated model for a desired model name available in the specified model scale.

        **Keyword Arguments:**

        +----------------+-------------+
        | Key            | Value type  |
        +================+=============+
        | ``modelscale`` | string      |
        +----------------+-------------+
        | ``modelname``  | string      |
        +----------------+-------------+

        *NOTE*: Currently only ``modelscale="cells"`` are supported. Future releases will include other model scales.
        """
        sm.lock_and_load_model_libraries(modelscale=modelscale,
                                         modelname=modelname)
        modelmodule = importlib.import_module("models." + modelscale +
                                              ".model" + modelname)
        chosenmodel = getattr(modelmodule,
                              uu.classesinmodule(modelmodule)[0].__name__)
        return chosenmodel()
Ejemplo n.º 11
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