Add support for raster and constant data to JPK driver.
authorW. Trevor King <wking@drexel.edu>
Wed, 8 Sep 2010 17:35:23 +0000 (13:35 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 8 Sep 2010 17:35:23 +0000 (13:35 -0400)
hooke/driver/jpk.py

index 948d75abc556aab463da004d4879add94ef9f70b..dcc10409a4dea2cb1cfd7484bcaf15cee65f820f 100644 (file)
@@ -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']: