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.7.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.7.0
File Size Uploaded Provenance
nglscenes-0.7.0.tar.gz 52.8 kB With provenance Details

Built distribution (wheel)

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

Total release size: 109.5 kB

Release files / nglscenes-0.7.0.tar.gz

Download URL nglscenes-0.7.0.tar.gz
Size 52.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6de58cde892c524b1f2f9a8614b0335f7db1ac411d3f13c5122e39a0218665bc
BLAKE2b-256 checksum
How to use checksums
963278cda7303c5605890dde19896adebb47bb08c8154f3b334d34ad3c7b7089
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 20, 2026.

Transparency log

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

Download URL nglscenes-0.7.0-py3-none-any.whl
Size 56.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
731eae80f7c88d2ebe25ba69a84f38639fe70cf8fe65dd1b9c12e4be67005b90
BLAKE2b-256 checksum
How to use checksums
f332be17c776b710bb3beb44489c007f3ecbeb154544199ea9a90e208c84eadf
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 20, 2026.

Transparency log

Security for nglscenes 0.7.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nglscenes-0.7.0.tar.gz

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 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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