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.1.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.1-py3-none-any.whl (51.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nglscenes-0.5.1.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.1.tar.gz
Algorithm Hash digest
SHA256 be730ede7f4a26fcab1af3ac4c744a45867032d575211c3b7db3f81e45d704f9
MD5 1c9912774f24ae58be108902a0a5dc59
BLAKE2b-256 0052d7288d33e561a01814614fbad366e668985246b745c0dc941012f5c52f43

See more details on using hashes here.

Provenance

The following attestation bundles were made for nglscenes-0.5.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: nglscenes-0.5.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a78b8a9a5d28ecdb747e66acb81c9e32a050016862a4a95a2eada2014e4bc2c4
MD5 0553d08756e91f39f6c3eeb70a7b134e
BLAKE2b-256 8fb2be8172ab880c23e095772e95c8366a0ca0863cf56aa8df83b9764327393b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nglscenes-0.5.1-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