コード例 #1
0
def plot_time_report(clusterlist, animalName, sessionList, siteName):
    '''
    clusterlist in format [(tetrode, cluster), (tetrode, cluster), etc.]
    #NOTE: I am here
    '''

    for indPair, (tetrode, cluster) in enumerate(clusterlist):

        oneTT = cms.MultipleSessionsToCluster(animalName, sessionList, tetrode,
                                              siteName)
        oneTT.load_all_waveforms()

        clusterFile = os.path.join(oneTT.clustersDir,
                                   'Tetrode%d.clu.1' % oneTT.tetrode)

        oneTT.set_clusters_from_file()

        normSpikeCount = 0
        spikeTimestamps = oneTT.timestamps[oneTT.clusters == cluster]
        chunkStarts = []
        chunkSpikeCounts = []
        EPHYS_SAMPLING_RATE = 30000.0

        #Get the start and end times of each session from the cont data
        #Cont channel 31 was recorded for each sesssion
        contFn = '109_CH31.continuous'
        sessionLims = np.empty((len(sessionList), 2))
        for indSession, session in enumerate(sessionList):
            contFile = os.path.join(settings.EPHYS_PATH, animalName, session,
                                    contFn)
            dataCont = loadopenephys.DataCont(contFile)
            dataCont.timestamps = dataCont.timestamps / EPHYS_SAMPLING_RATE
            sessionLims[indSession, 0] = dataCont.timestamps[0]
            sessionLims[indSession, 1] = dataCont.timestamps[-1]

        for indLims, lims in enumerate(sessionLims):
            #Break the session into 2 min segments and discard the last non-full segment
            splits = np.arange(lims[0], lims[1], 120)
            chunks = zip(splits, splits[1:])
            for indChunk, chunk in enumerate(chunks):
                spikesThisChunk = spikeTimestamps[(
                    (spikeTimestamps > chunk[0]) &
                    (spikeTimestamps < chunk[1]))]
                chunkStarts.append(chunk[0])
                chunkSpikeCounts.append(len(spikesThisChunk))
            if indLims == 1:
                normSpikeCount = len(spikesThisChunk)

        plt.subplot2grid((3, 1), (indPair, 0))
        timebase = np.array(chunkStarts) / 60.0
        timebase = timebase - timebase[0]
        spikeCounts = np.array(chunkSpikeCounts) / np.double(normSpikeCount)
        plt.plot(timebase, spikeCounts, 'ko-', lw=2)
        plt.hold(1)
        plt.axvline(x=(sessionLims[1, 1] - sessionLims[0, 0]) / 60.0,
                    color='r',
                    lw=3)
        plt.axhline(y=1, color='0.5', lw=1)
        plt.ylabel('tt{}c{}'.format(tetrode, cluster))
        plt.ylim([0, 2.5])
コード例 #2
0
ファイル: dataloader.py プロジェクト: nickponvert/jaratest
    def get_session_cont(self, session, channel):

        if self.mode=='online':
            ephysSession = self.get_session_filename(session)
            contFilename = os.path.join(self.onlineEphysPath, ephysSession, '109_CH{}.continuous'.format(channel))

        elif self.mode=='offline': #The session should already be relative to the mouse
            contFilename = os.path.join(settings.EPHYS_PATH, session, '109_CH{}.continuous'.format(channel))


        contData=loadopenephys.DataCont(contFilename) #FIXME: Convert to mV?

        return contData
コード例 #3
0
    def get_session_cont(self, sessionDir, channel):

        contFilename = os.path.join(self.ephysPath, sessionDir,
                                    '109_CH{}.continuous'.format(channel))
        contData = loadopenephys.DataCont(contFilename)  #FIXME: Convert to mV?
        return contData
コード例 #4
0
 def test_cont_loading(self):
     contFn = '100_CH11.continuous'
     contFile = os.path.join(testDataDir, contFn)
     contData = loadopenephys.DataCont(contFile)
     plt.plot(contData.samples[:10000], '.-')
コード例 #5
0
def butter_bandpass(lowcut, highcut, fs, order=5):
    nyq = 0.5 * fs
    low = lowcut / nyq
    high = highcut / nyq
    b, a = butter(order, [low, high], btype='band')
    return b, a


def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
    b, a = butter_bandpass(lowcut, highcut, fs, order=order)
    y = lfilter(b, a, data)
    return y


subject = 'pinp001'
#ephysSession = '2015-03-22_17-13-54' # tuning
ephysSession = '2015-03-22_17-27-28'  # laser

ephysRoot = os.path.join(settings.EPHYS_PATH, subject)

filename = os.path.join(ephysRoot, ephysSession, '109_CH11.continuous')

dc = loadopenephys.DataCont(filename)

fc = butter_bandpass_filter(dc.samples, 300, 6000, 30000)

x = 140000
plot(fc[x:x + 200000])

show()
コード例 #6
0
#maprow = tetrode
#mapcol = channel
#meanTraceEachChannel(sessions, tetrode, channel, samples)
meanTraceEachChannel = np.empty((len(sessions), np.shape(channelMap)[0], np.shape(channelMap)[1], secondsEachTrace*EPHYS_SAMPLING_RATE))

#for indChan, channel in enumerate(channels):


colors = plt.cm.viridis(np.linspace(0, 1, len(sessions)))

for indSession, session in enumerate(sessions):
    for (indr, indc), channel in np.ndenumerate(channelMap):
        contFn = '100_CH{}.continuous'.format(channel)
        fullContFile = os.path.join(settings.EPHYS_PATH, animalName, session, contFn)
        fullEventFile = os.path.join(settings.EPHYS_PATH, animalName, session, 'all_channels.events')
        contData = loadopenephys.DataCont(fullContFile)

        #Multiply by 1000 and div by gain (*1000/5000)
        contData.samples = contData.samples/5.0

        #Load the events
        eventData = loadopenephys.Events(fullEventFile)
        eventData.timestamps = eventData.timestamps[((eventData.eventID==1) & (eventData.eventChannel==0))]
        startTimestamp = contData.timestamps[0]
        eventSampleNumbers = eventData.timestamps - startTimestamp
        traces = np.empty((len(eventSampleNumbers), secondsEachTrace*EPHYS_SAMPLING_RATE))
        for indSamp, sampNumber in enumerate(eventSampleNumbers):
            trace = contData.samples[sampNumber:sampNumber + secondsEachTrace*EPHYS_SAMPLING_RATE]
            trace = trace - trace[0]
            traces[indSamp, :] = trace
        meanTrace = np.mean(traces, axis = 0)
コード例 #7
0
#To convert spikes to mV, you have to divide by the gain, 


from jaratoolbox import loadopenephys
from jaratoolbox import spikesorting
import os

#Data filenames
ephysPath = '/home/nick/data/ephys/pinp013/'
ephysFn='2016-05-27_14-08-54'
contFn = os.path.join(ephysPath, ephysFn, '109_CH23.continuous')
spikesFn = os.path.join(ephysPath, ephysFn, 'Tetrode2.spikes')

#Load data
dataCont = loadopenephys.DataCont(contFn)
dataSpikes = loadopenephys.DataSpikes(spikesFn)

#Convert to microvolts
GAIN = 5000.0
SAMPLING_RATE=30000.0
timebase = np.arange(len(dataCont.samples))/SAMPLING_RATE
dataCont.samples = (dataCont.samples / GAIN) * 1000
dataSpikes.samples = ((dataSpikes.samples - 32768.0) / GAIN) * 1000.0



#Set clusters
clustersFile = os.path.join(ephysPath, '{}_kk'.format(ephysFn), 'Tetrode2.clu.1')
dataSpikes.set_clusters(clustersFile)
コード例 #8
0
###eventTimes=ev.timestamps  #/SAMPLING_RATE
eventOnsetTimes = events.timestamps[events.eventID == 1]  # Stim onset
###eventOnsetTimes=eventOnsetTimes[:-1] # The last behavior trial is always started but never finishe

#channelsToPlot = [15,18]
channelsToPlot = [16, 17]
channelsToPlot = [3, 6, 11, 15, 19, 23]
nChannels = len(channelsToPlot)
clf()
for indc, channel in enumerate(channelsToPlot):
    #filenameOnly = '109_CH15.continuous'
    #filenameOnly = '109_CH18.continuous'
    filenameOnly = '109_CH{0}.continuous'.format(channel)
    #filenameOnly = '110_CH{0:02d}.continuous'.format(channel)
    filename = os.path.join(dataDir, filenameOnly)
    datacont = loadopenephys.DataCont(filename)
    (lockedLFP, timeVec) = datacont.lock_to_event(eventOnsetTimes, timeRange)

    subplot(nChannels, 1, indc + 1)
    maxAbsVal = np.max(abs(lockedLFP), axis=1)
    tooLarge = maxAbsVal > 6000
    plot(timeVec, mean(lockedLFP[~tooLarge, :], axis=0))
    #plot(timeVec,mean(lockedLFP,axis=0))
    #plot(timeVec,mean(lockedLFP[100:200,:],axis=0))
    ###plot(tile(timeVec,(1,locked)),lockedLFP) # NOT FINISHED
    ylim([-200, 80])
    show()

    if 0:
        clf()
        plot(datacont.samples[:10000], '-')
コード例 #9
0
possibleIntensity = np.unique(intensityEachTrial)

#Get the event timestamps from openEphys
ev=loadopenephys.Events(event_filename)
evID=np.array(ev.eventID)
eventOnsetTimes=ev.timestamps[evID==1] #The timestamps of all of the stimulus onsets

#These are the active channels in this recording, sorted by tetrode
tetrodeChannels = np.array([[9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]])

#Get the continuous data
channel = 24 #The channel to plot
reference = 9 #Experimental: plotting without subtracting a reference made all channels look the same. 
cont_filename = os.path.join(ephysDir, '109_CH{0}.continuous'.format(channel))
ref_filename = os.path.join(ephysDir, '109_CH{0}.continuous'.format(reference))
ephysData = loadopenephys.DataCont(cont_filename)
refData = loadopenephys.DataCont(ref_filename)

#Subtract the reference channel (not sure yet if this is a good thing to include.)
#ephysData.samples = ephysData.samples - refData.samples

#The ephys data starts with a positive nonzero timestamp, corresponding to the system time somehow. 
#We need to subtract this from all timestamp values if we want to know what sample number to get. 
startTimestamp = ephysData.timestamps[0]

#Preallocate an array in which to store the values of each mean trace
meanTraceEachSetting = np.empty((len(possibleIntensity), len(possibleFreq), secondsEachTrace*SAMPLING_RATE))

#Loop through the frequencies and intensities in the list of possible settings,
#extracting the trace after the presentation of each possible kind of stimulus.
for indFreq, currentFreq in enumerate(possibleFreq):