Package: microfilm
microfilmThis package is a collection of tools to display and analyze 2D and 2D time-lapse microscopy images. In particular it makes it straightforward to create figures containing multi-channel images represented in acompositecolor mode as done in the popular image processing softwareFiji. It also allows to easily complete such figures with standard annotations likelabelsandscale bars. In case of time-lapse data, the figures are turned intoanimationswhich can be interactively browsed from a Jupyter notebook, saved in standard movie formats (mp4, gif etc.) and completed withtime counters. Finally, figures and animations can easily be combined into largerpanels. These main functionalities are provided by themicrofilm.microplotandmicrofilm.microanimmodules.Following the model ofseaborn,microfilmis entirely based onMatplotliband tries to provide good defaults to produce good microcopy figuresout-of-the-box. It however also offers complete access to the Matplotlib structures like axis and figures underlying themicrofilmobjects, allowing thus for the creation of arbitrarily complex plots.InstallationYou can install this package directly with pip using:pip install microfilmTo get the latest stage of the package with yet unreleased features use:pip install git+https://github.com/guiwitz/microfilm.gitTo test the package via the Jupyter interface and the notebooks availablehereyou can create a conda environment using theenvironment.ymlfile:conda env create -f environment.ymlOptional installsIf you want to use thedatasetsubmodule (see below in Additional functionalities) and need to handle multipage tiff files or nd2 files, use:pip install "microfilm[multipage]"orpip install "microfilm[nd2]"If you plan to not just use simple plotting but want to create animations, you need to install:pip install "microfilm[animation]"To install all options use:pip install "microfilm[all]"Simple plotIt is straightforward to create a ready-to-use plot of a multi-channel image dataset. In the following code snippet, we load a Numpy array of a multi-channel time-lapse dataset with shapeCTXY(three channels). The figure below showing the time-pointt=10is generated in a single command with a few options and saved as a png:importnumpyasnpimportskimage.iofrommicrofilm.microplotimportmicroshowimage=skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')time=10microim=microshow(images=image[:,time,:,:],fig_scaling=5,cmaps=['pure_blue','pure_red','pure_green'],unit='um',scalebar_size_in_units=3,scalebar_unit_per_pix=0.065,scalebar_font_size=20,label_text='A',label_font_size=0.04)microim.savefig('../illustrations/composite.png',bbox_inches='tight',pad_inches=0,dpi=600)AnimationIt is then easy to extend a simple figure into an animation as both objects take the same options. Additionally, a time-stamp can be added to the animation. This code generates the movie visible below:importnumpyasnpimportskimage.iofrommicrofilm.microanimimportMicroanimimage=skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')microanim=Microanim(data=image,cmaps=['pure_blue','pure_red','pure_green'],fig_scaling=5,unit='um',scalebar_size_in_units=3,scalebar_unit_per_pix=0.065,scalebar_thickness=0.02,scalebar_font_size=20)microanim.add_label('A',label_font_size=30)microanim.add_time_stamp('T',10,location='lower left',timestamp_size=20)microanim.save_movie('../illustrations/composite_movie.gif',fps=15)PanelsBoth simple figures and animations can be combined into larger panels via themicroplot.Micropanelandmicroanim.Microanimpanelobjects. For example we can first create two figuresmicroim1andmicroim2and then combine them intomicropanel:frommicrofilmimportmicroplotimportskimage.ioimage=skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')microim1=microplot.microshow(images=[image[0,10,:,:],image[1,10,:,:]],cmaps=['Greys','pure_magenta'],flip_map=[False,False],label_text='A',label_color='black')microim2=microplot.microshow(images=[image[0,10,:,:],image[2,10,:,:]],cmaps=['Greys','pure_cyan'],flip_map=[False,False],label_text='B',label_color='black')micropanel=microplot.Micropanel(rows=1,cols=2,figsize=[4,3])micropanel.add_element(pos=[0,0],microim=microim1)micropanel.add_element(pos=[0,1],microim=microim2)micropanel.savefig('../illustrations/panel.png',bbox_inches='tight',pad_inches=0,dpi=600)And similarly for animations:frommicrofilmimportmicroanimimportskimage.ioimage=skimage.io.imread('../demodata/coli_nucl_ori_ter.tif')microanim1=microanim.Microanim(data=image[[0,1],::],cmaps=['Greys','pure_magenta'],flip_map=[False,False],label_text='A',label_color='black')microanim2=microanim.Microanim(data=image[[0,2],::],cmaps=['Greys','pure_cyan'],flip_map=[False,False],label_text='B',label_color='black')microanim1.add_time_stamp(unit='T',unit_per_frame='3',location='lower-right',timestamp_color='black')animpanel=microanim.Microanimpanel(rows=1,cols=2,figsize=[4,3])animpanel.add_element(pos=[0,0],microanim=microanim1)animpanel.add_element(pos=[0,1],microanim=microanim2)animpanel.save_movie('../illustrations/panel.gif')Additional functionalitiesIn addition to these main plotting capabilities, the packages also offers:microfilm.colorify: a series of utility functions used by the main functions to create the composite color images. It contains functions to create colormaps, to turn 2D arrays into 3D-RGB arrays with appropriate colormaps etc.microfilm.dataset: a module offering a simple common data structure to handle multi-channel time-lapse data from multipage tiffs, series of tiff files, Nikon ND2 files, H5 and Numpy arrays. Requirement to use this module are at the moment very constrained (e.g. dimension order of Numpy arrays, name of H5 content etc.) but might evolve in the future.AuthorsThis package has been created by Guillaume Witz, Microscopy Imaging Center and Science IT Support, University of Bern.