Skip to content

Instantly share code, notes, and snippets.

@DavidLutton
Last active June 23, 2019 19:09
Show Gist options
  • Save DavidLutton/ebf52aa0c98a3cc32fb1adbea7e6bffd to your computer and use it in GitHub Desktop.
Save DavidLutton/ebf52aa0c98a3cc32fb1adbea7e6bffd to your computer and use it in GitHub Desktop.
import math
import pandas as pd
import numpy as np
def measurementfunction(columns=['Input', 'Output']):
# Inital call of next() runs the init/setup
print('Init/Setup of Instrument')
buffer = {}
# A initial call of next(generatorobject) will get to this point
x = yield # Where first input is outside the while loop
# A subsequent call to the generator.send() allows input of infomation to the generator
# The output of the .send() will be the result of the yield statement
while x is not math.inf:
xcomputed = x**2
buffer[x] = xcomputed
x = yield f'For {x} Result of Measurement Process: {xcomputed}'
yield pd.DataFrame(buffer.items(), columns=columns)
gen = measurementfunction(columns=['Frequency (Hz)', 'Result (Watt)'])
next(gen)
# Init/Setup of Instrument
gen.send(5)
# Result of Measurement Process: 25
gen.send(10)
# Result of Measurement Process: 100
gen.send(1000)
# Result of Measurement Process: 100
df = gen.send(math.inf)
@DavidLutton
Copy link
Author

DavidLutton commented Jun 23, 2019

  • Collect inputs and measurements
  • return DataFrame of results
  • where do limits come into this
  • How to deal with multiple inputs
  • How to deal with multiple outputs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment