In [1]:
drive_path = 'c:/'
import numpy as np
import pandas as pd
import os
import sys
import matplotlib.pyplot as plt
%matplotlib inline
from scipy.stats import ks_2samp
from scipy.stats import anderson_ksamp
from scipy.stats import kruskal
from scipy.stats import variation
from scipy import signal as sps
import seaborn as sns
In [2]:
names=['Plane','Time','Elapsed (ms)']
df=pd.read_table('C:\\Users\Annie\Desktop\\160621_1_Notepad\\20.txt',skiprows=4)
names.extend([col for col in df.columns if 'G PMT' in col])
df=df.loc[df.Plane != 0,df.columns.isin(names)]
df.head()
Out[2]:
In [3]:
# odf is the original dataframe, only G PMT columns in this dataframe
odf=df[[col for col in df.columns if 'G PMT' in col]]
odf.head()
Out[3]:
In [4]:
plt.figure();
plt.plot(odf);
In [5]:
#ZERO PHASE FILTER
order=5
dodf=sps.filtfilt([1]*order,[order],odf['G PMT (1)'])
ndodf=sps.detrend(dodf,bp=(10,100,120,140))
# dodf=sps.detrend(dodf[:,1],bp=(10,18))
# dodf_1=sps.detrend(dodf[1],bp=(1,20))
In [6]:
#WIENER FILTER
# dodf=sps.detrend(dodf,bp=(10,15))
wdodf=sps.wiener(odf,2)
morewdodf=sps.detrend(wdodf[:,3],type='linear',bp=(1,15,30,120))
# dodf_1=sps.detrend(dodf[1],bp=(1,20))
In [7]:
odf.head()
Out[7]:
In [8]:
# Divided is DF/F
baseline=pd.DataFrame(odf.iloc[5:26,1]).mean();
example=pd.DataFrame(odf.iloc[:,1]);
divided=example.divide(baseline);
plt.figure();
plt.plot(divided);
In [89]:
detrend_divided=sps.detrend(divided,type='constant',axis=0)
plt.plot(detrend_divided);
In [95]:
# Detrending twice first with a constant and then with linear does nothing
# Just makes it back to whatever it would look like with one detrending
#constant is better for the beginning and linear is better for the ending
detrend_again=sps.detrend(detrend_divided,type='linear',axis=0)
plt.plot(detrend_again)
Out[95]:
In [ ]:
In [30]:
# This applies a wiener filter before detrending
baseline=pd.DataFrame(wdodf[10:26,1]).mean();
example=pd.DataFrame(wdodf[:,1]);
divided=example.divide(baseline);
plt.figure();
plt.plot(divided);
# plt.plot(example);
detrend_divided=sps.detrend(divided,axis=0,bp=(5,140))
plt.plot(detrend_divided);
In [382]:
# Comparison between weiner filter (wdodf) and first weiner second detrend
plt.plot(wdodf[:,3]);
plt.plot(morewdodf);
In [334]:
plt.plot(odf);
In [335]:
plt.plot(morewdodf);
In [330]:
plt.plot(wdodf);
In [319]:
#Zero phase filter (filtfilt from datta lab)
plt.plot(ndodf);
plt.plot(dodf);
In [321]:
plt.figure();
plt.plot(wdodf);
In [156]:
divided.to_csv('divided')
In [106]:
import matplotlib.mlab as mlab
In [123]:
a=mlab.detrend(divided,'mean',axis=0)
b=mlab.detrend(a,'linear',axis=0)
c=mlab.detrend(b,'mean',axis=0)
In [126]:
plt.plot(c);
plt.plot(b);
In [127]:
import obspy
In [139]:
obspy.core.trace.Trace.detrend(darray)
In [149]:
darray=divided.iloc[:,0].values
Out[149]:
In [151]:
dtrace=obspy.core.trace.Trace(darray)
In [153]:
dtrace.detrend(type='simple')
In [ ]: