def PhaseVectors(doc, neurons, binSize): ''' calculates instantaneous phase vectors for the given array of neurons see PhaseArray above ''' theStart = nex.GetDocStartTime(doc) theEnd = nex.GetDocEndTime(doc) numBins = np.int64(np.floor((theEnd - theStart) / binSize)) phaseVectors = [] for nr in neurons: ts = nr.Timestamps() if len(ts) == 0: # no spikes, fill with random phases phaseVectors.append(2 * np.pi * np.random.random(numBins)) continue ts = np.array(ts) - theStart # check if we need to add phantom spike at zero if ts[0] > 0: ts = np.insert(ts, 0, 0) binIndexes = np.int64(np.floor(ts / binSize)) phaseVectors.append(PhaseArray(binIndexes, numBins)) return phaseVectors
def Histograms(doc, neurons, binSize): ''' Calculates normalized rate histograms formula (1) in Li [2007], where Z is the rate histogram ''' theStart = nex.GetDocStartTime(doc) theEnd = nex.GetDocEndTime(doc) theBins = np.arange(theStart, theEnd, binSize) hists = [] for nr in neurons: ts = nr.Timestamps() hist, b = np.histogram(ts, bins=theBins) if len(ts) > 0: hist = (hist - np.mean(hist)) / np.std(hist) hists.append(hist) return hists
def IntervalFilterVarIfNeeded(doc, var, pars): selData = pars['Select Data'] theFilter = pars['Interval Filter'] if selData == 'All' and theFilter == 'None': # no need to filter return var mainFrom = 0.0 mainTo = nex.GetDocEndTime(doc) if selData == 'From Time Range': mainFrom = float(pars['Select Data From (sec)']) mainTo = float(pars['Select Data To (sec)']) tempInt = nex.NewIntEvent(doc, 0) nex.AddInterval(tempInt, mainFrom, mainTo) if theFilter == 'None': return nex.IntervalFilter(var, tempInt) else: tempInt1 = nex.IntAnd(tempInt, doc[theFilter]) return nex.IntervalFilter(var, tempInt1)
# # ################################## # 1. The path for where the results are saved destination = "C:/Users/earnestt/Desktop" # 2. The name of the template being applied: template = "coherence_4_tetrodes" # 3. The start time in seconds of the analysis window: start = 0 # 4. The end time in seconds of the analysis window: #To select the end of any document, you can use # end = nex.GetDocEndTime(doc) end = nex.GetDocEndTime(doc) # 5. The names of the interval variables to include; specify their names in this list: intervals = ['pre-cocaine', 'post-cocaine'] ##################################################### #moves to the specified director os.chdir(destination) #loop for creating a new folder #new directory name is the document title plus the name of the template used #if the name already exists, a number is added g = 1 basename = nex.GetDocTitle(doc) + " " + template + " with intervals"
#end = nex.GetDocEndTime(doc) end = 3750 # 5. The bin size for analysis, in seconds: #The bin size must be no larger than the analysis period (end-start) binsize = 30 ##################################################### #Checks some conditions about the user input to make sure the analysis will run properly #stops the program when there is an issue if start >= end: print "Starting point (start) must be before ending point (end)." sys.exit() if end > nex.GetDocEndTime(doc): print "The entered end of analysis period is outside of the recording length." sys.exit() if binsize > (end - start): print "Analysis bin (binsize) must be at least the size of the analysis period." sys.exit() #makes list of points where the start of a bin will be #if the last point in bin_starts is too close to the end of the analysis window, #there will not be enough data to have a full bin #in this case, this bin is dropped so that each bin has an equal amount of data bin_starts = [] c = start