Package: napari-assistant-plugin-generator
napari-assistant-plugin-generatorThe napari-assistant-plugin-generator is anapariplugin to generate python code which can be pip-installed and serve as napari-plugin compatible with thenapari-assistant.UsageFor demonstrating how one can generate a Napari plugin from an existing workflow, we demonstrate the procedure by reusing function fromnapari-segment-blobs-and-things-with-membranes(nsbatwm) for generating a plugin.After installing nsbatwm you can start the assistant from the menuTools > Utilities > Assistant (na)or runnapariafrom the command line.Open the blobs example imageBlobs, e.g. after downloading it fromhere.In the Assistant, click on theRemove noisebutton and selectGaussian (scikit-image, nsbatwm)from the operation pulldown.Click theBinarizebutton and selectThreshold (Otsu 1979, scikit-image, nsbatwm)operation.Click theLabelbutton and select 'Connected component labeling (scikit-image, nsbatwm)' from the operation pulldown.Afterwards, your Napari with the configured workflow should look like this:Plugin generationBefore running the plugin-generator, make sure you are connected to the internet,
because aplugin templatewill be downloaded.
The plugin generator can be found in the menuTools > Utilities > Generate Napari plugin from workflow (na)and also
in theGenerate code...of the Assistant:In the plugin generator dialog, please enter this information:output dir:Folder where the Napari plugin code should be saved. If not specified, the plugin will be stored in the current directory Napari was started from.plugin name:Name of the plugin. A folder with this name will be generated in the folder specified above. Plugin names must not contain special characters or spaces. Use_instead.developer name:Your name as it will be displayed later on thenapari-hubin case you decide to publish your plugin.developer email:Your email as it will be stored in the configuration of your plugin. This email-address is visible to the public.github username:Your username ongithub. URLs in the plugin documentation will point to your profile on github.short description:Please write one sentence explaining what the plugin is doing.license:Choose the open-source license your plugin code will be licensed. If you are not sure which one to use, consultchoosealicense.com.tools menuThe menu underToolswhere your plugin will be found after installing it.menu nameThe menu entry will have this title.After the Napari plugin code has been generated, open it in the integrated development environment (IDE) of your choice.
Go through the files in the directory and search forTODOentries. Start with thereadme.mdand therequirements.txtfiles:Highly relevant might be the python filemy_napari_assistant_plugin/_function.py. It contains a function with python code representing the workflow we designed by clicking above:fromnapari_plugin_engineimportnapari_hook_implementationfromnapari_tools_menuimportregister_functionfromnapari_time_slicerimporttime_slicer@napari_hook_implementationdefnapari_experimental_provide_function():return[process_image]@register_function(menu="Segmentation / labeling > Segment image")@time_slicerdefprocess_image(image0_b:"napari.types.ImageData",gaussian_blur_sigma_2:float=1.0,connected_component_labeling_exclude_on_edges_3:bool=False)->"napari.types.LabelsData":"""Short plugin description# TODO: Provide more detailed documentation here. E.g. specify the parameters and what values users should enter."""# TODO: Check the list of parameters of the function definition above.# If there are parameters that should not be editable by the end user, move their definition and values here instead.importnapari_segment_blobs_and_things_with_membranesasnsbatwm# version 0.3.3# gaussian blurimage1_G=nsbatwm.gaussian_blur(image0_b,sigma=gaussian_blur_sigma_2)# threshold otsuimage2_T=nsbatwm.threshold_otsu(image1_G)# connected component labelingimage3_C=nsbatwm.connected_component_labeling(image2_T,exclude_on_edges=connected_component_labeling_exclude_on_edges_3)returnimage3_CIt is recommended to inspect the generated code and rename variables to be more meaningful.
For renaming variables, make use of your IDE's tools.
For example variables can be renamed conveniently inpycharmusing the right-click menu:Thereadme.mdfile also contains instructions for how to install and distribute your plugin.
TL:DR: As a plugin developer you typically execute this command from the terminal within your plugin's root directory to install your plugin in aneditable.
This command allows you to modify the code and test it without the need for re-installing your plugin.pip install -e .If installation was successful, you will find your plugin in the menu you specified and a dialog will open requesting the parameters of the generated Python function in<your_plugin_folder>/<your_plugin_folder>/_function.py:InstallationIt is recommended to installdevbio-naparifirst. It comes with many image processing functions that can be combined in workflows and where it is easy to generate plugins from.Afterwards, the plugin generator can be installed usingpip:pip install napari-assistant-plugin-generatorAlso make sure you havegitinstalled. E.g. usingmamba/conda:mamba install gitFeedback welcome!The napari-assistant is developed in the open because we believe in the open source community. Feel free to drop feedback asgithub issueor viaimage.scContributingContributions are very welcome. Please ensure
the test coverage at least stays the same before you submit a pull request.LicenseDistributed under the terms of theBSD-3license,
"napari-assistant-plugin-generator" is free and open source softwareAcknowledgementsThis project was supported by the Deutsche Forschungsgemeinschaft under Germany’s Excellence Strategy – EXC2068 - Cluster of Excellence "Physics of Life" of TU Dresden.
This project has been made possible in part by grant number2021-240341 (Napari plugin accelerator grant)from the Chan Zuckerberg Initiative DAF, an advised fund of the Silicon Valley Community Foundation.