From: W. Trevor King Date: Fri, 20 Aug 2010 08:59:05 +0000 (-0400) Subject: Convert all channels to their default calibration in the JPK driver. X-Git-Url: http://git.tremily.us/?p=hooke.git;a=commitdiff_plain;h=53c9d7c2d07fba5c70955c80631e6c485f02de5d Convert all channels to their default calibration in the JPK driver. The previous implementation only scaled height and vDeflection, which meant that the other unscaled (and therefore unitless) columns broke distance formatting commands (e.g. 'point info'). --- diff --git a/hooke/driver/jpk.py b/hooke/driver/jpk.py index 1330713..9ba649c 100644 --- a/hooke/driver/jpk.py +++ b/hooke/driver/jpk.py @@ -29,6 +29,7 @@ import numpy from .. import curve as curve from .. import experiment as experiment from ..util.util import Closing as Closing +from ..util.si import join_data_label, split_data_label from . import Driver as Driver @@ -190,35 +191,45 @@ class JPKDriver (Driver): # raw column indices channels = segment.info['raw info']['channels']['list'] - z_col = channels.index('height') - d_col = channels.index('vDeflection') - - segment = self._zip_scale_channel( - segment, z_col, 'calibrated', path, info) - segment = self._zip_scale_channel( - segment, d_col, 'distance', path, info) - - assert segment.info['columns'][z_col] == 'height (m)', \ - segment.info['columns'][z_col] - assert segment.info['columns'][d_col] == 'vDeflection (m)', \ - segment.info['columns'][d_col] - - # scaled column indices same as raw column indices, - # because columns is a copy of channels.list - segment.info['columns'][z_col] = 'z piezo (m)' - segment.info['columns'][d_col] = 'deflection (m)' + for i,channel in enumerate(channels): + conversion = None + if channel == 'vDeflection': + conversion = 'distance' + segment = self._zip_scale_channel( + segment, channel, conversion=conversion, path=path, info=info) + name,unit = split_data_label(segment.info['columns'][i]) + if name == 'vDeflection': + assert unit == 'm', segment.info['columns'][i] + segment.info['columns'][i] = join_data_label('deflection', 'm') + elif name == 'height': + assert unit == 'm', segment.info['columns'][i] + segment.info['columns'][i] = join_data_label('z piezo', 'm') return segment - def _zip_scale_channel(self, segment, channel, conversion, path, info): - channel_name = segment.info['raw info']['channels']['list'][channel] + def _zip_scale_channel(self, segment, channel_name, conversion=None, + path=None, info={}): + channel = segment.info['raw info']['channels']['list'].index( + channel_name) conversion_set = segment.info['raw info']['channel'][channel_name]['conversion-set'] + 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') + return segment conversion_info = conversion_set['conversion'][conversion] + print channel_name, conversion_info.keys() if conversion_info['base-calibration-slot'] \ != conversion_set['conversions']['base']: # Our conversion is stacked on a previous conversion. Do # the previous conversion first. segment = self._zip_scale_channel( - segment, channel, conversion_info['base-calibration-slot'], + segment, channel_name, + conversion_info['base-calibration-slot'], path=path, info=info) if conversion_info['type'] == 'file': # Michael Haggerty at JPK points out that the conversion @@ -240,7 +251,7 @@ class JPKDriver (Driver): offset = float(conversion_info['scaling']['offset']) unit = conversion_info['scaling']['unit']['unit'] segment[:,channel] = segment[:,channel] * multiplier + offset - segment.info['columns'][channel] = '%s (%s)' % (channel_name, unit) + segment.info['columns'][channel] = join_data_label(channel_name, unit) return segment def _parse_params(self, lines):