diff --git a/glue/viewers/image/composite_array.py b/glue/viewers/image/composite_array.py index 131b45fc2..98cc9f6b2 100644 --- a/glue/viewers/image/composite_array.py +++ b/glue/viewers/image/composite_array.py @@ -91,10 +91,10 @@ def get_array(self, bounds): interval = ManualInterval(*layer['clim']) contrast_bias = ContrastBiasStretch(layer['contrast'], layer['bias']) - # if callable(layer['array']): - array = layer['array'](bounds=bounds) - # else: - # array = layer['array'] + if callable(layer['array']): + array = layer['array'](bounds=bounds) + else: + array = layer['array'] if array is None: continue diff --git a/glue/viewers/image/python_export.py b/glue/viewers/image/python_export.py index d9f4c4a6b..b1a2ac39f 100644 --- a/glue/viewers/image/python_export.py +++ b/glue/viewers/image/python_export.py @@ -15,8 +15,14 @@ def python_export_image_layer(layer, *args): # TODO: implement aggregation, ignore for now - script += "# Get main data values\n" - script += "image = layer_data['{0}', {1}]".format(layer.state.attribute, tuple(slices)) + # TODO: need to simplify this! + script += "# Define a function that will get a fixed resolution buffer\n" + + script += "def array_maker(bounds):\n full_bounds={0}\n".format(list(slices)) + script += " full_bounds[{0}] = bounds[0]\n".format(layer._viewer_state.y_att.axis) + script += " full_bounds[{0}] = bounds[1]\n".format(layer._viewer_state.x_att.axis) + script += " data = layer_data.data if hasattr(layer_data, 'to_mask') else layer_data\n" + script += " return data.get_fixed_resolution_buffer(target_cid=data.id['{0}'], bounds=full_bounds)\n\n".format(layer.state.attribute) if transpose: script += ".transpose()" @@ -30,7 +36,7 @@ def python_export_image_layer(layer, *args): else: color = layer.state.color - options = dict(array=code('image'), + options = dict(array=code('array_maker'), clim=(layer.state.v_min, layer.state.v_max), visible=layer.state.visible, zorder=layer.state.zorder, diff --git a/glue/viewers/image/state.py b/glue/viewers/image/state.py index da548ef71..1b9823acd 100644 --- a/glue/viewers/image/state.py +++ b/glue/viewers/image/state.py @@ -396,15 +396,15 @@ def slice_to_bound(slc, size): full_view[x_axis] = view[1] full_view[y_axis] = view[0] - for i in range(self.viewer_state.reference_data.ndim): - if isinstance(full_view[i], slice): - full_view[i] = slice_to_bound(full_view[i], self.viewer_state.reference_data.shape[i]) - else: full_view[x_axis] = bounds[1] full_view[y_axis] = bounds[0] + for i in range(self.viewer_state.reference_data.ndim): + if isinstance(full_view[i], slice): + full_view[i] = slice_to_bound(full_view[i], self.viewer_state.reference_data.shape[i]) + # We now get the fixed resolution buffer if isinstance(self.layer, BaseData): diff --git a/glue/viewers/matplotlib/qt/tests/test_python_export.py b/glue/viewers/matplotlib/qt/tests/test_python_export.py index d767aefe4..3317b362f 100644 --- a/glue/viewers/matplotlib/qt/tests/test_python_export.py +++ b/glue/viewers/matplotlib/qt/tests/test_python_export.py @@ -1,7 +1,9 @@ from __future__ import absolute_import, division, print_function import os +import sys import pytest +import subprocess import numpy as np @@ -29,8 +31,7 @@ def assert_same(self, tmpdir, tol=0.1): self.viewer.axes.figure.savefig(expected) self.viewer.export_as_script(script) - with open(script) as f: - exec(f.read()) + subprocess.call([sys.executable, script]) msg = compare_images(expected, actual, tol=tol)