49 lines
1.0 KiB
Python
49 lines
1.0 KiB
Python
import random
|
|
import ch.psi.pshell.device.Readable.ReadableArray as ReadableArray
|
|
|
|
class SimulatedOutput(Writable):
|
|
def write(self, value):
|
|
pass
|
|
|
|
|
|
class SimulatedInput(Readable):
|
|
def __init__(self):
|
|
self.x = 0.0
|
|
|
|
def read(self):
|
|
self.x = self.x + 0.2
|
|
noise = (random.random() - 0.5) / 20.0
|
|
return math.sin(self.x) + noise
|
|
|
|
|
|
sout = SimulatedOutput()
|
|
sinp = SimulatedInput()
|
|
|
|
def integrate_image():
|
|
data = scienta.data.read()
|
|
#Integrate and plot
|
|
(width,height) = scienta.getImageSize().tolist()
|
|
integration = []
|
|
for i in range(width):
|
|
p=0.0
|
|
for j in range(height):
|
|
p=p+data[j*width+i]
|
|
integration.append(p)
|
|
return integration
|
|
|
|
|
|
class ImageIntegrator(ReadableArray):
|
|
def getSize(self):
|
|
(width,height) = scienta.getImageSize().tolist()
|
|
return width
|
|
|
|
def read(self):
|
|
return to_array(integrate_image(),'d')
|
|
|
|
integration = ImageIntegrator()
|
|
|
|
|
|
def trig_scienta():
|
|
scienta.start()
|
|
scienta.waitReady(-1)
|