holoviz / datashader

Quickly and accurately render even the largest data.
http://datashader.org
BSD 3-Clause "New" or "Revised" License
3.32k stars 365 forks source link

Distortions between quadmesh and input points #952

Closed jcfbeardsley closed 4 years ago

jcfbeardsley commented 4 years ago

Hi all,

I've noticed when using canvas.quadmesh with an irregularly spaced grid of lat/lons (EPSG: 4326) to generate a Datashader image that there seems to be some distortion of the resulting mesh locations relative to the original input locations. I've provided an example script of what I'm referring to, along with the source data (NetCDF), here:

Script: https://github.com/jcfbeardsley/tastemp/blob/datashader/quadmesh.py Output: https://github.com/jcfbeardsley/tastemp/blob/datashader/quadmesh_demo.html

In this example, I'm plotting the original cell centre coordinates on a Mapbox plot using Plotly within Python. I realise I'm using the cell centres to form the bounding coordinates of the image (where in reality this should be the SW, SE, NE and NW cell corners for each location, but this doesn't explain the discrepancy by approx 3 grid cells in the Y direction. Interestingly, the same distortion occurs if replacing quadmesh with a canvas.points render or a canvas.polygons render using GeoJSON of the original irregular grid cells.

The following shows the output Datashader image (displaced) overlaid with the original cell centres plotted (in the correct location) as scatter dots. The north-south discrepancy is obvious, by approx 2.5 to 3 grid cells:

image

image

To ensure this wasn't an issue with the Plotly/Mapbox representation of the shading result, I've independently georeferenced the resulting datashader image to the same corners with the same result:

image

Can someone explain what's going on here, and more importantly, how it can be corrected?

Thanks in advance, J.

philippjfr commented 4 years ago

Thanks for the issue. Is there any way to get access to the dataset so I can reproduce it?

jcfbeardsley commented 4 years ago

Thanks for the issue. Is there any way to get access to the dataset so I can reproduce it?

Sure thing, the original data is available at https://github.com/jcfbeardsley/tastemp/blob/datashader/temp.nc (or you can just pull the entire https://github.com/jcfbeardsley/tastemp/tree/datashader repo). For context, the dataset represents ocean temperature at the surface, so the grid cell centres are expected to be overlaying the ocean neatly around the coastline.

philippjfr commented 4 years ago

Here's what I get when I plot it with hvPlot:

Screen Shot 2020-08-18 at 9 38 03 PM

This differs from your output a fair bit but I'm not sure it's any more correct. I'll keep looking from here.

philippjfr commented 4 years ago

Actually at the k=-0.5 level this seems to work out pretty well:

Screen Shot 2020-08-18 at 9 40 34 PM

Screen Shot 2020-08-18 at 9 46 56 PM

So I don't think datashader is at fault here, seems like something either in your transforms or in plotly seems to be off.

philippjfr commented 4 years ago

For reference hvPlot is using GeoViews and Cartopy to do the projection from EPSG: 4326 to EPSG: 3857 under the hood and that's where I think Plotly/Mapbox is messing things up.