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

geo=True and rasterize=True makes the plot disappear #673

Closed
ahuang11 opened this issue Sep 18, 2023 · 15 comments · Fixed by #722
Closed

geo=True and rasterize=True makes the plot disappear #673

ahuang11 opened this issue Sep 18, 2023 · 15 comments · Fixed by #722

Comments

@ahuang11
Copy link
Collaborator

ahuang11 commented Sep 18, 2023

import xarray as xr
import panel as pn
import holoviews as hv
from holoviews.operation.datashader import rasterize
import geoviews as gv
import cartopy.crs as ccrs

hv.renderer("bokeh").webgl = False
import hvplot.xarray
ds = xr.tutorial.open_dataset("air_temperature").isel(time=0)

rasterize((gv.Image(ds, ["lon", "lat"], ["air"]))) * gv.feature.coastline()

image

Data disappears on zoom.

@hoxbro
Copy link
Member

hoxbro commented Sep 18, 2023

It is again coming from changes made in holoviz/hvplot#1053

Edit: I was wrong

@ahuang11
Copy link
Collaborator Author

Nice! git bisect again?

@hoxbro
Copy link
Member

hoxbro commented Sep 18, 2023

I was too quick; does not seem to be an hvplot as I can recreate it with:

import xarray as xr
import geoviews as gv
import numpy as np
from holoviews.operation.datashader import rasterize

gv.extension("bokeh")

data = xr.DataArray(
    np.random.random((100, 50)),
    coords=dict(lon=np.arange(200, 300), lat=np.arange(25, 75)),
)

rasterize(gv.Image(data), width=10, height=10)

@hoxbro
Copy link
Member

hoxbro commented Sep 18, 2023

Tried going back in time, and it does not seem to be a recent regression, as no one of the following works:

❯ conda list "python|holoviews|geoviews|bokeh"
# packages in environment at /home/shh/miniconda3/envs/geo_bug:
#
# Name                    Version                   Build  Channel
bokeh                     2.4.3              pyhd8ed1ab_3    conda-forge
brotli-python             1.1.0            py38h17151c0_0    conda-forge
geoviews                  1.9.3              pyhd8ed1ab_0    conda-forge
geoviews-core             1.9.3              pyha770c72_0    conda-forge
holoviews                 1.14.5             pyhd8ed1ab_0    conda-forge
python                    3.8.17          he550d4f_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-tzdata             2023.3             pyhd8ed1ab_0    conda-forge
python_abi                3.8                      3_cp38    conda-forge
# packages in environment at /home/shh/miniconda3/envs/geo_bug:
#
# Name                    Version                   Build  Channel
bokeh                     2.2.3            py38h578d9bd_0    conda-forge
brotli-python             1.1.0            py38h17151c0_0    conda-forge
geoviews                  1.8.2                      py_0    conda-forge
geoviews-core             1.8.2                      py_0    conda-forge
holoviews                 1.14.5             pyhd8ed1ab_0    conda-forge
python                    3.8.17          he550d4f_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-tzdata             2023.3             pyhd8ed1ab_0    conda-forge
python_abi                3.8                      3_cp38    conda-forge

Will move it to GeoViews for now.

@hoxbro hoxbro transferred this issue from holoviz/hvplot Sep 18, 2023
@ahuang11
Copy link
Collaborator Author

What about including datashader?

@hoxbro
Copy link
Member

hoxbro commented Sep 18, 2023

I used Datashader 1.15.2.

I did not expect Datashader to be a problem as it doesn't have any knowledge of geo-related information, and just get coordinates and data passed through it.

Did a test with 0.14.4, which reproduced the same results.

@ahuang11
Copy link
Collaborator Author

I'm quite surprised that no one has commented about this yet besides me haha. I should probably dive deeper into this soon...

@itsgifnotjiff
Copy link

I believe i had posted something about it a year or two ago but no one was interested so I deleted the post :) glad to see it ressurface.

@ahuang11
Copy link
Collaborator Author

Workaround seems to work

import xarray as xr
import panel as pn
import holoviews as hv
from holoviews.operation.datashader import rasterize
import geoviews as gv
import cartopy.crs as ccrs

hv.renderer("bokeh").webgl = False
import hvplot.xarray
ds = xr.tutorial.open_dataset("air_temperature").isel(time=0)
# pn.serve(ds.hvplot("lon", "lat", rasterize=True, crs=ccrs.PlateCarree(), projection=ccrs.PlateCarree()))

pn.serve(rasterize(gv.project(gv.Image(ds, ["lon", "lat"], ["air"]))))

@ahuang11
Copy link
Collaborator Author

There are two separate issues here.

  1. Bounciness with aspect(?) seen in hvplot:
ds.hvplot("lon", "lat", geo=True, rasterize=True, coastline=True, project=True)
Screen.Recording.2024-04-11.at.3.42.38.PM.mov

No problem in geoviews

import xarray as xr
import panel as pn
import holoviews as hv
from holoviews.operation.datashader import rasterize
import geoviews as gv
import cartopy.crs as ccrs

hv.renderer("bokeh").webgl = False
import hvplot.xarray
ds = xr.tutorial.open_dataset("air_temperature").isel(time=0)

rasterize(gv.project(gv.Image(ds, ["lon", "lat"], ["air"]))) * gv.feature.coastline()
Screen.Recording.2024-04-11.at.3.43.28.PM.mov
  1. If project=True isn't set, the data disappears on zoom
import xarray as xr
import panel as pn
import holoviews as hv
from holoviews.operation.datashader import rasterize
import geoviews as gv
import cartopy.crs as ccrs

hv.renderer("bokeh").webgl = False
import hvplot.xarray
ds = xr.tutorial.open_dataset("air_temperature").isel(time=0)

rasterize((gv.Image(ds, ["lon", "lat"], ["air"]))) * gv.feature.coastline()
image

@ahuang11
Copy link
Collaborator Author

x0 == x1 here for some reason after zooming


    def _process(self, img, key=None):
        from cartopy.img_transform import warp_array

        if self.p.fast:
            return self._fast_process(img, key)

        proj = self.p.projection
        x0, x1 = img.range(0, dimension_range=False)
        y0, y1 = img.range(1, dimension_range=False)
        yn, xn = img.interface.shape(img, gridded=True)[:2]
        (px0, py0, px1, py1) = project_extents((x0, y0, x1, y1), img.crs, proj)

@ahuang11
Copy link
Collaborator Author

Aha, I think it's an issue with 0 to 360 vs -180 to 180

import xarray as xr
import panel as pn
import holoviews as hv
from holoviews.operation.datashader import rasterize
import geoviews as gv
import cartopy.crs as ccrs

hv.renderer("bokeh").webgl = False
import hvplot.xarray
ds = xr.tutorial.open_dataset("air_temperature").isel(time=0)
# 0-360 to -180-180
ds["lon"] = (ds["lon"] + 180) % 360 - 180

rasterize((gv.Image(ds, ["lon", "lat"], ["air"]))) * gv.feature.coastline()

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Apr 11, 2024

Something happening here:
image

image image

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Apr 11, 2024

https://github.com/holoviz/holoviews/blame/main/holoviews/operation/resample.py#L142

I think it comes down to: x0, x1 is ranged from -180 to 180, while ex0 is ex1 is ranged from 0 to 360, so when the following computed, it gives x_range=(198.75, 198.75)

import numpy as np
 
 
x0, x1, ex0, ex1 = -154.39239111669974, -33.72522063810877, 198.75, 331.25


x_range = (np.nanmin([np.nanmax([x0, ex0]), ex1]),
            np.nanmax([np.nanmin([x1, ex1]), ex0]))
x_range
image

@ahuang11
Copy link
Collaborator Author

This original issue was an hvplot issue. Renaming this issue for the geoviews issue. holoviz/hvplot#1105

@ahuang11 ahuang11 changed the title geo=True and rasterize=True makes the plot bounce around when zooming geo=True and rasterize=True makes the plot disappear Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants