Metadata-Version: 2.5
Name: kiln-render
Version: 0.2.0
Summary: Jupyter widget for Kiln: stream and explore large OME-Zarr volumes and NumPy arrays in your notebook with WebGPU.
Project-URL: Homepage, https://kilnrender.com
Project-URL: Repository, https://github.com/kilnrender/kiln-jupyter
Author: Martin Panknin
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.9
Requires-Dist: anywidget>=0.9
Provides-Extra: dev
Requires-Dist: jupyterlab; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Description-Content-Type: text/markdown

# kiln-jupyter

[![PyPI](https://img.shields.io/pypi/v/kiln-render?color=3775a9)](https://pypi.org/project/kiln-render/)

Jupyter widget for [Kiln](https://kilnrender.com): stream and explore large OME-Zarr volumes and NumPy arrays in your notebook with WebGPU.

<img width="1721" height="873" alt="image" src="https://github.com/user-attachments/assets/bf524e41-8428-4995-bc6c-f1deb49f3f76" />


```bash
pip install kiln-render
```

```python
import kiln_render as kiln

v = kiln.view("https://d39zu0xtgv0613.cloudfront.net/chameleon-16bit")
v
```

Every field syncs both ways. Set it from Python to change the view; `camera` also follows the mouse. The line under the view shows how much has been streamed so far, out of the dataset's full uncompressed size.

```python
v.mode = "mip"
v.auto_contrast()  # fit the window to the data, e.g. after changing url
v.camera  # [rotation x, rotation y, distance, target x, y, z]
v.screenshot("figure.png")  # save the view as PNG
v.set_channel(1, visible=False)  # multichannel data: change one channel
```

`kiln.controls(v)` gives the view ready-made controls: render mode, contrast per channel (colour map and contrast for single-channel data), a time slider for time series, auto contrast and reset view.

| Field | Values |
|---|---|
| `url` | OME-Zarr image or Kiln sharded volume: URL or local path (arrays get a URL of their own) |
| `mode` | `dvr`, `mip`, `iso`, `slice` |
| `colormap` | single-channel data: `grayscale`, `grayscale-inverted`, `hot`, `cool`, `viridis`, `plasma`, `coolwarm`, `seismic` |
| `window_center`, `window_width` | single-channel data, 0–1; `None` fits it to the data once loaded |
| `up` | volume axis that points up: `x`, `y`, `z`, `-x`, `-y`, `-z` |
| `camera` | orbit state, as in Kiln's `cam` URL parameter; `[]` returns to the view the dataset opened with |
| `timepoint` | timepoint shown, from 0; `timepoints` holds the count, set by the browser |
| `channels` | multichannel data, per channel: `name`, `color` (`#rrggbb`), `visible`, `window_center`, `window_width`; empty for single-channel data |
| `height` | pixels |
| `status` | loading state or error, set by the browser |

## Local files

```python
v = kiln.view("~/data/cells.ome.zarr")
```

A local path is served to the browser over `127.0.0.1` under a random URL while the kernel runs. This needs the browser and the kernel on the same computer, as in JupyterLab or VS Code. It doesn't work in Colab or on a remote JupyterHub.

## Arrays

```python
v = kiln.view(volume, scale=(2.0, 0.5, 0.5), unit="micrometer")  # voxel size (z, y, x)
```

A 3D array (z, y, x) is served like a local path, so the same limits apply. Kiln gets it as OME-Zarr with a pyramid built in memory; nothing is written to disk. The pyramid adds about 15 % to the array's memory, which is freed with `v.close()`. Kiln reads uint8, uint16, int16, float32 and float64; booleans become uint8, int8 becomes int16 and other numbers become float32.

See [examples/quickstart.ipynb](https://github.com/kilnrender/kiln-jupyter/blob/main/examples/quickstart.ipynb).

## Requirements

- Works in JupyterLab, VS Code, Google Colab (`!pip install kiln-render`) and marimo. Local paths and arrays need the kernel on your own computer, so not in Colab.
- A browser with WebGPU, such as Chrome or Edge.
- The browser reads the data, so the URL must be reachable from it and allow cross-origin requests.
- Kiln itself is loaded from jsDelivr at a pinned version (`KILN_URL` in `src/kiln_render/widget.js`), so the browser needs internet access.

## Examples

- [Quickstart](https://github.com/kilnrender/kiln-jupyter/blob/main/examples/quickstart.ipynb)
- [Explore the IDR](https://github.com/kilnrender/kiln-jupyter/blob/main/examples/explore-idr.ipynb): pick a dataset from the Image Data Resource, up to 139 GB, and stream it [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/kilnrender/kiln-jupyter/blob/main/examples/explore-idr.ipynb)
- [Beyond the basics](https://github.com/kilnrender/kiln-jupyter/blob/main/examples/advanced.ipynb): controls with ipywidgets, saving views, several views
- [Process in NumPy, compare in 3D](https://github.com/kilnrender/kiln-jupyter/blob/main/examples/compare.ipynb): input and result side by side with one shared camera

## License

Apache-2.0
