Skip to main content

Tools to generate and manipulate neuroglancer scenes

Project description

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

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]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nglscenes-0.5.0.tar.gz (46.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nglscenes-0.5.0-py3-none-any.whl (51.1 kB view details)

Uploaded Python 3

File details

Details for the file nglscenes-0.5.0.tar.gz.

File metadata

  • Download URL: nglscenes-0.5.0.tar.gz
  • Upload date:
  • Size: 46.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nglscenes-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2949a80b491cda66eb8d38f947e4aa23c89b45b3f17f46504b83926ed12280e9
MD5 e86a64f3e9a2562d10be0c6f9d0ac2ec
BLAKE2b-256 eb791371f42ee0179cdbe22ce43c49ba7d0f5c7310a32eeca2f46bc2888b327e

See more details on using hashes here.

Provenance

The following attestation bundles were made for nglscenes-0.5.0.tar.gz:

Publisher: publish.yml on schlegelp/nglscenes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nglscenes-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: nglscenes-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 51.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nglscenes-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3411d97818d03a4d8d4536008aec102837349d4dd3960fc9fcd03e565e0d3018
MD5 a153506c06188a204f9911cdfe35d0fd
BLAKE2b-256 e9d17bfc2e823d9a4ce22c3bf5866ab5e039a409cfa6d214ce509ddbdb7fa743

See more details on using hashes here.

Provenance

The following attestation bundles were made for nglscenes-0.5.0-py3-none-any.whl:

Publisher: publish.yml on schlegelp/nglscenes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page