Skip to content

Commit

Permalink
Fix coordinate ordering of Image returned by _colorize [#792]
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Oct 3, 2019
1 parent fb97f9a commit 1a46786
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions datashader/tests/test_transfer_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import xarray as xr
import PIL
import pytest

from collections import OrderedDict
import datashader.transfer_functions as tf


coords = [np.array([0, 1, 2]), np.array([3, 4, 5])]
coords = OrderedDict([('x_axis', [3, 4, 5]), ('y_axis', [0, 1, 2])])
dims = ['y_axis', 'x_axis']

a = np.arange(10, 19, dtype='i4').reshape((3, 3))
Expand Down Expand Up @@ -111,6 +111,9 @@ def test_shade(attr, span):
img = tf.shade(x, cmap=cmap, how='log', span=span)
sol = solutions['log']
assert img.equals(sol)
# Check dims/coordinates order
assert list(img.coords) == ['x_axis', 'y_axis']
assert list(img.dims) == ['y_axis', 'x_axis']

img = tf.shade(x, cmap=cmap, how='cbrt', span=span)
sol = solutions['cbrt']
Expand Down Expand Up @@ -250,6 +253,9 @@ def test_shade_category():
[4283774890, 3707764991]], dtype='u4')
sol = tf.Image(sol, coords=coords, dims=dims)
assert img.equals(sol)
# Check dims/coordinates order
assert list(img.coords) == ['x_axis', 'y_axis']
assert list(img.dims) == ['y_axis', 'x_axis']

colors = dict(zip('abc', colors))

Expand Down
12 changes: 9 additions & 3 deletions datashader/transfer_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, division, print_function

from collections import Iterator
from collections import Iterator, OrderedDict
from io import BytesIO

import numpy as np
Expand Down Expand Up @@ -288,8 +288,14 @@ def _colorize(agg, color_key, how, min_alpha, name):
a = np.interp(a, [np.nanmin(a), np.nanmax(a)],
[min_alpha, 255], left=0, right=255).astype(np.uint8)
r[mask] = g[mask] = b[mask] = 255
return Image(np.dstack([r, g, b, a]).view(np.uint32).reshape(a.shape),
dims=agg.dims[:-1], coords=list(agg.coords.values())[:-1],
values = np.dstack([r, g, b, a]).view(np.uint32).reshape(a.shape)

return Image(values,
dims=agg.dims[:-1],
coords=OrderedDict([
(agg.dims[1], agg.coords[agg.dims[1]]),
(agg.dims[0], agg.coords[agg.dims[0]]),
]),
name=name)


Expand Down

0 comments on commit 1a46786

Please sign in to comment.