Here, we provide an example concerning how to benefit from QCoDeS logs by simple analysis and visualisation.
%matplotlib inline
import dateutil
import os
import pandas as pd
import matplotlib.pyplot as plt
import qcodes as qc
from qcodes.logger import logfile_to_dataframe, time_difference, log_to_dataframe
from zipfile import ZipFile
# put the 30MB into a zip file
filepath = os.path.join(os.getcwd(), 'static', 'pythonlog.zip')
with ZipFile(filepath) as z:
with z.open('pythonlog.log', 'r') as f:
my_log = [line.decode() for line in f]
os.path.exists(filepath)
logdata = log_to_dataframe(my_log, separator=' - ', columns=['time', 'module', 'function', 'loglevel', 'message'])
The logdata
is, now, a nice and tidy DataFrame
that one can further manipulate to extract more information, if needed.
logdata
data = logdata
We know that the log file documents an experiment quering an SR860 for R and amplitude over and over. Let us analyse and visualise query response times.
qstr_R = 'Querying instrument SR860_120: OUTP\? 2' # remember to escape
queries_R = data[data.message.str.contains(qstr_R)]
responses_R = data.loc[queries_R.index + 1]
qstr_lvl = 'Querying instrument SR860_120: SLVL\?' # remember to escape
queries_lvl = data[data.message.str.contains(qstr_lvl)][:-1]
responses_lvl = data.loc[queries_lvl.index + 1]
elapsed_times_R = time_difference(queries_R.time, responses_R.time)
elapsed_times_lvl = time_difference(queries_lvl.time, responses_lvl.time)
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
fig, ax = plt.subplots(1,1)
ax.plot(queries_R.time.str.replace(',', '.').astype("datetime64[ns]"), elapsed_times_R, '.', label='R')
ax.plot(queries_lvl.time.str.replace(',', '.').astype("datetime64[ns]"), elapsed_times_lvl, '.', label='LVL')
fig.autofmt_xdate()
ax.set_ylabel('Response time (s)')
plt.legend()