-
-def calib_load_all(filename, group='/'):
- "Load all data from a `calib()` run."
- assert group.endswith('/'), group
- bumps,temperatures,vibrations,calibration_config,k,k_s = calib_load(
- filename, group+'calibration/')
- bump_details = []
- for i in range(calibration_config['num-bumps']):
- (raw_bump,bump_config,z_axis_config,deflection_channel_config,
- processed_bump) = _bump_load(
- filename=filename, group='%sbump/%d/' % (group, i))
- bump_details.append({
- 'raw_bump': raw_bump,
- 'bump_config': bump_config,
- 'z_axis_config': z_axis_config,
- 'deflection_channel_config': deflection_channel_config,
- 'processed_bump': processed_bump,
- })
- temperature_details = []
- for i in range(calibration_config['num-temperatures']):
- (raw_temperature,temperature_config,processed_temperature
- ) = _temperature_load(
- filename=filename, group='%stemperature/%d/' % (group, i))
- temperature_details.append({
- 'raw_temperature': raw_temperature,
- 'temperature_config': temperature_config,
- 'processed_temperature': processed_temperature,
- })
- vibration_details = []
- for i in range(calibration_config['num-vibrations']):
- (raw_vibration,vibration_config,deflection_channel_config,
- processed_vibration) = _vibration_load(
- filename=filename, group='%svibration/%d/' % (group, i))
- vibration_details.append({
- 'raw_vibration': raw_vibration,
- 'vibration_config': vibration_config,
- 'deflection_channel_config': deflection_channel_config,
- 'processed_vibration': processed_vibration,
- })
- return {
- 'bumps': bumps,
- 'bump_details': bump_details,
- 'temperatures': temperatures,
- 'temperature_details': temperature_details,
- 'vibrations': vibrations,
- 'vibration_details': vibration_details,
- 'calibration_config': calibration_config,
- 'k': k,
- 'k_s': k_s,
- }
-
-def calib_analyze_all(filename, group='/', maximum_relative_error=1e-5,
- dry_run=False):
- "(Re)analyze all data from a `calib()` run."
- assert group.endswith('/'), group
- bumps,temperatures,vibrations,calibration_config,k,k_s = calib_load(
- filename, group+'calibration/')
- if bumps is None:
- bumps = _numpy.zeros(
- (calibration_config['num-bumps'],), dtype=float)
- if temperatures is None:
- temperatures = _numpy.zeros(
- (calibration_config['num-temperatures'],), dtype=float)
- if vibrations is None:
- vibrations = _numpy.zeros(
- (calibration_config['num-vibrations'],), dtype=float)
- changed_bump = changed_temperature = changed_vibration = False
- for i in range(calibration_config['num-bumps']):
- _changed_bump = False
- bump_group = '%sbump/%d/' % (group, i)
- (raw_bump,bump_config,z_axis_config,
- deflection_channel_config,processed_bump) = _bump_load(
- filename=filename, group=bump_group)
- sensitivity = _bump_analyze(
- data=raw_bump, bump_config=bump_config,
- z_axis_config=z_axis_config,
- deflection_channel_config=deflection_channel_config)
- bumps[i] = sensitivity
- if processed_bump is None:
- _changed_bump = True
- _LOG.warn('new analysis for bump %d: %g' % (i, sensitivity))
- else:
- rel_error = abs(sensitivity - processed_bump)/processed_bump
- if rel_error > maximum_relative_error:
- _changed_bump = True
- _LOG.warn(("new analysis doesn't match for bump %d: %g -> %g "
- "(difference: %g, relative error: %g)")
- % (i, processed_bump, sensitivity,
- sensitivity-processed_bump, rel_error))
- if _changed_bump and not dry_run:
- changed_bump = True
- _bump_save(filename, bump_group, processed_bump=sensitivity)
- for i in range(calibration_config['num-temperatures']):
- _changed_temperature = False
- temperature_group = '%stemperature/%d/' % (group, i)
- (raw_temperature,temperature_config,processed_temperature
- ) = _temperature_load(
- filename=filename, group=temperature_group)
- temperature = _temperature_analyze(
- raw_temperature, temperature_config)
- temperatures[i] = temperature
- if processed_temperature is None:
- _changed_temperature = True
- _LOG.warn('new analysis for temperature %d: %g' % (i, temperature))
- else:
- rel_error = abs(temperature - processed_temperature
- )/processed_temperature
- if rel_error > maximum_relative_error:
- _changed_temperature = True
- _LOG.warn(("new analysis doesn't match for temperature %d: "
- "%g -> %g (difference: %g, relative error: %g)")
- % (i, processed_temperature, temperature,
- temperature-processed_temperature, rel_error))
- if _changed_temperature and not dry_run:
- changed_temperature = True
- _temperature_save(
- filename, temperature_group,
- processed_T=temperature)
- for i in range(calibration_config['num-vibrations']):
- _changed_vibration = False
- vibration_group = '%svibration/%d/' % (group, i)
- (raw_vibration,vibration_config,deflection_channel_config,
- processed_vibration) = _vibration_load(
- filename=filename, group=vibration_group)
- variance = _vibration_analyze(
- deflection=raw_vibration, vibration_config=vibration_config,
- deflection_channel_config=deflection_channel_config)
- vibrations[i] = variance
- if processed_vibration is None:
- _changed_vibration = True
- _LOG.warn('new analysis for vibration %d: %g' % (i, variance))
- else:
- rel_error = abs(variance - processed_vibration)/processed_vibration
- if rel_error > maximum_relative_error:
- _changed_vibration = True
- _LOG.warn(("new analysis doesn't match for vibration %d: "
- "%g -> %g (difference: %g, relative error: %g)")
- % (i, processed_vibration, variance,
- variance-processed_vibration, rel_error))
- if _changed_vibration and not dry_run:
- changed_vibration = True
- _vibration_save(
- filename, vibration_group, processed_vibration=variance)
-
- calib_group = '%scalibration/' % group
-
- if changed_bump and not dry_run:
- calib_save(filename, calib_group, bumps=bumps)
- if changed_temperature and not dry_run:
- calib_save(filename, calib_group, temperatures=temperatures)
- if changed_vibration and not dry_run:
- calib_save(filename, calib_group, vibrations=vibrations)
-
- new_k,new_k_s = calib_analyze(
- bumps=bumps, temperatures=temperatures, vibrations=vibrations)
- new_calib_k = False
+def check_bump(index, bump, maximum_relative_error, **kwargs):
+ changed = False
+ sensitivity = _bump_analyze(
+ config=bump['config']['bump'], data=bump['raw'], **kwargs)
+ if bump.get('processed', None) is None:
+ changed = True
+ _LOG.warn('new analysis for bump {}: {}'.format(index, sensitivity))
+ else:
+ rel_error = abs(sensitivity - bump['processed'])/bump['processed']
+ if rel_error > maximum_relative_error:
+ changed = True
+ _LOG.warn(("new analysis doesn't match for bump {}: {} -> {} "
+ "(difference: {}, relative error: {})").format(
+ index, bump['processed'], sensitivity,
+ sensitivity-bump['processed'], rel_error))
+ return (sensitivity, changed)
+
+def check_temperature(index, temperature, maximum_relative_error, **kwargs):
+ changed = False
+ temp = _temperature_analyze(
+ config=temperature['config']['temperature'],
+ temperature=temperature['raw'], **kwargs)
+ if temperature.get('processed', None) is None:
+ changed = True
+ _LOG.warn('new analysis for temperature {}: {}'.format(index, temp))
+ else:
+ rel_error = abs(temp - temperature['processed']
+ )/temperature['processed']
+ if rel_error > maximum_relative_error:
+ changed = True
+ _LOG.warn(("new analysis doesn't match for temperature "
+ "{} -> {} (difference: {}, relative error: {})"
+ ).format(
+ index, temperature['processed'], temp,
+ temp-temperature['processed'], rel_error))
+ return (temp, changed)
+
+def check_vibration(index, vibration, maximum_relative_error, **kwargs):
+ changed = False
+ variance = _vibration_analyze(
+ config=vibration['config']['vibration'],
+ deflection=vibration['raw'], **kwargs)
+ if vibration.get('processed', None) is None:
+ changed = True
+ _LOG.warn('new analysis for temperature {}: {}'.format(
+ index, variance))
+ else:
+ rel_error = abs(variance-vibration['processed'])/vibration['processed']
+ if rel_error > maximum_relative_error:
+ _LOG.warn(("new analysis doesn't match for vibration {}: {} != {} "
+ "(difference: {}, relative error: {})").format(
+ index, variance, vibration['processed'],
+ variance-vibration['processed'], rel_error))
+ return (variance, changed)
+
+def check_calibration(k, k_s, maximum_relative_error, **kwargs):
+ changed = False
+ new_k,new_k_s = analyze(**kwargs)