In [1]:
%matplotlib inline
import pdb
import sys
import pandas as pd
import numpy as np
import scipy.io as sio
import matplotlib.pyplot as plt
import matplotlib
import scipy.signal as sg
import math
import scipy as sp
import socket
import os
matplotlib.style.use('ggplot')
comp_name=socket.gethostname()
if comp_name == 'Ezequiels-MacBook-Pro.local':
print 'Computer: ' + comp_name
sys.path.append('/Users/zeke/experiment/ephysDataManagement/ephysScripts')
experiment_folder = os.path.join('/Users','zeke','experiment')
else:
print 'Computer: ' + 'server'
sys.path.append('/experiment/ephysDataManagement/ephysScripts')
experiment_folder = os.path.join('/','experiment')
import unitToolsv2
from data_handling import ephys_names as en
from data_handling.basic_plot import decim, plot_raster, make_psth
from data_handling import data_load as dl
from analysis import stimulus as st
In [2]:
mouse = 'ZKawakeM72'
sess = 27
rec = 'a'
fn = en.file_names(mouse,sess,rec,root=experiment_folder)
In [3]:
mat_file = os.path.join(fn.fold_exp_data,'ZKawakeM72_027_006_cell.mat')
r=dl.load_cell(mat_file, as_dict=True)
print r.keys()
In [4]:
#Load a baseline sniff file
mat_file = os.path.join(fn.fold_exp_data,'ZKawakeM72_027_e_trialsBase.mat')
sniffs= dl.load_sniff_base(mat_file, as_dict=False)
#plot all the baseline sniffs
snif_plot = plt.figure()
all_ax = snif_plot.add_axes([0, 0, 1, .4])
avg_ax = snif_plot.add_axes([0, .5, 1, .4])
t=np.arange(0, 450, 1)
avg_line = avg_ax.plot(np.average(-sniffs['flow'][250:750,:],axis=1))
lines=all_ax.plot(-sniffs['flow'][250:750,:50])
In [5]:
#load the spikes baseline raster file
'ZKawakeM72_010_001_cell.mat'
mat_file = os.path.join(fn.fold_exp_data,'ZKawakeM72_010_001_spikesBase.mat')
bases = dl.load_baseline(mat_file)
print bases.keys()
spikes = [bases[a_key] for a_key in bases.keys()]
#spikes = load_baseline(mat_file, as_dict = False)
#print spikes
#print spikes[0]['u_id']
#print spikes[0]['id']
sr_spikes = spikes[0]['spikes']
sr_t0 = spikes[0]['t_0']
#plot all the baseline sniffs
sr_plot = plt.figure()
ras_ax = sr_plot.add_axes([0, 0, 1, .4])
hist_ax = sr_plot.add_axes([0, .5, 1, .4])
t0 = 500
t1 = 0
t2= 2500
bin_size=10
#plot the raster
lines,_ = plot_raster(sr_spikes,t0=t0,t1=t1,t2=t2,ax=ras_ax)
ras_ax.set_xlim(-500,2500)
#the psth
hist_line, hist_ax = plot_raster(sr_spikes,t0=t0, t1=t1,t2=t2, bin_size=15, ax=hist_ax)
#hist_ax.set_ylim(0.9,1.1)
hist_ax.set_xlim(-500,2500)
Out[5]:
In [6]:
# get all the cells
cells_path = fn.fold_exp_data
records = dl.load_cells(cells_path)
In [27]:
records['responses'].keys()
Out[27]:
In [10]:
## plot the psth of an odor, by odorName and concentration
def conc_compare(conc1, conc2, tolerance=1.5):
return 1./float(tolerance) < float(conc1)/float(conc2) and float(conc1)/float(conc2) < float(tolerance)
odor_name = ['2-hydroxyacetophenone','2hydroxyacetophenone']
odor_conc = 0.0051
cell_id = 'ZKawakeM72_020_c_001'
#get the rec
a_record = records['responses'][cell_id]
print a_record['rec_id']
print a_record['odor_resp'].keys()
#get the indexes of the trials with this odor
this_odor_conc = [i for i in range(len(a_record['odor_resp']['odors'])) if a_record['odor_resp']['odors'][i].lower() in odor_name \
and conc_compare(a_record['odor_resp']['concs'][i], odor_conc)
]
#plot the psth
#
In [26]:
this_odor_conc
Out[26]:
In [57]:
# plot a raster for a record, odor, concentration
# the record was selected, the type of response was selected.
# entered:
response = a_record['odor_resp']
sr_spikes = response['spikes'][this_odor_conc]
sr_t0 = response['t_0']
sr_t1 = response['t_1']
sr_t2 = response['t_2']
#pre and post stimulus windows
t_pre = 100;
t_post = 300;
#plot the psth
sr_plot = plt.figure()
ras_ax = sr_plot.add_axes([0, 0, 1, .45])
hist_ax = sr_plot.add_axes([0, .5, 1, .45])
t0=t_pre
t1 = -sr_t1-t_pre
t2=t_post-sr_t1
bin_size=10
#plot the raster
lines,_ = plot_raster(sr_spikes,t0=t0,t1=t1,t2=t2,ax=ras_ax)
ras_ax.set_xlim(-t0,t2-t1-t0)
#the psth
hist_line, hist_ax = plot_raster(sr_spikes,t0=t0, t1=t1,t2=t2, bin_size=bin_size, ax=hist_ax)
psth = make_psth(sr_spikes,t0=t0, t1=t1,t2=t2, bin_size=bin_size)
#hist_ax.set_ylim(0.9,1.1)
hist_ax.set_xlim(-t0,t2-t1-t0)
hist_ax.set_xticklabels([])
#the baseline
#get the baseline for the cell
baseline = records['baselines'][a_record['meta']['id']]
bl_spikes = baseline['spikes']
#plot it
bl_t0 = baseline['t_0']
bl_t1 = baseline['t_1']
bl_t2 = baseline['t_2']
t0=t_pre
t1 = -bl_t1-t_pre
t2=t_post-bl_t1
base_line, hist_ax = plot_raster(bl_spikes,t0=t0, t1=t1,t2=t2, bin_size=bin_size, ax=hist_ax)
hist_ax.set_ylim(0,max(psth[0])*1.2)
Out[57]:
In [59]:
a_record['odor_resp']['concs'][3]
Out[59]:
In [16]:
h_cells = dl.cells_for_odor(records['responses'],['2-hydroxyacetophenone'],0.0051)
h_cells.keys()
odor_conc = 0.0051
hlitral = dl.cells_by_tag(records['responses'], light=1, odor=1)
hlitral.keys()
Out[16]:
In [17]:
print h_cells['KPawakeM72_014_a_001'].keys()
h_cells['KPawakeM72_014_a_001']['rec_id']
h_cells['KPawakeM72_014_a_001']['meta']
Out[17]:
In [18]:
records.keys()
Out[18]:
In [19]:
records['base_sniff'][h_cells['KPawakeM72_014_a_001']['rec_id']].keys()
Out[19]:
In [20]:
records['trials'][h_cells['KPawakeM72_014_a_001']['rec_id']].keys()
Out[20]:
In [21]:
resp = h_cells['KPawakeM72_014_a_001']['odor_resp']
In [22]:
[type(r) for r in resp.values()]
Out[22]:
In [54]:
resp.keys()
Out[54]:
In [39]:
resp['concs'].ndim
Out[39]:
In [38]:
sup=[1,4,5]
con = resp['concs'][sup,:]
type(con) in [list, np.ndarray]
In [55]:
y = (np.round(np.random.random((3,4))))
y
Out[55]:
In [58]:
y = 1 if 1 in sup else 2
In [59]:
y
Out[59]:
In [63]:
records['responses']['KPawakeM72_016_a_023'].keys()
Out[63]:
In [62]:
records.keys()
Out[62]:
In [2]:
## create a stimulus and initialize it (load its responses)
high_2hydroxy = st.Odor(['2-hydroxyacetophenone','2hydroxyacetophenone'], 0.0051)
st_1 = st.Stimulus(high_2hydroxy)
In [21]:
st_1.responses.keys()
Out[21]:
In [24]:
# plot a raster for a record, odor, concentration
# the record was selected, the type of response was selected.
# entered:
stim_resp = st_1.responses['ZKawakeM72_027_e_004']
response = stim_resp.raster
sr_spikes = response['spikes']
sr_t0 = response['t_0']
sr_t1 = response['t_1']
sr_t2 = response['t_2']
#pre and post stimulus windows
t_pre = 100;
t_post = 300;
#plot the psth
sr_plot = plt.figure()
ras_ax = sr_plot.add_axes([0, 0, 1, .45])
hist_ax = sr_plot.add_axes([0, .5, 1, .45])
t0=t_pre
t1 = -sr_t1-t_pre
t2=t_post-sr_t1
bin_size=10
#plot the raster
lines,_ = plot_raster(sr_spikes,t0=t0,t1=t1,t2=t2,ax=ras_ax)
ras_ax.set_xlim(-t0,t2-t1-t0)
#the psth
hist_line, hist_ax = plot_raster(sr_spikes,t0=t0, t1=t1,t2=t2, bin_size=bin_size, ax=hist_ax)
psth = make_psth(sr_spikes,t0=t0, t1=t1,t2=t2, bin_size=bin_size)
#hist_ax.set_ylim(0.9,1.1)
hist_ax.set_xlim(-t0,t2-t1-t0)
hist_ax.set_xticklabels([])
#the baseline
#get the baseline for the cell
baseline = stim_resp.baseline.data
bl_spikes = baseline['spikes']
#plot it
bl_t0 = baseline['t_0']
bl_t1 = baseline['t_1']
bl_t2 = baseline['t_2']
t0=t_pre
t1 = -bl_t1-t_pre
t2=t_post-bl_t1
base_line, hist_ax = plot_raster(bl_spikes,t0=t0, t1=t1,t2=t2, bin_size=bin_size, ax=hist_ax)
hist_ax.set_ylim(0,max(psth[0])*1.2)
Out[24]:
In [28]:
sr_ax = matplotlib.figure.AxesStack
In [34]:
# plot a raster for a record, odor, concentration
# the record was selected, the type of response was selected.
# entered:
stim_resp = st_1.responses['ZKawakeM72_027_e_004']
response = stim_resp.raster
sr_spikes = response['spikes']
sr_t0 = response['t_0']
sr_t1 = response['t_1']
sr_t2 = response['t_2']
#pre and post stimulus windows
t_pre = 100;
t_post = 300;
#plot the psth
sr_plot = plt.figure()
sr_ax = matplotlib.figure.AxesStack()
ras_ax = sr_plot.add_axes([0, 0, 1, .45])
hist_ax = sr_plot.add_axes([0, .5, 1, .45])
sr_ax.add('raster', ras_ax)
sr_ax.add('psth', hist_ax)
t0=t_pre
t1 = -sr_t1-t_pre
t2=t_post-sr_t1
bin_size=10
#plot the raster
lines,_ = plot_raster(sr_spikes,t0=t0,t1=t1,t2=t2,ax=ras_ax)
ras_ax.set_xlim(-t0,t2-t1-t0)
#the psth
hist_line, hist_ax = plot_raster(sr_spikes,t0=t0, t1=t1,t2=t2, bin_size=bin_size, ax=hist_ax)
psth = make_psth(sr_spikes,t0=t0, t1=t1,t2=t2, bin_size=bin_size)
#hist_ax.set_ylim(0.9,1.1)
hist_ax.set_xlim(-t0,t2-t1-t0)
hist_ax.set_xticklabels([])
#the baseline
#get the baseline for the cell
baseline = stim_resp.baseline.data
bl_spikes = baseline['spikes']
#plot it
bl_t0 = baseline['t_0']
bl_t1 = baseline['t_1']
bl_t2 = baseline['t_2']
t0=t_pre
t1 = -bl_t1-t_pre
t2=t_post-bl_t1
base_line, hist_ax = plot_raster(bl_spikes,t0=t0, t1=t1,t2=t2, bin_size=bin_size, ax=hist_ax)
hist_ax.set_ylim(0,max(psth[0])*1.2)
Out[34]:
In [40]:
sr_ax.current_key_axes()
Out[40]:
In [ ]: