Skip to content

Commit

Permalink
Remove empty histogram bins in eq_hist (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed Jun 17, 2022
1 parent 4cbda49 commit 2557fae
Show file tree
Hide file tree
Showing 32 changed files with 14 additions and 12 deletions.
Binary file modified datashader/tests/data/test_001_antialias_clipped.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_001_antialias_clipped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_001_antialias_normal.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_001_antialias_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_002_antialias_clipped.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_002_antialias_clipped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_002_antialias_normal.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_002_antialias_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_003_antialias_clipped.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_003_antialias_clipped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_003_antialias_normal.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_003_antialias_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_004_antialias_clipped.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_004_antialias_clipped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_004_antialias_normal.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_004_antialias_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_005_antialias_clipped.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_005_antialias_clipped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_005_antialias_normal.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_005_antialias_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_005_noaa_normal.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_005_noaa_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_006_antialias_clipped.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_006_antialias_clipped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_006_antialias_normal.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_006_antialias_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_007_antialias_normal.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_007_antialias_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified datashader/tests/data/test_007_noaa_normal.nc
Binary file not shown.
Binary file modified datashader/tests/data/test_007_noaa_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 8 additions & 11 deletions datashader/tests/test_transfer_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,18 @@ def create_dask_array_np(*args, **kwargs):
coords=coords, dims=dims)
for how, v in solution_lists.items()}

eq_hist_sol = {'a': np.array([[0, 4291543295, 4288846335],
[4286149631, 0, 4283518207],
[4280821503, 4278190335, 0]], dtype='u4'),
'b': np.array([[0, 4291543295, 4288846335],
[4286609919, 0, 4283518207],
[4281281791, 4278190335, 0]], dtype='u4')}
eq_hist_sol['c'] = eq_hist_sol['b']
# Same result obtained regardless of data dtype (u4, f4, f8)
eq_hist_sol = np.array([[0, 4291543295, 4288846335],
[4286149631, 0, 4283518207],
[4280821503, 4278190335, 0]], dtype='u4')

eq_hist_sol_rescale_discrete_levels = {
'a': np.array([[0, 4289306879, 4287070463],
[4284834047, 0, 4282597631],
[4280361215, 4278190335, 0]], dtype='u4'),
'b': np.array([[0, 4291543295, 4288846335],
[4286609919, 0, 4283518207],
[4281281791, 4278190335, 0]], dtype='u4')}
'b': np.array([[0, 4289306879, 4287070207],
[4284834047, 0, 4282597375],
[4280361215, 4278190335, 0]], dtype='u4')}
eq_hist_sol_rescale_discrete_levels['c'] = eq_hist_sol_rescale_discrete_levels['b']


Expand Down Expand Up @@ -167,7 +164,7 @@ def test_shade(agg, attr, span):
# span option not supported with how='eq_hist'
if span is None:
img = tf.shade(x, cmap=cmap, how='eq_hist', rescale_discrete_levels=False)
sol = tf.Image(eq_hist_sol[attr], coords=coords, dims=dims)
sol = tf.Image(eq_hist_sol, coords=coords, dims=dims)
assert_eq_xr(img, sol)

img = tf.shade(x, cmap=cmap, how='eq_hist', rescale_discrete_levels=True)
Expand Down
7 changes: 6 additions & 1 deletion datashader/transfer_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ def eq_hist(data, mask=None, nbins=256*256):
else:
hist, bin_edges = np.histogram(data2, bins=nbins)
bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2
discrete_levels = None
keep_mask = (hist > 0)
discrete_levels = np.count_nonzero(keep_mask)
if discrete_levels != len(hist):
# Remove empty histogram bins.
hist = hist[keep_mask]
bin_centers = bin_centers[keep_mask]
cdf = hist.cumsum()
cdf = cdf / float(cdf[-1])
out = interp(data, bin_centers, cdf).reshape(data.shape)
Expand Down

0 comments on commit 2557fae

Please sign in to comment.