From 1407a48836403af249bfe822a7604a413210d978 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 7 Jan 2015 21:41:31 +0800 Subject: [PATCH] examples: use run arguments --- examples/photon_histogram.py | 12 +++++------- examples/transport.py | 20 +++++++++----------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/examples/photon_histogram.py b/examples/photon_histogram.py index 9e0d281d4..a77349095 100644 --- a/examples/photon_histogram.py +++ b/examples/photon_histogram.py @@ -5,8 +5,6 @@ class PhotonHistogram(AutoContext): bd = Device("dds") bdd = Device("dds") pmt = Device("ttl_in") - repeats = Parameter(100) - nbins = Parameter(100) @kernel def cool_detect(self): @@ -22,13 +20,13 @@ class PhotonHistogram(AutoContext): return self.pmt.count() @kernel - def run(self): - hist = [0 for _ in range (self.nbins)] + def run(self, nbins=100, repeats=100): + hist = [0 for _ in range (nbins)] - for i in range(self.repeats): + for i in range(repeats): n = self.cool_detect() - if n >= self.nbins: - n = self.nbins-1 + if n >= nbins: + n = nbins - 1 hist[n] += 1 print(hist) diff --git a/examples/transport.py b/examples/transport.py index 5f1d92bff..3f4b3fe0d 100644 --- a/examples/transport.py +++ b/examples/transport.py @@ -16,8 +16,6 @@ class Transport(AutoContext): pmt = Device("ttl_in") electrodes = Device("pdq") - repeats = Parameter(100) - nbins = Parameter(100) wait_at_stop = Parameter(100*us) speed = Parameter(1.5) @@ -93,27 +91,27 @@ class Transport(AutoContext): return self.detect() @kernel - def repeat(self): - self.histogram = [0 for _ in range(self.nbins)] + def repeat(self, repeats, nbins): + self.histogram = [0 for _ in range(nbins)] - for i in range(self.repeats): + for i in range(repeats): n = self.one() - if n >= self.nbins: - n = self.nbins-1 + if n >= nbins: + n = nbins - 1 self.histogram[n] += 1 - def scan(self, stops): + def scan(self, repeats, nbins, stops): for s in stops: self.histogram = [] # non-kernel, calculate waveforms, build frames # could also be rpc'ed from repeat() self.prepare(s) # kernel part - self.repeat() + self.repeat(repeats, nbins) # live update 2d plot with current self.histogram # broadcast(s, self.histogram) - def run(self): + def run(self, repeats=100, nbins=100): # scan transport endpoint stops = range(10, len(transport_data["t"]), 10) - self.scan(stops) + self.scan(repeats, nbins, stops)