Exemplo n.º 1
0
    def extractPopulations(self, netpyne_model, netpyne_geppetto_library, geppetto_model):
        # Initialise network
        network = pygeppetto.CompositeType(id='network_netpyne', name='network_netpyne')
        netpyne_geppetto_library.types.append(network)

        # Create intermediate population structure for easy access (by key)
        populations = {}
        for index, cell in enumerate(netpyne_model.net.allCells):
            # This will be only executed the first time for each population
            if cell['tags']['pop'] not in populations:
                # Create CellType, VisualType, ArrayType, ArrayVariable and append to netpyne library
                if 'cellType' in cell['tags']:
                    composite_id = cell['tags']['cellType']
                else: 
                    composite_id = cell['tags']['pop'] + "_cell"

                cellType = pygeppetto.CompositeType(id=str(composite_id), name=str(composite_id), abstract= False)

                visualType = pygeppetto.CompositeVisualType(id='cellMorphology', name='cellMorphology')
                cellType.visualType = visualType
                defaultValue = ArrayValue(elements=[])
                arrayType = pygeppetto.ArrayType(size=0,
                                                    arrayType=cellType,
                                                    id=str(cell['tags']['pop']),
                                                    name=str(cell['tags']['pop']),
                                                    defaultValue= defaultValue)
                arrayVariable = pygeppetto.Variable(id=str(cell['tags']['pop']))
                arrayVariable.types.append(arrayType)
                network.variables.append(arrayVariable)

                netpyne_geppetto_library.types.append(cellType)
                netpyne_geppetto_library.types.append(visualType)
                netpyne_geppetto_library.types.append(arrayType)

                # Save in intermediate structure
                populations[cell['tags']['pop']] = arrayType

                # Note: no need to check if pt3d since already done via netpyne sim.net.defineCellShapes() in instantiateNetPyNEModel
                secs = cell['secs']
                
                # Iterate sections creating spheres and cylinders
                if hasattr(secs, 'items'):
                    for sec_name, sec in list(secs.items()):
                        if 'pt3d' in sec['geom']:
                            points = sec['geom']['pt3d']
                            for i in range(len(points) - 1):
                                # draw soma as a cylinder, not as a sphere (more accurate representation of 3d pts)  
                                visualType.variables.append(self.factory.createCylinder(str(sec_name),
                                                                                            bottomRadius=float(points[i][3] / 2),
                                                                                            topRadius=float(points[i + 1][3] / 2),
                                                                                            position=Point(x=float(points[i][0]),y=float(points[i][1]), z=float(points[i][2])),
                                                                                            distal=Point(x=float(points[i + 1][0]), y=float(points[i + 1][1]), z=float(points[i + 1][2]))))
                    

            # Save the cell position and update elements in defaultValue and size
            populations[cell['tags']['pop']].size = populations[cell['tags']['pop']].size + 1
            populations[cell['tags']['pop']].defaultValue.elements.append(ArrayElement(index=len(populations[cell['tags']['pop']].defaultValue.elements) , position=Point(x=float(cell['tags']['x']), y=-float(cell['tags']['y']), z=float(cell['tags']['z']))))
Exemplo n.º 2
0
    def importType(self, url, typeName, library, commonLibraryAccess):
        logging.debug('Creating a Geppetto Model')

        geppetto_model = self.factory.createGeppettoModel('GepettoModel')
        nwb_geppetto_library = pygeppetto.GeppettoLibrary(name='nwblib',
                                                          id='nwblib')
        geppetto_model.libraries.append(nwb_geppetto_library)

        # read data
        io = NWBHDF5IO(url, 'r')
        nwbfile = io.read()

        # get the processing module
        mod = nwbfile.get_processing_module('ophys_module')

        # get the RoiResponseSeries from the Fluorescence data interface
        # get the data...
        rrs = mod['dff_interface'].get_roi_response_series()
        rrs_data = rrs.data
        rrs_timestamps = rrs.timestamps

        stimulus = nwbfile.get_stimulus('locally_sparse_noise_4deg')
        stimulus_data = [float(i) for i in stimulus.data]
        stimulus_timestamps = stimulus.timestamps[()]

        nwbType = pygeppetto.CompositeType(id=str('nwb'),
                                           name=str('nwb'),
                                           abstract=False)
        dff_val1 = self.factory.createTimeSeries('myTimeSeriesValue',
                                                 rrs_data[()][0].tolist(), 'V')
        nwbType.variables.append(
            self.factory.createStateVariable('DfOverF_1', dff_val1))
        dff_val2 = self.factory.createTimeSeries('myTimeSeriesValue',
                                                 rrs_data[()][1].tolist(), 'V')
        nwbType.variables.append(
            self.factory.createStateVariable('DfOverF_2', dff_val2))
        time = self.factory.createTimeSeries('myTimeSeriesValue',
                                             rrs_timestamps[()].tolist(), 's')
        geppetto_model.variables.append(
            self.factory.createStateVariable('time', time))

        stimulus_value = self.factory.createTimeSeries('myTimeSeriesValue',
                                                       stimulus_data, 'V')
        nwbType.variables.append(
            self.factory.createStateVariable('Stimulus', stimulus_value))
        stimulus_time = self.factory.createTimeSeries(
            'myTimeSeriesValue', stimulus_timestamps.tolist(), 's')
        geppetto_model.variables.append(
            self.factory.createStateVariable('stimulus_time', stimulus_time))

        # add type to nwb
        nwb_geppetto_library.types.append(nwbType)

        # add top level variables
        nwb_variable = Variable(id='nwb')
        nwb_variable.types.append(nwbType)
        geppetto_model.variables.append(nwb_variable)

        return geppetto_model