コード例 #1
0
    def _append_synapse_annotation_layer(
            self, viewer_state: ng.viewer_state.ViewerState, name: str,
            synapses: Synapses):
        annotations = []

        pre_synapses = synapses.pre_with_physical_coordinate
        self._append_point_annotation_layer(viewer_state, name + '_pre',
                                            pre_synapses)

        post_synapses = synapses.post_with_physical_coordinate
        if post_synapses is not None:
            for post_idx in range(post_synapses.shape[0]):
                pre_idx = post_synapses[post_idx, 0]
                pre_coordinate = pre_synapses[pre_idx, :]
                post_coordinate = post_synapses[post_idx, 1:]
                post_annotation = ng.LineAnnotation(
                    id=str(post_idx),
                    # note that the synapse coordinate is already in xyz order
                    # so we do not need to reverse it!
                    pointA=pre_coordinate,
                    pointB=post_coordinate,
                    props=['#0ff', 5])
                annotations.append(post_annotation)

        viewer_state.layers.append(
            name=name,
            layer=ng.LocalAnnotationLayer(
                dimensions=ng.CoordinateSpace(names=['z', 'y', 'x'],
                                              units="nm",
                                              scales=(1, 1, 1)),
                annotation_properties=[
                    ng.AnnotationPropertySpec(
                        id='color',
                        type='rgb',
                        default='red',
                    ),
                    ng.AnnotationPropertySpec(id='size',
                                              type='float32',
                                              default=5)
                ],
                annotations=annotations,
                shader='''
void main() {
  setColor(prop_color());
  setPointMarkerSize(prop_size());
}
''',
            ),
        )
コード例 #2
0
def pointlayer(txn,
               name,
               x,
               y,
               z,
               color="yellow",
               size=5,
               shader=pointlayer_shader,
               voxel_size=default_voxel_size):
    """Add a point layer.

    :param txn: the neuroglancer viewer transaction context
    :param name: the displayable name of the point layer
    :param x: the x coordinate per point
    :param y: the y coordinate per point
    :param z: the z coordinate per point
    :param color: the color of the points in the layer, e.g. "red", "yellow"
    :param size: the size of the points
    :param voxel_size: the size of a voxel (x, y, z)
    """

    dimensions = neuroglancer.CoordinateSpace(names=["x", "y", "z"],
                                              units=["µm", "µm", "µm"],
                                              scales=voxel_size)
    layer = neuroglancer.LocalAnnotationLayer(
        dimensions=dimensions,
        annotation_properties=[
            neuroglancer.AnnotationPropertySpec(
                id='color',
                type='rgb',
                default=color,
            ),
            neuroglancer.AnnotationPropertySpec(
                id='size',
                type='float32',
                default=float(size),
            )
        ],
        annotations=[
            neuroglancer.PointAnnotation(
                id=i + 1, point=[zz, yy,
                                 xx])  # input points should be in zyx order
            for i, (xx, yy, zz) in enumerate(zip(x, y, z))
        ],
        shader=shader)
    txn.layers[name] = layer
コード例 #3
0
    def _append_point_annotation_layer(
            self, viewer_state: ng.viewer_state.ViewerState, name: str,
            points: np.ndarray):
        annotations = []

        for sid in range(points.shape[0]):
            # we would like to show line first and then the presynapse point
            # so, we have distinct color to show T-bar
            pre_annotation = ng.PointAnnotation(id=str(sid),
                                                point=points[sid, :].tolist(),
                                                props=['#ff0', 8])
            annotations.append(pre_annotation)

        viewer_state.layers.append(
            name=name,
            layer=ng.LocalAnnotationLayer(
                dimensions=ng.CoordinateSpace(names=['z', 'y', 'x'],
                                              units="nm",
                                              scales=(1, 1, 1)),
                annotation_properties=[
                    ng.AnnotationPropertySpec(
                        id='color',
                        type='rgb',
                        default='red',
                    ),
                    ng.AnnotationPropertySpec(id='size',
                                              type='float32',
                                              default=5)
                ],
                annotations=annotations,
                shader='''
void main() {
  setColor(prop_color());
  setPointMarkerSize(prop_size());
}
''',
            ),
        )
コード例 #4
0
ファイル: points.py プロジェクト: VarunSane97/pyroglancer
def annotate_points(ngviewer, dimensions, pointscolor, points_df, layer_name,
                    layer_scale):
    """Annotate points from a dataframe (defunct do not use..).

    Parameters
    ----------
    ngviewer:        Neuroglancer viewer
    dimensions :     dimensions and units of 'x', 'y', 'z'
    points_df :      dataframe containing 'x', 'y', 'z' columns
    layer_scale :    scaling from voxel to native space in 'x', 'y', 'z'
    """
    pointname = points_df['description']
    points_df.loc[:, ['x', 'y', 'z'
                      ]] = points_df.loc[:, ['x', 'y', 'z']].values / 1000

    with ngviewer.txn() as s:
        s.layers.append(name=layer_name,
                        layer=neuroglancer.LocalAnnotationLayer(
                            dimensions=dimensions,
                            ignore_null_segment_filter=False,
                            annotation_properties=[
                                neuroglancer.AnnotationPropertySpec(
                                    id='color',
                                    type='rgb',
                                    default='blue',
                                )
                            ],
                            shader='''
                        void main() {
                          setColor(prop_color());
                          setPointMarkerSize(5.0);
                        }
                        ''',
                        ))
        for index, indivpoints in points_df.iterrows():
            s.layers[layer_name].annotations.append(
                neuroglancer.PointAnnotation(
                    id=str(index),
                    point=[
                        indivpoints.x * layer_scale[0],
                        indivpoints.y * layer_scale[1],
                        indivpoints.z * layer_scale[2]
                    ],
                    props=[pointscolor],
                    description=pointname[index]))

    status = True
    return status
コード例 #5
0
def test_annotate(webdriver):
    with webdriver.viewer.txn() as s:
        s.dimensions = neuroglancer.CoordinateSpace(names=["x", "y"],
                                                    units="nm",
                                                    scales=[1, 1])
        s.position = [0, 0]
        s.layers.append(
            name='seg1',
            layer=neuroglancer.SegmentationLayer(
                source=neuroglancer.LocalVolume(
                    dimensions=s.dimensions,
                    data=np.full(shape=(1, 1), dtype=np.uint32, fill_value=42),
                ),
            ),
            segments=[42],
            visible=False,
        )
        s.layers.append(
            name='seg2',
            layer=neuroglancer.SegmentationLayer(
                source=neuroglancer.LocalVolume(
                    dimensions=s.dimensions,
                    data=np.full(shape=(1, 1), dtype=np.uint32, fill_value=43),
                ),
            ),
            segments=[],
            visible=False,
        )
        s.layers.append(
            name="a",
            layer=neuroglancer.LocalAnnotationLayer(
                dimensions=s.dimensions,
                annotation_relationships=['a', 'b'],
                linked_segmentation_layer={'a': 'seg1', 'b': 'seg2'},
                filter_by_segmentation=['a', 'b'],
                ignore_null_segment_filter=False,
                annotation_properties=[
                    neuroglancer.AnnotationPropertySpec(
                        id='color',
                        type='rgb',
                        default='red',
                    )
                ],
                annotations=[
                    neuroglancer.PointAnnotation(
                        id='1',
                        point=[0, 0],
                        segments=[[42], []],
                        props=['#0f0'],
                    ),
                    neuroglancer.PointAnnotation(
                        id='2',
                        point=[0, 0],
                        segments=[[], [43]],
                        props=['#00f'],
                    ),
                    neuroglancer.PointAnnotation(
                        id='3',
                        point=[0, 0],
                        segments=[[], [44]],
                        props=['#0ff'],
                    ),
                ],
                shader='''
void main() {
  setColor(prop_color());
  setPointMarkerSize(1000.0);
}
''',
            ),
        )
        s.layout = 'xy'
        s.cross_section_scale = 1e-6
        s.show_axis_lines = False
        s.selected_layer.layer = 'a'

    def expect_color(seg1, seg2, color):
        with webdriver.viewer.txn() as s:
            s.layers['seg1'].segments = seg1
            s.layers['seg2'].segments = seg2
        screenshot = webdriver.viewer.screenshot(size=[10, 10]).screenshot
        np.testing.assert_array_equal(screenshot.image_pixels,
                                      np.tile(np.array(color, dtype=np.uint8), (10, 10, 1)))

    expect_color(seg1=[42], seg2=[], color=[0, 255, 0, 255])
    expect_color(seg1=[], seg2=[43], color=[0, 0, 255, 255])
    expect_color(seg1=[], seg2=[44], color=[0, 255, 255, 255])
コード例 #6
0
def annotate_synapses(ngviewer, dimensions, x):
    """Annotate postsynapses of a neuron/neuronlist. (defunct do not use..).

    This function annotates synapses of a neuron/neuronlist

    Parameters
    ----------
    x :             CatmaidNeuron | CatmaidNeuronList or TreeNeuron | NeuronList
    ngviewer:        Neuroglancer viewer


    """
    if isinstance(x, pymaid.core.CatmaidNeuron):
        neuronlist = pymaid.core.CatmaidNeuronList(x)
    elif isinstance(x, navis.core.TreeNeuron):
        neuronlist = navis.core.NeuronList(x)
    elif (isinstance(x, pymaid.core.CatmaidNeuronList) or isinstance(x, navis.core.NeuronList)):
        neuronlist = x
    else:
        raise TypeError(f'Expected neuron or neuronlist, got "{type(x)}"')

    skeldatasegidlist = []
    for neuron in neuronlist:
        skeldatasegidlist.append(neuron.id)

    # postsynapses first..
    with ngviewer.txn() as s:
        s.layers.append(
            name="post_synapses",
            layer=neuroglancer.LocalAnnotationLayer(
                dimensions=dimensions,
                annotation_relationships=['post_synapses'],
                linked_segmentation_layer={'post_synapses': 'skeletons'},
                filter_by_segmentation=['post_synapses'],
                ignore_null_segment_filter=False,
                annotation_properties=[
                    neuroglancer.AnnotationPropertySpec(
                        id='color',
                        type='rgb',
                        default='blue',
                    )
                ],
                shader='''
                        void main() {
                          setColor(prop_color());
                          setPointMarkerSize(5.0);
                        }
                        ''',
            ))

    with ngviewer.txn() as s:
        for neuronidx in range(len(neuronlist)):
            neuronelement = neuronlist[neuronidx]
            postsynapses = neuronelement.postsynapses
            postsynapses = postsynapses.reset_index()

            for index, postsyn in postsynapses.iterrows():
                s.layers['post_synapses'].annotations.append(
                    neuroglancer.PointAnnotation(
                        id=str(index),
                        point=[postsyn.x/1000, postsyn.y/1000, postsyn.z/1000],
                        segments=[[skeldatasegidlist[neuronidx]]],
                        props=['#0000ff'],
                    )
                )

    # presynapses next..
    with ngviewer.txn() as s:
        s.layers.append(
            name="pre_synapses",
            layer=neuroglancer.LocalAnnotationLayer(
                dimensions=dimensions,
                annotation_relationships=['pre_synapses'],
                linked_segmentation_layer={'pre_synapses': 'skeletons'},
                filter_by_segmentation=['pre_synapses'],
                ignore_null_segment_filter=False,
                annotation_properties=[
                    neuroglancer.AnnotationPropertySpec(
                        id='color',
                        type='rgb',
                        default='red',
                    )
                ],
                shader='''
                        void main() {
                          setColor(prop_color());
                          setPointMarkerSize(5.0);
                        }
                        ''',
            ))

    with ngviewer.txn() as s:
        for neuronidx in range(len(neuronlist)):
            neuronelement = neuronlist[neuronidx]
            presynapses = neuronelement.presynapses
            presynapses = presynapses.reset_index()

            for index, presyn in presynapses.iterrows():
                s.layers['pre_synapses'].annotations.append(
                    neuroglancer.PointAnnotation(
                        id=str(index),
                        point=[presyn.x/1000, presyn.y/1000, presyn.z/1000],
                        segments=[[skeldatasegidlist[neuronidx]]],
                        props=['#ff0000'],
                    )
                )

    status = True
    return status
 args = ap.parse_args()
 neuroglancer.cli.handle_server_arguments(args)
 viewer = neuroglancer.Viewer()
 with viewer.txn() as s:
     s.dimensions = neuroglancer.CoordinateSpace(names=["x", "y"],
                                                 units="nm",
                                                 scales=[1, 1])
     s.position = [150, 150]
     s.layers.append(
         name="a",
         layer=neuroglancer.LocalAnnotationLayer(
             dimensions=s.dimensions,
             annotation_properties=[
                 neuroglancer.AnnotationPropertySpec(
                     id='color',
                     type='rgb',
                     default='red',
                 ),
                 neuroglancer.AnnotationPropertySpec(
                     id='size',
                     type='float32',
                     default=10,
                 )
             ],
             annotations=[
                 neuroglancer.PointAnnotation(
                     id='1',
                     point=[150, 150],
                     props=['#0f0', 5],
                 ),
                 neuroglancer.PointAnnotation(