diff --git a/.gitignore b/.gitignore index 23910be..e96bc05 100644 --- a/.gitignore +++ b/.gitignore @@ -160,4 +160,5 @@ cython_debug/ #.idea/ */node_modules/ -examples/datasets \ No newline at end of file +examples/datasets/ +datasets/ \ No newline at end of file diff --git a/examples/histogram.py b/examples/histogram.py new file mode 100644 index 0000000..fbcfda1 --- /dev/null +++ b/examples/histogram.py @@ -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() diff --git a/examples/max_projection.py b/examples/max_projection.py index 11e1cee..4ebadbe 100644 --- a/examples/max_projection.py +++ b/examples/max_projection.py @@ -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 diff --git a/examples/minimal_max.py b/examples/minimal_max.py new file mode 100644 index 0000000..3b3f305 --- /dev/null +++ b/examples/minimal_max.py @@ -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() diff --git a/examples/serve_default_dir.py b/examples/serve_default_dir.py index be57274..57193e1 100644 --- a/examples/serve_default_dir.py +++ b/examples/serve_default_dir.py @@ -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") diff --git a/neuroglancer_utils/create_datasets/create_cdf_example.py b/neuroglancer_utils/create_datasets/create_cdf_example.py new file mode 100644 index 0000000..c0d94b7 --- /dev/null +++ b/neuroglancer_utils/create_datasets/create_cdf_example.py @@ -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, + )