In [1]:
%%writefile procedures.py
import random
from time import sleep
import logging
log = logging.getLogger('')
log.addHandler(logging.NullHandler())
from pymeasure.experiment import Procedure, IntegerParameter, Parameter, FloatParameter
class TestProcedure(Procedure):
iterations = IntegerParameter('Loop Iterations', default=100)
delay = FloatParameter('Delay Time', units='s', default=0.2)
seed = Parameter('Random Seed', default='12345')
DATA_COLUMNS = ['Iteration', 'Random Number']
def startup(self):
log.info("Setting up random number generator")
random.seed(self.seed)
def execute(self):
log.info("Starting to generate numbers")
for i in range(self.iterations):
data = {
'Iteration': i,
'Random Number': random.random()
}
log.debug("Produced numbers: %s" % data)
self.emit('results', data)
self.emit('progress', 100.*i/self.iterations)
sleep(self.delay)
if self.should_stop():
log.warning("Catch stop command in procedure")
break
def shutdown(self):
log.info("Finished")
In [2]:
from pymeasure.experiment import Experiment
from procedures import TestProcedure
%matplotlib inline
In [3]:
experiment = Experiment('test', TestProcedure(iterations=100, delay=.1))
In [4]:
experiment.start()
experiment.plot_live('Iteration', 'Random Number')
In [ ]: