Skip to content

Commit

Permalink
docs(python): add example_coordinate_transform.py
Browse files Browse the repository at this point in the history
Fixes #517.
  • Loading branch information
jbms committed Jan 18, 2024
1 parent 45f6578 commit e43ed3c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions python/examples/example_coordinate_transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import argparse

import neuroglancer
import neuroglancer.cli
import numpy as np

if __name__ == "__main__":
ap = argparse.ArgumentParser()
neuroglancer.cli.add_server_arguments(ap)
args = ap.parse_args()
neuroglancer.cli.handle_server_arguments(args)
viewer = neuroglancer.Viewer()

ix, iy, iz = np.meshgrid(
*[np.linspace(0, 1, n) for n in [100, 100, 100]], indexing="ij"
)
data = np.cast[np.uint32](
np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10)
)
data = np.pad(data, 1, "constant")
dimensions = neuroglancer.CoordinateSpace(
names=["x", "y", "z"], units="nm", scales=[10, 10, 10]
)

with viewer.txn() as s:
s.dimensions = dimensions
s.layers["original"] = neuroglancer.SegmentationLayer(
source=[
neuroglancer.LayerDataSource(
neuroglancer.LocalVolume(data=data, dimensions=dimensions)
)
],
)
s.layers["transformed"] = neuroglancer.SegmentationLayer(
source=[
neuroglancer.LayerDataSource(
neuroglancer.LocalVolume(data=data, dimensions=dimensions),
transform=neuroglancer.CoordinateSpaceTransform(
output_dimensions=dimensions,
matrix=[[1, 0, 0, 0], [1, 1, 0, 0], [0, 0, 1, 0]],
),
)
],
)
print(viewer)

0 comments on commit e43ed3c

Please sign in to comment.