Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Dec 8, 2018
1 parent 039d0bc commit e448709
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
8 changes: 4 additions & 4 deletions glue/viewers/image/composite_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions glue/viewers/image/python_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions glue/viewers/image/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions glue/viewers/matplotlib/qt/tests/test_python_export.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import absolute_import, division, print_function

import os
import sys
import pytest
import subprocess

import numpy as np

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e448709

Please sign in to comment.