Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
.DS_Store
20 changes: 0 additions & 20 deletions Build Instructions.md

This file was deleted.

4 changes: 3 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Copyright (c) 2018 The Python Packaging Authority
The MIT License (MIT)

Copyright (c) 2023 LabShare

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
79 changes: 38 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Polus Render

Render application is loaded in an iframe. The package allows pointing the iframe at:
* Render deployed to a server
* A Python server running on localhost and serving a production build of render, which has been bundled with this package
`polus-render` makes Polus Render available as a Pypi package for Jupyter Lab.

Polus Render allows visualizing tiled raster datasets in Zarr and TIFF formats, as well as vector overlays in MicroJSON format. It uses lookup tables to map intensity values in these datasets to colors.

The are three ways to load the data:
1. Specifying a URL to a server
2. Specifying a local path will start a Python server on localhost. The URL to the dataset on localhost will be passed to the application in the iframe
3. Dragging-and-dropping the dataset does not use a server, it calls an API from the front end (It should the this under the hood https://developer.mozilla.org/en-US/docs/Web/API/File_API)
</br>

Has the ability to work both local and remote versions of Jupyter Notebook.
1. Specifying a URL to a server serving the data.
2. Specifying a local path to a file from JupyterLab.
3. Dragging-and-dropping the dataset does not use a server.

Please note that [jupyterlab_polus_render](https://github.com/PolusAI/jupyterlab-extensions/tree/master/jupyterlab_polus_render) is the improved version of this package.

![image](https://github.com/jcaxle/polus-render/assets/145499292/2fcd525e-d97a-40fa-87f8-37981bd24be1)
<img src="images/home.png"/>

# Requirements
* Python 3.9+
Expand Down Expand Up @@ -41,36 +41,36 @@ polus-render
| pyproject.toml // Pypi config
| README
| requirements.txt
└───src
| polus.py // Main file, contains render function used by user
| polus-render-wrapper.py // Unused file used for a scrapped project. Can be used as a reference for input sanitization
| zarr_file_server.py // Contains server only used for serving local build of Polus Render
└───polus
| polus_render.py // Main file, contains render function used by user
| render_server.py // Contains server only used for serving local build of Polus Render
├───apps
│ ├───render-ui // Build files of Polus Render
│ ├───render-ui // Static Polus Render files
│ └───updog-render // Server used for serving files.
```

# Build Instructions
- Refer to [Build Instructions.md](https://github.com/jcaxle/polus-render/blob/0.0.4/Build%20Instructions.md)
- cd to `polus-render` root directory.
- `py -m build`
- `py -m twine upload dist/*`
- Enter `__token__` as user and reference API keys for password

# Adding a static build of Polus Render
- Remove all existing files in `~/polus-render/polus/apps/render-ui`.
- Run `npx nx build render-ui` in your Polus Render folder.
- Tranfer generated files from `/Polus Render/dist/apps/render-ui` into `/polus-render/polus/apps/render-ui`.

# Submodules
- [Updog-Render](https://github.com/jcaxle/updog-render/tree/71b6b938452f63412eea8edf29b9ff10f4c243dd)

# Render: Local build vs online
polus-render is bundled with a build of Polus Render which supports additional functionality compared to the web version. Table
is accurate as of 10/4/2023.
# Static Render Features
| Version | Zarr from URL/Path | TIF from URL/Path | Micro-JSON Support | Zarr/TIF Drag & Drop | Micro-JSON Drag & Drop |
|----------------|---------------|---------------|----------------|-----------|-----|
| Local | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:
| Online | :heavy_check_mark: | | | |

# Drag & Drop Demo
![ezgif-4-7162ca42b5](https://github.com/jcaxle/polus-render/assets/145499292/7a59db1e-3128-4ee0-b9cc-ad1be7d3faee)
<img src="images/drag-drop.gif"/>

# Local Jupyter Notebooks Demo
>TODO
# Remote Jupyter Notebooks Demo
>TODO
# Sample usage
``` Python
from polus.polus_render import render, nb_render
Expand All @@ -79,30 +79,30 @@ from polus.polus_render import render, nb_render
from urllib.parse import urlparse
from pathlib import Path

# Embeds an IFrame of a local build of Polus Render into Jupyter Notebooks
# Embeds an IFrame of a static build of Polus Render into Jupyter Notebooks
render()

# Embeds an IFrame of Polus Render into Jupyter Notebooks
render(use_local_render=False)

# Embeds an IFrame of a local build of Polus Render with an image file hosted at "https://viv-demo.storage.googleapis.com/LuCa-7color_Scan1/"
# Embeds an IFrame of a static build of Polus Render with an image file hosted at "https://viv-demo.storage.googleapis.com/LuCa-7color_Scan1/"
render(image_location=urlparse("https://viv-demo.storage.googleapis.com/LuCa-7color_Scan1/"))

# Embeds an IFrame of a local build of Polus Render with an image hosted locally at "C:\Users\JeffChen\OneDrive - Axle Informatics\Documents\zarr files\pyramid.zarr"
# Embeds an IFrame of a static build of Polus Render with an image hosted locally at "C:\Users\JeffChen\OneDrive - Axle Informatics\Documents\zarr files\pyramid.zarr"
render(image_location=Path(r"C:\Users\JeffChen\OneDrive - Axle Informatics\Documents\zarr files\pyramid.zarr"))

# Embeds an IFrame of a local build of Polus Render with an image and overlay file that is hosted locally
# Embeds an IFrame of a static build of Polus Render with an image and overlay file that is hosted locally
render(image_location=Path(r"C:\Users\JeffChen\OneDrive - Axle Informatics\Documents\zarr files\pyramid.zarr"), \
microjson_overlay_location=Path(r"C:\Users\JeffChen\OneDrive - Axle Informatics\Documents\overlay files\x00_y01_c1_segmentations.json"))

# Embeds an IFrame of a local build of Polus Render with an image and overlay file that is hosted online
# Embeds an IFrame of a static build of Polus Render with an image and overlay file that is hosted online
render(image_location=urlparse("https://files.scb-ncats.io/pyramids/segmentations/x00_y01_c1.ome.tif"), \
microjson_overlay_location=urlparse("https://files.scb-ncats.io/pyramids/segmentations/x00_y03_c1_segmentations.json"))

# Embeds an IFrame with a height of 1080 of a local build of Polus Render.
render(height=1080)

# Embeds an IFrame into remote jupyter notebooks. Use this function with argument nbhub_url to specify your notebooks url which must have lab in its url
# Embeds an IFrame into remote JupyterLab notebook. Use this function with argument nbhub_url to specify your notebooks url which must have lab in its url
nb_render(nbhub_url=urlparse("https://jh.scb-ncats.io/user/jeff.chen@axleinfo.com/user-namespaces/lab?"), image_location=Path("work/pyramid.zarr"))
```

Expand All @@ -121,8 +121,8 @@ def render(image_location:Union[ParseResult, PurePath] = "", microjson_overlay_l
If not specified, renders default render url
width (int): width of render to be displayed, default is 960
height (int): height of render to be displayed, default is 500
image_port (int): Port to run local zarr server on if used (default is 0 which is the 1st available port).
microjson_overlay_port (int): Port to run local json server on if used (default is 0 which is the 1st available port).
image_port (int): Port to run local image server if used (default is 0 which is the 1st available port).
microjson_overlay_port (int): Port to run local overlay server if used (default is 0 which is the 1st available port).
use_local_render (bool): True to run local build of render with 1st available port, False to use render_url (default is True)
render_url (str): URL which refers to Polus Render. Used when run_local_render is False. (default is https://render.ci.ncats.io/)
Pre: zarr_port and json_port selected (if used) is not in use IF path given is Purepath
Expand All @@ -149,18 +149,15 @@ def nb_render(nbhub_url:ParseResult,image_location:Union[ParseResult, PurePath]
```

# Implementation Details
- render() receives sanatized input. Check [polus-render-wrapper.py](https://github.com/jcaxle/polus-render/blob/dev-experimental/src/polus-render-wrapper.py) or [sample usage](https://github.com/jcaxle/polus-render/edit/dev-experimental/README.md#sample-usage) for examples on sanitizing input.
- render() builds up URL scheme fragments for render url, image url, and microjson url.
- If the image url and microjson url are file paths, serve the files on file servers pointing to either user specified port or a free port.
- If local render is used, build a server for it as well.
- At the end, combine render url fragments into a single url, insert it into an IFrame, and display it.
- Complete url string is returned not printed.
- For nb_render(), no servers are launched. Files are served from endpoints generated from the remote Jupyter Notebook's URL. The local build of render is served from the [polus-server-ext](https://github.com/jcaxle/polus-server-ext) instead of the bundled build files. Essentially, nb_render() runs serverless with the exception of the server that serves the remote Jupyter Notebooks itself.
- Render application is loaded in an IFrame.
- `render()` and `nb_render()` builds up URL scheme fragments for render url, image url, and microjson url. It then combines url fragments into a single url which is displayed through an embedded IFrame.
- Static build of Polus Render as well as files to be displayed in `nb_render()` are served by Jupyter Server extension.
- Dragging-and-dropping the dataset does not use a server. It calls an API from the front end (It should the this under the hood https://developer.mozilla.org/en-US/docs/Web/API/File_API).

# Misc Implementation Details
- Two type of servers are used.
>1. Python HTTPServer with CORS and OPTIONS functionality to serve RenderUI
>2. Modified UpDog Flask server to serve local files to RenderUI
>1. Python HTTPServer with CORS and OPTIONS functionality to serve Render.
>2. Modified UpDog Flask server to serve local files to Render.

# Acknowledgements
- UpDog: https://github.com/sc0tfree/updog
Binary file added images/drag-drop.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed polus/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file removed polus/__pycache__/polus.cpython-311.pyc
Binary file not shown.
Binary file removed polus/__pycache__/polus_render.cpython-39.pyc
Binary file not shown.
Binary file removed polus/__pycache__/render_server.cpython-39.pyc
Binary file not shown.
Binary file removed polus/__pycache__/zarr_file_server.cpython-311.pyc
Binary file not shown.
83 changes: 0 additions & 83 deletions polus/polus-render-wrapper.py

This file was deleted.

Binary file removed polus/x00_y01_p01_c1.ome.tif
Binary file not shown.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespaces = true

[project]
name = "polus-render"
version = "0.0.4.0.1.5"
version = "0.1.0"
authors = [
{ name="Jeff Chen", email="Jeff.Chen@axleinfo.com" },
]
description = "Displays Polus Render dashboard in Jupyter Notebooks."
description = "Displays Polus Render dashboard in JupyterLabs."
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
Expand Down