From 1ecb3a3a26f5cbd82a5bded3b8b51fca5affec93 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 8 Sep 2010 15:45:20 -0400 Subject: [PATCH] Improve handling of the base calibration slot units in JPK driver. --- hooke/driver/jpk.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/hooke/driver/jpk.py b/hooke/driver/jpk.py index 760d9f1..4e5ab0f 100644 --- a/hooke/driver/jpk.py +++ b/hooke/driver/jpk.py @@ -199,20 +199,24 @@ class JPKDriver (Driver): 'raw info':params, #'time':self._time_from_TODO(raw_info[]), } - force_unit = self._zip_segment_conversion_unit( - chan_info['channel']['vDeflection']['conversion-set']['conversion']['force'], + force_unit = self._zip_unit( + chan_info['channel']['vDeflection']['conversion-set']['conversion']['force']['scaling'], version) assert force_unit == 'N', force_unit force_base = chan_info['channel']['vDeflection']['conversion-set']['conversion']['force']['base-calibration-slot'] assert force_base == 'distance', force_base - dist_unit = self._zip_segment_conversion_unit( - chan_info['channel']['vDeflection']['conversion-set']['conversion']['distance'], + dist_unit = self._zip_unit( + chan_info['channel']['vDeflection']['conversion-set']['conversion']['distance']['scaling'], version) assert dist_unit == 'm', dist_unit distance_base = chan_info['channel']['vDeflection']['conversion-set']['conversion']['distance']['base-calibration-slot'] assert distance_base == 'volts', distance_base - # Assume volts unit is V, but it is not specified in the JPK - # file format. + base_conversion = chan_info['channel']['vDeflection']['conversion-set']['conversions']['base'] + assert base_conversion == distance_base, base_conversion + distance_base_unit = self._zip_unit( + chan_info['channel']['vDeflection']['data'], + version) + assert distance_base_unit == 'V', distance_base_unit force_mult = float( chan_info['channel']['vDeflection']['conversion-set']['conversion']['force']['scaling']['multiplier']) sens_mult = float( @@ -278,12 +282,11 @@ class JPKDriver (Driver): if conversion == None: conversion = conversion_set['conversions']['default'] if conversion == conversion_set['conversions']['base']: - # Our conversion is the base data. - if conversion != 'volts': - raise NotImplementedError( - 'unknown units for base channel: %s' % conversion) segment.info['columns'][channel] = join_data_label( - channel_name, 'V') + channel_name, + self._zip_unit( + segment.info['raw info']['channel'][channel_name]['data'], + version)) return segment conversion_info = conversion_set['conversion'][conversion] if conversion_info['base-calibration-slot'] \ @@ -312,16 +315,16 @@ class JPKDriver (Driver): conversion_info['scaling']['style'] multiplier = float(conversion_info['scaling']['multiplier']) offset = float(conversion_info['scaling']['offset']) - unit = self._zip_segment_conversion_unit(conversion_info, version) + unit = self._zip_unit(conversion_info['scaling'], version) segment[:,channel] = segment[:,channel] * multiplier + offset segment.info['columns'][channel] = join_data_label(channel_name, unit) return segment - def _zip_segment_conversion_unit(self, conversion_info, version): + def _zip_unit(self, conversion_info, version): if version in ['0.%d' % i for i in range(3)]: - return conversion_info['scaling']['unit'] + return conversion_info['unit'] else: - return conversion_info['scaling']['unit']['unit'] + return conversion_info['unit']['unit'] def _parse_params(self, lines): info = {} -- 2.26.2