Executed: Mon Mar 27 11:43:18 2017
Duration: 26 seconds.
This notebook computes the detectors DCR for the two 8-pixel arrays used for the 8-spot smFRET measurements
In [1]:
import phconvert as phc
phc.__version__
Out[1]:
In [2]:
from __future__ import division
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
import seaborn as sns
from cycler import cycler
%matplotlib inline
%config InlineBackend.figure_format='retina' # for hi-dpi displays
sns.set_style('whitegrid')
#sns.set_palette('deep')
# palette = ('Paired', 10)
# sns.palplot(sns.color_palette(*palette))
# sns.set_palette(*palette)
bmap = sns.color_palette("Set1", 9)
colors = np.array(bmap)[(1,0,2,3,4,8,6,7), :]
sns.palplot(sns.color_palette(colors))
sns.set_palette(colors)
In [3]:
data_dir = './data/multispot/'
In [4]:
fname = 'Z2014-02-26_DCR_test_2.hdf5'
In [5]:
full_fname = data_dir + fname
In [6]:
d = phc.hdf5.load_photon_hdf5(full_fname, require_setup=False)
In [7]:
type(d._v_file)
Out[7]:
In [8]:
# Compute DCR
A_em = phc.hdf5.photon_data_mapping(d._v_file, 'detectors')
In [9]:
A_em = [a.read().view(bool) for a in A_em.values()]
accept_dcr = [a.sum()/d.acquisition_duration.read() for a in A_em]
donor_dcr = [(~a).sum()/d.acquisition_duration.read() for a in A_em]
# Make a DataFrame
dcr_data = pd.DataFrame(columns = ['Donor DCR', 'Acceptor DCR'], dtype=float)
dcr_data.index.name = 'CH'
dcr_data['Donor DCR'] = donor_dcr
dcr_data['Acceptor DCR'] = accept_dcr
dcr_data = dcr_data.round(1)
dcr_data
Out[9]:
In [10]:
# Output plot and tables
dcr_data.plot.bar(table=np.round(dcr_data, 2).T)
plt.ylabel('DCR (cps)')
plt.gca().xaxis.set_visible(False)
In [11]:
from fretbursts import *
In [12]:
def compute_dcr(d):
# Compute DCR
accept_dcr = [a.sum()/(d.time_max - d.time_min) for a in d.A_em]
donor_dcr = [(~a).sum()/(d.time_max - d.time_min) for a in d.A_em]
# Make a DataFrame
dcr_data = pd.DataFrame(columns = ['Donor DCR', 'Acceptor DCR'], dtype=float)
dcr_data['Donor DCR'] = donor_dcr
dcr_data['Acceptor DCR'] = accept_dcr
dcr_data.index.name = 'CH'
return dcr_data
In [13]:
d = loader.photon_hdf5(full_fname)
In [14]:
d_small = d.slice_ph(time_s2=30)
In [15]:
dcr_small = compute_dcr(d_small).round(1)
dcr_small
Out[15]:
In [16]:
print('Percentage DCR change:')
100*(dcr_small - dcr_data)/dcr_data
Out[16]:
In [17]:
print('Percentage DCR change:')
100*(dcr_small - dcr_data)/dcr_data
Out[17]:
In [18]:
#d.calc_bg(fun=fb.bg.raw_fit, time_s=30)
In [19]:
#%matplotlib qt
In [20]:
Ax = dplot(d, timetrace_single, ph_sel=Ph_sel(Dex='Aem'), binwidth=5,
tmax=None, show_rate_th=False, sharey=False, set_ax_limits=False)
for ax in Ax.ravel():
ax.axvline(120)
ax.axvline(3800)
In [21]:
d_sel = d.slice_ph(time_s1=120, time_s2=3800)
dcr_sel = compute_dcr(d_sel).round(1)
dcr_sel
Out[21]:
In [22]:
dcr_sel - dcr_data
Out[22]:
In [23]:
d_sel.calc_bg(bg.exp_fit, time_s=30, tail_min_us='auto')
In [24]:
raw_bg_rates_d = np.asfarray(d_sel.bg_dd).mean(1)
raw_bg_rates_a = np.asfarray(d_sel.bg_ad).mean(1)
dcr_sel['Donor DCR tail fit'] = raw_bg_rates_d.round(1)
dcr_sel['Acceptor DCR tail fit'] = raw_bg_rates_a.round(1)
In [25]:
dcr_sel_d = dcr_sel[['Donor DCR', 'Donor DCR tail fit']]
dcr_sel_d.plot.bar(table=np.round(dcr_sel_d, 2).T)
plt.ylabel('DCR (cps)')
plt.gca().xaxis.set_visible(False)
In [26]:
dcr_sel_a = dcr_sel[['Acceptor DCR', 'Acceptor DCR tail fit']]
dcr_sel_a.plot.bar(table=np.round(dcr_sel_a, 2).T)
plt.ylabel('DCR (cps)')
plt.gca().xaxis.set_visible(False)
In [27]:
dcr_sel
Out[27]:
In [28]:
dcr_fit = dcr_sel[['Donor DCR tail fit', 'Acceptor DCR tail fit']]
dcr_fit.columns = ['Donor DCR', 'Acceptor DCR']
dcr_fit
Out[28]:
In [29]:
dcr_data.to_csv('results/8-pixels_DCR.csv')
In [30]:
pd.read_csv('results/8-pixels_DCR.csv', index_col=0)
Out[30]:
In [31]: