In [1]:
%matplotlib inline
%reload_ext autoreload
%autoreload 2
%qtconsole

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='ticks', context='poster', font_scale=0.9,
            rc={'xtick.major.size': 3,
                'ytick.major.size': 3,
                'xtick.major.width': 1,
                'ytick.major.width': 1,
                'xtick.major.pad': 3.5,
                'ytick.major.pad': 3.5,
                'axes.linewidth': 1,
                'lines.linewidth': 2,
               })

In [2]:
from IPython.display import HTML

HTML('''<script>
code_show=true; 
function code_toggle() {
 if (code_show){
 $('div.input').hide();
 $('div.output_stderr').hide();
 } else {
 $('div.input').show();
 $('div.output_stderr').show();
 }
 code_show = !code_show
} 
$( document ).ready(code_toggle);
</script>
<form action='javascript:code_toggle()'><input STYLE='color: #4286f4' type='submit' value='Click here to toggle on/off the raw code.'></form>''')


Out[2]:

Gamma Band (30 - 125 Hz)

Power

All Animals


In [164]:
from src.spectral import plot_spectrogram

def plot_power(animal, multitaper_parameter_name):
    gamma_power = pd.read_hdf(
        '../scripts/results.h5',
        key='/{animal}/{multitaper_parameter_name}/power/all_ripples/ripple_difference_from_baseline'.format(
            animal=animal,
            multitaper_parameter_name=multitaper_parameter_name))

    fig, ax = plt.subplots(1, 3, figsize=(15, 5), sharex=True, sharey=True)
    brain_areas_of_interest = ['CA1', 'iCA1', 'PFC']
    for area_ind, brain_area in enumerate(brain_areas_of_interest):
        mesh = plot_spectrogram(gamma_power[brain_area], spectrum_name='power_spectrum',
                                axis_handle=ax[area_ind], vmin=0.9, vmax=1.4)
        ax[area_ind].set_title(brain_area)

    ax[0].set_xlabel('Time (seconds)')
    ax[0].set_ylabel('Frequency (Hz)')
    plt.colorbar(mesh, ax=ax.ravel().tolist(),
                 label='Power change from before ripple',
                 orientation='horizontal',
                 shrink=0.3);
    
plot_power('all_animals', 'gamma_frequencies_5Hz_Res')


Each Animal

HPa

In [165]:
plot_power('HPa', 'gamma_frequencies_5Hz_Res')


HPb

In [166]:
plot_power('HPb', 'gamma_frequencies_5Hz_Res')


HPc

In [152]:
plot_power('HPc', 'gamma_frequencies_10Hz_Res')


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-152-b95873e4cbd2> in <module>()
----> 1 plot_power('HPc', 'gamma_frequencies_10Hz_Res')

<ipython-input-149-01b1951487c6> in plot_power(animal, multitaper_parameter_name)
      6         key='/{animal}/{multitaper_parameter_name}/power/all_ripples/ripple_difference_from_baseline'.format(
      7             animal=animal,
----> 8             multitaper_parameter_name=multitaper_parameter_name))
      9 
     10     fig, ax = plt.subplots(1, 3, figsize=(15, 5), sharex=True, sharey=True)

/Users/edeno/anaconda3/envs/Jadhav-2016-Data-Analysis/lib/python3.5/site-packages/pandas/io/pytables.py in read_hdf(path_or_buf, key, **kwargs)
    358                                      'contains multiple datasets.')
    359             key = candidate_only_group._v_pathname
--> 360         return store.select(key, auto_close=auto_close, **kwargs)
    361     except:
    362         # if there is an error, close the store

/Users/edeno/anaconda3/envs/Jadhav-2016-Data-Analysis/lib/python3.5/site-packages/pandas/io/pytables.py in select(self, key, where, start, stop, columns, iterator, chunksize, auto_close, **kwargs)
    704         group = self.get_node(key)
    705         if group is None:
--> 706             raise KeyError('No object named %s in the file' % key)
    707 
    708         # create the storer and axes

KeyError: 'No object named /HPc/gamma_frequencies_10Hz_Res/power/all_ripples/ripple_difference_from_baseline in the file'

Coherence


In [167]:
from src.spectral import plot_coherogram

def plot_coherence(animal, multitaper_parameter_name):
    coherence_change = pd.read_hdf(
        '../scripts/results.h5',
        key='/{animal}/{multitaper_parameter_name}/coherence/all_ripples/ripple_difference_from_baseline'.format(
            animal=animal,
            multitaper_parameter_name=multitaper_parameter_name))
    coherence_baseline = pd.read_hdf(
        '../scripts/results.h5',
        key='/{animal}/{multitaper_parameter_name}/coherence/all_ripples/baseline'.format(
            animal=animal,
            multitaper_parameter_name=multitaper_parameter_name))
    coherence_raw = pd.read_hdf(
        '../scripts/results.h5',
        key='/{animal}/{multitaper_parameter_name}/coherence/all_ripples/ripple_locked'.format(
            animal=animal,
            multitaper_parameter_name=multitaper_parameter_name))

    brain_area_pairs_of_interest = [('CA1', 'PFC'), ('PFC', 'iCA1')]

    fig, ax = plt.subplots(2, 3, figsize=(15, 10))

    for pair_ind, brain_area_pair in enumerate(brain_area_pairs_of_interest):
        coherence_baseline[brain_area_pair].coherence_magnitude.plot(ax=ax[pair_ind, 0])
        plot_coherogram(coherence_raw[brain_area_pair], axis_handle=ax[pair_ind, 1], vmin=0.0, vmax=0.3)
        plot_coherogram(coherence_change[brain_area_pair], axis_handle=ax[pair_ind, 2], vmin=-0.05, vmax=0.05)
        ax[pair_ind, 0].set_title(brain_area_pair)

    plt.tight_layout()
    
plot_coherence('all_animals', 'gamma_frequencies_5Hz_Res')



In [115]:
plot_coherence('HPa', 'gamma_frequencies_10Hz_Res')


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-115-38f956a83155> in <module>()
----> 1 plot_coherence('HPa', 'gamma_frequencies_10Hz_Res')

<ipython-input-114-53ea69bcd801> in plot_coherence(animal, multitaper_parameter_name)
     23 
     24     for pair_ind, brain_area_pair in enumerate(brain_area_pairs_of_interest):
---> 25         gamma_coherence_baseline[brain_area_pair].coherence_magnitude.plot(ax=ax[pair_ind, 0])
     26         plot_coherogram(gamma_coherence_raw[brain_area_pair], axis_handle=ax[pair_ind, 1], vmin=0.0, vmax=0.3)
     27         plot_coherogram(gamma_coherence_change[brain_area_pair], axis_handle=ax[pair_ind, 2], vmin=-0.05, vmax=0.05)

/Users/edeno/anaconda3/envs/Jadhav-2016-Data-Analysis/lib/python3.5/site-packages/pandas/core/panel.py in __getitem__(self, key)
    270 
    271         if isinstance(self._info_axis, MultiIndex):
--> 272             return self._getitem_multilevel(key)
    273         if not (is_list_like(key) or isinstance(key, slice)):
    274             return super(Panel, self).__getitem__(key)

/Users/edeno/anaconda3/envs/Jadhav-2016-Data-Analysis/lib/python3.5/site-packages/pandas/core/panel.py in _getitem_multilevel(self, key)
    277     def _getitem_multilevel(self, key):
    278         info = self._info_axis
--> 279         loc = info.get_loc(key)
    280         if isinstance(loc, (slice, np.ndarray)):
    281             new_index = info[loc]

/Users/edeno/anaconda3/envs/Jadhav-2016-Data-Analysis/lib/python3.5/site-packages/pandas/indexes/multi.py in get_loc(self, key, method)
   1661             key = _values_from_object(key)
   1662             key = tuple(map(_maybe_str_to_time_stamp, key, self.levels))
-> 1663             return self._engine.get_loc(key)
   1664 
   1665         # -- partial selection or non-unique index

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4433)()

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4279)()

pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13742)()

pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13696)()

KeyError: ('PFC', 'iCA1')

In [116]:
plot_coherence('HPc', 'gamma_frequencies_10Hz_Res')


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-116-9f0f8b1c4ade> in <module>()
----> 1 plot_coherence('HPc', 'gamma_frequencies_10Hz_Res')

<ipython-input-114-53ea69bcd801> in plot_coherence(animal, multitaper_parameter_name)
      6         key='/{animal}/{multitaper_parameter_name}/coherence/all_ripples/ripple_difference_from_baseline'.format(
      7             animal=animal,
----> 8             multitaper_parameter_name=multitaper_parameter_name))
      9     gamma_coherence_baseline = pd.read_hdf(
     10         '../scripts/results.h5',

/Users/edeno/anaconda3/envs/Jadhav-2016-Data-Analysis/lib/python3.5/site-packages/pandas/io/pytables.py in read_hdf(path_or_buf, key, **kwargs)
    358                                      'contains multiple datasets.')
    359             key = candidate_only_group._v_pathname
--> 360         return store.select(key, auto_close=auto_close, **kwargs)
    361     except:
    362         # if there is an error, close the store

/Users/edeno/anaconda3/envs/Jadhav-2016-Data-Analysis/lib/python3.5/site-packages/pandas/io/pytables.py in select(self, key, where, start, stop, columns, iterator, chunksize, auto_close, **kwargs)
    704         group = self.get_node(key)
    705         if group is None:
--> 706             raise KeyError('No object named %s in the file' % key)
    707 
    708         # create the storer and axes

KeyError: 'No object named /HPc/gamma_frequencies_10Hz_Res/coherence/all_ripples/ripple_difference_from_baseline in the file'

Canonical Coherence


In [168]:
def plot_canonical_coherence(animal, multitaper_parameter_name):
    coherence_change = pd.read_hdf(
        '../scripts/results.h5',
        key='/{animal}/{multitaper_parameter_name}/canonical_coherence/all_ripples/ripple_difference_from_baseline'.format(
            animal=animal,
            multitaper_parameter_name=multitaper_parameter_name))
    coherence_baseline = pd.read_hdf(
        '../scripts/results.h5',
        key='/{animal}/{multitaper_parameter_name}/canonical_coherence/all_ripples/baseline'.format(
            animal=animal,
            multitaper_parameter_name=multitaper_parameter_name))
    coherence_raw = pd.read_hdf(
        '../scripts/results.h5',
        key='/{animal}/{multitaper_parameter_name}/canonical_coherence/all_ripples/ripple_locked'.format(
            animal=animal,
            multitaper_parameter_name=multitaper_parameter_name))

    brain_area_pairs_of_interest = [('CA1', 'PFC'), ('PFC', 'iCA1')]

    fig, ax = plt.subplots(2, 3, figsize=(15, 10))

    for pair_ind, brain_area_pair in enumerate(brain_area_pairs_of_interest):
        coherence_baseline[brain_area_pair].coherence_magnitude.plot(ax=ax[pair_ind, 0])
        plot_coherogram(coherence_raw[brain_area_pair], axis_handle=ax[pair_ind, 1], vmin=0.0, vmax=0.5)
        plot_coherogram(coherence_change[brain_area_pair], axis_handle=ax[pair_ind, 2], vmin=-0.05, vmax=0.05)
        ax[pair_ind, 0].set_title(brain_area_pair)

    plt.tight_layout()
    
plot_canonical_coherence('all_animals', 'gamma_frequencies_5Hz_Res')


Group Delay

Slow Gamma (30-60 Hz)


In [146]:
def plot_group_delay(animal, multitaper_parameter_name, frequency_band):
    group_delay = pd.read_hdf(
        '../scripts/results.h5',
        key='/{animal}/{multitaper_parameter_name}/group_delay/all_ripples/ripple_locked/{frequency_band}'.format(
            animal=animal,
            multitaper_parameter_name=multitaper_parameter_name,
            frequency_band=frequency_band))

    brain_area_pairs_of_interest = [('CA1', 'PFC'), ('PFC', 'iCA1')]

    fig, ax = plt.subplots(2, 1, figsize=(15, 10))

    for pair_ind, brain_area_pair in enumerate(brain_area_pairs_of_interest):
        group_delay[brain_area_pair].delay.plot(ax=ax[pair_ind])
        ax[pair_ind].set_title(brain_area_pair)
        ax[pair_ind].axhline(0, color='black', linestyle='--', alpha=0.3)
        ax[pair_ind].set_ylabel('Delay (seconds)')

    plt.tight_layout()
    
plot_group_delay('all_animals', 'gamma_frequencies_10Hz_Res', 'slow_gamma')


Mid-Gamma (60-100 Hz)


In [147]:
plot_group_delay('all_animals', 'gamma_frequencies_10Hz_Res', 'mid_gamma')


Fast Gamma (100-125 Hz)


In [148]:
plot_group_delay('all_animals', 'gamma_frequencies_10Hz_Res', 'fast_gamma')


Beta Band

Power


In [153]:
plot_power('all_animals', 'low_frequencies_4Hz_Res')



In [154]:
plot_power('HPa', 'low_frequencies_4Hz_Res')



In [155]:
plot_power('HPb', 'low_frequencies_4Hz_Res')



In [156]:
plot_power('HPc', 'low_frequencies_4Hz_Res')


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-156-325a4ad3d810> in <module>()
----> 1 plot_power('HPc', 'low_frequencies_4Hz_Res')

<ipython-input-149-01b1951487c6> in plot_power(animal, multitaper_parameter_name)
      6         key='/{animal}/{multitaper_parameter_name}/power/all_ripples/ripple_difference_from_baseline'.format(
      7             animal=animal,
----> 8             multitaper_parameter_name=multitaper_parameter_name))
      9 
     10     fig, ax = plt.subplots(1, 3, figsize=(15, 5), sharex=True, sharey=True)

/Users/edeno/anaconda3/envs/Jadhav-2016-Data-Analysis/lib/python3.5/site-packages/pandas/io/pytables.py in read_hdf(path_or_buf, key, **kwargs)
    358                                      'contains multiple datasets.')
    359             key = candidate_only_group._v_pathname
--> 360         return store.select(key, auto_close=auto_close, **kwargs)
    361     except:
    362         # if there is an error, close the store

/Users/edeno/anaconda3/envs/Jadhav-2016-Data-Analysis/lib/python3.5/site-packages/pandas/io/pytables.py in select(self, key, where, start, stop, columns, iterator, chunksize, auto_close, **kwargs)
    704         group = self.get_node(key)
    705         if group is None:
--> 706             raise KeyError('No object named %s in the file' % key)
    707 
    708         # create the storer and axes

KeyError: 'No object named /HPc/low_frequencies_4Hz_Res/power/all_ripples/ripple_difference_from_baseline in the file'

Coherence


In [157]:
plot_coherence('all_animals', 'low_frequencies_4Hz_Res')


Canonical Coherence


In [159]:
plot_canonical_coherence('all_animals', 'low_frequencies_4Hz_Res')


Group Delay


In [158]:
plot_group_delay('all_animals', 'low_frequencies_4Hz_Res', 'beta')


Ripple Band

Power


In [160]:
plot_power('all_animals', 'ripple_frequencies_50Hz_Res')



In [161]:
plot_coherence('all_animals', 'ripple_frequencies_50Hz_Res')



In [162]:
plot_canonical_coherence('all_animals', 'ripple_frequencies_50Hz_Res')



In [163]:
plot_group_delay('all_animals', 'ripple_frequencies_50Hz_Res', 'ripple')



In [ ]: