holoviz / geoviews

Simple, concise geographical visualization in Python
http://geoviews.org
BSD 3-Clause "New" or "Revised" License
578 stars 75 forks source link

link_selections selection_expr incorrect when using Orthographic projection #477

Open WesleyTheGeolien opened 3 years ago

WesleyTheGeolien commented 3 years ago

ALL software version info

geoviews: 1.8.1 holoviews: 1.13.4 bokeh: 2.2.3 cartopy: 0.18.0 python: 3.8.5

Description of expected behavior and the observed behavior

When using holoviews.selection.link_selections on an Orthographic plot (we are particularly interested in plots around the poles but realise this is more complicated) the selection_expr appears to be incorrect, this means that any selection carried out on the map will not carry across to the other plots.

This functionality works when using PlateCarree projections for example.

Complete, minimal, self-contained example code that reproduces the issue

import xarray as xr
import geoviews as gv
from holoviews.selection import link_selections
from cartopy import crs

# Load in a dataset anything will do
ds = xr.open_dataset('TopoBathyc38.nc')

# Convert dataset to geoviews dataset
dataset = gv.Dataset(ds)

# Create the maps
# Plate carree works
# Orthographic
fig_plate_carree = dataset.to(gv.Image, ['longitude', 'latitude'], 'Z').opts(projection=crs.PlateCarree())
fig_ortho = dataset.to(gv.Image, ['longitude', 'latitude'], 'Z').opts(projection=crs.Orthographic())

# This selection will work as expected
selection_working = link_selections.instance()
selection_working(fig_plate_carree  + ds.hvplot.hist())

# This will not work
selection_not_working = link_selections.instance()
selection_not_working(fig_ortho  + ds.hvplot.hist())

Screenshots or screencasts of the bug in action

Not working cf. selection_expr image

Working: image

WesleyTheGeolien commented 3 years ago

This also seems to occur with:

jbednar commented 3 years ago

For debugging purposes, does a geographic selection made on plots where such projection is working apply correctly to one of these other projections? I.e. if you put a Plate Carree projection next to an Orthographic projection and select on Plate Caree, does that work at least? (Especially if crossing a zero-longitude boundary, where I think some issues remain in general.)

WesleyTheGeolien commented 3 years ago

It doesn't appear so, see code and screenshot below.

I am guessing because they are both using the same variable name holoviz is trying to do some trickery to get them both to line up correctly. Notice the grid coordinates on the Plate Carre have extents from -6e6 to 6e6 for longitude instead of -180 to 180.

import xarray as xr
import geoviews as gv
from holoviews.selection import link_selections
from cartopy import crs

# Load in a dataset anything will do
ds = xr.open_dataset('/home/wesley/Documents/CEREGE/Data/TopoBathyc38.nc')

# Convert dataset to geoviews dataset
dataset = gv.Dataset(ds, crs = crs.PlateCarree())

# Create the maps
# Plate carree works
# Orthographic
fig_plate_carree = dataset.to(gv.Image, ['longitude', 'latitude'], 'Z').opts(projection=crs.PlateCarree(), width=500)
fig_ortho = dataset.to(gv.Image, ['longitude', 'latitude'], 'Z').opts(projection=crs.Orthographic())

selection = link_selections.instance()
selection(fig_ortho + fig_plate_carree)

image

Zooming in massively show the data on the plate carree is there notice how the orthographic is zoomed in as well.

image

Finally selection Northern Africa on Plate Carree correctly selects Northern Africa on the orthographic projection.

image

image

jlstevens commented 3 years ago

Given that linked selections is a really cool new feature we want to promote, I hope we can fix this ASAP (and I'll assign this issue to the next milestone).