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

Projection sometimes required in .opts #366

Closed
kcpevey opened this issue Oct 15, 2019 · 14 comments
Closed

Projection sometimes required in .opts #366

kcpevey opened this issue Oct 15, 2019 · 14 comments

Comments

@kcpevey
Copy link

kcpevey commented Oct 15, 2019

I have a local jupyter lab instance where this code works just fine:

import geoviews as gv
import cartopy.crs as ccrs
gv.extension('bokeh')

poly = [
    (-95.777304976205, 29.70081935868131),
    (-95.777131944776, 29.70009523405696),
    (-95.780067725666, 29.69971579007273),
    (-95.780184253531, 29.70061729352786),
    (-95.778716019600, 29.70071746836681),
    (-95.777304976205, 29.70081935868131)
]
gv.Polygons([poly], crs=ccrs.PlateCarree())

Then I have a JupyterHub instance with the same holoviz packages, but the above code produces a warning about the projection being wrong and results in an empty plot.
While projecting a Polygons element from a PlateCarree coordinate reference system (crs) to a Mercator projection none of the projected paths were contained within the bounds specified by the projection.

If I add the projection to .opts, e.g.:
gv.Polygons([poly], crs=ccrs.PlateCarree()).opts(projection=ccrs.PlateCarree())
it will work properly on JHub. Any idea why the extra projection specification is required for my JHub instance?

geoviews=1.6.4 from conda-forge

@philippjfr
Copy link
Member

Nothing to do with jupyter at all. This is the documented and expected behaviour when using the bokeh backend, which always defaults to Mercator to allow the use of tile sources.

@philippjfr
Copy link
Member

I suppose it's not clear to me why it can't project it to Mercator though

@jbednar
Copy link
Member

jbednar commented Oct 15, 2019

Seems like GeoViews should assume data in lon,lat unless specified otherwise, and with the Bokeh backend should project into Web Mercator by default since that's what Bokeh supports. I think this issue came up for someone else recently on gitter or github as well.

@philippjfr
Copy link
Member

Seems like GeoViews should assume data in lon,lat unless specified otherwise, and with the Bokeh backend should project into Web Mercator by default since that's what Bokeh supports. I think this issue came up for someone else recently on gitter or github as well.

I'm confused, that's exactly what it does now.

@kcpevey
Copy link
Author

kcpevey commented Oct 15, 2019

I think this issue came up for someone else recently on gitter or github as well.

^ Might have been me the other day. I was still pinning down the error at the time

I can see how specifying crs in the Polygons constructor is an expected requirement, but having to also specify projection in the .opts? I've never had to do that before.

This is what I expected to work (and it does work locally):
gv.Polygons([poly], crs=ccrs.PlateCarree())
This is what I have to do in JHub instance to make it work:
gv.Polygons([poly], crs=ccrs.PlateCarree()).opts(projection=ccrs.PlateCarree())

@kcpevey
Copy link
Author

kcpevey commented Oct 15, 2019

both are using a bokeh backend

@kcpevey
Copy link
Author

kcpevey commented Oct 21, 2019

@philippjfr 's comment made me realize the root of this problem is actually that it can't reproject the data into Mercator. This code:

data = [
    (-95.777304976205, 29.70081935868131),
    (-95.777131944776, 29.70009523405696),
    (-95.780067725666, 29.69971579007273),
    (-95.780184253531, 29.70061729352786),
    (-95.778716019600, 29.70071746836681),
    (-95.777304976205, 29.70081935868131)
]
polys = gv.Polygons([data], crs=ccrs.PlateCarree())
polys_reproj = gv.operation.project(polys, projection=ccrs.GOOGLE_MERCATOR)

Produces this warning:

WARNING:param.project_path03359: While projecting a Polygons element from a PlateCarree coordinate reference system (crs) to a Mercator projection none of the projected paths were contained within the bounds specified by the projection. Ensure you have specified the correct coordinate system for your data.

And polys_reproj.data is empty.

So my workaround for simply displaying gv elements is to add.opts(projection=ccrs.PlateCarree()), but that won't work if I want to underlay a tile source.

@philippjfr
Copy link
Member

@kcpevey Could you report all your versions? That Polygon reprojects just fine when I try it.

@kcpevey
Copy link
Author

kcpevey commented Oct 21, 2019

cartopy 0.17.0
geoviews 1.6.5
holoviews 1.12.6
bokeh 1.3.4

@philippjfr
Copy link
Member

Strange, same versions here and this produces no warnings:

data = [
    (-95.777304976205, 29.70081935868131),
    (-95.777131944776, 29.70009523405696),
    (-95.780067725666, 29.69971579007273),
    (-95.780184253531, 29.70061729352786),
    (-95.778716019600, 29.70071746836681),
    (-95.777304976205, 29.70081935868131)
]
polys = gv.Polygons([data], crs=ccrs.PlateCarree())
polys_reproj = gv.operation.project(polys, projection=ccrs.GOOGLE_MERCATOR)

As an aside, that code is exactly equivalent to:

polys = gv.Polygons([data])
polys_reproj = gv.project(polys)

@kcpevey
Copy link
Author

kcpevey commented Oct 21, 2019

I know, my local setup is the same and produces no warnings, works like expected. I can't imagine what else it could be.

@philippjfr
Copy link
Member

Could you export the environment so I can reproduce?

@philippjfr philippjfr added this to the Version 1.6.6 milestone Oct 24, 2019
@kcpevey
Copy link
Author

kcpevey commented Nov 5, 2019

It turns out this was a problem on our end. We have a complex kubernetes setup and we had a version mismatch that was not immediately apparent. We got it tracked down. Sorry for the confusion!

@kcpevey kcpevey closed this as completed Nov 5, 2019
@philippjfr
Copy link
Member

Thanks for reporting back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants