Ejemplo n.º 1
0
    def _tetrode_tuning(dataTuple):
        '''
        The data tuple must be exactly this: (spikeTimestamps, eventOnsetTimes, freqEachTrial, tetrode, rasterRange, tcRange)
        '''

        #Unpack the data tuple (Watch out - make sure things from the above method are in the right order)
        spikeTimestamps, eventOnsetTimes, freqEachTrial, tetrode, rasterRange, tcRange = dataTuple

        possibleFreq = np.unique(freqEachTrial)
        freqLabels = ['{0:.1f}'.format(freq / 1000.0) for freq in possibleFreq]
        fig = plt.gcf()

        ax1 = plt.subplot2grid((3, 3), (0, 0), rowspan=3, colspan=2)
        dataplotter.plot_raster(spikeTimestamps,
                                eventOnsetTimes,
                                sortArray=freqEachTrial,
                                ms=1,
                                labels=freqLabels,
                                timeRange=rasterRange)
        plt.title("Tetrode {}".format(tetrode))
        ax1.set_ylabel('Freq (kHz)')
        ax1.set_xlabel('Time from sound onset (sec)')

        ax2 = plt.subplot2grid((3, 3), (0, 2), rowspan=3, colspan=1)
        dataplotter.one_axis_tc_or_rlf(spikeTimestamps,
                                       eventOnsetTimes,
                                       freqEachTrial,
                                       timeRange=tcRange)

        ax2.set_ylabel("Avg spikes in range {}".format(tcRange))
        ax2.set_xticks(range(len(freqLabels)))
        ax2.set_xticklabels(freqLabels, rotation='vertical')
        ax2.set_xlabel('Freq (kHz)')
Ejemplo n.º 2
0
    def plot_session_raster(self,
                            session,
                            tetrode,
                            cluster=None,
                            sortArray=[],
                            timeRange=[-0.5, 1],
                            replace=0,
                            ms=4):

        plotTitle = self.loader.get_session_filename(session)
        spikeData = self.loader.get_session_spikes(session, tetrode)
        eventData = self.loader.get_session_events(session)
        eventOnsetTimes = self.loader.get_event_onset_times(eventData)
        spikeTimestamps = spikeData.timestamps

        if cluster:
            spikeTimestamps = spikeTimestamps[spikeData.clusters == cluster]

        if replace:
            plt.cla()
        else:
            plt.figure()

        dataplotter.plot_raster(spikeTimestamps,
                                eventOnsetTimes,
                                sortArray=sortArray,
                                timeRange=timeRange,
                                ms=ms)

        plt.show()
Ejemplo n.º 3
0
def simple_raster(cellDataTuple):
    spikeTimestamps = cellDataTuple[0]
    eventOnsetTimes = cellDataTuple[1]
    dataplotter.plot_raster(spikeTimestamps, eventOnsetTimes)
    plt.title('My title')
    plt.xlabel('My X Label')
    plt.ylabel('My Y Label')
Ejemplo n.º 4
0
def compare_session_spike_waveforms(spikeSamples, spikeTimes, eventOnsetTimes,
                                    rasterTimeRange, timeRangeList):

    fig = plt.figure()
    plt.subplot2grid((3, 2), (0, 0), rowspan=2, colspan=2)
    dataplotter.plot_raster(spikeTimes,
                            eventOnsetTimes,
                            timeRange=rasterTimeRange)

    for ind, tr in enumerate(timeRangeList):

        plt.subplot2grid((3, 2), (2, ind), rowspan=1, colspan=1)
        dataplotter.plot_waveforms_in_event_locked_timerange(
            spikeSamples, spikeTimes, eventOnsetTimes, tr)

    plt.subplots_adjust(hspace=0.7)
Ejemplo n.º 5
0
 def plot_array_raster(self,
                       session,
                       replace=0,
                       sortArray=[],
                       timeRange=[-0.5, 1],
                       tetrodes=None,
                       ms=4,
                       electrodeName='Tetrode'):
     '''
     This is the much-improved version of a function to plot a raster for each tetrode. All rasters
     will be plotted using standardized plotting code, and we will simply call the functions.
     In this case, we get the event data once, and then loop through the tetrodes, getting the
     spike data and calling the plotting code for each tetrode.
     '''
     if not tetrodes:
         tetrodes = self.defaultTetrodes
     numTetrodes = len(tetrodes)
     eventData = self.loader.get_session_events(session)
     eventOnsetTimes = self.loader.get_event_onset_times(eventData)
     plotTitle = self.loader.get_session_filename(session)
     if replace:
         fig = plt.gcf()
         plt.clf()
     else:
         fig = plt.figure()
     for ind, tetrode in enumerate(tetrodes):
         spikeData = self.loader.get_session_spikes(
             session, tetrode, electrodeName=electrodeName)
         if ind == 0:
             ax = fig.add_subplot(numTetrodes, 1, ind + 1)
         else:
             ax = fig.add_subplot(numTetrodes,
                                  1,
                                  ind + 1,
                                  sharex=fig.axes[0],
                                  sharey=fig.axes[0])
         spikeTimestamps = spikeData.timestamps
         dataplotter.plot_raster(spikeTimestamps,
                                 eventOnsetTimes,
                                 sortArray=sortArray,
                                 ms=ms,
                                 timeRange=timeRange)
         if ind == 0:
             plt.title(plotTitle)
         plt.ylabel('TT {}'.format(tetrode))
     plt.xlabel('time (sec)')
     plt.show()
Ejemplo n.º 6
0
def am_mod_report(site, siteName, amSessionInd):
    '''

    '''
    loader = dataloader.DataLoader('offline', experimenter=site.experimenter)

    for tetrode in site.tetrodes:
        try:
            oneTT = cluster_site(site, siteName, tetrode)
        except AttributeError:
            print "There was an attribute error for tetrode {} at {}".format(tetrode, siteName)
            continue
        possibleClusters=np.unique(oneTT.clusters)

        for indClust, cluster in enumerate(possibleClusters):


            amFilename = site.get_mouse_relative_ephys_filenames()[amSessionInd]
            amBehav = site.get_mouse_relative_behav_filenames()[amSessionInd]

            plt.clf()

            spikeData = loader.get_session_spikes(amFilename, tetrode, cluster=cluster)
            spikeTimes = spikeData.timestamps

            eventData = loader.get_session_events(amFilename)
            eventOnsetTimes = loader.get_event_onset_times(eventData)

            bdata = loader.get_session_behavior(amBehav)

            currentFreq = bdata['currentFreq']

            dataplotter.plot_raster(spikeTimes, eventOnsetTimes, sortArray=currentFreq)
            fig_path = oneTT.clustersDir
            fig_name = 'TT{0}Cluster{1}_Amp_Mod.png'.format(tetrode, cluster)
            full_fig_path = os.path.join(fig_path, fig_name)
            print full_fig_path
            plt.savefig(full_fig_path, format = 'png')
from jaratoolbox.test.nick.database import cellDB
reload(cellDB)

from jaratoolbox.test.nick.database import dataplotter
from jaratoolbox import spikesorting
from jaratoolbox.test.nick import clustercutting

from pylab import *


loader = dataloader.DataLoader('offline', experimenter='nick')

dbFn = '/home/nick/data/database/nick_thalamus_cells.json'
db = cellDB.CellDB()
db.load_from_json(dbFn)


c = db[0]
spikeData, eventData, behavData = loader.get_cluster_data(c, 'tc_heatmap')

spikeTimes = spikeData.timestamps
eventOnsetTimes = loader.get_event_onset_times(eventData)
currentFreq = behavData['currentFreq']
currentIntensity = behavData['currentIntensity']
trialsToPlot = currentIntensity==70
eventOnsetTimes=eventOnsetTimes[trialsToPlot]
currentFreq = currentFreq[trialsToPlot]

dataplotter.plot_raster(spikeTimes, eventOnsetTimes, sortArray=currentFreq)
plt.show()
Ejemplo n.º 8
0
# - I tried to keep the session types somewhat consistent but they are not all the same

## ------ Plotting a raster----------

#I usually use plotting functions that live in my dataplotter module.
#These fns take spiketimes and eventOnsetTimes and take care of calling
#spikesanalysis and behavioranalysis methods, and then use extraplots methods to do the plotting

#Lets look at the noise burst response from the first cluster
spikeData, eventData, behavData = loader.get_cluster_data(
    figdb[0], 'noiseBurst')
spikeTimestamps = spikeData.timestamps
eventOnsetTimes = loader.get_event_onset_times(eventData)

plt.clf()
dataplotter.plot_raster(spikeTimestamps, eventOnsetTimes)
plt.show()

#All rasters in the reports are plotted this way.

## ------ Plotting a sorted raster ----

#The nice thing about the raster plotting methods is that they can accept an array to sort by
#Lets look at the AM responses from the last cluster (9)

spikeData, eventData, behavData = loader.get_cluster_data(figdb[9], 'AM')

spikeTimestamps = spikeData.timestamps
eventOnsetTimes = loader.get_event_onset_times(eventData)
currentFreq = behavData['currentFreq']
Ejemplo n.º 9
0
def nick_lan_daily_report(site, siteName, mainRasterInds, mainTCind, pcasort=True):
    '''

    '''

    loader = dataloader.DataLoader('offline', experimenter=site.experimenter)


    for tetrode in site.tetrodes:

        #Tetrodes with no spikes will cause an error when clustering
        try:
            if pcasort:
                oneTT = cluster_site_PCA(site, siteName, tetrode)
            else:
                oneTT = cluster_site(site, siteName, tetrode)
        except AttributeError:
            print "There was an attribute error for tetrode {} at {}".format(tetrode, siteName)
            continue

        possibleClusters=np.unique(oneTT.clusters)


        #Iterate through the clusters, making a new figure for each cluster.
        #for indClust, cluster in enumerate([3]):
        for indClust, cluster in enumerate(possibleClusters):


            mainRasterEphysFilenames = [site.get_mouse_relative_ephys_filenames()[i] for i in mainRasterInds]
            mainRasterTypes = [site.get_session_types()[i] for i in mainRasterInds]
            if mainTCind:
                mainTCsession = site.get_mouse_relative_ephys_filenames()[mainTCind]
                mainTCbehavFilename = site.get_mouse_relative_behav_filenames()[mainTCind]
                mainTCtype = site.get_session_types()[mainTCind]
            else:
                mainTCsession=None

            # plt.figure() #The main report for this cluster/tetrode/session
            plt.clf()

            for indRaster, rasterSession in enumerate(mainRasterEphysFilenames):
                plt.subplot2grid((6, 6), (indRaster, 0), rowspan = 1, colspan = 3)

                rasterSpikes = loader.get_session_spikes(rasterSession, tetrode)
                spikeTimestamps = rasterSpikes.timestamps[rasterSpikes.clusters==cluster]

                rasterEvents = loader.get_session_events(rasterSession)
                eventOnsetTimes = loader.get_event_onset_times(rasterEvents)

                dataplotter.plot_raster(spikeTimestamps, eventOnsetTimes, ms=1)

                plt.ylabel('{}\n{}'.format(mainRasterTypes[indRaster], rasterSession.split('_')[1]), fontsize = 10)
                ax=plt.gca()
                extraplots.set_ticks_fontsize(ax,6) #Should this go in dataplotter?

            #We can only do one main TC for now.
            if mainTCsession:

                plt.subplot2grid((6, 6), (0, 3), rowspan = 3, colspan = 3)


                bdata = loader.get_session_behavior(mainTCbehavFilename)
                plotTitle = loader.get_session_filename(mainTCsession)
                eventData = loader.get_session_events(mainTCsession)
                spikeData = loader.get_session_spikes(mainTCsession, tetrode)

                spikeTimestamps = spikeData.timestamps[spikeData.clusters==cluster]

                eventOnsetTimes = loader.get_event_onset_times(eventData)

                freqEachTrial = bdata['currentFreq']
                intensityEachTrial = bdata['currentIntensity']

                possibleFreq = np.unique(freqEachTrial)
                possibleIntensity = np.unique(intensityEachTrial)

                xlabel='Frequency (kHz)'
                ylabel='Intensity (dB SPL)'

                # firstSortLabels = ["%.1f" % freq for freq in possibleFreq/1000.0]
                # secondSortLabels = ['{}'.format(inten) for inten in possibleIntensity]

                # dataplotter.two_axis_heatmap(spikeTimestamps,
                #                             eventOnsetTimes,
                #                             freqEachTrial,
                #                             intensityEachTrial,
                #                             firstSortLabels,
                #                             secondSortLabels,
                #                             xlabel,
                #                             ylabel,
                #                             plotTitle=plotTitle,
                #                             flipFirstAxis=False,
                #                             flipSecondAxis=True,
                #                             timeRange=[0, 0.1])

                freqLabels = ["%.1f" % freq for freq in possibleFreq/1000.0]
                intenLabels = ["%.1f" % inten for inten in possibleIntensity]

                dataplotter.two_axis_heatmap(spikeTimestamps=spikeTimestamps,
                                            eventOnsetTimes=eventOnsetTimes,
                                            firstSortArray=intensityEachTrial,
                                            secondSortArray=freqEachTrial,
                                            firstSortLabels=intenLabels,
                                            secondSortLabels=freqLabels,
                                            xlabel=xlabel,
                                            ylabel=ylabel,
                                            plotTitle=plotTitle,
                                            flipFirstAxis=True,
                                            flipSecondAxis=False,
                                            timeRange=[0, 0.1])

                plt.title("{0}\n{1}".format(mainTCsession, mainTCbehavFilename), fontsize = 10)
                plt.show()


            nSpikes = len(oneTT.timestamps)
            nClusters = len(possibleClusters)

            tsThisCluster = oneTT.timestamps[oneTT.clusters==cluster]
            wavesThisCluster = oneTT.samples[oneTT.clusters==cluster]


            # -- Plot ISI histogram --
            plt.subplot2grid((6,6), (4,0), rowspan=1, colspan=3)
            spikesorting.plot_isi_loghist(tsThisCluster)
            plt.ylabel('c%d'%cluster,rotation=0,va='center',ha='center')
            plt.xlabel('')

            # -- Plot waveforms --
            plt.subplot2grid((6,6), (5,0), rowspan=1, colspan=3)
            spikesorting.plot_waveforms(wavesThisCluster)

            # -- Plot projections --
            plt.subplot2grid((6,6), (4,3), rowspan=1, colspan=3)
            spikesorting.plot_projections(wavesThisCluster)

            # -- Plot events in time --
            plt.subplot2grid((6,6), (5,3), rowspan=1, colspan=3)
            spikesorting.plot_events_in_time(tsThisCluster)

            plt.subplots_adjust(wspace = 0.7)
            fig_path = oneTT.clustersDir
            fig_name = 'TT{0}Cluster{1}.png'.format(tetrode, cluster)
            full_fig_path = os.path.join(fig_path, fig_name)
            print full_fig_path
            #plt.tight_layout()
            plt.savefig(full_fig_path, format = 'png')
interface.plot_session_raster('15-31-48', 6)
interface.plot_sorted_tuning_raster('15-31-48', 6, 'a')
interface.plot_session_tc_heatmap('15-31-48', 6, 'a')
interface.plot_array_freq_tuning('15-31-48', 'a')
interface.plot_am_tuning('15-31-48', 6, 'a')

#This is working now but needs to have some return object
flipper=interface.flip_tetrode_tuning('15-31-48', 'a', tetrodes=[3, 4, 5, 6])


#Dataplotter base plotting functions
from jaratoolbox.test.nick.database import dataplotter
reload(dataplotter)

#Test plot_raster
dataplotter.plot_raster(spikeTimestamps, eventOnsetTimes, sortArray=bdata['currentFreq'])

#Test two_axis_sorted_raster
dataplotter.two_axis_sorted_raster(spikeTimestamps,
                                   eventOnsetTimes,
                                   bdata['currentFreq'],
                                   bdata['currentIntensity'])

#Test two_axis_heatmap - have to reverse first and second array
dataplotter.two_axis_heatmap(spikeTimestamps,
                             eventOnsetTimes,
                             bdata['currentIntensity'],
                             bdata['currentFreq'])

#Test one_axis_tc_or_rlf
#TC
Ejemplo n.º 11
0
spikeData, eventData, behavData = loader.get_cluster_data(figdb[0], 'noiseBurst')
# - I tried to keep the session types somewhat consistent but they are not all the same

## ------ Plotting a raster----------

#I usually use plotting functions that live in my dataplotter module.
#These fns take spiketimes and eventOnsetTimes and take care of calling
#spikesanalysis and behavioranalysis methods, and then use extraplots methods to do the plotting

#Lets look at the noise burst response from the first cluster
spikeData, eventData, behavData = loader.get_cluster_data(figdb[0], 'noiseBurst')
spikeTimestamps = spikeData.timestamps
eventOnsetTimes = loader.get_event_onset_times(eventData)

plt.clf()
dataplotter.plot_raster(spikeTimestamps, eventOnsetTimes)
plt.show()

#All rasters in the reports are plotted this way. 

## ------ Plotting a sorted raster ----

#The nice thing about the raster plotting methods is that they can accept an array to sort by
#Lets look at the AM responses from the last cluster (9)

spikeData, eventData, behavData = loader.get_cluster_data(figdb[9], 'AM')

spikeTimestamps = spikeData.timestamps
eventOnsetTimes = loader.get_event_onset_times(eventData)
currentFreq = behavData['currentFreq']