Esempio n. 1
0
    def refresh_data(self, data, geometry_identifier, point):
        logging.debug('Refreshing space plot with selected geometry: ' +
                      data + "." + geometry_identifier)

        self.vectors = []

        for geometry in GeppettoJupyterModelSync.current_model.geometries_raw:
            if geometry.id == geometry_identifier:

                logging.debug('Loading values for geometry ' +
                              str(geometry_identifier))

                GeppettoJupyterModelSync.current_model.highlight_visual_group_element(
                    geometry.python_variable["section"].name())

                self.geometry = geometry
                self.state_variables = []

                self.section = geometry.python_variable["section"]
                for index, segment in enumerate(self.section):
                    vector = h.Vector()
                    vector.record(segment._ref_v)
                    state_variable = neuron_utils.createStateVariable(id=self.section.name() + "_" + str(index), name=self.section.name() + "_" + str(index),
                                                                      units='mV', python_variable={"record_variable": vector,
                                                                                                   "segment": segment})
                    self.state_variables.append(state_variable)


                if hasattr(self, 'derived_state_variables'):
                    self.derived_state_variables[0].set_inputs(self.state_variables)
                    self.derived_state_variables[1].timeSeries = list(range(len(self.state_variables)))
                else:
                    self.derived_state_variables = []
                    self.derived_state_variables.append(G.createDerivedStateVariable(id="space_plot", name="Space Plot",
                                                                                    units='mV', inputs=self.state_variables, normalizationFunction='SPACEPLOT'))
                    self.derived_state_variables.append(G.createDerivedStateVariable(id="space_plot_2", name="Space Plot 2",
                                                                                    units='nm', timeSeries=list(range(len(self.state_variables))), normalizationFunction='CONSTANT'))
                GeppettoJupyterModelSync.current_model.addDerivedStateVariables(self.derived_state_variables)

                # FIXME: We can not be sured the new variables are created by
                # this time probably is better if we register an event for
                # model loaded and we listen to it
                GeppettoJupyterModelSync.events_controller.register_to_event(
                    [GeppettoJupyterModelSync.events_controller._events['Instances_created']], self.updatePlots)

                # GeppettoJupyterModelSync.current_model.sync()
                

                break
Esempio n. 2
0
    def plot_voltage(self):
        """Plot the recorded traces"""
        #pyplot.figure(figsize=(8,4)) # Default figsize is (8,6)
        #pyplot.plot(self.t_vec, self.soma_v_vec, color='black', label='soma(0.5')
        #pyplot.plot(self.t_vec, self.dend_v_vec, color='red', label='dend(0.5)')
        #pyplot.legend()
        #pyplot.xlabel('time (ms)')
        #pyplot.ylabel('mV')
        #pyplot.ylim(-80,20)
        #pyplot.title('Cell voltage')
        #pyplot.show()

        G.plotVariable('Plot', [
            'SimpleNetwork.soma_v_vec_' + str(self.cell_index),
            'SimpleNetwork.dend_v_vec_' + str(self.cell_index)
        ])
Esempio n. 3
0
    def __init__(self):
        logging.debug('Initializing Space Plot')

        self.geometry = None
        self.section = None
        self.state_variables = []

        self.plot_widget = G.plotVariable(
            'Plot', position_x=90, position_y=405)
        self.plot_widget_2 = G.plotVariable(
            'Plot', position_x=490, position_y=405)
        self.plot_widget.on_close(self.close)
        self.plot_widget_2.on_close(self.close)

        GeppettoJupyterModelSync.events_controller.register_to_event(
            [GeppettoJupyterModelSync.events_controller._events['Select']], self.refresh_data)
Esempio n. 4
0
def add_button(name, actions=None, value=None, extraData=None):
    if value is not None:
        valueUnits = h.units(value)
        if valueUnits != '':
            name += " (" + valueUnits + ")"

    button = GeppettoJupyterGUISync.ButtonSync(widget_id=G.newId(),
                                               widget_name=name,
                                               extraData=extraData)
    if actions is not None:
        button.on_click(actions)
    return button
Esempio n. 5
0
def add_text_field(name, value=None, read_only=False):
    parameters = {'widget_id': G.newId(), 'widget_name': name}
    parameters['read_only'] = read_only

    if value is not None:
        parameters['sync_value'] = str(eval("h." + value))
        parameters['extraData'] = {'originalValue': str(eval("h." + value))}
        parameters['value'] = value
    else:
        parameters['value'] = ''
    textfield = GeppettoJupyterGUISync.TextFieldSync(**parameters)
    if value is not None:
        textfield.on_blur(sync_value)
    return textfield
Esempio n. 6
0
def createStateVariable(id=None,
                        name='Untitled State Variable',
                        units='Unknown',
                        timeSeries=[],
                        python_variable=None):
    geometries = []
    if python_variable["segment"] is not None:
        geometries = neuron_geometries_utils.getGeometriesBySegment(
            python_variable["segment"],
            neuron_geometries_utils.getNeuronGeometries())
    return G.createStateVariable(id=id,
                                 name=name,
                                 units=units,
                                 python_variable=python_variable,
                                 geometries=geometries)
Esempio n. 7
0
def add_panel(name,
              items=[],
              widget_id=None,
              position_x=-1,
              position_y=-1,
              width=-1,
              height=-1,
              properties={"closable": True}):
    if widget_id is None:
        widget_id = G.newId()
    for item in items:
        item.embedded = True
    return GeppettoJupyterGUISync.PanelSync(widget_id=widget_id,
                                            widget_name=name,
                                            items=items,
                                            embedded=False,
                                            position_x=position_x,
                                            position_y=position_y,
                                            width=width,
                                            height=height,
                                            properties=properties)
def getGeometriesBySegment(segment, secs):
    secData = None
    secDataName = None
    for sec_name, sec in list(secs.items()):
        if sec['neuronSec'] == segment.sec:
            secData = sec
            secDataName = sec_name
            break
    section_points = secData['geom']['pt3d']
    section_length = calculate_section_length(section_points)
    interval = section_length / segment.sec.nseg
    seg_index = ceil(segment.x * segment.sec.nseg) - 1
    if seg_index < 0:
        seg_index = 0
    seg_init = seg_index * interval
    seg_end = (seg_index + 1) * interval

    geometries = []
    length = 0
    for point_index in range(len(section_points) - 1):
        # Calculate geometry length
        proximal = section_points[point_index]
        distal = section_points[point_index + 1]
        geometry_length = sqrt(
            pow(distal[0] - proximal[0], 2) + pow(distal[1] - proximal[1], 2) +
            pow(distal[2] - proximal[2], 2))

        # Add geometry length or distance to selection
        if length >= seg_init and length < seg_end:
            geometries.append(GeppettoJupyterModelSync.current_model.id + "." +
                              G.removeSpecialCharacters(secDataName) + "_" +
                              str(point_index))
        elif length > seg_end:
            break

        length += geometry_length

    return geometries
def extractGeometries(reload=False):
    global secs
    secs = getNeuronGeometries(reload)

    geometries = []
    logging.debug("Converting sections and segments to Geppetto")
    for sec_name, sec in list(secs.items()):
        if 'pt3d' in sec['geom']:
            points = sec['geom']['pt3d']
            for i in range(len(points) - 1):
                geometries.append(
                    G.createGeometry(sec_name=sec_name,
                                     index=i,
                                     position=points[i],
                                     distal=points[i + 1],
                                     python_variable={
                                         'section': sec['neuronSec'],
                                         'section_points': sec['geom']['pt3d']
                                     }))

    logging.debug("Sections and segments converted to Geppetto")
    logging.debug("Geometries found: " + str(len(geometries)))
    GeppettoJupyterModelSync.current_model.addGeometries(geometries)
    return geometries
Esempio n. 10
0
 def set_recording(self):
     """Set soma, dendrite, and time recording vectors on the cell. """
     self.soma_v_vec = h.Vector()  # Membrane potential vector at soma
     self.dend_v_vec = h.Vector()  # Membrane potential vector at dendrite
     self.t_vec = h.Vector()  # Time stamp vector
     self.soma_v_vec.record(self.soma(0.5)._ref_v)
     G.createStateVariable(id='soma_v_vec_' + str(self.cell_index),
                           name='soma_v_vec for cell ' +
                           str(self.cell_index),
                           units='mV',
                           python_variable=self.soma_v_vec)
     self.dend_v_vec.record(self.dend(0.5)._ref_v)
     G.createStateVariable(id='dend_v_vec_' + str(self.cell_index),
                           name='dend_v_vec for cell ' +
                           str(self.cell_index),
                           units='mV',
                           python_variable=self.dend_v_vec)
     self.t_vec.record(h._ref_t)
     G.createStateVariable(id='time',
                           name='time',
                           units='ms',
                           python_variable=self.t_vec)
Esempio n. 11
0
 def analysis(self):
     self.plotWidget = G.plotVariable('Plot', ['VerySimpleCell.v_vec'])
Esempio n. 12
0
def createProject(name='Project'):
    neuron_geometries_utils.secs = {}
    G.createProject(name=name)
Esempio n. 13
0
 def analysis(self):
     # plot voltage vs time
     self.plotWidget = G.plotVariable(
         'Plot', ['SimpleCell.v_vec_dend', 'SimpleCell.v_vec_soma'])
Esempio n. 14
0
 def analysis(self):
     # plot voltage vs time
     self.plotWidget = G.plotVariable(
         'Plot', ['Ring.v_vec_dend_0', 'Ring.v_vec_soma_0'])
Esempio n. 15
0
def add_label(id, name):
    return GeppettoJupyterGUISync.LabelSync(widget_id=G.newId(),
                                            widget_name=name,
                                            sync_value=id)
Esempio n. 16
0
def add_checkbox(name, sync_value='false', extraData=None):
    return GeppettoJupyterGUISync.CheckboxSync(widget_id=G.newId(),
                                               widget_name=name,
                                               sync_value=sync_value,
                                               extraData=extraData)
Esempio n. 17
0
def add_drop_down(name, items):
    return GeppettoJupyterGUISync.DropDownSync(widget_id=G.newId(),
                                               widget_name=name,
                                               items=items)