Use anywidget for viewer without jupyter-server-proxy#219
Use anywidget for viewer without jupyter-server-proxy#219banesullivan wants to merge 6 commits intomainfrom
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #219 +/- ##
==========================================
- Coverage 83.15% 79.35% -3.81%
==========================================
Files 26 27 +1
Lines 1033 1085 +52
==========================================
+ Hits 859 861 +2
- Misses 174 224 +50 |
|
Wow, this is amazing! I am excited. This can potentially resolve the proxy issue once and for all🚀 |
|
I asked ChatGPT for help. See the conversations here. Not sure if it helps. |
|
This maybe relevant https://x.com/kylebarron2/status/1823849445575852135?s=46 |
Well @manzt had pointed me to this PR for reference, so we have some circular references going on 😉 . |
| # NOTE: when calling from a thread executor, we need a different dataset handle for each thread | ||
| # finding that the kernel crashes... is rio-tiler or rasterio not thread safe? |
There was a problem hiding this comment.
No, definitely not thread safe by default. https://github.com/gjoseph92/stackstac/blob/main/stackstac/rio_reader.py Is a really cool implementation of threading for some specific rasterio drivers (e.g. COG)
|
|
||
| # t = threading.Thread(target=target) | ||
| # t.start() | ||
| THREAD_EXECUTOR.submit(target) |
There was a problem hiding this comment.
I'm curious if you get much of a speedup with a threadpool executor. I would've thought the GIL would be held most of the time.
There was a problem hiding this comment.
Yes, I think I did notice a significant speed up using multiple threads -- I'll have to make a comparison exmaple
|
In the longer term, I'm curious if we can make this performant by having the python callback be async so that it's not blocking other tiles' requests. But that's a bit of work to get there. |
That's an interesting idea! I'll have to give this a try! Hey @kylebarron, love seeing you here -- I've seen you up to some awesome work with Lonboard! I'm curious if you're looking at localtileserver (or rio-tiler more broadly) for some raster support in Lonboard? I'd love to contribute/help (albeit my time is incredibly limited these days) |
|
Thank you! I'm bummed I missed the chance to say hello at scipy! The prototype I have in lonboard uses rio-tiler to manage the abstraction of getting tiles to send to the frontend. It's not really possible to make rio-tiler async, at least not with the gdal backend, so the long term goal is to have a stable async cog reader that we can use instead of gdal for COG inputs specifically |
@manzt gave an excellent talk on
anywidgetat SciPy 2024 and I was blown away! Immediately, I saw a ton of potential for the widgets I work on across localtileserver and pyvista.I thought I'd experiment with anywidget and see if I could use it to mitigate all of the issues around localtileserver's reliance on
jupyter-server-proxysince there are countless examples of people struggling to getjupyter-server-proxyproperly configured.The changes in this PR are the result of a few hours of hacking with @manzt's help (thank you!!). This provides a fallback widget for the
_ipython_display_method on theTileClientclass to immediately provide a working viewer for any raster after installation -- no configuration needed!Ideally, I'd like to see if I can use the comms mechanism demonstrated here when creating a TileLayer with both
ipyleafletandfolium. However, I couldn't figure out how to get this widget to talk to and add itsTileLayerelement to those widgets' maps... challenge for another day.cc @giswqs