In [1]:
%matplotlib inline
%reload_ext autoreload
%autoreload 2
In [2]:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import xarray as xr
Let's try reading in ripple-locked power for all ripples with a 4Hz frequency resolution.
In [9]:
from src.data_processing import read_netcdfs
In [3]:
combined = read_netcdfs('../Processed-Data/*.nc', dim='session',
group='4Hz_Resolution/all_ripples/power',
transform_func=None)
combined
Out[3]:
In [5]:
from functools import partial
def select_brain_areas(dataset, area1='', area2=''):
if 'tetrode1' in dataset.coords:
return dataset.sel(
tetrode1=dataset.tetrode1[dataset.brain_area1==area1],
tetrode2=dataset.tetrode2[dataset.brain_area2==area2]
)
else:
# The dataset is power
return dataset.sel(
tetrode=dataset.tetrode[dataset.brain_area==area1],
)
CA1_PFC = partial(select_brain_areas, area1='CA1', area2='PFC')
combined = read_netcdfs('../Processed-Data/*.nc', dim='session',
group='4Hz_Resolution/all_ripples/coherence',
transform_func=CA1_PFC)
combined
Out[5]:
In [54]:
coh = combined.mean(['tetrode1', 'tetrode2', 'session']).coherence_magnitude
fig, axes = plt.subplots(2, 1, figsize=(12, 9))
coh.sel(frequency=slice(0, 30)).plot(x='time', y='frequency', ax=axes[0]);
coh.sel(frequency=slice(30, 125)).plot(x='time', y='frequency', ax=axes[1]);
In [14]:
coh_diff = (combined - combined.isel(time=0)).mean(['tetrode1', 'tetrode2', 'session']).coherence_magnitude
fig, axes = plt.subplots(2, 1, figsize=(12, 9))
coh_diff.sel(frequency=slice(0, 30)).plot(x='time', y='frequency', ax=axes[0]);
coh_diff.sel(frequency=slice(30, 125)).plot(x='time', y='frequency', ax=axes[1]);
In [6]:
def plot_measure(ds, connectivity_measure,
figsize=(15, 5), brain_area1='brain_area1',
brain_area2='brain_area2'):
baseline = ds.isel(time=0)[connectivity_measure].mean(['tetrode1', 'tetrode2', 'session'])
raw_measure = ds[connectivity_measure].mean(['tetrode1', 'tetrode2', 'session'])
diff_from_baseline = (ds - ds.isel(time=0)).mean(['tetrode1', 'tetrode2', 'session'])[connectivity_measure]
fig, axes = plt.subplots(1, 3, figsize=figsize)
baseline.plot(ax=axes[0]);
raw_measure.plot(x='time', y='frequency', ax=axes[1]);
axes[1].set_title(
'Raw {connectivity_measure}'.format(connectivity_measure=connectivity_measure))
diff_from_baseline.plot(x='time', y='frequency', ax=axes[2]);
axes[2].set_title(
'Difference from baseline {connectivity_measure}'.format(connectivity_measure=connectivity_measure))
plt.tight_layout()
plt.suptitle(
'{brain_area1} - {brain_area2}'.format(
brain_area1=brain_area1, brain_area2=brain_area2),
fontsize=16)
plt.subplots_adjust(top=0.85)
plot_measure(combined.sel(frequency=slice(0, 30)), 'coherence_magnitude')
In [7]:
def plot_connectivity(
group, brain_area1, brain_area2,
connectivity_measure, frequency_of_interest):
ds = read_netcdfs(
'../Processed-Data/*.nc',
dim='session', group=group,
transform_func=partial(
select_brain_areas,
area1=brain_area1,
area2=brain_area2)
)
plot_measure(
ds.sel(frequency=frequency_of_interest),
connectivity_measure,
brain_area1=brain_area1,
brain_area2=brain_area2
)
In [41]:
brain_area1 = 'PFC'
brain_area2 = 'PFC'
group = '4Hz_Resolution/all_ripples/coherence'
connectivity_measure = 'coherence_magnitude'
frequency_of_interest = slice(0, 30)
plot_connectivity(
group, brain_area1, brain_area2,
connectivity_measure, frequency_of_interest)
In [42]:
brain_area1 = 'PFC'
brain_area2 = 'PFC'
group = '4Hz_Resolution/all_ripples/coherence'
connectivity_measure = 'coherence_magnitude'
frequency_of_interest = slice(30, 125)
plot_connectivity(
group, brain_area1, brain_area2,
connectivity_measure, frequency_of_interest)
In [44]:
brain_area1 = 'CA1'
brain_area2 = 'CA1'
group = '4Hz_Resolution/all_ripples/coherence'
connectivity_measure = 'coherence_magnitude'
frequency_of_interest = slice(0, 30)
plot_connectivity(
group, brain_area1, brain_area2,
connectivity_measure, frequency_of_interest)
In [45]:
brain_area1 = 'CA1'
brain_area2 = 'CA1'
group = '4Hz_Resolution/all_ripples/coherence'
connectivity_measure = 'coherence_magnitude'
frequency_of_interest = slice(30, 125)
plot_connectivity(
group, brain_area1, brain_area2,
connectivity_measure, frequency_of_interest)
In [16]:
brain_area1 = 'iCA1'
brain_area2 = 'iCA1'
group = '4Hz_Resolution/all_ripples/coherence'
connectivity_measure = 'coherence_magnitude'
frequency_of_interest = slice(0, 30)
plot_connectivity(
group, brain_area1, brain_area2,
connectivity_measure, frequency_of_interest)
In [17]:
brain_area1 = 'PFC'
brain_area2 = 'iCA1'
group = '4Hz_Resolution/all_ripples/coherence'
connectivity_measure = 'coherence_magnitude'
frequency_of_interest = slice(0, 30)
plot_connectivity(
group, brain_area1, brain_area2,
connectivity_measure, frequency_of_interest)
In [47]:
combined = read_netcdfs('../Processed-Data/*.nc', dim='session',
group='4Hz_Resolution/all_ripples/canonical_coherence',
transform_func=None)
combined
Out[47]:
In [56]:
def plot_canonical_coherence(group, brain_area1, brain_area2, frequencies_of_interest, figsize=(15, 5)):
ds = (
read_netcdfs(
'../Processed-Data/*.nc',
dim='session', group=group)
.sel(
brain_area1=brain_area1,
brain_area2=brain_area2,
frequency=frequencies_of_interest)
.canonical_coherence
)
baseline = ds.isel(time=0).mean('session')
raw_measure = ds.mean('session')
diff_from_baseline = (ds - ds.isel(time=0)).mean('session')
fig, axes = plt.subplots(1, 3, figsize=figsize)
baseline.plot(ax=axes[0]);
raw_measure.plot(x='time', y='frequency', ax=axes[1]);
axes[1].set_title(
'Raw canonical coherence')
diff_from_baseline.plot(x='time', y='frequency', ax=axes[2]);
axes[2].set_title(
'Difference from baseline canonical coherence')
plt.tight_layout()
plt.suptitle(
'{brain_area1} - {brain_area2}'.format(
brain_area1=brain_area1, brain_area2=brain_area2),
fontsize=16)
plt.subplots_adjust(top=0.85)
plot_canonical_coherence('4Hz_Resolution/all_ripples/canonical_coherence', 'PFC', 'CA1', slice(0, 30))
In [57]:
plot_canonical_coherence('4Hz_Resolution/all_ripples/canonical_coherence', 'PFC', 'iCA1', slice(0, 30))
In [61]:
plot_canonical_coherence('10Hz_Resolution/all_ripples/canonical_coherence', 'PFC', 'iCA1', slice(30, 125))
In [60]:
plot_canonical_coherence('10Hz_Resolution/all_ripples/canonical_coherence', 'PFC', 'CA1', slice(30, 125))
In [62]:
plot_canonical_coherence('20Hz_Resolution/all_ripples/canonical_coherence', 'PFC', 'CA1', slice(100, 300))
In [63]:
plot_canonical_coherence('20Hz_Resolution/all_ripples/canonical_coherence', 'PFC', 'iCA1', slice(100, 300))
In [64]:
plot_canonical_coherence('10Hz_Resolution/all_ripples/canonical_coherence', 'PFC', 'iCA1', slice(100, 300))
In [65]:
combined = read_netcdfs('../Processed-Data/*.nc', dim='session',
group='4Hz_Resolution/all_ripples/group_delay',
transform_func=None)
combined
Out[65]:
In [67]:
combined.sel(frequency_band='ripple').delay
Out[67]:
In [69]:
from functools import partial
def select_brain_areas(dataset, area1='', area2=''):
if 'tetrode1' in dataset.coords:
return dataset.sel(
tetrode1=dataset.tetrode1[dataset.brain_area1==area1],
tetrode2=dataset.tetrode2[dataset.brain_area2==area2]
)
else:
# The dataset is power
return dataset.sel(
tetrode=dataset.tetrode[dataset.brain_area==area1],
)
CA1_PFC = partial(select_brain_areas, area1='iCA1', area2='PFC')
combined = read_netcdfs('../Processed-Data/HPa_06_02.nc', dim='session',
group='4Hz_Resolution/all_ripples/coherence',
transform_func=CA1_PFC)
combined
Out[69]:
In [18]:
brain_area1 = 'PFC'
brain_area2 = 'iCA1'
group = '4Hz_Resolution/all_ripples/pairwise_spectral_granger_prediction'
connectivity_measure = 'pairwise_spectral_granger_prediction'
frequency_of_interest = slice(0, 30)
plot_connectivity(
group, brain_area1, brain_area2,
connectivity_measure, frequency_of_interest)
In [19]:
brain_area1 = 'iCA1'
brain_area2 = 'PFC'
group = '4Hz_Resolution/all_ripples/pairwise_spectral_granger_prediction'
connectivity_measure = 'pairwise_spectral_granger_prediction'
frequency_of_interest = slice(0, 30)
plot_connectivity(
group, brain_area1, brain_area2,
connectivity_measure, frequency_of_interest)
In [20]:
combined = read_netcdfs('../Processed-Data/HPa_*.nc', dim='session',
group='4Hz_Resolution/all_ripples/power',
transform_func=None)
combined
Out[20]:
In [21]:
combined = read_netcdfs('../Processed-Data/HPb_*.nc', dim='session',
group='4Hz_Resolution/all_ripples/power',
transform_func=None)
combined
Out[21]:
In [22]:
combined = read_netcdfs('../Processed-Data/*_01_*.nc', dim='session',
group='4Hz_Resolution/all_ripples/power',
transform_func=None)
combined
Out[22]:
In [23]:
combined.tetrode
Out[23]:
In [29]:
combined = read_netcdfs('../Processed-Data/*.nc', dim='session',
group='4Hz_Resolution/all_ripples/group_delay',
transform_func=(
lambda ds: ds.sel(
tetrode1=ds.tetrode1[ds.brain_area1=='PFC'],
tetrode2=ds.tetrode2[ds.brain_area1=='CA1'],
frequency_band='beta'))
).mean(['session', 'tetrode1', 'tetrode2'])
combined.delay.plot()
Out[29]:
In [30]:
combined = read_netcdfs('../Processed-Data/*.nc', dim='session',
group='4Hz_Resolution/all_ripples/group_delay',
transform_func=(
lambda ds: ds.sel(
tetrode1=ds.tetrode1[ds.brain_area1=='PFC'],
tetrode2=ds.tetrode2[ds.brain_area1=='iCA1'],
frequency_band='beta'))
).mean(['session', 'tetrode1', 'tetrode2'])
combined.delay.plot()
Out[30]:
In [37]:
combined = read_netcdfs('../Processed-Data/*.nc', dim='session',
group='4Hz_Resolution/all_ripples/group_delay',
transform_func=(
lambda ds: ds.sel(
tetrode1=ds.tetrode1[ds.brain_area1=='PFC'],
tetrode2=ds.tetrode2[ds.brain_area1=='iCA1'],
frequency_band='beta'))
)
fig, ax = plt.subplots(1,1)
(combined.mean(['session', 'tetrode1', 'tetrode2']).delay +
combined.var(['session', 'tetrode1', 'tetrode2']).delay
).plot(ax=ax, color='blue', linestyle='--')
(combined.mean(['session', 'tetrode1', 'tetrode2']).delay -
combined.var(['session', 'tetrode1', 'tetrode2']).delay
).plot(ax=ax, color='blue', linestyle='--')
(combined.mean(['session', 'tetrode1', 'tetrode2']).delay
).plot(ax=ax, color='blue')
Out[37]:
In [ ]: