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
Speeding up projected maps in geoviews? #230
Comments
Apologies for not replying sooner, I do think this is down to cartopy but it's also possible that I'm using a suboptimal codepath. To project images we are currently calling |
Can the data in the image be projected ahead of time, before displaying it? |
Yes, |
So I'm guessing |
That's right, it mostly just calls the appropriate cartopy transform depending on the input type. I've played around parallelizing this with dask with very mixed results. |
Just as an experiment, I tried downloading the tif image locally and using gdalwarp to warp to a regular lon/lat grid. It took 2 seconds to download the image and 3 seconds to warp onto a regular lon/lat grid, so it seems that there must be something very inefficient going on to make: crs = ccrs.UTM(zone='10n')
display(band1.hvplot(crs=crs, rasterize=True, width=600, height=400, cmap='viridis')) take 3 minutes. Here's the jovyan@jupyter-rsignell-2dusgs:~/Landsat$ time wget https://storage.googleapis.com/gcp-public-data-landsat/LC08/01/047/027/LC08_L1TP_047027_20130421_20170310_01_T1/LC08_L1TP_047027_20130421_20170310_01_T1_B4.TIF
LC08_L1TP_047027_20130421 100%[=====================================>] 77.16M 37.4MB/s in 2.1s
2018-11-02 13:09:55 (37.4 MB/s) - ‘LC08_L1TP_047027_20130421_20170310_01_T1_B4.TIF’ saved [80907084/80907084]
real 0m2.217s
user 0m0.096s
sys 0m0.312s jovyan@jupyter-rsignell-2dusgs:~/Landsat$ time gdalwarp -t_srs EPSG:4326 LC08_L1TP_047027_20130421_20170310_01_T1_B4.TIF lonlat.tif
Creating output file that is 9183P x 5981L.
Processing input file LC08_L1TP_047027_20130421_20170310_01_T1_B4.TIF.
0...10...20...30...40...50...60...70...80...90...100 - done.
real 0m3.102s
user 0m2.852s
sys 0m0.248s Even if I try the more time consuming jovyan@jupyter-rsignell-2dusgs:~/Landsat$ time gdalwarp -t_srs EPSG:4326 -r lanczos LC08_L1TP_047027_20130421_20170310_01_T1_B4.TIF lonlat.tif
Creating output file that is 9183P x 5981L.
Processing input file LC08_L1TP_047027_20130421_20170310_01_T1_B4.TIF.
0...10...20...30...40...50...60...70...80...90...100 - done.
real 0m15.343s
user 0m15.016s
sys 0m0.324s |
Thanks, for your experiments, I'll play around with this now. The equivalent operation using geoviews which ends up making a call to import geoviews as gv
import cartopy.crs as ccrs
img = gv.load_tiff('/Users/philippjfr/Downloads/LC08_L1TP_047027_20130421_20170310_01_T1_B4.TIF')
projected = gv.project(img, projection=ccrs.PlateCarree()) |
Here's the output of profiling the project operation with
|
Wow @philippjfr , looks like we have some room for improvement! Great! |
@philippjfr this Cartopy PR from @QuLogic looks promising! |
Definitely some solid improvement there, but not enough to make it very usable: Using scipy's kdtree:
using pykdtree:
|
Actually, after calling |
Okay, I'm now wondering whether hvplot is doing something quite suboptimal, using geoviews directly things are pretty quick: import geoviews as gv
from holoviews.operation.datashader import rasterize
gv.extension('bokeh')
tiff = gv.load_tiff('/Users/philippjfr/Downloads/LC08_L1TP_047027_20130421_20170310_01_T1_B4.TIF')
rasterize(tiff) It seems like hvplot is projecting before rasterizing, which would explain the slow speed. |
Okay to summarize, the main issue here was that hvplot always projects all the data before it applies rasterize/datashade options. This makes sense in some cases because it means the data does not have to be reprojected every time you zoom or pan, but it can also result in a huge initial overhead like this case. My suggestion is to add an explicit The secondary problem is that projecting images using cartopy is pretty slow, which is substantially improved using pykdtree instead of scipy's kdtree. The timings now (with and without the new pykdtree implementation in cartopy) are as follows:
Once I've added the |
I've opened holoviz/hvplot#106 to add the project=True/False argument to hvplot. |
So roughly a 100 fold speedup? I think we will notice that! 😜 |
I'm visualizing public Landsat data with
hvplot.xarray
but I think this is likely ageoviews
issue.It takes about 3 seconds to render an image when not using the
crs
:It takes about 3 minutes to render an image when using the
crs
:Without
crs
it's using my dask cluster, but withcrs
it does not use the cluster.This is the code I'm using:
Here is the notebook.
Is this expected?
Is there anything I can do to speed up visualization with
crs
specified?The text was updated successfully, but these errors were encountered: