Skip to main content

Tests

nglscenes

An interface to generate and manipulate neuroglancer scenes.

Features

  • extract scenes from URLs, clipboard, (JSON) files or strings
  • manipulate state dictionary
  • write scenes to files or clipboard
  • easily create segment properties
  • run and remote-control a local neuroglancer

Install

$ pip install nglscenes

The base install is lightweight and covers constructing, parsing and manipulating scenes. Heavier dependencies are optional and can be installed via extras:

Extra Installs Needed for
local neuroglancer, trimesh LocalScene and local mesh/skeleton/annotation layers
cave cloud-volume CAVE/graphene credentials (e.g. FlyWire) for local scenes
serve flask, flask-cors + local nglscenes.viewer (local data server)
all all of the above
$ pip install "nglscenes[all]"

From Github:

$ pip install git+https://github.com/schlegelp/nglscenes@main

Usage

Overview

At this point, nglscenes has two different types of "scenes":

  1. Use a basic Scene to construct and manipulate neuroglancer states.
  2. Use a LocalScene to starts a local neuroglancer server which then keeps the state between the browser and Python synced.

Examples

Manually construct a simple scene

>>> from nglscenes import *
>>> # Generate empty scene
>>> scene = Scene()

>>> # Generate some layers
>>> img = ImageLayer(source='precomputed://gs://neuroglancer-fafb-data/fafb_v14/fafb_v14_clahe')
>>> seg = SegmentationLayer(source="precomputed://gs://fafb-ffn1-20200412/segmentation")
>>> an = AnnotationLayer(source="precomputed://gs://neuroglancer-20191211_fafbv14_buhmann2019_li20190805")

>>> # Add layers to scene
>>> scene.add_layers(img, seg, an)
>>> scene
<Scene(1 segmentation, 0 mesh, 1 image, 1 annotation)>

https://neuroglancer-demo.appspot.com/#!%7B%22laye[...]

>>> # Open in browser
>>> scene.open()

>>> # Copy to clipborad
>>> scene.to_clipboard()
URL copied to clipboard.

Manipulate a scene

>>> from nglscenes import *
>>> # Read scene from URL or JSON-formatted string
>>> scene = Scene.from_clipboard()
>>> scene
<Scene(3 segmentation, 1 mesh, 3 image, 1 annotation)>

https://fafb-dot-neuroglancer-demo.appspot.com/#!%7[...]

>>> # Inspect layers
>>> scene.layers[2]
<SegmentationLayer(name=fafb-ffn1-20200412, source=precomputed://gs://fafb-ffn1-20200412/segmentation, selected segments=1)>
>>> # Drop the last layer
>>> scene.drop_layer(-1)
>>> # Add segments to the segmentation layer
>>> len(scene.layers[2]['segments'])
1
>>> scene.layers[2]['segments'] += [12345, 56789]
>>> len(scene.layers[2]['segments'])
3

Combine two scenes

>>> # Read two scenes
>>> scene1 = Scene.from_clipboard()
>>> scene2 = Scene.from_clipboard()

>>> # Use addition to simply combine the layers of both scenes
>>> comb = scene1 + scene2
>>> len(comb) == len(scene1) + len(scene2)
True

>>> # Use OR operator to merge the layers
>>> # This will merge layers with the same data source
>>> # For segmentation layers, this will merge the selected segments
>>> merged = scene1 | scene2
>>> len(merged) < len(scene1) + len(scene2)
True

All of the above examples will also work with the other scene types.

Remote controlling neuroglancer

>>> from nglscenes import *
>>> # Generate empty scene
>>> scene = LocalScene()
>>> scene
<LocalScene(1 segmentation, 0 mesh, 1 image, 1 annotation)>

http://127.0.0.1:53955/v/4dc530306753007bd4fc39b745673d604e58d2a5/

>>> # Open scene in browser
>>> scene.open()

>>> # Generate and add layers
>>> # -> you should see the layers appear in the browser window
>>> scene.add_layers(ImageLayer(source='precomputed://gs://neuroglancer-fafb-data/fafb_v14/fafb_v14_clahe'))
>>> scene.add_layers(SegmentationLayer(source="precomputed://gs://fafb-ffn1-20200412/segmentation"))
>>> scene.add_layers(AnnotationLayer(source="precomputed://gs://neuroglancer-20191211_fafbv14_buhmann2019_li20190805"))

>>> # The state is automatically synced:
>>> scene.layers[-1].state
OrderedDict([('source',
              'precomputed://gs://neuroglancer-20191211_fafbv14_buhmann2019_li20190805'),
             ('type', 'annotation'),
             ('name', 'annotations'),
             ('tab', 'source'),
             ('visible', False)])
>>> # Hide the layer
>>> scene.layers[-1]['visible'] = False
>>> # Get the same layer by name and unhide
>>> scene.layers['annotations']['visible'] = True
>>> # Set selected segments
>>> scene.layers[1]['segments'] = [5280982928, 5517604362]

>>> # Serve skeletons from a local folder containing SWC files
>>> # (this also works from a zip file)
>>> scene.add_layers(LocalSkeletonLayer(LocalSkeletonLayer(source='~/skeletons/')))
>>> scene.layers[-1]['segments'] = [123456]

Metadata

Release files for nglscenes 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nglscenes 0.6.0
File Size Uploaded
nglscenes-0.6.0.tar.gz 48.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nglscenes 0.6.0
File Interpreter ABI Platform
nglscenes-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 102.6 kB

Release files / nglscenes-0.6.0.tar.gz

Download URL nglscenes-0.6.0.tar.gz
Size 48.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8f200b34723c9954491f79dff33b883c7e1cfc1e4159337e1663bd569e6d1b14
BLAKE2b-256 checksum
How to use checksums
a87207366083d9a6b55a971e4a3ea17021374837159e32f6baf449f8e7d5cecc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / nglscenes-0.6.0-py3-none-any.whl

Download URL nglscenes-0.6.0-py3-none-any.whl
Size 54.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea5d97652d7b9bd39c64e134b9c6ca4038883992e624b2ddaebd188f0fbf2a14
BLAKE2b-256 checksum
How to use checksums
90be34013dbb7250d6b73ce7891481e1642486017fb51bf544f91e721799e03e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page