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

Add support for ImageStack #693

Merged
merged 10 commits into from
Jan 22, 2024
Merged

Add support for ImageStack #693

merged 10 commits into from
Jan 22, 2024

Conversation

ahuang11
Copy link
Collaborator

@ahuang11 ahuang11 commented Jan 4, 2024

Closes #691

import numpy as np
import geoviews as gv
import holoviews as hv
import cartopy.crs as ccrs

hv.extension("bokeh")

x = np.arange(-120, -117)
y = np.arange(40, 43)
a = np.array([[np.nan, np.nan, 1], [np.nan, np.nan, 1], [np.nan] * 3])
b = np.array([[np.nan] * 3, [1, 1, 1], [np.nan] * 3])

img_stack = gv.ImageStack(
    (x, y, a, b), kdims=["x", "y"], vdims=["a", "b"], crs=ccrs.PlateCarree()
).opts(cmap=["red", "blue"])

gv.feature.coastline() * img_stack
image

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Jan 4, 2024

Weird thing is in MPL, the data is flipped vertically:

import numpy as np
import geoviews as gv
import holoviews as hv
import cartopy.crs as ccrs

hv.extension("matplotlib")

x = np.arange(-120, -117)
y = np.arange(40, 43)
a = np.array([[np.nan, np.nan, 1], [np.nan, np.nan, 1], [np.nan] * 3])
b = np.array([[np.nan] * 3, [1, 1, 1], [np.nan] * 3])

img_stack = gv.ImageStack(
    (x, y, a, b), kdims=["x", "y"], vdims=["a", "b"], crs=ccrs.PlateCarree()
).opts(cmap=["red", "blue"], xlim=(-122.2, -110), ylim=(39, 42))

gv.feature.coastline() * img_stack
image

Seems to be only an issue in ImageStack, gv.Image looks fine:
image

hv.ImageStack also looks fine.
image

Comment on lines 294 to 305
def __init__(self, element, **params):
super().__init__(element, **params)

def get_data(self, element, ranges, style):
self._norm_kwargs(element, ranges, style, element.vdims[0])
style.pop('interpolation', None)
xs, ys, zs = geo_mesh(element)
xs = GridInterface._infer_interval_breaks(xs)
ys = GridInterface._infer_interval_breaks(ys)
if self.geographic:
style['transform'] = element.crs
return (xs, ys, zs), style, {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why MPL ImageStack is not going through this code; if I add print/raise, it doesn't do anything.

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Jan 4, 2024

I am so stumped on how this works:

import numpy as np
import geoviews as gv
import cartopy.crs as ccrs
import panel as pn

gv.extension("matplotlib")

x = np.arange(-120, -117)
y = np.arange(40, 43)
a = np.array([[np.nan, np.nan, 1], [np.nan, np.nan, 1], [np.nan] * 3])
b = np.array([[np.nan] * 3, [1, 1, 1], [np.nan] * 3])

img_stack = gv.ImageStack(
    (x, y, a, b), kdims=["x", "y"], vdims=["a", "b"], crs=ccrs.PlateCarree()
)

img_stack

when I have raise sprinkled all across its methods.

@ahuang11 ahuang11 requested a review from hoxbro January 4, 2024 00:48
Copy link
Member

@hoxbro hoxbro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test if this works with non-equal lengths of x and y?

geoviews/element/geo.py Outdated Show resolved Hide resolved
@ahuang11
Copy link
Collaborator Author

ahuang11 commented Jan 16, 2024

Can you test if this works with non-equal lengths of x and y?

Like this?

import numpy as np
import geoviews as gv
import holoviews as hv
import cartopy.crs as ccrs

hv.extension("bokeh")

x = np.arange(-120, -115)
y = np.arange(40, 43)
a = np.random.rand(len(y), len(x))
b = np.random.rand(len(y), len(x))

img_stack = gv.ImageStack(
    (x, y, a, b), kdims=["x", "y"], vdims=["a", "b"], crs=ccrs.PlateCarree()
).opts(cmap=["red", "blue"], xlim=(-122.2, -110), ylim=(39, 42))

gv.feature.coastline() * img_stack
image

geoviews/element/geo.py Outdated Show resolved Hide resolved
geoviews/element/geo.py Outdated Show resolved Hide resolved
geoviews/tests/plotting/mpl/test_chart.py Show resolved Hide resolved
geoviews/plotting/bokeh/__init__.py Outdated Show resolved Hide resolved
geoviews/plotting/mpl/__init__.py Show resolved Hide resolved
@hoxbro hoxbro enabled auto-merge (squash) January 22, 2024 19:36
@hoxbro hoxbro merged commit e2bf963 into main Jan 22, 2024
9 checks passed
@hoxbro hoxbro deleted the image_stack branch January 22, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support projecting ImageStacks in geoviews
2 participants