get_json_state_from_url - jaybgager/tracertools GitHub Wiki

Derives a neuroglancer JSON state from a shortened sharing url and returns it as a dictionary. Useful as a starting point when a specific piece of information needs to be extracted from a list of links (e.g. you need to programmatically pull all the line annotation layers from a long list of urls in a project spreadsheet).

Arguments:

  • datastack (string, mandatory)
    • the name of the CAVE datastack in the share url
  • share_url (string, mandatory)
    • the shortened neuroglancer url you want the JSON state for

Returns:

  • json_state (dictionary)
    • the JSON state from the shortened link as a dictionary

Example

The code below gets a JSON state dictionary from a brain_and_nerve_cord share url.

INPUT:

import tracertools as tt

state = tt.get_json_state_from_url(
    datastack = "brain_and_nerve_cord",
    share_url = "https://spelunker.cave-explorer.org/#!middleauth+https://global.daf-apis.com/nglstate/api/v1/6734515480297472",
)

print(state)

OUTPUT:

{
    'crossSectionOrientation': [0, 1, 0, 0],
    'crossSectionScale': 4.124877700286996,
    'dimensions': {'x': [4e-09, 'm'], 'y': [4e-09, 'm'], 'z': [4.5e-08, 'm']},
    'layers': [{'name': 'BANC EM',
                'source': 'precomputed://gs://seunglab_lee_fly_cns_001_alignment/aligned/v0',
                'tab': 'source',
                'type': 'image'},
                {'colorSeed': 171511409,
                'name': 'segmentation proofreading',
                'segmentColors': {'720575941450261831': '#00ff00',
                                '720575941518561971': '#0000ff',
                                '720575941545083784': '#ff0000',
                                '720575941609904714': '#54bcd1'},
                'segments': ['720575941413124779'],
                'selectedAlpha': 0.4,
                'source': {'state': {'findPath': {},
                                    'merge': {'merges': []},
                                    'multicut': {'sinks': [], 'sources': []}},
                            'url': 'graphene://middleauth+https://cave.fanc-fly.com/segmentation/table/wclee_fly_cns_001'},
                'tab': 'segments',
                'toolBindings': {'C': 'grapheneMulticutSegments',
                                'F': 'grapheneFindPath',
                                'M': 'grapheneMergeSegments'},
                'type': 'segmentation'},
                {'colorSeed': 260226408,
                'meshSilhouetteRendering': 2,
                'name': 'region outlines',
                'objectAlpha': 0.35,
                'pick': False,
                'segmentColors': {'1': '#f0f2f4', '2': '#e7e9d8'},
                'segmentQuery': '<id',
                'segments': ['1', '2'],
                'source': {'enableDefaultSubsources': False,
                            'subsources': {'bounds': True,
                                        'mesh': True,
                                        'properties': True},
                            'url': 'precomputed://gs://lee-lab_brain-and-nerve-cord-fly-connectome/region_outlines'},
                'tab': 'rendering',
                'type': 'segmentation'},
                {'annotationColor': '#e01b24',
                'annotations': [{'id': '5982b74cd362c84281a904ca59768e0d874b7e92',
                                'point': [194490.25,
                                            32266.216796875,
                                            1977.9444580078125],
                                'type': 'point'},
                                {'id': '520971d0a979ff93352ebce7be7fbf3bd44ea1f7',
                                'point': [48411.7421875,
                                            34597.68359375,
                                            2096.408935546875],
                                'type': 'point'}],
                'name': 'annotation',
                'source': {'transform': {'outputDimensions': {'x': [4e-09, 'm'],
                                                            'y': [4e-09, 'm'],
                                                            'z': [4.5e-08,
                                                                    'm']}},
                            'url': 'local://annotations'},
                'tab': 'annotations',
                'tool': 'annotatePoint',
                'type': 'annotation'}],
    'layout': 'xy-3d',
    'position': [123863.0625, 113466.2734375, 3157.3271484375],
    'projectionOrientation': [-0.0051445323042571545,
                            0.9996799230575562,
                            -0.0048975832760334015,
                            -0.024281617254018784],
    'projectionScale': 360848.9354568101,
    'selectedLayer': {'layer': 'annotation', 'visible': True},
    'selection': {'layers': {'annotation': {'annotationId': '520971d0a979ff93352ebce7be7fbf3bd44ea1f7',
                                            'annotationSource': 0,
                                            'annotationSubsource': 'default'}}},
    'showSlices': False,
    'systemMemoryLimit': 1000000000
}