<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Summary
<p class="lead">This notebook summarizes the realtime-kinetic measurements.
</p>
Requirement
Before running this notebook, you need to pre-process the data with
Step1:  Measurement 0
Step2:  Measurement 1
Step3:  Measurement 2
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
from pathlib import Path
from scipy.stats import linregress
dir_ = r'C:\Data\Antonio\data\8-spot 5samples data\2013-05-15/'
filenames = [str(f) for f in Path(dir_).glob('*.hdf5')]
filenames
keys = [f.stem.split('_')[0] for f in Path(dir_).glob('*.hdf5')]
keys
filenames_dict = {k: v.stem for k, v in zip(keys, Path(dir_).glob('*.hdf5'))}
filenames_dict
def _filename_fit(idx, method, window, step):
    return 'results/%s_%sfit_ampl_only__window%ds_step%ds.txt' % (filenames_dict[idx], method, window, step)
def _filename_nb(idx, window, step):
    return 'results/%s_burst_data_vs_time__window%ds_step%ds.txt' % (filenames_dict[idx], window, step)
def process(meas_id):
    methods = ['em', 'll', 'hist']
    fig_width = 14
    fs = 18
    def savefig(title, **kwargs):
        plt.savefig("figures/Meas%s %s" % (meas_id, title))
    bursts = pd.DataFrame.from_csv(_filename_nb(meas_id, window=30, step=1))
    
    nbm = bursts.num_bursts.mean()
    nbc = bursts.num_bursts_detrend
    print("Number of bursts (detrended): %7.1f MEAN, %7.1f VAR, %6.3f VAR/MEAN" % 
          (nbm, nbc.var(), nbc.var()/nbm))
    
    fig, ax = plt.subplots(figsize=(fig_width, 3))
    ax.plot(bursts.tstart, bursts.num_bursts)
    ax.plot(bursts.tstart, bursts.num_bursts_linregress, 'r')
    title = 'Number of bursts - Full measurement'
    ax.set_title(title, fontsize=fs)
    savefig(title)
    fig, ax = plt.subplots(figsize=(fig_width, 3))
    ax.plot(bursts.tstart, bursts.num_bursts_detrend)
    ax.axhline(nbm, color='r')
    title = 'Number of bursts (detrended) - Full measurement'
    ax.set_title(title, fontsize=fs)
    savefig(title)
    
    params = {}
    for window in (5, 30):
        for method in methods:
            p = pd.DataFrame.from_csv(_filename_fit(meas_id, method=method, 
                                                    window=window, step=1))
            params[method, window, 1] = p
    meth = 'em'
    fig, ax = plt.subplots(figsize=(fig_width, 3))
    ax.plot('kinetics', data=params[meth, 5, 1], marker='h', lw=0, color='gray', alpha=0.2)
    ax.plot('kinetics', data=params[meth, 30, 1], marker='h', lw=0, alpha=0.5)
    ax.plot('kinetics_linregress', data=params[meth, 30, 1], color='r')
    title = 'Population fraction - Full measurement'
    ax.set_title(title, fontsize=fs)
    savefig(title)
    
    px = params
    print('Kinetics 30s:                    %.3f STD, %.3f STD detrended.' % 
      ((100*px[meth, 30, 1].kinetics).std(), 
       (100*px[meth, 30, 1].kinetics_linregress).std()))
Explanation: Summary
<p class="lead">This notebook summarizes the realtime-kinetic measurements.
</p>
Requirement
Before running this notebook, you need to pre-process the data with:
8-spot dsDNA-steady-state - Run-All
This pre-processing analyzes the measurement data files, 
compute the moving-window slices, the number of bursts 
and fits the population fractions. All results are saved as TXT in 
the results folder.
The present notebook loads these results and presents a summary.
End of explanation
process(meas_id = '7d')
Explanation: Measurement 0
End of explanation
process(meas_id = '12d')
Explanation: Measurement 1
End of explanation
process(meas_id = '17d')
Explanation: Measurement 2
End of explanation
<END_TASK>