From cdb7248ef52ee414051c0737311901d4810267e0 Mon Sep 17 00:00:00 2001 From: Jordao Bragantini Date: Thu, 11 May 2023 13:56:35 -0700 Subject: [PATCH] first commit --- .gitignore | 1 + LICENSE | 29 +++++++++++++++++++++++++++ README.md | 17 ++++++++++++++++ main.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 3 +++ 5 files changed, 102 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2641667 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.mp4 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..85da9d3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2023, Royerlab +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cf83a20 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Zebrahub's `napari-animation` Demo + +This repository contains an example of how the videos from the zebrahub articles were rendered. + +## Installation + +``` +pip install -r requirements.txt +``` + +## Usage + +Edit the `MULTISCALE` variable inside the script to load a lower or higher resolution version of the dataset. + +``` +python main.py +``` diff --git a/main.py b/main.py new file mode 100644 index 0000000..67fdef1 --- /dev/null +++ b/main.py @@ -0,0 +1,52 @@ +import napari +from napari_animation import Animation + + +def main() -> None: + # toggle multiscale to tradeoff between speed and resolution + MULTISCALE = False + + viewer = napari.Viewer() + + viewer.open( + "http://public.czbiohub.org/royerlab/zebrahub/imaging/multi-view/ZMNS001.ome.zarr", + plugin="napari-ome-zarr", + rendering="attenuated_mip", + gamma=0.7, + ) + + # disabling multiscale + if not MULTISCALE: + for channel in ("mezzo", "h2afva"): + viewer.layers[channel].multiscale = False + viewer.layers[channel].data = viewer.layers[channel].data[0] + + # aesthetics changes + viewer.layers["h2afva"].colormap = "cyan" + viewer.layers["h2afva"].contrast_limits = (50, 850) + viewer.layers["mezzo"].colormap = "magenta" + viewer.layers["mezzo"].contrast_limits = (50, 500) + + # making it 3D + viewer.dims.ndisplay = 3 + + # setting t = 0 + viewer.dims.set_point(0, 0) + + # starting recording + animation = Animation(viewer) + animation.capture_keyframe() + + # setting t = 220 + viewer.dims.set_point(0, 220) + + # updating contrasts + viewer.layers["h2afva"].contrast_limits = (50, 2500) + + # ending recording + animation.capture_keyframe(600) + animation.animate('video.mp4', fps=60) + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2316002 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +napari==0.4.17 +napari-animation +napari-ome-zarr==0.5.2