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

Add ipyleaflet representation #1065

Merged
merged 28 commits into from
Jun 20, 2023
Merged

Add ipyleaflet representation #1065

merged 28 commits into from
Jun 20, 2023

Conversation

banesullivan
Copy link
Contributor

@banesullivan banesullivan commented Feb 22, 2023

A first pass at adding an _ipython_display_ repr to visualize a tile source in Jupyter dynamically

resolves #1059

I'm having a bit of trouble getting this to work consistently for non-geospatial tile sources

This adds a new rest.py module which is leveraged to launch a minimal tile server for a TileSource using a tornado web server (the same web server Jupyter uses, thus requiring no extra dependencies).

The TileLayer creation is abstracted in getIpyleafletTileLayer() so that users can build the tile layer more easily and/or create custom maps.

Screen Shot 2023-02-22 at 11 47 06 AM

import large_image

path = 'oahu-dense.tiff'

source = large_image.open(
    path,
    encoding="PNG",
    projection="EPSG:3857",
)
source
from ipyleaflet import Map

t = source.getIpyleafletTileLayer(attribution="My tile source!!")

m = Map(center=source.getCenter(srs="EPSG:4326"))
m.add_layer(t)
m

Potential remaining tasks

  • Add testing
  • Figure out why the tornado enpoints only work in JupyterLab and break classic notebook. Perhaps switch to using a background thread
  • Verify orientation of medical/non-geo images

@manthey
Copy link
Member

manthey commented Feb 22, 2023

I like where this is heading. I'm vacillating on where some of this code should be located -- I half feel it should be in an "IPyLeafletMixin" class that would be added to the TileSource class so that it can live in a separate file.

Comment on lines 127 to 143
proj = dict(
name='PixelSpace',
custom=True,
# Why does this need to be 256?
resolutions=[256 * 2 ** (-l) for l in range(20)],

# This works but has x and y reversed
proj4def='+proj=longlat +axis=esu',
bounds=[[0, 0], [metadata['sizeY'], metadata['sizeX']]],
origin=[0, 0],

# This almost works to fix the x, y reversal, but
# - bounds are weird and other issues occur
# proj4def='+proj=longlat +axis=seu',
# bounds=[[-metadata['sizeX'],-metadata['sizeY']],[metadata['sizeX'],metadata['sizeY']]],
# origin=[0,0],
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manthey, I copied this from https://gist.github.com/manthey/a66f69ae84dc59bbd54c2fbbb1c8844f and I'm not seeing the XY reversal issues mentioned in your comments (or am I??). I think this projection generally works, though we could probably improve it to address the following issues I do see (for non-geospatial):

  1. Map is centered on top-left corner of image
  2. Bounds of map do not match bounds of image
  3. Some zoom levels yield "edge"/"border" tiles ... not sure how best to describe these, but I can provide screenshots where black tiles outside the bounds of the image are generated/shown
  4. Zoom level 0 does not show the full image in the frame
  5. Max zoom level is not working

@banesullivan
Copy link
Contributor Author

CI is passing tests but codecov client is failing.

@manthey, this is ready for another review

@banesullivan
Copy link
Contributor Author

@zachmullen and I are experiencing issues where the tornado endpoints here are breaking Classic Notebook, but this works fin in JupyterLab

@banesullivan
Copy link
Contributor Author

@manthey, this is ready for review. There are some quirks and known issues, but I think this is at a point where it is highly valuable/useful.

  1. This does not work in Classic Notebook, only JupyterLab. We may have to switch to using FastAPI over Tornado for Classic Notebook, but I don't think as many people still use Classic Notebook
  2. See the inline comment above about potential improvements to the map/projection
  3. Testing is just a smoke test to ensure these functions run and don't error (requests are not made)

@manthey
Copy link
Member

manthey commented Jun 20, 2023

Let's merge this and refine it in future PRs.

Copy link
Member

@manthey manthey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make an issue to revisit the coordinate system of non-geospatial data.

@banesullivan banesullivan merged commit e9c8012 into master Jun 20, 2023
@banesullivan banesullivan deleted the feat/ipyleaflet branch June 20, 2023 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

_repr_html_ for interactive tile viewing in Jupyter
2 participants