+_plot = plot # alternative name for use inside analyze_all()
+
+
+def analyze_all(config, data, raw_data, maximum_relative_error=1e-5,
+ filename=None, group=None, plot=False, dry_run=False):
+ "(Re)analyze (and possibly plot) all data from a `calib()` run."
+ if not data.get('bump', None):
+ data['bump'] = _numpy.zeros((config['num-bumps'],), dtype=float)
+ if not data.get('temperature', None):
+ data['temperature'] = _numpy.zeros(
+ (config['num-temperatures'],), dtype=float)
+ if not data.get('vibrations', None):
+ data['vibration'] = _numpy.zeros(
+ (config['num-vibrations'],), dtype=float)
+ axis_config = config['afm']['piezo'].select_config(
+ setting_name='axes',
+ attribute_value=config['afm']['main-axis'],
+ get_attribute=_get_axis_name)
+ input_config = config['afm']['piezo'].select_config(
+ setting_name='inputs', attribute_value='deflection')
+ bumps_changed = temperatures_changed = vibrations_changed = False
+ if not isinstance(group, _h5py.Group) and not dry_run:
+ f = _h5py.File(filename, mode)
+ group = _h5_create_group(f, group)
+ else:
+ f = None
+ try:
+ for i,bump in enumerate(raw_data['bump']):
+ data['bump'][i],changed = check_bump(
+ index=i, bump=bump, z_axis_config=axis_config,
+ deflection_channel_config=input_config, plot=plot,
+ maximum_relative_error=maximum_relative_error)
+ if changed and not dry_run:
+ bumps_changed = True
+ bump_group = _h5_create_group(group, 'bump/{}'.format(i))
+ _bump_save(group=bump_group, processed=data['bump'][i])
+ for i,temperature in enumerate(raw_data['temperature']):
+ data['temperature'][i],changed = check_temperature(
+ index=i, temperature=temperature,
+ maximum_relative_error=maximum_relative_error)
+ if changed and not dry_run:
+ temperatures_changed = True
+ temperature_group = _h5_create_group(
+ group, 'temperature/{}'.format(i))
+ _temperature_save(
+ group=temerature_group, processed=data['temperature'][i])
+ for i,vibration in enumerate(raw_data['vibration']):
+ data['vibration'][i],changed = check_vibration(
+ index=i, vibration=vibration,
+ deflection_channel_config=input_config, plot=plot,
+ maximum_relative_error=maximum_relative_error)
+ if changed and not dry_run:
+ vibrations_changed = True
+ vibration_group = _h5_create_group(
+ group, 'vibration/{}'.format(i))
+ _vibration_save(
+ group=vibration_group, processed=data['vibration'])
+ k,k_s,changed = check_calibration(
+ k=data['processed']['spring_constant'],
+ k_s=data['processed']['spring_constant_deviation'],
+ bumps=data['bump'],
+ temperatures=data['temperature'], vibrations=data['vibration'],
+ maximum_relative_error=maximum_relative_error)
+ if (changed or bumps_changed or temperatures_changed or
+ vibrations_changed) and not dry_run:
+ calibration_group = _h5_create_group(group, 'calibration')
+ if bumps_changed:
+ calib_save(group=calibration_group, bump=data['bump'])
+ if temperatures_changed:
+ calib_save(
+ group=calibration_group, temperature=data['temperature'])
+ if vibrations_changed:
+ calib_save(
+ group=calibration_group, vibration=data['vibration'])
+ if changed:
+ calib_save(group=calibration_group, k=k, k_s=k_s)
+ finally:
+ if f:
+ f.close()
+ if plot:
+ _plot(bumps=data['raw']['bump'],
+ temperatures=data['raw']['temperature'],
+ vibrations=data['raw']['vibration'])
+ return (k, k_s)