text
stringlengths
0
828
if not hasattr(app, 'extensions'):
app.extensions = dict()
if 'statics' in app.extensions:
raise ValueError('Already registered extension STATICS.')
app.extensions['statics'] = _StaticsState(self, app)
# Initialize blueprint.
name = 'flask_statics_helper'
static_url_path = '{0}/{1}'.format(app.static_url_path, name)
self.blueprint = Blueprint(name, __name__, template_folder='templates', static_folder='static',
static_url_path=static_url_path)
self.blueprint.add_app_template_global(self.all_variables, '_flask_statics_helper_all_variables')
self.blueprint.add_app_template_global(self.all_resources, '_flask_statics_helper_all_resources')
app.register_blueprint(self.blueprint)"
588,"def measure_board_rms(control_board, n_samples=10, sampling_ms=10,
delay_between_samples_ms=0):
'''
Read RMS voltage samples from control board high-voltage feedback circuit.
'''
try:
results = control_board.measure_impedance(n_samples, sampling_ms,
delay_between_samples_ms,
True, True, [])
except RuntimeError:
# `RuntimeError` may be raised if, for example, current limit was
# reached during measurement. In such cases, return an empty frame.
logger.warning('Error encountered during high-voltage RMS '
'measurement.', exc_info=True)
data = pd.DataFrame(None, columns=['board measured V',
'divider resistor index'])
else:
data = pd.DataFrame({'board measured V': results.V_hv})
data['divider resistor index'] = results.hv_resistor
return data"
589,"def find_good(control_board, actuation_steps, resistor_index, start_index,
end_index):
'''
Use a binary search over the range of provided actuation_steps to find the
maximum actuation voltage that is measured by the board feedback circuit
using the specified feedback resistor.
'''
lower = start_index
upper = end_index
while lower < upper - 1:
index = lower + (upper - lower) / 2
v = actuation_steps[index]
control_board.set_waveform_voltage(v)
data = measure_board_rms(control_board)
valid_data = data[data['divider resistor index'] >= 0]
if (valid_data['divider resistor index'] < resistor_index).sum():
# We have some measurements from another resistor.
upper = index
else:
lower = index
control_board.set_waveform_voltage(actuation_steps[lower])
data = measure_board_rms(control_board)
return lower, data"
590,"def resistor_max_actuation_readings(control_board, frequencies,
oscope_reading_func):
'''
For each resistor in the high-voltage feedback resistor bank, read the
board measured voltage and the oscilloscope measured voltage for an
actuation voltage that nearly saturates the feedback resistor.
By searching for an actuation voltage near saturation, the signal-to-noise
ratio is minimized.
'''
# Set board amplifier gain to 1.
# __NB__ This is likely _far_ lower than the actual gain _(which may be a
# factor of several hundred)_..
control_board.set_waveform_voltage(0)
control_board.auto_adjust_amplifier_gain = False
control_board.amplifier_gain = 1.
# Set waveform voltage to a low value and obtain the corresponding
# oscilloscope reading to calculate an approximate gain of the amplifier.
target_voltage = 0.1
control_board.set_waveform_voltage(target_voltage)
oscope_rms = oscope_reading_func()
estimated_amplifier_gain = oscope_rms / target_voltage
# Based on the maximum amplified RMS voltage, define a set of actuation
# voltages to search when performing calibration.
max_post_gain_V = 0.8 * control_board.max_waveform_voltage
max_actuation_V = max_post_gain_V / estimated_amplifier_gain
actuation_steps = np.linspace(0.005, max_actuation_V, num=50)
resistor_count = len(control_board.a0_series_resistance)
# Define frequency/resistor index pairs to take measurements at.
conditions = pd.DataFrame([[r, f] for r in range(resistor_count - 1, -1, -1)
for f in frequencies],
columns=['resistor index', 'frequency'])
# Define function to process each frequency/resistor index pair.
def max_actuation_reading(x):
'''
Measure maximum board RMS voltage using specified feedback resistor, at
the specified frequency.