コード例 #1
0
 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
コード例 #2
0
 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
コード例 #3
0
ファイル: tabModels.py プロジェクト: cerebunit/cerebmodels
 def simulate():
     print "running"
     #if modelscales_select.value == "No_Models":
     #print modelscales_select.value
     #else:
     #print modelscales_select.value
     print pwd
     sys.path.append(pwd)  # uncomment only when using executiveViz
     ec = ExecutiveControl()
     modelscale = models_select.value.split()[0]
     modelname = models_select.value.split()[1]
     chosenmodel = ec.choose_model(modelscale=modelscale,
                                   modelname=modelname)
     parameters = ast.literal_eval(runtime_input.value)
     print parameters
     print stimulation.value
     if stimulation.value == "yes":
         stimparameters = ast.literal_eval(stim_type_input.value)
         stimparameters.update(
             {"stimlist": ast.literal_eval(stim_list_input.value)})
         ec.launch_model(parameters=parameters,
                         onmodel=chosenmodel,
                         stimparameters=stimparameters,
                         stimloc=stim_loc_input.value)
         #with Profiler() as prof, ResourceProfiler() as rprof:
         #    ec.launch_model ( parameters=parameters, onmodel=chosenmodel,
         #                      stimparameters=stimparameters, stimloc=stim_loc_input.value )
     else:
         ec.launch_model(parameters=parameters, onmodel=chosenmodel)
         #with Profiler() as prof, ResourceProfiler() as rprof:
         #    ec.launch_model( parameters=parameters, onmodel=chosenmodel )
         #myplot = visualize([prof, rprof])
     ec.save_response()
     print "done running"
コード例 #4
0
ファイル: readerTest.py プロジェクト: cerebunit/cerebmodels
 def setUp(self):
     self.pwd = os.getcwd()
     # Create two files with/without stimulus
     #fab = Fabricator() # NOTE: Reader() is an exception for not instantiating
     os.chdir(rootwd)
     self.chosenmodel = DummyCell()
     os.chdir(pwd)
     #
     self.ec = ExecutiveControl()
     #
     if os.path.isdir(pwd + os.sep + "responses"):
         shutil.rmtree("responses")
     #
     runtimeparam = {"dt": 0.1, "celsius": 30, "tstop": 200.0, "v_init": 65}
     stimparam = {
         "type": ["current", "IClamp"],
         "stimlist": [{
             "amp": 0.5,
             "dur": 100.0,
             "delay": 10.0
         }, {
             "amp": 1.0,
             "dur": 50.0,
             "delay": 10.0 + 100.0
         }],
         "tstop":
         runtimeparam["tstop"]
     }
     #
     # Write for stimulus
     self.ec.launch_model(parameters=runtimeparam,
                          stimparameters=stimparam,
                          stimloc=self.chosenmodel.cell.soma,
                          onmodel=self.chosenmodel)
     self.ec.save_response()
     # Get filename
     self.file_stim = fm.show_filenames_with_path(
         ["responses", "cells", "DummyTest"])
     # save for comparison
     self.stimulus_for_comparison = numpy.array(
         self.ec.recordings["stimulus"])
     #
     # Write for nostimulus
     self.ec.launch_model(parameters=runtimeparam, onmodel=self.chosenmodel)
     self.ec.save_response()
     # Get filename
     self.file_nostim = fm.show_filenames_with_path(
         ["responses", "cells", "DummyTest"])
     for key in self.file_stim:
         del self.file_nostim[key]
コード例 #5
0
 def generate_prediction(self, model, verbose=False):
     """
     Generates resting Vm from soma.
     The function is automatically called by sciunit.Test which this test is a child of.
     Therefore as part of sciunit generate_prediction is mandatory.
     """
     #self.confidence = confidence # set confidence for test 90%, 95% (default), 99%
     #
     runtimeparam = {
         "dt": 0.025,
         "celsius": 30,
         "tstop": 1000.0,
         "v_init": -80.
     }
     stimparam = {
         "type": ["current", "IClamp"],
         "stimlist": [{
             "amp": 0.006,
             "dur": 800.0,
             "delay": 100.0
         }],
         "tstop": runtimeparam["tstop"]
     }
     ec = ExecutiveControl()
     #ec.chosenmodel = model
     #ec.chosenmodel.restingVm = \
     model = ec.launch_model(parameters=runtimeparam,
                             stimparameters=stimparam,
                             stimloc="soma",
                             onmodel=model,
                             capabilities={
                                 "model": "produce_restingVm",
                                 "vtest": ProducesSomaRestingVm
                             },
                             mode="capability")
     #return pq.Quantity( numpy.mean(ec.chosenmodel.prediction), # prediction
     #                    units = self.observation["units"] )
     return pq.Quantity(
         numpy.mean(model.prediction),  # prediction
         units=self.observation["units"])
コード例 #6
0
    def produce_voltage_response(self, **kwargs):
        """generic/essential model response

        **Keyword Arguments:**

        kwargs = { "parameters": dictionary with keys,
                   "stimparameters": None or dictionary with keys "type" and "stimlist",
                   "onmodel": instantiated model }
        """
        #ExecutiveControl.launch_model_raw("cells")
        print("Simulation produce_voltage_response starting ...")
        ec = ExecutiveControl() # only works when in ~/cerebmodels
        model = ec.launch_model( parameters = kwargs["parameters"],
                                 stimparameters = kwargs["stimparameters"],
                                 stimloc = kwargs["stimloc"],
                                 onmodel = kwargs["onmodel"], mode = "raw" )
        print("File saving ...")
        fullfilename = ec.save_response()
        setattr(model, "fullfilename", fullfilename)
        print("File saved.")
        print("Simulation produce_voltage_response Done.")
        return model
コード例 #7
0
ファイル: tabModels.py プロジェクト: cerebunit/cerebmodels
 def update_global_model(attr, old, new):
     menu_list = new.split()
     modelscale = menu_list[0]  # update global modelscale
     modelname = menu_list[1]  # update glocal modelname
     #print modelscale, modelname
     sys.path.append(pwd)  # uncomment only when using executiveViz
     chosenmodel = ExecutiveControl.choose_model(modelscale=str(modelscale),
                                                 modelname=str(modelname))
     modeltitle.text = chosenmodel.name
     modeldescr.text = chosenmodel.description
     modelregions.text = "Potential stimulation sites: " + str(
         chosenmodel.regions)
     runmodel.disabled = False
コード例 #8
0
 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
コード例 #9
0
    def __init__(self, model, validation_test, alpha=0.05, epsilon=5):
        """
        This constructor method initializes the dictionary ``.model``, 
        validation test ``.validation_test``, level of significance ``.alpha``
        and error limit (Epsilon) ``.epsilon``.

        Default value for ``.alpha`` is set to 0.05 while value of ``.epsilon`` is set to 5.  
        """
        self.level_of_significance = alpha
        self.epsilon = epsilon
        self.modelscale = model["modelscale"]
        self.modelname = model["modelname"]
        self.validation_test = validation_test

        from executive import ExecutiveControl as ec
        self.exc = ec()
        self.desired_model = ec.choose_model(modelscale=self.modelscale,
                                             modelname=self.modelname)
コード例 #10
0
class SpontaneousFiringTest(sciunit.Test):
    """
    This test compares the measured unstimulated firing frequency observed in real animal (in-vitro or in-vivo, depending on the data) generated from neuron against those by the model.
    """
    required_capabilities = (ProducesEphysMeasurement,)
    score_type = TScore
    ec = ExecutiveControl()

    def generate_prediction(self, model, confidence=0.95, verbose=False):
        """
        Generates resting Vm from soma.
        The function is automatically called by sciunit.Test which this test is a child of.
        Therefore as part of sciunit generate_prediction is mandatory.
        """
        self.confidence = confidence # set confidence for test 90%, 95% (default), 99%
        #
        runtimeparam = {"dt": 0.025, "celsius": 30, "tstop": 1000.0, "v_init": -80.}
        stimparam = {"type": ["current", "IClamp"],                                                  
                     "stimlist": [ {"amp": 0.006, "dur": 800.0, "delay": 100.0} ],                 
                     "tstop": runtimeparam["tstop"] }
        ec.launch_model( parameters = runtimeparam, stimparameters = stimparam,
                         stimloc = "soma", onmodel = model,
                         capabilities = {"model": "produce_restingVm",
                                         "vtest": ProducesEphysMeasurement} )
        return pq.Quantity( numpy.mean(model.restingVm) # prediction
                            units = observation["units"] )

    def validate_observation(self, observation, first_try=True):
        """
        This function is called automatically by sciunit and
        clones it into self.observation
        This checks if the experimental_data is of some desired
        form or magnitude.
        Not exactly this function but a version of this is already
        performed by the ValidationTestLibrary.get_validation_test
        """
        if ("mean" not in observation or
            "margin_of_error" not in observation or
            "sample_size" not in observation or
            "units" not in observation):
            raise sciunit.ObservationError
        self.observation["mean"] = pq.Quantity( self.observation["mean"],
                                                units=observation["units"] )
        self.observation["margin_of_error"] = pq.Quantity( self.observation["margin_of_error"],
                                                          units=observation["units"] )
        self.observation["standard_error"] = self.observation["margin_of_error"] / \
                               self.get_tmultiplier(self.confidence, observation["sample_size"])

    @staticmethod
    def get_tmultiplier(confidence, n):
        return scipy.stats.t.ppf( (1+confidence)/2, n-1 )

    def compute_score(self, observation, prediction, verbose=False):
        """
        This function like generate_pediction is called automatically by sciunit
        which RestingVmTest is a child of. This function must be named compute_score
        The prediction processed from "vm_soma" is compared against
        the experimental_data to get the binary score; 0 if the
        prediction correspond with experiment, else 1.
        """
        score = TScore.compute( observation, prediction  )
        score.description = HtestAboutMeans( observation, prediction, score )
        print score.hypotest
        return score
コード例 #11
0
ファイル: tabModels.py プロジェクト: cerebunit/cerebmodels
def TabModels():
    """available_modelscales = ['cells', 'microcircuit', 'network']
    """
    def get_select_menu(menu_type, menu_list):
        if menu_type == "modelscales":
            title = "Modeling Scale Options"
        elif menu_type == "models":
            title = "Choose a model name"
        elif menu_type == "responses":
            title = "Choose a response (file)"
        return Select(title=title, value=menu_list[0][0], options=menu_list)

    def get_menu_modelscales():
        #NOTE: available_modelscale & scale_and_models are global variables
        menu = [("None", "None")]
        for modelscale in available_modelscales:
            # tag the modelscale as first element in the value = modellist
            modellist = ' '.join([modelscale] + scale_and_models[modelscale])
            menu.append(
                (modellist, modelscale))  # tuple (string of models, scale)
        return menu

    def get_menu_models(modellist):
        #NOTE: models_with_filenames is a global variable
        menu = [("None", "Below are available models")]
        if modellist[1] == "No_Models":  #modellist[0]=modelname
            menu[0] = (modellist[1], modellist[1].replace("_", " ")
                       )  #tuple (scale, string of models)
        else:
            for modelname in modellist[1:]:
                # tag modelscale & modelname as 1st-two elements in the value
                itsvalue = ' '.join([modellist[0], modelname])
                menu.append(
                    (itsvalue, modelname))  # tuple (string of models, scale)
        return menu

    def update_models_list(attr, old, new):
        if new == "No_Models":
            menu_list = [''.join(list(new))]  # ["No Models"]
        else:
            menu_list = new.split()
        models_select.options = get_menu_models(menu_list)
        runmodel.disabled = True
        #print new
        #print modelscales_select.value
        #print menu_list
        #print menu_list[0]

    def update_global_model(attr, old, new):
        menu_list = new.split()
        modelscale = menu_list[0]  # update global modelscale
        modelname = menu_list[1]  # update glocal modelname
        #print modelscale, modelname
        sys.path.append(pwd)  # uncomment only when using executiveViz
        chosenmodel = ExecutiveControl.choose_model(modelscale=str(modelscale),
                                                    modelname=str(modelname))
        modeltitle.text = chosenmodel.name
        modeldescr.text = chosenmodel.description
        modelregions.text = "Potential stimulation sites: " + str(
            chosenmodel.regions)
        runmodel.disabled = False

    def update_stimulation_parameters_input_status(attr, old, new):
        if new == "no":
            stim_type_input.disabled = True
            stim_list_input.disabled = True
            stim_loc_input.disabled = True
        else:
            stim_type_input.disabled = False
            stim_list_input.disabled = False
            stim_loc_input.disabled = False

    def clicked():
        print "clicked"

    def simulate():
        print "running"
        #if modelscales_select.value == "No_Models":
        #print modelscales_select.value
        #else:
        #print modelscales_select.value
        print pwd
        sys.path.append(pwd)  # uncomment only when using executiveViz
        ec = ExecutiveControl()
        modelscale = models_select.value.split()[0]
        modelname = models_select.value.split()[1]
        chosenmodel = ec.choose_model(modelscale=modelscale,
                                      modelname=modelname)
        parameters = ast.literal_eval(runtime_input.value)
        print parameters
        print stimulation.value
        if stimulation.value == "yes":
            stimparameters = ast.literal_eval(stim_type_input.value)
            stimparameters.update(
                {"stimlist": ast.literal_eval(stim_list_input.value)})
            ec.launch_model(parameters=parameters,
                            onmodel=chosenmodel,
                            stimparameters=stimparameters,
                            stimloc=stim_loc_input.value)
            #with Profiler() as prof, ResourceProfiler() as rprof:
            #    ec.launch_model ( parameters=parameters, onmodel=chosenmodel,
            #                      stimparameters=stimparameters, stimloc=stim_loc_input.value )
        else:
            ec.launch_model(parameters=parameters, onmodel=chosenmodel)
            #with Profiler() as prof, ResourceProfiler() as rprof:
            #    ec.launch_model( parameters=parameters, onmodel=chosenmodel )
            #myplot = visualize([prof, rprof])
        ec.save_response()
        print "done running"
        #viz_source.data['diagnostic'][0] = prof
        #viz_source.data['diagnostic'][1] = rprof
        #viz_source.data['diagnostic'] = [prof, rprof]
        #viz_source.data['diagnostic'][0].results[0] = prof.results[0]
        #myplot.data['diagplots'][0] = visualize([prof, rprof])

        #return visualize([prof, rprof])

    #
    ### +++++++++++++++++++GENERATE DATA FOR THE OPTIONS MENU++++++++++++++++++
    # available_modelscales -- list
    # scale_and_models -- dictionary with list as key value
    # models_with_filenames -- dictionary with list as key value
    # responses_with_filepaths -- dictionary with string as key value
    # Generate Model Info
    #os.chdir("..") # line required for calling ~/managers/bokehtest.py
    #available_modelscales = fm.available_modelscales()
    #os.chdir(rootwd) # for running it from ~/managers
    available_modelscales = ExecutiveControl.list_modelscales()
    scale_and_models = {}
    for modelscale in available_modelscales:  # get list of models in each scale
        try:
            #modelslist = fm.modelscale_inventory(model_scale=modelscale)
            modelslist = ExecutiveControl.list_models(modelscale=modelscale)
        except:
            modelslist = ["No_Models"]
        scale_and_models.update({modelscale: modelslist})
    #os.chdir(pwd) # for running it from ~/managers
    #print scale_and_models
    ### ++++++++++++++++++++END GENERATE DATA FOR THE OPTIONS++++++++++++++++++
    #
    modelscale = None
    modelname = None
    chosenmodel = None
    #
    menu = get_menu_modelscales()
    modelscales_select = get_select_menu("modelscales", menu)
    #
    dummy_model_menu = [('None', "First select a model scale")]
    models_select = get_select_menu("models", dummy_model_menu)
    #
    runtime_input = TextInput(
        value="{'dt': 0.1, 'celsius': 30, 'tstop': 10, 'v_init': 65}",
        title="Runtime Parameters:")
    #print runtime_input.value
    #print type(runtime_input.value)
    #
    stimulation_menu = [("No", "no"), None, ("Yes", "yes")]
    stimulation = Dropdown(label="Stimulation Yes/No",
                           button_type="warning",
                           menu=stimulation_menu)
    stim_type_input = TextInput(
        value="{'type': ['current', 'IClamp']}",
        title="Stimulation Parameters (Stimulation Type):")
    stim_list_input = TextInput(
        value="[{'amp': 0.5, 'dur': 10.0, 'delay': 5.0}, "
        " {'amp': 1.0, 'dur': 20.0, 'delay': 15.0}]",
        title="Stimulation Parameters (Stimuli):")
    stim_loc_input = TextInput(value='soma', title="Stimulation location:")
    # disable stimulation by DEFAULT
    stim_type_input.disabled = True
    stim_list_input.disabled = True
    stim_loc_input.disabled = True
    #
    runmodel = Button(label="Run Simulation", button_type="success")
    runmodel.disabled = True
    #
    modeltitle = Div(text="""No Model has been selected yet.""",
                     width=290,
                     height=40)
    modeldescr = Paragraph(text="""There is no Model Description.""",
                           width=290,
                           height=200)
    modelregions = Div(
        text="""Main Locations within the model for stimulation""",
        width=290,
        height=50)
    # disable the model texts by DEFAULT
    modeltitle.disabled = True
    modeldescr.disabled = True
    modelregions.disabled = True

    def viz():
        return visualize(viz_source.data['diagnostic'])

    # Put controls in a single element
    viz_source = ColumnDataSource(
        data={'diagnostic': [Profiler(), ResourceProfiler()]})
    myplot = viz()
    #diagplot = visualize( viz_source.data['diagnostic'] )
    #myplot = ColumnDataSource(data={'diagplots': [diagplot]})
    #myplot = ColumnDataSource(data={'diagplots': [visualize([Profiler(), ResourceProfiler()])]})

    # INTERACTION
    modelscales_select.on_change("value", update_models_list)
    models_select.on_change("value", update_global_model)
    #responses_select.on_change("value", update_plot)
    stimulation.on_change("value", update_stimulation_parameters_input_status)
    runmodel.on_click(simulate)

    # Create a row layout
    mylayout = row(
        WidgetBox(modelscales_select, models_select, runtime_input,
                  stimulation, stim_type_input, stim_list_input,
                  stim_loc_input, runmodel),
        WidgetBox(modeltitle, modeldescr, modelregions),
        #row(viz_source.data['diagnostic'][0].visualize()))
        #row(myplot.data['diagplots'][0]))
        row(myplot))
    # Make a tab with the layout
    tab = Panel(child=mylayout, title='Choose Model')

    return tab
コード例 #12
0
ファイル: readerTest.py プロジェクト: cerebunit/cerebmodels
class ReaderTest(unittest.TestCase):
    def setUp(self):
        self.pwd = os.getcwd()
        # Create two files with/without stimulus
        #fab = Fabricator() # NOTE: Reader() is an exception for not instantiating
        os.chdir(rootwd)
        self.chosenmodel = DummyCell()
        os.chdir(pwd)
        #
        self.ec = ExecutiveControl()
        #
        if os.path.isdir(pwd + os.sep + "responses"):
            shutil.rmtree("responses")
        #
        runtimeparam = {"dt": 0.1, "celsius": 30, "tstop": 200.0, "v_init": 65}
        stimparam = {
            "type": ["current", "IClamp"],
            "stimlist": [{
                "amp": 0.5,
                "dur": 100.0,
                "delay": 10.0
            }, {
                "amp": 1.0,
                "dur": 50.0,
                "delay": 10.0 + 100.0
            }],
            "tstop":
            runtimeparam["tstop"]
        }
        #
        # Write for stimulus
        self.ec.launch_model(parameters=runtimeparam,
                             stimparameters=stimparam,
                             stimloc=self.chosenmodel.cell.soma,
                             onmodel=self.chosenmodel)
        self.ec.save_response()
        # Get filename
        self.file_stim = fm.show_filenames_with_path(
            ["responses", "cells", "DummyTest"])
        # save for comparison
        self.stimulus_for_comparison = numpy.array(
            self.ec.recordings["stimulus"])
        #
        # Write for nostimulus
        self.ec.launch_model(parameters=runtimeparam, onmodel=self.chosenmodel)
        self.ec.save_response()
        # Get filename
        self.file_nostim = fm.show_filenames_with_path(
            ["responses", "cells", "DummyTest"])
        for key in self.file_stim:
            del self.file_nostim[key]

    #@unittest.skip("reason for skipping")
    def test_1_init(self):
        # loads nwbfile, extracts modelname, modelscale & instantiate model
        os.chdir(rootwd)
        for key in self.file_nostim:
            reader_io_nostim = Reader(self.file_nostim[key])
        for key in self.file_stim:
            reader_io_stim = Reader(self.file_stim[key])
        os.chdir(pwd)
        #
        reader_io_nostim.chosenmodel = self.chosenmodel
        reader_io_stim.chosenmodel = self.chosenmodel
        #print self.chosenmodel.name
        # this tests extract_modelname_modelscale & load_model
        compare1 = [
            reader_io_nostim.modelname,  # output of 
            reader_io_nostim.modelscale
        ]  # extract_modelname_modelscale()
        compare2 = [
            reader_io_stim.chosenmodel.modelname,  # output of
            reader_io_stim.chosenmodel.modelscale
        ]  # load_model()
        self.assertEqual(compare1, compare2)
        reader_io_nostim.closefile()
        reader_io_stim.closefile()

    #@unittest.skip("reason for skipping")
    def test_2_visualizetable(self):
        # gives you session of the nwbfile
        os.chdir(rootwd)
        for key in self.file_nostim:
            reader_io_nostim = Reader(self.file_nostim[key])
        os.chdir(pwd)
        reader_io_nostim.session_info()  # pretty prints table
        reader_io_nostim.closefile()

    #@unittest.skip("reason for skipping")
    def test_3_pull_epochindices_chosenregion(self):
        os.chdir(rootwd)
        for key in self.file_stim:
            reader_io_stim = Reader(self.file_stim[key])
        os.chdir(pwd)
        epoch_indices_soma = reader_io_stim.pull_epochindices_chosenregion(
            'soma')
        epoch_indices_axon = reader_io_stim.pull_epochindices_chosenregion(
            'axon')
        #print epoch_indices_soma
        #print epoch_indices_axon
        self.assertNotEqual(epoch_indices_soma, epoch_indices_axon)
        reader_io_stim.closefile()
        #shutil.rmtree("responses")

    #@unittest.skip("reason for skipping")
    def test_4_pull_epochid(self):
        os.chdir(rootwd)
        for key in self.file_stim:
            reader_io_stim = Reader(self.file_stim[key])
        os.chdir(pwd)
        epoch_indices_soma = reader_io_stim.pull_epochindices_chosenregion(
            'soma')
        epoch_indices_axon = reader_io_stim.pull_epochindices_chosenregion(
            'axon')
        epoch_ids_soma = [
            reader_io_stim.pull_epochid(epoch_indices_soma[0]),
            reader_io_stim.pull_epochid(epoch_indices_soma[1]),
            reader_io_stim.pull_epochid(epoch_indices_soma[2]),
            reader_io_stim.pull_epochid(epoch_indices_soma[3])
        ]
        epoch_ids_axon = [
            reader_io_stim.pull_epochid(epoch_indices_axon[0]),
            reader_io_stim.pull_epochid(epoch_indices_axon[1]),
            reader_io_stim.pull_epochid(epoch_indices_axon[2]),
            reader_io_stim.pull_epochid(epoch_indices_axon[3])
        ]
        #print epoch_indices_soma
        #print epoch_indices_axon
        #print epoch_ids_soma
        #print epoch_ids_axon
        #print len(reader_io_stim.nwbfile.epochs.epochs.data)
        #print reader_io_stim.nwbfile.epochs.epochs.data[0]#[3][0]
        #print reader_io_stim.nwbfile.epochs.epochs.data[3]#[3][0]
        #print reader_io_stim.nwbfile.epochs.epochs.data[4]#[3][0]
        #print reader_io_stim.nwbfile.epochs.epochs.data[5]#[3][0]
        #print epoch_indices_soma, epoch_id_soma
        #print epoch_indices_soma, reader_io_stimulus.pull_epochid(epoch_indices_soma[1])
        #print epoch_indices_axon, epoch_id_axon
        #print reader_io_stimulus.nwbfile.epochs.epochs.data
        #print reader_io_stimulus.nwbfile.epochs.epochs.data[0]
        #print reader_io_stimulus.nwbfile.epochs.epochs.data[1][2]
        self.assertNotEqual(epoch_ids_soma, epoch_ids_axon)
        reader_io_stim.closefile()

    #@unittest.skip("reason for skipping")
    def test_5_drawout_orderedepochs(self):
        os.chdir(rootwd)
        for key in self.file_stim:
            reader_io_stim = Reader(self.file_stim[key])
        os.chdir(pwd)
        orderedepochs_soma = reader_io_stim.drawout_orderedepochs('soma')
        #print orderedepochs_soma
        #print len(orderedepochs_soma)
        #print orderedepochs_soma[0]          # first, i.e, epoch
        #print orderedepochs_soma[0][2]       # get root tuple
        #print orderedepochs_soma[0][2][3]    # get array
        #print orderedepochs_soma[0][2][3][0] # take out tuple from the array
        #print orderedepochs_soma[0][2][3][0][2] # take out timeseries object from tuple
        #print orderedepochs_soma[0][2][3][0][2].data.value
        #print type(orderedepochs_soma[0][2][3][0][2].data.value)
        #print orderedepochs_soma[0][2][3][0][2].timestamps.value
        #print len([ orderedepochs_soma[0][2][3][0][2].timestamps.value[i]
        #          for i in numpy.arange(orderedepochs_soma[0][2][3][0][0],
        #                                orderedepochs_soma[0][2][3][0][1]) ])
        #print orderedepochs_soma[0][1]
        #print orderedepochs_soma[0][0]
        #print reader_io_stim.nwbfile.epochs.epochs.data[orderedepochs_soma[0][0]]
        #to compare
        compare1 = [orderedepochs_soma[0][1], orderedepochs_soma[1][1]]
        self.assertEqual(compare1, [0, 1])
        reader_io_stim.closefile()

    #@unittest.skip("reason for skipping")
    def test_6_get_tuple_for_epoch(self):
        # To get an epoch
        os.chdir(rootwd)
        for key in self.file_stim:
            reader_io_stim = Reader(self.file_stim[key])
        os.chdir(pwd)
        orderedepochs_soma = reader_io_stim.drawout_orderedepochs(
            'soma')  # drawout orderedepochs
        #epochs = []
        #for i in range(len(orderedepochs_soma)):
        #    epoch_id = orderedepochs_soma[i][1]
        #    epochs.append( Reader.get_array_for_epoch(epoch_id, orderedepochs_soma) ) # get epoch
        #print epochs
        #print epochs[0]
        #print epochs[1]
        epoch_id = 0
        epochtuple = Reader.get_tuple_for_epoch(epoch_id, orderedepochs_soma)
        #print epochtuple
        #print epochtuple[2].timestamps_unit #description/unit/time_unit/timestamps_unit
        self.assertNotEqual(
            epochtuple[0],  # tstart index
            epochtuple[1])  # counts
        #self.assertNotEqual( epochs[0], epochs[1] )
        reader_io_stim.closefile()

    #@unittest.skip("reason for skipping")
    def test_7_get_timestamps_for_epoch(self):
        os.chdir(rootwd)
        for key in self.file_nostim:
            reader_io_nostim = Reader(self.file_nostim[key])
        os.chdir(pwd)
        orderedepochs_soma = reader_io_nostim.drawout_orderedepochs(
            'soma')  #drawout orderedepoch
        orderedepochs_axon = reader_io_nostim.drawout_orderedepochs('axon')
        epoch_id = 0
        times_soma = reader_io_nostim.get_timestamps_for_epoch(
            epoch_id, orderedepochs_soma)
        times_axon = reader_io_nostim.get_timestamps_for_epoch(
            epoch_id, orderedepochs_axon)
        #
        self.assertEqual([len(times_soma), times_soma],
                         [len(times_axon), times_axon])
        reader_io_nostim.closefile()

    #@unittest.skip("reason for skipping")
    def test_8_get_datavalues_for_epoch(self):
        os.chdir(rootwd)
        for key in self.file_stim:
            reader_io_stim = Reader(self.file_stim[key])
        os.chdir(pwd)
        orderedepochs_soma = reader_io_stim.drawout_orderedepochs(
            'soma')  #drawout orderedepoch
        orderedepochs_axon = reader_io_stim.drawout_orderedepochs('axon')
        epoch_id = 1
        data_soma = reader_io_stim.get_datavalues_for_epoch(
            epoch_id, orderedepochs_soma)
        data_axon = reader_io_stim.get_datavalues_for_epoch(
            epoch_id, orderedepochs_axon)
        #
        self.assertNotEqual(data_soma, data_axon)
        reader_io_stim.closefile()

    #@unittest.skip("reason for skipping")
    def test_9_get_stimulus(self):
        os.chdir(rootwd)
        for key in self.file_stim:
            reader_io_stim = Reader(self.file_stim[key])
        os.chdir(pwd)
        #print help(reader_io_stim.nwbfile)
        #print reader_io_stim.nwbfile.get_stimulus["DummyTest_stimulus"]
        #print help(reader_io_stim.nwbfile)
        #print reader_io_stim.nwbfile.acquisition
        #print reader_io_stim.nwbfile.stimulus
        #print reader_io_stim.nwbfile
        #
        #print reader_io_stim.nwbfile.stimulus
        #print reader_io_stim.nwbfile.stimulus["DummyTest_stimulus"]
        #print reader_io_stim.nwbfile.stimulus["DummyTest_stimulus"].data
        #print reader_io_stim.nwbfile.stimulus["DummyTest_stimulus"].data.value
        reader_io_stim.chosenmodel = self.chosenmodel
        stimulus = reader_io_stim.get_stimulus()
        #print stimulus
        #print stimulus.data
        #print stimulus.timestamps
        a = all(
            boolean == True
            for boolean in stimulus.data.value == self.stimulus_for_comparison)
        self.assertTrue(a is True)
        reader_io_stim.closefile()

    #@unittest.skip("reason for skipping")
    def test_x_get_stimulus(self):
        os.chdir(rootwd)
        for key in self.file_nostim:
            reader_io_nostim = Reader(self.file_nostim[key])
        for key in self.file_stim:
            reader_io_stim = Reader(self.file_stim[key])
        os.chdir(pwd)
        reader_io_stim.chosenmodel = self.chosenmodel
        stimulus = reader_io_stim.get_stimulus()
        timestamps = reader_io_nostim.get_timestamps()
        #print stimulus
        #print stimulus.data
        #print stimulus.timestamps.value
        #print timestamps.value
        #print help(timestamps)
        a = all(boolean == True
                for boolean in stimulus.timestamps.value == timestamps.value)
        self.assertTrue(a is True)
        reader_io_stim.closefile()

    #@unittest.skip("reason for skipping")
    def test_xi_get_description_epoch(self):
        #print "test XI"
        os.chdir(rootwd)
        for key in self.file_stim:
            reader_io_stim = Reader(self.file_stim[key])
        os.chdir(pwd)
        orderedepochs_soma = reader_io_stim.drawout_orderedepochs(
            'soma')  #drawout ordered epoch
        descrip_0soma = Reader.get_description_epoch(
            0, orderedepochs_soma)  # get epoch
        descrip_1soma = Reader.get_description_epoch(1, orderedepochs_soma)
        #
        #print descrip_0soma
        #print descrip_1soma
        self.assertNotEqual(descrip_0soma, descrip_1soma)
        reader_io_stim.closefile()
        shutil.rmtree("responses")
コード例 #13
0
 def setUp(self):
     self.ec = ExecutiveControl(
     )  #instance for non: static & class methods.
     self.pwd = os.getcwd()
コード例 #14
0
class ExecutiveControlTest(unittest.TestCase):
    def setUp(self):
        self.ec = ExecutiveControl(
        )  #instance for non: static & class methods.
        self.pwd = os.getcwd()

    #@unittest.skip("reason for skipping")
    def test_1_list_modelscales(self):
        x = len(self.ec.list_modelscales()) != 0
        self.assertEqual(x, True)

    #@unittest.skip("reason for skipping")
    def test_2_list_models(self):
        dummyscale_path = self.pwd + os.sep + "models" + os.sep + "dummyscale"
        for i in range(3):  # create three dummymodels
            os.makedirs(dummyscale_path + os.sep + "dummymodel" + str(i + 1))
        self.assertEqual(len(self.ec.list_models(modelscale="dummyscale")), 3)
        shutil.rmtree(dummyscale_path)

    #@unittest.skip("reason for skipping")
    def test_3_choose_model(self):
        # NOTE: this only works if the 'minimal' script
        # ~/models/cells/model2015Masoli.py exists
        # 'minimal' => a class with __init__ method with
        # self.modelname = "PC2015Masoli.py"
        x = self.ec.choose_model(modelscale="cells",
                                 modelname="PC2015Masoli")  #"DummyTest"
        self.assertEqual(x.modelname, "PC2015Masoli")

    #@unittest.skip("reason for skipping")
    def test_4_launch_model_NEURON_nostimulus_with_capability(self):
        pickedmodel = self.ec.choose_model(modelscale="cells",
                                           modelname="DummyTest")
        parameters = {"dt": 0.01, "celsius": 30, "tstop": 100, "v_init": 65}
        self.assertEqual(
            self.ec.launch_model(parameters=parameters,
                                 onmodel=pickedmodel,
                                 capabilities={
                                     'model': None,
                                     'vtest': None
                                 }), pickedmodel)

    @unittest.skip("reason for skipping")
    def test_5_launch_model_NEURON_nostimulus_raw(self):
        pickedmodel = self.ec.choose_model(modelscale="cells",
                                           modelname="PC2015Masoli")
        parameters = {"dt": 0.1, "celsius": 30, "tstop": 10, "v_init": 65}
        self.assertEqual(
            self.ec.launch_model(parameters=parameters, onmodel=pickedmodel),
            pickedmodel)

    @unittest.skip("reason for skipping")
    def test_6_save_response(self):
        pickedmodel = self.ec.choose_model(modelscale="cells",
                                           modelname="PC2015Masoli")
        parameters = {"dt": 0.1, "celsius": 30, "tstop": 10, "v_init": 65}
        stimparameters = {
            "type": ["current", "IClamp"],
            "stimlist": [{
                "amp": 0.5,
                "dur": 5.0,
                "delay": 1.0
            }, {
                "amp": 1.0,
                "dur": 5.0,
                "delay": 0.0 + 5.0
            }],
            "tstop":
            parameters["tstop"]
        }
        model = self.ec.launch_model(parameters=parameters,
                                     onmodel=pickedmodel,
                                     stimparameters=stimparameters,
                                     stimloc="soma")
        fullfilename = self.ec.save_response()
        #
        sesstime = str(self.ec.tm.nwbfile.session_start_time).replace(
            " ", "_")[0:-6]
        filename_shouldbe = self.ec.tm.nwbfile.session_id + "_" + sesstime.replace(
            ":", "-") + ".h5"
        #
        path = os.getcwd(
        ) + os.sep + "responses" + os.sep + model.modelscale + os.sep + model.modelname
        shutil.rmtree(path)
        #
        fullname_shouldbe = path + os.sep + filename_shouldbe
        #
        self.assertEqual(fullfilename, fullname_shouldbe)