Exemple #1
0
 def calc(self, var='ori', fixed=None, force=False):
     """Calculate the actual tuning curve"""
     if not force and self.var == var:
         return  # calc was already run with desired var, so results should be fine
     if fixed != None:
         fixedsweepis = []
         for fixedvar, fixedvals in fixed.items():
             vals = self.experiment.sweeptable.data[fixedvar]
             if fixedvar == 'ori':  # correct for orientation offset by adding
                 if (vals > 180).any():
                     maxori = 360
                 else:
                     maxori = 180
                 vals = vals.copy()  # don't modify the sweeptable!
                 vals += self.experiment.s.orioff  # static parameter
                 vals %= maxori
             sweepis = []
             for fixedval in toiter(fixedvals):
                 sweepis.append(np.where(vals == fixedval)[0])
             sweepis = np.concatenate(sweepis)
             fixedsweepis.append(sweepis)
         # intersect all fixedvar arrays in fixedsweepis:
         fixedsweepis = core.intersect1d(fixedsweepis)
         #print(fixedsweepis)
     # get values for var at all unique sweep indices:
     try:
         vals = self.experiment.sweeptable.data[var]
     except AttributeError:
         # something different about ptc15, new bug?. Also, sweeptable values are in a list
         # instead of an array like for post ptc15. Should be converted to an array
         # somewhere, so it need not be done here? Also, ptc15 experiments are missing
         # .s and .d attribs, whose contents seems to be found in .oldparams
         vals = np.asarray(self.experiment.sweeptable[var])
     if var == 'ori':  # correct for orientation offset by adding it to ori vals
         if (vals > 180).any():
             maxori = 360
         else:
             maxori = 180
         vals = vals.copy()  # don't modify the sweeptable!
         try:
             vals += self.experiment.s.orioff  # static parameter
         except AttributeError:  # for ptc15, should be fixed:
             vals += self.experiment.oldparams['orioff']  # static parameter
         vals %= maxori
     x = np.unique(vals)  # x axis
     y = np.zeros(len(x), dtype=int)  # spike counts for each variable value
     for vali, val in enumerate(x):
         sweepis = np.where(vals == val)[0]
         if fixed != None:
             sweepis = np.intersect1d(sweepis,
                                      fixedsweepis,
                                      assume_unique=True)
             print(sweepis)
         for sweepi in sweepis:
             y[vali] += self.counts[sweepi].sum()
     self.x, self.y = x, y
     self.peak = x[y.argmax()]
Exemple #2
0
 def calc(self, var='ori', fixed=None, force=False):
     """Calculate the actual tuning curve"""
     if not force and self.var == var:
         return # calc was already run with desired var, so results should be fine
     if fixed != None:
         fixedsweepis = []
         for fixedvar, fixedvals in fixed.items():
             vals = self.experiment.sweeptable.data[fixedvar]
             if fixedvar == 'ori': # correct for orientation offset by adding
                 if (vals > 180).any():
                     maxori = 360
                 else:
                     maxori = 180
                 vals = vals.copy() # don't modify the sweeptable!
                 vals += self.experiment.s.orioff # static parameter
                 vals %= maxori
             sweepis = []
             for fixedval in toiter(fixedvals):
                 sweepis.append(np.where(vals == fixedval)[0])
             sweepis = np.concatenate(sweepis)
             fixedsweepis.append(sweepis)
         # intersect all fixedvar arrays in fixedsweepis:
         fixedsweepis = core.intersect1d(fixedsweepis)
         #print(fixedsweepis)
     # get values for var at all unique sweep indices:
     try:
         vals = self.experiment.sweeptable.data[var]
     except AttributeError:
         # something different about ptc15, new bug?. Also, sweeptable values are in a list
         # instead of an array like for post ptc15. Should be converted to an array
         # somewhere, so it need not be done here? Also, ptc15 experiments are missing
         # .s and .d attribs, whose contents seems to be found in .oldparams
         vals = np.asarray(self.experiment.sweeptable[var])
     if var == 'ori': # correct for orientation offset by adding it to ori vals
         if (vals > 180).any():
             maxori = 360
         else:
             maxori = 180
         vals = vals.copy() # don't modify the sweeptable!
         try:
             vals += self.experiment.s.orioff # static parameter
         except AttributeError: # for ptc15, should be fixed:
             vals += self.experiment.oldparams['orioff'] # static parameter
         vals %= maxori
     x = np.unique(vals) # x axis
     y = np.zeros(len(x), dtype=int) # spike counts for each variable value
     for vali, val in enumerate(x):
         sweepis = np.where(vals == val)[0]
         if fixed != None:
             sweepis = np.intersect1d(sweepis, fixedsweepis, assume_unique=True)
             print(sweepis)
         for sweepi in sweepis:
             y[vali] += self.counts[sweepi].sum()
     self.x, self.y = x, y
     self.peak = x[y.argmax()]
Exemple #3
0
 def sta(self, neurons=None, **kwargs):
     """Return an STAs RevCorrs object"""
     if neurons == None:
         # no Neurons were passed, use all the Neurons from the default Sort for this
         # experiment's Recording
         keyvals = self.r.n.items() # get key val pairs in a list of tuples
         keyvals.sort() # make sure they're sorted by key
         neurons = []
         for key, val in keyvals:
             neurons.append(val)
     else:
         try:
             # assume neurons is a Neuron id or list of Neuron ids, get the associated
             # Neuron objects from the default Sort for this experiment's Recording
             neurons = [ self.r.n[ni] for ni in toiter(neurons) ]
         except KeyError: # neurons is probably a list of Neuron objects
             pass
     staso = STAs(neurons=neurons, experiment=self, **kwargs) # init a new STAs object
     staso.calc()
     return staso
Exemple #4
0
 def plot(self, var='ori', fixed=None):
     """var: string name of variable you want to plot a tuning curve for
     fixed: dict with keys containing names of vars to keep fixed when building tuning
     curve, and values containing each var's value(s) to fix at
     
     Ex: r71.n[1].tune().plot('phase0', fixed={'ori':138, 'sfreqCycDeg':[0.4, 0.8]})
     """
     if not self.done:
         self.calc(tdelay=self.tdelay)
     if fixed != None:
         fixedsweepis = []
         for fixedvar, fixedvals in fixed.items():
             vals = self.experiment.sweeptable.data[fixedvar]
             if fixedvar == 'ori': # correct for orientation offset by adding
                 if (vals > 180).any():
                     maxori = 360
                 else:
                     maxori = 180
                 vals = vals.copy() # don't modify the sweeptable!
                 vals += self.experiment.s.orioff # static parameter
                 vals %= maxori
             sweepis = []
             for fixedval in toiter(fixedvals):
                 sweepis.append(np.where(vals == fixedval)[0])
             sweepis = np.concatenate(sweepis)
             fixedsweepis.append(sweepis)
         # intersect all fixedvar arrays in fixedsweepis:
         fixedsweepis = core.intersect1d(fixedsweepis)
         #print(fixedsweepis)
     # get values for var at all unique sweep indices:
     vals = self.experiment.sweeptable.data[var]
     if var == 'ori': # correct for orientation offset by adding
         if (vals > 180).any():
             maxori = 360
         else:
             maxori = 180
         vals = vals.copy() # don't modify the sweeptable!
         vals += self.experiment.s.orioff # static parameter
         vals %= maxori
     x = np.unique(vals) # x axis
     y = np.zeros(len(x), dtype=int) # spike counts for each variable value
     for vali, val in enumerate(x):
         sweepis = np.where(vals == val)[0]
         if fixed != None:
             sweepis = np.intersect1d(sweepis, fixedsweepis, assume_unique=True)
             print sweepis
         for sweepi in sweepis:
             y[vali] += self.counts[sweepi].sum()
     # create a new figure:
     f = pl.figure()
     a = f.add_subplot(111)
     a.plot(x, y, 'k.-')
     a.set_xlabel(var)
     a.set_ylabel('spike count')
     titlestr = lastcmd()
     titlestr += ' nid%d' % self.neuron.id
     a.set_title(titlestr)
     f.canvas.window().setWindowTitle(titlestr)
     a.text(0.99, 0.99, 'peak=(%s, %s)' % (x[y.argmax()], y.max()),
            transform=a.transAxes,
            horizontalalignment='right',
            verticalalignment='top')
     f.tight_layout(pad=0.3) # crop figure to contents
     self.f = f
     self.x, self.y = x, y
     return self