Ejemplo n.º 1
0
    def _ploter(self, idx, gs):
        pair = self.pairs[idx]
        # Let's figure out the varying parameters
        p1 = varying_parameters(pair)
        if pair[0].stimulus_id == None or pair[1].stimulus_id == None:
            p2 = []
        elif MozaikParametrized.idd(pair[0].stimulus_id).name != MozaikParametrized.idd(pair[1].stimulus_id).name:
            p2 = ['name']
        else:
            p2 = varying_parameters([MozaikParametrized.idd(p.stimulus_id) for p in pair])
        p1 = [x for x in p1 if ((x != 'value_name') and (x != 'stimulus_id'))]

        x_label = pair[0].value_name + '(' + pair[0].value_units.dimensionality.latex + ')'
        y_label = pair[1].value_name + '(' + pair[1].value_units.dimensionality.latex + ')'

        for p in p1:
            x_label += '\n' + str(p) + " = " + str(getattr(pair[0],p))
            y_label += '\n' + str(p) + " = " + str(getattr(pair[1],p))
        
        for p in p2:
            x_label += '\n' + str(p) + " = " + str(getattr(MozaikParametrized.idd(pair[0].stimulus_id),p))
            y_label += '\n' + str(p) + " = " + str(getattr(MozaikParametrized.idd(pair[1].stimulus_id),p))
        
        params = {}
        params["x_label"] = x_label
        params["y_label"] = y_label
        params["title"] = self.sheets[idx]
        if pair[0].value_units != pair[1].value_units or pair[1].value_units == pq.dimensionless:
           params["equal_aspect_ratio"] = False
        
        ids = list(set(pair[0].ids) & set(pair[1].ids))
        return [("ScatterPlot",ScatterPlot(pair[0].get_value_by_id(ids), pair[1].get_value_by_id(ids)),gs,params)]
Ejemplo n.º 2
0
    def __init__(self, datastore, single_trial=False, **params):
        self.single_trial = single_trial
        PerDSVPlot.__init__(self, datastore, **params)
        ss = self._get_stimulus_ids()
        assert ss != [], "Error, empty datastore!"
        if self.title_style == "Clever":
            stimulus = MozaikParametrized.idd(ss[0])
            for s in ss:
                s = MozaikParametrized.idd(s)
                if s.name != stimulus.name:
                    logger.warning(
                        'Datastore does not contain same type of stimuli: changing title_style from Clever to Standard'
                    )
                    self.title_style = "Standard"
                    break

        # lets find parameter indexes that vary if we need 'Clever' title style
        if self.title_style == "Clever":
            self.varied = varying_parameters(
                [MozaikParametrized.idd(s) for s in ss])

            if not self.single_trial:
                self.varied = [x for x in self.varied if x != 'trial']

        if self.title_style == "Standard":
            self.extra_space_top = 0.07
        if self.title_style == "Clever":
            self.extra_space_top = len(self.varied) * 0.005
Ejemplo n.º 3
0
    def  __init__(self, datastore,single_trial=False, **params):
        self.single_trial = single_trial
        PerDSVPlot.__init__(self, datastore, **params)
        ss = self._get_stimulus_ids()
        assert ss != [], "Error, empty datastore!"
        if self.title_style == "Clever":
            stimulus = MozaikParametrized.idd(ss[0])
            for s in ss:
                s = MozaikParametrized.idd(s)
                if s.name != stimulus.name:
                    logger.warning('Datastore does not contain same type of stimuli: changing title_style from Clever to Standard')
                    self.title_style = "Standard"
                    break

        # lets find parameter indexes that vary if we need 'Clever' title style
        if self.title_style == "Clever":
            self.varied = varying_parameters([MozaikParametrized.idd(s) for s in ss])
            
            if not self.single_trial:
                self.varied = [x for x in self.varied if x != 'trial']
            
            
        if self.title_style == "Standard":
            self.extra_space_top = 0.07
        if self.title_style == "Clever":
            self.extra_space_top = len(self.varied)*0.005
Ejemplo n.º 4
0
def exportToElphy(data_store_location,elphy_export_location,sheets=None,threshold=None):
    import os.path
    if not os.path.isdir(elphy_export_location):
       if os.path.exists(elphy_export_location):
          raise ValueError("The elphy export path is not a directory")
       else:
          os.makedirs(elphy_export_location)
              
    setup_logging()
    data_store = PickledDataStore(load=True,parameters=ParameterSet({'root_directory':data_store_location, 'store_stimuli' : False}))
    ps = MP.parameter_value_list([MP.MozaikParametrized.idd(s) for s in data_store.get_stimuli()],'name')
    for i,sn in enumerate(ps):
        if sheets == None: sheets = data_store.sheets() 
        
        for shn in sheets:
            dsv = param_filter_query(data_store,st_name = sn,sheet_name = shn)
            if dsv.get_stimuli() == []: continue
            varying_parameters = MP.varying_parameters([MP.MozaikParametrized.idd(s) for s in dsv.get_stimuli()])
            
            segments,stimuli = MP.colapse(dsv.get_segments(),[MP.MozaikParametrized.idd(s) for s in dsv.get_stimuli()],parameter_list=['trial'],allow_non_identical_objects=True)
            j = 0 
            for segs,st in zip(segments,stimuli):
                # just make sure all segments are fully loaded, in future this should probably soreted out such that this line can be deleted
                for s in segs: s.load_full()
                
                # create file name:
                filename = "name=" + sn + "#" + "sheet_name=" + shn 
                for pn in varying_parameters:
                    if pn != "trial":
                        filename += "#" + str(pn) + "=" + str(getattr(MP.MozaikParametrized.idd(st),pn)) 
                path = os.path.join(elphy_export_location,filename+".dat")
                
                # if the threshold is defined add spikes into Vms
                if threshold != None:
                    for seg in segs : addSpikes(seg,threshold)
                    
                createFileFromSegmentList( segs, path)
                print "Finished saving file %d/%d for sheet %s and %d-th stimulus" % (j+1,len(segments),shn,i)
                # release segments from memory
                for s in segs: s.release()
                j = j + 1
        print "Finished saving %d/%d stimulus" % (i+1,len(ps))
Ejemplo n.º 5
0
def exportToElphy(data_store_location,
                  elphy_export_location,
                  sheets=None,
                  threshold=None):
    import os.path
    if not os.path.isdir(elphy_export_location):
        if os.path.exists(elphy_export_location):
            raise ValueError("The elphy export path is not a directory")
        else:
            os.makedirs(elphy_export_location)

    setup_logging()
    data_store = PickledDataStore(load=True,
                                  parameters=ParameterSet({
                                      'root_directory':
                                      data_store_location,
                                      'store_stimuli':
                                      False
                                  }))
    ps = MP.parameter_value_list(
        [MP.MozaikParametrized.idd(s) for s in data_store.get_stimuli()],
        'name')
    for i, sn in enumerate(ps):
        if sheets == None: sheets = data_store.sheets()

        for shn in sheets:
            dsv = param_filter_query(data_store, st_name=sn, sheet_name=shn)
            if dsv.get_stimuli() == []: continue
            varying_parameters = MP.varying_parameters(
                [MP.MozaikParametrized.idd(s) for s in dsv.get_stimuli()])

            segments, stimuli = MP.colapse(
                dsv.get_segments(),
                [MP.MozaikParametrized.idd(s) for s in dsv.get_stimuli()],
                parameter_list=['trial'],
                allow_non_identical_objects=True)
            j = 0
            for segs, st in zip(segments, stimuli):
                # just make sure all segments are fully loaded, in future this should probably soreted out such that this line can be deleted
                for s in segs:
                    s.load_full()

                # create file name:
                filename = "name=" + sn + "#" + "sheet_name=" + shn
                for pn in varying_parameters:
                    if pn != "trial":
                        filename += "#" + str(pn) + "=" + str(
                            getattr(MP.MozaikParametrized.idd(st), pn))
                path = os.path.join(elphy_export_location, filename + ".dat")

                # if the threshold is defined add spikes into Vms
                if threshold != None:
                    for seg in segs:
                        addSpikes(seg, threshold)

                createFileFromSegmentList(segs, path)
                print "Finished saving file %d/%d for sheet %s and %d-th stimulus" % (
                    j + 1, len(segments), shn, i)
                # release segments from memory
                for s in segs:
                    s.release()
                j = j + 1
        print "Finished saving %d/%d stimulus" % (i + 1, len(ps))
Ejemplo n.º 6
0
    def _ploter(self, idx, gs):
        plots  = []
        gs = gridspec.GridSpecFromSubplotSpec(len(self.st), 1, subplot_spec=gs)
        for i,(dic, st, pnvs) in enumerate(zip(self.tc_dict,self.st,self.pnvs)):
            period = st[0].params()[self.parameters.parameter_name].period
            if self.parameters.centered:        
               assert period != None, "ERROR: You asked for centering of tuning curves even though the domain over which it is measured is not periodic." 
            xs = []
            ys = []
            labels = []
                
            for k in dic.keys():    
                (par, val) = dic[k]
                if self.parameters.mean:
                    v = 0
                    for idx in xrange(0,len(self.parameters.neurons)):
                        vv,p = self.center_tc(val[:,idx],par,period,self.max_mean_response_indexes[i][idx])
                        v = v + vv
                    val = v / len(self.parameters.neurons)
                    par = p
                else:
                    val,par = self.center_tc(val[:,idx],par,period,self.max_mean_response_indexes[i][idx])
                    
                if period != None:
                    par = list(par)
                    val = list(val)
                    par.append(par[0] + period)
                    val.append(val[0])
                    if par != sorted(par):
                       print "BBBBBBB"
                       print par
              
                xs.append(numpy.array(par))
                ys.append(numpy.array(val))
                
                l = ""
                for p in varying_parameters([MozaikParametrized.idd(e) for e in dic.keys()]):
                    l = l + str(p) + " : " + str(getattr(MozaikParametrized.idd(k),p))
                labels.append(l)
            
                
            
            params={}
            params["x_label"] = self.parameters.parameter_name
            params["y_label"] = pnvs[0].value_name
            params['labels']=None
            params['linewidth'] = 2
            params['colors'] = [cm.jet(j/float(len(xs))) for j in xrange(0,len(xs))] 
            if pnvs == self.pnvs[0]:
                params["title"] =  'Neuron ID: %d' % self.parameters.neurons[idx]
            
            if self.parameters.centered:        
                if period == pi:
                    params["x_ticks"] = [-pi/2, 0, pi/2]
                    params["x_lim"] = (-pi/2, pi/2)
                    params["x_tick_style"] = "Custom"
                    params["x_tick_labels"] = ["-$\\frac{\\pi}{2}$", "0", "$\\frac{\\pi}{2}$"]
               
                if period == 2*pi:
                    params["x_ticks"] = [-pi, 0, pi]
                    params["x_lim"] = (-pi, pi)
                    params["x_tick_style"] = "Custom"
                    params["x_tick_labels"] = ["-$\\pi$","0", "$\\pi$"]
            else:
                if period == pi:
                    params["x_ticks"] = [0, pi/2, pi]
                    params["x_lim"] = (0, pi)
                    params["x_tick_style"] = "Custom"
                    params["x_tick_labels"] = ["0", "$\\frac{\\pi}{2}$", "$\\pi$"]
               
                if period == 2*pi:
                    params["x_ticks"] = [0, pi, 2*pi]
                    params["x_lim"] = (0, 2*pi)
                    params["x_tick_style"] = "Custom"
                    params["x_tick_labels"] = ["0", "$\\pi$", "$2\\pi$"]

            if pnvs != self.pnvs[-1]:
                params["x_axis"] = None
            plots.append(("TuningCurve_" + pnvs[0].value_name,StandardStyleLinePlot(xs, ys),gs[i],params))
        return plots