Skip to content

Commit

Permalink
removed yaml.load warning; updates to log
Browse files Browse the repository at this point in the history
  • Loading branch information
slongwell committed Aug 27, 2019
1 parent eeb6133 commit d679f48
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion acqpack/asicontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, config_file, init_xy=True):
self.serial = s.Serial() # placeholder

f = open(config_file, 'r')
self.config = yaml.load(f)
self.config = yaml.full_load(f)
f.close()

self.config['conv'] = float(self.config['conv'])
Expand Down
35 changes: 24 additions & 11 deletions acqpack/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
import time

# TODO:
# - continously updating display with new events (flag?)
# - conditional formatting (pandas styler)
# - plotting
# - use python built-in logging backend (cross-notebook)?
# - logging/inspection from Jupyter? reproducable Juyter plugin?
# - fix signature of wrapper [e.g. f.goto(lookup, blah,...)]
# - keyword args
# - bug where __init__ time logging doesn't work properly
# - how to handle re-running cells/etc
# - single .track() function
# - config .show() to hide fields
# - 'cls' usage problem: https://stackoverflow.com/questions/4613000/what-is-the-cls-variable-used-for-in-python-classes
class Log():
"""
Creates a pandas df for logging function calls.
Expand Down Expand Up @@ -53,7 +63,7 @@ def f2(input):
"""
def __init__(self):
self.df = pd.DataFrame(columns=['t_in', 'ts_in', 't_out', 'ts_out',
self.df = pd.DataFrame(columns=['t_in', 'ts_in', 't_out', 'ts_out', 'dt',
'class', 'fn', 'in', 'out'])
self.write = self.track_fn(self.write)
self.write('init')
Expand All @@ -63,14 +73,17 @@ def format_time(self, time_s):
return time.strftime("%Y%m%d_%H:%M:%S", time.localtime(time_s))


def show(self, ascending=False, clear_display=False):
def show(self, ascending=True, clear_display=False):
ret = (self.df[['ts_in', 'ts_out', 'dt',
'class', 'fn', 'in', 'out']].sort_index(ascending=ascending)
.style
.set_properties(subset=['in','out'], **{'text-align': 'left'})
.set_table_styles([dict(selector='th', props=[('text-align', 'left')] ) ]))
if clear_display:
disp.clear_output(wait=True)
disp.display(self.df[['ts_in', 'ts_out',
'class', 'fn', 'in', 'out']].sort_index(ascending=ascending)
.style
.set_properties(subset=['in','out'], **{'text-align': 'left'})
.set_table_styles([dict(selector='th', props=[('text-align', 'left')] ) ]))
disp.display(ret)
else:
return ret.data

def write(self, msg):
pass
Expand All @@ -90,11 +103,11 @@ def wrapper(*args):
fn = f.__name__
i = len(self.df)

t = time.time()
self.df.loc[i, ['t_in','ts_in','class','fn','in']] = [t, self.format_time(t), cls, fn, inputs]
t_in = time.time()
self.df.loc[i, ['t_in','ts_in','class','fn','in']] = [t_in, self.format_time(t_in), cls, fn, inputs]
outputs = f(*args)
t = time.time()
self.df.loc[i, ['t_out','ts_out','out']] = [t, self.format_time(t), outputs]
t_out = time.time()
self.df.loc[i, ['t_out','ts_out','dt','out']] = [t_out, self.format_time(t_out), t_out-t_in, outputs]

return outputs
wrapper.__doc__ = f.__doc__
Expand Down
2 changes: 1 addition & 1 deletion acqpack/mfcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Mfcs:
def __init__(self, config_file, chanmap_path):

with open(config_file) as file:
self.config = yaml.load(file)
self.config = yaml.full_load(file)

self.config['conversion_to_mbar'] = float(self.config['conversion_to_mbar']) # ensure conversion factor is float
self.dll = cdll.LoadLibrary(DLL_PATH) # load dll (i.e. MFCS API)
Expand Down
2 changes: 1 addition & 1 deletion acqpack/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, config_file, home=True):
self.serial = s.Serial() # placeholder

f = open(config_file, 'r')
self.config = yaml.load(f)
self.config = yaml.full_load(f)
f.close()

self.config['conv'] = float(self.config['conv'])
Expand Down

0 comments on commit d679f48

Please sign in to comment.