Skip to content

Commit

Permalink
feat: more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
seankmartin committed Jul 30, 2024
1 parent 712f4c5 commit 499759f
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,5 @@ cython_debug/
#.idea/

*/node_modules/
examples/datasets
examples/datasets/
datasets/
51 changes: 51 additions & 0 deletions examples/histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import argparse
import webbrowser
import neuroglancer
import numpy as np
import neuroglancer.cli


def add_image_layer(state):
shape = (40,) * 3
dimensions = neuroglancer.CoordinateSpace(
names=["x", "y", "z"], units="nm", scales=[40, 40, 40]
)
data = np.zeros(shape=shape, dtype=np.uint8)
data[:10] = 0
data[10:20] = 1
data[20:30] = 2
data[30:] = 3
local_volume = neuroglancer.LocalVolume(data, dimensions)
state.layers.append(
name="image",
layer=neuroglancer.ImageLayer(
source=local_volume,
volume_rendering_mode="max",
volume_rendering_depth_samples=40,
),
shader="""
#uicontrol invlerp normalized(range=[1,2])
void main() {
emitGrayscale(normalized());
}
""",
)


def launch_nglancer():
ap = argparse.ArgumentParser()
neuroglancer.cli.add_server_arguments(ap)
args = ap.parse_args()
neuroglancer.cli.handle_server_arguments(args)
viewer = neuroglancer.Viewer()
return viewer


def main():
viewer = launch_nglancer()
with viewer.txn() as s:
add_image_layer(s)
webbrowser.open_new(viewer.get_viewer_url())

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion examples/max_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def add_image_layer(state):
)
local_volume = neuroglancer.LocalVolume(create_volume(), dimensions)
state.layers["image"] = neuroglancer.ImageLayer(
source=local_volume, volume_rendering_mode="MAX", shader=get_shader()
source=local_volume, volume_rendering_mode="max", shader=get_shader()
)
state.layout = "3d"
state.show_axis_lines = False
Expand Down
48 changes: 48 additions & 0 deletions examples/minimal_max.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import argparse
import webbrowser
import neuroglancer
import numpy as np
import neuroglancer.cli


def add_image_layer(state):
shape = (50,) * 3
dimensions = neuroglancer.CoordinateSpace(
names=["x", "y", "z"], units="nm", scales=[40, 40, 40]
)
data = np.full(shape=shape, fill_value=255, dtype=np.uint8)
local_volume = neuroglancer.LocalVolume(data, dimensions)
state.layers.append(
name="image",
layer=neuroglancer.ImageLayer(
source=local_volume,
volume_rendering_mode="max",
volume_rendering_depth_samples=400,
),
shader="""
void main() {
emitIntensity(1.0);
emitRGBA(vec4(1.0, 1.0, 1.0, 0.01));
}
""",
)
state.layout = "3d"


def launch_nglancer():
ap = argparse.ArgumentParser()
neuroglancer.cli.add_server_arguments(ap)
args = ap.parse_args()
neuroglancer.cli.handle_server_arguments(args)
viewer = neuroglancer.Viewer()
return viewer


def main():
viewer = launch_nglancer()
with viewer.txn() as s:
add_image_layer(s)
webbrowser.open_new(viewer.get_viewer_url())

if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions examples/serve_default_dir.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from neuroglancer_utils.create_datasets.create_full_cube import create_cube
from neuroglancer_utils.create_datasets.create_sphere import create_sphere
from neuroglancer_utils.create_datasets.create_allen_multi import create_allen_multi
from neuroglancer_utils.create_datasets.create_cdf_example import create_cdf_example
from neuroglancer_utils.local_server import create_server

create_cube()
create_sphere()
create_allen_multi()
create_server(directory="datasets")
create_cdf_example()
input("Press enter to continue")
20 changes: 20 additions & 0 deletions neuroglancer_utils/create_datasets/create_cdf_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from cloudvolume import CloudVolume
import numpy as np


def create_cdf_example(output_path="file://datasets/cdf"):
shape = (40,) * 3
data = np.zeros(shape=shape, dtype=np.uint8)
data[:10] = 0
data[10:20] = 1
data[20:30] = 2
data[30:] = 3
CloudVolume.from_numpy(
data,
vol_path=output_path,
resolution=(40, 40, 40),
chunk_size=(40, 40, 40),
layer_type="image",
progress=True,
compress=False,
)

0 comments on commit 499759f

Please sign in to comment.