Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improvements to ImageStack #5961

Merged
merged 15 commits into from
Nov 4, 2023
Merged

Fix and improvements to ImageStack #5961

merged 15 commits into from
Nov 4, 2023

Conversation

hoxbro
Copy link
Member

@hoxbro hoxbro commented Oct 26, 2023

Fixes #5959 and fixes #5960


TODO:

  • Think about the transpose problem The main problem is that a 2D Numpy array shape is defined as (y, x), not (x, y)
  • Add tests
  • Improve the docstring of hv.ImageStack

import holoviews as hv
import numpy as np
import panel as pn
import xarray as xr


hv.extension("bokeh")


p0 = hv.ImageStack(
    (np.arange(10), np.arange(15), np.arange(150).reshape(10, 15, 1))
).opts(num_colors=150, width=500)


p1 = hv.ImageStack(
    (np.arange(20, 30), np.arange(10, 20), np.arange(100).reshape(10, 10, 1))
).opts(num_colors=100, width=500)


p2 = hv.ImageStack(np.arange(100).reshape(10, 10, 1)).opts(num_colors=100, width=500)


da = xr.DataArray(coords={"x": np.arange(10), "y": np.arange(15)}, dims=["x", "y"])

da_1 = da.copy()
da_1.name = "a"
da_1.values = np.arange(150).reshape(10, 15)

ds = xr.merge([da_1])

p3 = hv.ImageStack(ds).opts(
    num_colors=140,
    width=500,
)

p = (p0 + p1 + p2 + p3).opts(shared_axes=False)

pn.panel(p).servable()

image

@hoxbro hoxbro marked this pull request as draft October 26, 2023 07:31
@codecov-commenter
Copy link

codecov-commenter commented Oct 26, 2023

Codecov Report

Merging #5961 (93dce3a) into main (3adb998) will decrease coverage by 0.03%.
The diff coverage is 98.48%.

@@            Coverage Diff             @@
##             main    #5961      +/-   ##
==========================================
- Coverage   88.58%   88.55%   -0.03%     
==========================================
  Files         315      315              
  Lines       65500    65545      +45     
==========================================
+ Hits        58020    58046      +26     
- Misses       7480     7499      +19     
Flag Coverage Δ
ui-tests 23.13% <4.54%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
holoviews/tests/plotting/bokeh/test_rasterplot.py 98.82% <100.00%> (+0.12%) ⬆️
holoviews/element/raster.py 80.30% <95.23%> (+0.30%) ⬆️

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@hoxbro
Copy link
Member Author

hoxbro commented Oct 26, 2023

Added conversion of different inputs:

import holoviews as hv
import numpy as np

hv.extension("bokeh")

np.random.seed(42)
data = np.random.random((10, 15, 3))

p0 = hv.ImageStack(data)
p1 = hv.ImageStack([data[:, :, i] for i in range(3)])
p2 = hv.ImageStack({str(i): data[:, :, i] for i in range(3)})
p0 + p1 + p2

image

@hoxbro
Copy link
Member Author

hoxbro commented Oct 26, 2023

I'm not sure about the transposing, needs to think more about it.

With the following code:

import xarray as xr
import holoviews as hv
import numpy as np

hv.extension("bokeh")
x = np.arange(0, 3)
y = np.arange(5, 8)
a = np.array([[np.nan, np.nan, 1], [np.nan] * 3, [np.nan] * 3])
b = np.array([[np.nan] * 3, [1, 1, np.nan], [np.nan] * 3])
c = np.array([[np.nan] * 3, [np.nan] * 3, [1, 1, 1]])

ds = (x, y, a, b, c)
im_tuple = hv.ImageStack(ds).opts(title="Tuple")

ds = {"x": x, "y": y, "a": a, "b": b, "c": c}
im_dict = hv.ImageStack(ds).opts(title="Dict")

ds = xr.Dataset(
    {"a": (["x", "y"], a), "b": (["x", "y"], b), "c": (["x", "y"], c)},
    coords={"x": x, "y": y},
)
im_xr = hv.ImageStack(ds).opts(title="xarray")

im_tuple + im_dict + im_xr

I get this on the current branch:
image

And this on main:
image

@hoxbro
Copy link
Member Author

hoxbro commented Oct 26, 2023

This work on the current branch but not on main:

import xarray as xr
import holoviews as hv
import numpy as np

hv.extension("bokeh")
x = np.arange(0, 3)
y = np.arange(5, 9)
a = np.array([[np.nan, np.nan, 1, np.nan], [np.nan] * 4, [np.nan] * 4])
b = np.array([[np.nan] * 4, [1, 1, np.nan, np.nan], [np.nan] * 4])
c = np.array([[np.nan] * 4, [np.nan] * 4, [1, 1, 1, np.nan]])

ds = {"x": x, "y": y, "a": a, "b": b, "c": c}
im_dict = hv.ImageStack(ds).opts(title="Dict")

ds = xr.Dataset(
    {"a": (["x", "y"], a), "b": (["x", "y"], b), "c": (["x", "y"], c)},
    coords={"x": x, "y": y},
)
im_xr = hv.ImageStack(ds).opts(title="xarray")

im_dict + im_xr

image

@hoxbro hoxbro added this to the 1.18.1 milestone Oct 26, 2023
@hoxbro hoxbro marked this pull request as ready for review November 3, 2023 11:40
@philippjfr philippjfr merged commit 6c9f359 into main Nov 4, 2023
10 checks passed
@philippjfr philippjfr deleted the fix_imagestack branch November 4, 2023 14:46
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImageStack docstring is wrong ImageStack doesn't allow non-square data
3 participants