In [1]:
%matplotlib inline
import cPickle as pickle

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from path_helpers import path
import matplotlib.mlab as mlab

from microdrop.experiment_log import ExperimentLog

log_path = path('.').abspath() / path('data')

# load the experiment log
log = ExperimentLog.load(log_path)

# get the start time for each step (in seconds), relative to the beginning of the protocol
step_time = log.get('time')

# get the FeedbackResults object for each step
results = log.get('FeedbackResults', plugin_name='wheelerlab.dmf_control_board')

df = pd.DataFrame()
for step_number, feedback_result in enumerate(results):
    if feedback_result is None:
        continue

    # get the raw dx/dt and interpolate it to use the same time points as the
    # impedance values.
    t, dxdt = feedback_result.dxdt()
    dxdt_raw = np.interp(feedback_result.time,
                         t, dxdt) * 1e3 # multiply by 1000 to convert to mm/s
        
    # get the smoothed dx/dt and interpolate it to use the same time points as the
    # impedance values.
    t, dxdt = feedback_result.dxdt(filter_order=3)
    dxdt_smoothed = np.interp(feedback_result.time,
                              t, dxdt) * 1e3 # multiply by 1000 to convert to mm/s
    
    # append the fields for this step to a pandas data frame
    df = df.append(pd.DataFrame([step_number*np.ones(len(feedback_result.time)),
                                 step_time[step_number] + feedback_result.time / 1000.,
                                 feedback_result.time / 1000.,
                                 feedback_result.V_actuation(),
                                 feedback_result.capacitance(),
                                 feedback_result.x_position(),
                                 dxdt_raw,
                                 dxdt_smoothed,
                                ],
                                index=['step number', 'protocol time (s)', 'step time (s)',
                                       'V_actuation (V)', 'capacitance (F)', 'x_position (mm)',
                                       'dx/dt (mm/s)', 'smoothed dx/dt (mm/s)'
                                ]).T
    )
    
# save the data frame to a csv file
df.to_csv(path_or_buf='log.csv', index=False)
[interfaces] <_MainThread(MainThread, started 54584)>

Plotting data

The following cells show some examples of plotting data.

In [2]:
# Plot the velocity of the first 5 steps versus the protocol time
plt.figure()
filtered_steps = df[df['step number'] < 5]
plt.plot(filtered_steps['protocol time (s)'], filtered_steps['smoothed dx/dt (mm/s)'])
plt.xlabel('Protocol time (s)')
plt.ylabel('dx/dt (mm/s)')
Out[2]:
<matplotlib.text.Text at 0x38f2930>

Plot of the drop velocity versus the protcol time (i.e., time since the protocol started).

In [3]:
# Plot the velocity of the first 5 steps versus the relative step time
plt.figure()
filtered_steps = df[df['step number'] < 5]
for step_number, feedback_result in filtered_steps.groupby(['step number']):
    plt.plot(feedback_result['step time (s)'],
             feedback_result['smoothed dx/dt (mm/s)'],
             label='step %d' % step_number)
plt.xlabel('Step time (s)')
plt.ylabel('dx/dt (mm/s)')
plt.legend()
Out[3]:
<matplotlib.legend.Legend at 0x3909d10>

You can also plot versus the step time (i.e., time since the step started).

In []: