Exemplo n.º 1
0
def setup():
    from jaratest.nick.database import ephysinterface
    reload(ephysinterface)

    global interface
    interface = ephysinterface.EphysInterface('pinp003', '2015-06-24', 'nick',
                                              'laser_tuning_curve')
    global spikeTimestamps
    global events
    global eventOnsetTimes
    global bdata
    spikeTimestamps = interface.loader.get_session_spikes('15-31-48',
                                                          6).timestamps
    events = interface.loader.get_session_events('15-31-48')
    eventOnsetTimes = interface.loader.get_event_onset_times(events)
    bdata = interface.loader.get_session_behavior('a')
Exemplo n.º 2
0
def plot_bandwidth_report(mouse, date, site, siteName):
    sessions = site.get_session_ephys_filenames()
    behavFilename = site.get_session_behav_filenames()
    ei = ephysinterface.EphysInterface(mouse, date, '', 'bandwidth_am')
    bdata = ei.loader.get_session_behavior(behavFilename[3][-4:-3])
    charfreq = str(np.unique(bdata['charFreq'])[0] / 1000)
    modrate = str(np.unique(bdata['modRate'])[0])
    ei2 = ephysinterface.EphysInterface(mouse, date, '', 'am_tuning_curve')
    bdata2 = ei2.loader.get_session_behavior(behavFilename[1][-4:-3])
    bdata3 = ei2.loader.get_session_behavior(behavFilename[2][-4:-3])
    currentFreq = bdata2['currentFreq']
    currentBand = bdata['currentBand']
    currentAmp = bdata['currentAmp']
    currentInt = bdata2['currentIntensity']
    currentRate = bdata3['currentFreq']

    #for tetrode in site.tetrodes:
    for tetrode in [2]:
        oneTT = sitefuncs.cluster_site(site, siteName, tetrode)
        dataSpikes = ei.loader.get_session_spikes(sessions[3], tetrode)
        dataSpikes2 = ei2.loader.get_session_spikes(sessions[1], tetrode)
        #clusters = np.unique(dataSpikes.clusters)
        clusters = [8]
        for cluster in clusters:
            plt.clf()

            # -- plot bandwidth rasters --
            eventData = ei.loader.get_session_events(sessions[3])
            spikeData = ei.loader.get_session_spikes(sessions[3],
                                                     tetrode,
                                                     cluster=cluster)
            eventOnsetTimes = ei.loader.get_event_onset_times(eventData)
            spikeTimestamps = spikeData.timestamps
            timeRange = [-0.2, 1.5]

            numBands = np.unique(currentBand)
            numAmps = np.unique(currentAmp)

            firstSortLabels = [
                '{}'.format(band) for band in np.unique(currentBand)
            ]
            secondSortLabels = [
                'Amplitude: {}'.format(amp) for amp in np.unique(currentAmp)
            ]

            trialsEachCond = behavioranalysis.find_trials_each_combination(
                currentBand, numBands, currentAmp, numAmps)
            spikeTimesFromEventOnset, trialIndexForEachSpike, indexLimitsEachTrial = spikesanalysis.eventlocked_spiketimes(
                spikeTimestamps, eventOnsetTimes, timeRange)
            for ind, secondArrayVal in enumerate(numAmps):
                plt.subplot2grid((12, 15), (5 * ind, 0), rowspan=4, colspan=7)
                trialsThisSecondVal = trialsEachCond[:, :, ind]
                pRaster, hcond, zline = extraplots.raster_plot(
                    spikeTimesFromEventOnset,
                    indexLimitsEachTrial,
                    timeRange,
                    trialsEachCond=trialsThisSecondVal,
                    labels=firstSortLabels)
                plt.setp(pRaster, ms=4)

                plt.title(secondSortLabels[ind])
                plt.ylabel('bandwidth (octaves)')
                if ind == len(np.unique(currentAmp)) - 1:
                    plt.xlabel("Time from sound onset (sec)")

            # -- plot Yashar plots for bandwidth data --
            plt.subplot2grid((12, 15), (10, 0), rowspan=2, colspan=3)
            band_select_plot(spikeTimestamps,
                             eventOnsetTimes,
                             currentAmp,
                             currentBand, [0.0, 1.0],
                             title='bandwidth selectivity')
            plt.subplot2grid((12, 15), (10, 3), rowspan=2, colspan=3)
            band_select_plot(spikeTimestamps,
                             eventOnsetTimes,
                             currentAmp,
                             currentBand, [0.2, 1.0],
                             title='first 200ms excluded')

            # -- plot frequency tuning heat map --
            plt.subplot2grid((12, 15), (5, 7), rowspan=4, colspan=4)

            eventData = ei2.loader.get_session_events(sessions[1])
            spikeData = ei2.loader.get_session_spikes(sessions[1],
                                                      tetrode,
                                                      cluster=cluster)
            eventOnsetTimes = ei2.loader.get_event_onset_times(eventData)
            spikeTimestamps = spikeData.timestamps

            dataplotter.two_axis_heatmap(
                spikeTimestamps=spikeTimestamps,
                eventOnsetTimes=eventOnsetTimes,
                firstSortArray=currentInt,
                secondSortArray=currentFreq,
                firstSortLabels=[
                    "%.1f" % inten for inten in np.unique(currentInt)
                ],
                secondSortLabels=[
                    "%.1f" % freq for freq in np.unique(currentFreq) / 1000.0
                ],
                xlabel='Frequency (kHz)',
                ylabel='Intensity (dB SPL)',
                plotTitle='Frequency Tuning Curve',
                flipFirstAxis=True,
                flipSecondAxis=False,
                timeRange=[0, 0.1])
            plt.ylabel('Intensity (dB SPL)')
            plt.xlabel('Frequency (kHz)')
            plt.title('Frequency Tuning Curve')

            # -- plot frequency tuning raster --
            plt.subplot2grid((12, 15), (0, 7), rowspan=4, colspan=4)
            freqLabels = [
                "%.1f" % freq for freq in np.unique(currentFreq) / 1000.0
            ]
            dataplotter.plot_raster(spikeTimestamps,
                                    eventOnsetTimes,
                                    sortArray=currentFreq,
                                    timeRange=[-0.1, 0.5],
                                    labels=freqLabels)
            plt.xlabel('Time from sound onset (sec)')
            plt.ylabel('Frequency (kHz)')
            plt.title('Frequency Tuning Raster')

            # -- plot AM PSTH --
            eventData = ei2.loader.get_session_events(sessions[2])
            spikeData = ei2.loader.get_session_spikes(sessions[2],
                                                      tetrode,
                                                      cluster=cluster)
            eventOnsetTimes = ei2.loader.get_event_onset_times(eventData)
            spikeTimestamps = spikeData.timestamps
            timeRange = [-0.2, 1.5]

            spikeTimesFromEventOnset, trialIndexForEachSpike, indexLimitsEachTrial = spikesanalysis.eventlocked_spiketimes(
                spikeTimestamps, eventOnsetTimes, timeRange)
            colourList = ['b', 'g', 'y', 'orange', 'r']
            numRates = np.unique(currentRate)
            trialsEachCond = behavioranalysis.find_trials_each_type(
                currentRate, numRates)
            binEdges = np.around(np.arange(-0.2, 0.85, 0.05), decimals=2)
            spikeCountMat = spikesanalysis.spiketimes_to_spikecounts(
                spikeTimesFromEventOnset, indexLimitsEachTrial, binEdges)
            plt.subplot2grid((12, 15), (5, 11), rowspan=4, colspan=4)
            pPSTH = extraplots.plot_psth(spikeCountMat / 0.05,
                                         1,
                                         binEdges[:-1],
                                         trialsEachCond,
                                         colorEachCond=colourList)
            plt.setp(pPSTH)
            plt.xlabel('Time from sound onset (sec)')
            plt.ylabel('Firing rate (Hz)')
            plt.title('AM PSTH')

            # -- plot AM raster --
            plt.subplot2grid((12, 15), (0, 11), rowspan=4, colspan=4)
            rateLabels = ["%.1f" % rate for rate in np.unique(currentRate)]
            dataplotter.plot_raster(spikeTimestamps,
                                    eventOnsetTimes,
                                    sortArray=currentRate,
                                    timeRange=[-0.2, 0.8],
                                    labels=rateLabels,
                                    colorEachCond=colourList)
            plt.xlabel('Time from sound onset (sec)')
            plt.ylabel('Modulation Rate (Hz)')
            plt.title('AM Raster')

            # -- show cluster analysis --
            tsThisCluster = oneTT.timestamps[oneTT.clusters == cluster]
            wavesThisCluster = oneTT.samples[oneTT.clusters == cluster]

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

            # -- Plot waveforms --
            plt.subplot2grid((12, 15), (10, 9), rowspan=2, colspan=3)
            spikesorting.plot_waveforms(wavesThisCluster)

            # -- Plot projections --
            plt.subplot2grid((12, 15), (10, 12), rowspan=1, colspan=3)
            spikesorting.plot_projections(wavesThisCluster)

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

            plt.subplots_adjust(wspace=1.5)
            plt.suptitle(
                '{0}, {1}, {2}, Tetrode {3}, Cluster {4}, {5}kHz, {6}Hz modulation'
                .format(mouse, date, siteName, tetrode, cluster, charfreq,
                        modrate))
            fig_path = oneTT.clustersDir
            fig_name = 'TT{0}Cluster{1}.png'.format(tetrode, cluster)
            full_fig_path = os.path.join(fig_path, fig_name)
            fig = plt.gcf()
            fig.set_size_inches(24, 12)
            fig.savefig(full_fig_path, format='png', bbox_inches='tight')
Exemplo n.º 3
0
from jaratest.nick.database import ephysinterface
reload(ephysinterface)

#Some sessions from 2015-06-24 for reference. 
# d1site1 = day1.add_site(depth = 3543, tetrodes = [6])
# d1site1.add_session('15-22-29', None, sessionTypes['nb'])
# d1site1.add_session('15-27-37', None, sessionTypes['lt'])
# d1site1.add_session('15-31-48', 'a', sessionTypes['tc'])
# d1site1.add_session('15-45-22', 'b', sessionTypes['bf'])

interface = ephysinterface.EphysInterface('pinp003', '2015-06-24', 'nick', 'laser_tuning_curve')

#Plotting session rasters seems to work when providing an ind
# interface.plot_session_raster(-1, 6)
# interface.plot_session_raster('19-16-41', 6, replace=1)

#interface.plot_array_raster(-1)

#This is working as expected. 

# 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.flip_tetrode_tuning('15-31-48', 'a')

from jaratest.nick.database import ephysinterface
from jaratest.nick.database import dataplotter

ei = ephysinterface.EphysInterface('pinp013', '2016-05-25', 'nick',
                                   'am_tuning_curve')
bdata = ei.loader.get_session_behavior('a')

plotTitle = ei.loader.get_session_filename(
    site1.get_mouse_relative_ephys_filenames()[1])

#Why is this giving an error
eventData = ei.loader.get_session_events(
    site1.get_mouse_relative_ephys_filenames()[1])

eventData = ei.loader.get_session_events('14-41-52')
spikeData = ei.loader.get_session_spikes('14-41-52', 1)
cluster = 5
spikeTimestamps = spikeData.timestamps[spikeData.clusters == cluster]
eventOnsetTimes = ei.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)'

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