Package: napari-macrokit
napari-macrokitExecutable script generation for napari plugins.↑Exampleshowing the real-time recording of GUI operation.This napari plugin aims at making image analysis reproducible with arbitrary input/output types.UsageCreate a macro object, decorate functions withrecordmethod and run!fromnapari_macrokitimportget_macromacro=get_macro("my-plugin-specifier")# get macro object# define a function@macro.recorddefadd(a:float,b:float)->float:returna+b# runresult=add(3.2,5.4)add(result,1.0)macro# Out:# >>> float0 = add(3.2, 5.4)# >>> float1 = add(float0, 1.0)Record GUI OperationsYou can use recordable functions in your widgets to keep tracks of GUI operations.
More simply, you can double-decorate functions withrecordandmagicgui.importnumpyasnpfrommagicguiimportmagicguiimportnaparifromnapari.typesimportImageDatafromnapari_macrokitimportget_macromacro=get_macro("my-plugin-specifier")# get macro object# define recordable magicgui@magicgui@macro.recorddefadd(image:ImageData,b:float)->ImageData:returnimage+bviewer=napari.Viewer()# launch a viewerviewer.add_image(np.random.random((100,100)))# image dataviewer.window.add_dock_widget(add)# add magicgui to the viewerRunning add twice in GUI and you'll find macro updated like below.macro# Out# >>> image0 = add(viewer.layers['Image'].data, 0.06)# >>> image1 = add(image0, 0.12)Combining PluginsSuppose you have two modules that usenapari-macrokit.# napari_module_0.pyfromnapari.typesimportImageDatafromscipyimportndimageasndifromnapari_macrokitimportget_macromacro=get_macro("napari-module-0")@macro.recorddefgaussian_filter(image:ImageData,sigma:float)->ImageData:returnndi.gaussian_filter(image,sigma=sigma)@macro.recorddefthreshold(image:ImageData,value:float)->ImageData:returnimage>value# napari_module_1.pyfromnapari.typesimportImageDataimportnumpyasnpfromnapari_macrokitimportget_macromacro=get_macro("napari-module-1")@macro.recorddefestimate_background(image:ImageData)->float:returnnp.percentile(image,10.0)You can use functions from both modules to build an analysis workflow by collecting existing macro objects withcollect_macrofunction. All the recordable actions in the modules will also be recorded to the returned macro object.importnumpyasnpfromnapari_macrokitimportcollect_macrofromnapari_module_0importgaussian_filter,thresholdfromnapari_module_1importestimate_background# global_macro will record all the macro available at this pointglobal_macro=collect_macro()# start image analysis!image=np.random.random((100,100))out=gaussian_filter(image,2.0)thresh=estimate_background(out)binary=threshold(out,thresh)macro# Out# >>> image0 = gaussian_filter(arr0, 2.0)# >>> float0 = estimate_background(image0)# >>> image1 = threshold(image1, float0)Thisnapariplugin was generated withCookiecutterusing@napari'scookiecutter-napari-plugintemplate.InstallationYou can installnapari-macrokitviapip:pip install napari-macrokitTo install latest development version :pip install git+https://github.com/hanjinliu/napari-macrokit.gitContributingContributions are very welcome. Tests can be run withtox, please ensure
the coverage at least stays the same before you submit a pull request.LicenseDistributed under the terms of theBSD-3license,
"napari-macrokit" is free and open source softwareIssuesIf you encounter any problems, pleasefile an issuealong with a detailed description.