Skip to content

Commit

Permalink
Return/plot logged cal. results
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ristè committed Nov 5, 2019
1 parent 3ba9ca0 commit d6961a4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions QGL/ChannelLibraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,42 @@ def cal_ls(self):
table_code += f"<tr><td>{id}</td><td>{d}</td><td>{t.split('.')[0]}</td><td>{sample.name}</td><td>{name}</td><td>{round(value,9)}</td></tr>"
display(HTML(f"<table><tr><th>id</th><th>Date</th><th>Time</th><th>Sample</th><th>Name</th><th>Value</th></tr><tr>{table_code}</tr></table>"))

def get_cals(qubit, params, make_plots=True, depth=0):
"""
Return and optionally plot the result of the most recent calibrations/characterizations
Parameters
-------------
qubit : qubit name (string)
params: parameter(s) to plot (string or list of strings)
make_plots: optional bool (default = True)
depth: optional integer, number of most recent calibrations to load (default = 0 for all cals)
-------------
Returns
List of: dates, values, errors
"""
#TODO: extend to multiple qubits, subplots etc.
if isinstance(params, str):
params = [params]
caldb = bbndb.calibration.Calibration
sample_id = cl.session.query(bbndb.calibration.Sample).filter_by(name=qubit).first().id
for param in params:
c = cl.session.query(caldb.id, caldb.name, caldb.value, caldb.uncertainty, caldb.date).filter_by(name=param,sample_id=sample_id).order_by(-caldb.id).all()
dates = [cc[4] for cc in c]
values = [cc[2] for cc in c]
errors = [cc[3] if cc[3] else 0 for cc in c]
if make_plots:
plt.errorbar(dates[-depth:], values[-depth:], yerr=errors[-depth:], fmt='-o', elinewidth=2.0, capsize=4.0, label=param)
plt.title(qubit)
plt.xlabel("Time")
units = {'T1':'s', 'T2':'s', 'f':'Hz'}
unit = f'({units[param]})' if param in units else ''
plt.ylabel(f'{param} {unit}')
if make_plots:
plt.legend()
ylabels = [f'{param} ({units[param]})' if param in units else '' for param in params]
plt.ylabel(", ".join(ylabels))
return dates, values, errors

def ent_by_type(self, obj_type, show=False):
q = self.session.query(obj_type).filter(obj_type.channel_db.has(label="working")).order_by(obj_type.label).all()
if show:
Expand Down

0 comments on commit d6961a4

Please sign in to comment.