From 682818b2ba05c787bf99bdb5884e5337d6b88f73 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 11 May 2012 12:21:56 -0400 Subject: [PATCH] Better errors from analyze_all when we're missing raw data. --- calibcant/analyze.py | 46 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/calibcant/analyze.py b/calibcant/analyze.py index 0cfab7c..a8dda10 100644 --- a/calibcant/analyze.py +++ b/calibcant/analyze.py @@ -130,6 +130,13 @@ def analyze(bumps, temperatures, vibrations): v2_m = vibrations.mean() # average voltage variance v2_s = vibrations.std() + if ps_m == 0: + raise ValueError('invalid bumps: {}'.format(bumps)) + if T_m == 0: + raise ValueError('invalid temperatures: {}'.format(temperatures)) + if v2_m == 0: + raise ValueError('invalid vibrations: {}'.format(vibrations)) + # Vphoto / photo_sensitivity = x # k = kB T / = kB T photo_sensitivity**2 / Vphoto_var # @@ -224,6 +231,7 @@ def analyze_all(config, data, raw_data, maximum_relative_error=1e-5, input_config = config['afm']['piezo'].select_config( setting_name='inputs', attribute_value='deflection') bumps_changed = temperatures_changed = vibrations_changed = False + calibration_group = None if not isinstance(group, _h5py.Group) and not dry_run: f = _h5py.File(filename, mode='a') group = _h5_create_group(f, group) @@ -266,14 +274,8 @@ def analyze_all(config, data, raw_data, maximum_relative_error=1e-5, group, 'vibration/{}'.format(i)) _vibration_save( group=vibration_group, processed=data['vibration']) - k,k_s,changed = check_calibration( - k=data.get('processed/spring_constant', None), - k_s=data.get('processed/spring_constant_deviation', None), - 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: + if (bumps_changed or temperatures_changed or vibrations_changed + ) and not dry_run: calibration_group = _h5_create_group(group, 'calibration') if bumps_changed: save_results( @@ -284,10 +286,30 @@ def analyze_all(config, data, raw_data, maximum_relative_error=1e-5, if vibrations_changed: save_results( group=calibration_group, vibration=data['vibration']) - if changed: - save_results( - group=calibration_group, - spring_constant=k, spring_constant_deviation=k_s) + if len(raw_data['bump']) != len(data['bump']): + raise ValueError( + 'not enough raw bump data: {} of {}'.format( + len(raw_data['bump']), len(data['bump']))) + if len(raw_data['temperature']) != len(data['temperature']): + raise ValueError( + 'not enough raw temperature data: {} of {}'.format( + len(raw_data['temperature']), len(data['temperature']))) + if len(raw_data['vibration']) != len(data['vibration']): + raise ValueError( + 'not enough raw vibration data: {} of {}'.format( + len(raw_data['vibration']), len(data['vibration']))) + k,k_s,changed = check_calibration( + k=data.get('processed/spring_constant', None), + k_s=data.get('processed/spring_constant_deviation', None), + bumps=data['bump'], + temperatures=data['temperature'], vibrations=data['vibration'], + maximum_relative_error=maximum_relative_error) + if changed and not dry_run: + if calibration_group is None: + calibration_group = _h5_create_group(group, 'calibration') + save_results( + group=calibration_group, + spring_constant=k, spring_constant_deviation=k_s) finally: if f: f.close() -- 2.26.2