From: W. Trevor King Date: Wed, 8 Sep 2010 17:35:23 +0000 (-0400) Subject: Add support for raster and constant data to JPK driver. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=150994731a725cb117b19cf136c621008daa91ca;p=hooke.git Add support for raster and constant data to JPK driver. --- diff --git a/hooke/driver/jpk.py b/hooke/driver/jpk.py index 948d75a..dcc1040 100644 --- a/hooke/driver/jpk.py +++ b/hooke/driver/jpk.py @@ -127,6 +127,8 @@ class JPKDriver (Driver): return self._zip_scale_segment(d, path, info) def _zip_channel(self, zipfile, segment_index, channel_name, chan_info): + if chan_info['data']['type'] in ['constant-data', 'raster-data']: + return self._zip_calculate_channel(chan_info) with Closing(zipfile.open(os.path.join( 'segments', str(segment_index), chan_info['data']['file']['name']), 'r')) as f: @@ -138,6 +140,24 @@ class JPKDriver (Driver): dtype=dtype,) return data + def _zip_calculate_channel(self, chan_info): + type_ = chan_info['data']['type'] + n = int(chan_info['data']['num-points']) + if type_ == 'constant-data': + return float(chan_info['data']['value'])*numpy.ones( + shape=(n,), + dtype=numpy.float32) + elif type_ == 'raster-data': + start = float(chan_info['data']['start']) + step = float(chan_info['data']['step']) + return numpy.arange( + start=start, + stop=start + step*(n-0.5), + step=step, + dtype=numpy.float32) + else: + raise ValueError('Unrecognized data format "%s"' % type_) + def _zip_channel_dtype(self, chan_info): type_ = chan_info['data']['type'] if type_ in ['float-data', 'float']: