From 8f6bf16ae1306bcf96aed0678b4847a21feeca31 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 20 Apr 2012 14:17:30 -0400 Subject: [PATCH] Further fixups to get calibcant-analyze.py working. --- calibcant/analyze.py | 31 ++++++++++++++++++++++++++----- calibcant/calibrate.py | 20 +++----------------- calibcant/util.py | 13 +++++-------- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/calibcant/analyze.py b/calibcant/analyze.py index b6807f8..ab3fbbb 100644 --- a/calibcant/analyze.py +++ b/calibcant/analyze.py @@ -95,6 +95,8 @@ from .temperature_analyze import analyze as _temperature_analyze from .temperature_analyze import save as _temperature_save from .vibration_analyze import analyze as _vibration_analyze from .vibration_analyze import save as _vibration_save +from .util import SaveSpec as _SaveSpec +from .util import save as _save def analyze(bumps, temperatures, vibrations): @@ -189,6 +191,20 @@ def plot(bumps, temperatures, vibrations): return figure _plot = plot # alternative name for use inside analyze_all() +def save_results(filename=None, group='/', bump=None, + temperature=None, vibration=None, spring_constant=None, + spring_constant_deviation=None): + specs = [ + _SaveSpec(item=bump, relpath='raw/photodiode-sensitivity', + array=True, units='V/m'), + _SaveSpec(item=temperature, relpath='raw/temperature', + array=True, units='K'), + _SaveSpec(item=vibration, relpath='raw/vibration', + array=True, units='V^2/Hz'), + _SaveSpec(item=spring_constant, relpath='processed/spring-constant', + units='N/m', deviation=spring_constant_deviation), + ] + _save(filename=filename, group=group, specs=specs) def analyze_all(config, data, raw_data, maximum_relative_error=1e-5, filename=None, group=None, plot=False, dry_run=False): @@ -260,15 +276,18 @@ def analyze_all(config, data, raw_data, maximum_relative_error=1e-5, vibrations_changed) and not dry_run: calibration_group = _h5_create_group(group, 'calibration') if bumps_changed: - calib_save(group=calibration_group, bump=data['bump']) + save_results( + group=calibration_group, bump=data['bump']) if temperatures_changed: - calib_save( + save_results( group=calibration_group, temperature=data['temperature']) if vibrations_changed: - calib_save( + save_results( group=calibration_group, vibration=data['vibration']) if changed: - calib_save(group=calibration_group, k=k, k_s=k_s) + save_results( + group=calibration_group, + spring_constant=k, spring_constant_deviation=k_s) finally: if f: f.close() @@ -342,6 +361,7 @@ def check_calibration(k, k_s, maximum_relative_error, **kwargs): else: rel_error = abs(new_k-k)/k if rel_error > maximum_relative_error: + changed = True _LOG.warn(("new analysis doesn't match for the spring constant: " "{} != {} (difference: {}, relative error: {})").format( new_k, k, new_k-k, rel_error)) @@ -350,8 +370,9 @@ def check_calibration(k, k_s, maximum_relative_error, **kwargs): _LOG.warn('new analysis for the spring constant deviation: {}'.format( new_k_s)) else: - rel_error = abs(new_k-k)/k + rel_error = abs(new_k_s-k_s)/k_s if rel_error > maximum_relative_error: + changed = True _LOG.warn( ("new analysis doesn't match for the spring constant deviation" ": {} != {} (difference: {}, relative error: {})").format( diff --git a/calibcant/calibrate.py b/calibcant/calibrate.py index 8a68cbe..964ee24 100644 --- a/calibcant/calibrate.py +++ b/calibcant/calibrate.py @@ -96,8 +96,8 @@ from .temperature_analyze import load as _temperature_load from .vibration import run as _vibration from .vibration_analyze import load as _vibration_load from .analyze import analyze as _analyze +from .analyze import save_results as _save_results from .util import SaveSpec as _SaveSpec -from .util import save as _save from .util import load as _load @@ -556,22 +556,6 @@ class Calibrator (object): storage = _HDF5_Storage(filename=filename, group=group) storage.save(config=self.config) - @staticmethod - def save_results(filename=None, group='/', bump=None, - temperature=None, vibration=None, spring_constant=None, - spring_constant_deviation=None): - specs = [ - _SaveSpec(item=bump, relpath='raw/photodiode-sensitivity', - array=True, units='V/m'), - _SaveSpec(item=temperature, relpath='raw/temperature', - array=True, units='K'), - _SaveSpec(item=vibration, relpath='raw/vibration', - array=True, units='V^2/Hz'), - _SaveSpec(item=spring_constant, relpath='processed/spring-constant', - units='N/m', deviation=spring_constant_deviation), - ] - _save(filename=filename, group=group, specs=specs) - @staticmethod def load_results(filename, group='/'): """Load results saved with `.save_results()`.""" @@ -609,3 +593,5 @@ class Calibrator (object): else: data[name].append(loader(group=cwg)) return data + +Calibrator.save_results = _save_results diff --git a/calibcant/util.py b/calibcant/util.py index 8d24a35..8f4c439 100644 --- a/calibcant/util.py +++ b/calibcant/util.py @@ -41,14 +41,11 @@ def save(filename=None, group='/', specs=tuple()): storage.save(config=spec.item, group=cwg) continue assert spec.units, spec.item - try: - del cwg['data'] - except KeyError: - pass - try: - del cwg['units'] - except KeyError: - pass + for k in ['data', 'units', 'standard-deviation']: + try: + del cwg[k] + except KeyError: + pass cwg['data'] = spec.item cwg['units'] = spec.units if spec.deviation is not None: -- 2.26.2