import%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20by%20Andreas%20Bauer%20and%20David%20Boehringer%2C%2019.06.2020%0A%20%20%20%20This%20script%20contains%20two%20examples%20for%203D-PIV%3A%20The%20shift%20of%20a%20bar%20of%20binary%20pixels%20in%20one%20direction%2C%20the%20expansion%0A%20%20%20%20and%20a%20real%20data%20set%20where%20we%20recorded%20two%20stacks%20of%20collagen%20fibres%20at%20the%20same%20field%20of%20view%20with%20confocal%20microscopy%0A%20%20%20%20%20in%20reflection%20mode.%20%20One%20stack%20contains%20a%20NK%20cell%20that%20deforms%20the%20matrix%20and%20the%20other%20doe%20not.%0A%20%20%20%20Please%20download%20the%20data%20at%20https%3A%2F%2Fgithub.com%2Ffabrylab%2F3D_piv_example_data.git%20(180%20MB%2C%20unpacked)%20and%20provide%20the%0A%20%20%20%20folder%20in%20the%20code%20below.%0A%20%20%20%20We%20tested%20this%20on%20ubuntu%2016%20and%2018%2C%20with%20Anaconda%20Python%20installation.%20The%20whole%20script%0A%20%20%20%20takes%20about%205%20minutes%20on%20my%204%20core-intel%20i5%20%402.5%20GHz%20Laptop.%20You%20should%20have%20!!!%208%20Gb%20ob%20Memory%20!!!!%20or%20take%20care%20not%0A%20%20%20%20to%20open%20%20all%20matplotlib%20plots%20as%20interactive%20windows%20at%20once.%0A%20%20%20%20For%20questions%20contact%20andreas.b.bauer%40fau.de%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aapp._unparsable_cell(%0A%20%20%20%20r%22%22%22%0A%20%20%20%20from%20openpiv.pyprocess3D%20import%20*%0A%20%20%20%20from%20openpiv.PIV_3D_plotting%20import%20*%0A%20%20%20%20from%20openpiv.validation%20import%20sig2noise_val%0A%20%20%20%20from%20openpiv.filters%20import%20replace_outliers%0A%20%20%20%20from%20openpiv.lib%20import%20replace_nans%0A%20%20%20%20import%20glob%20as%20glob%0A%20%20%20%20import%20os%0A%20%20%20%20from%20natsort%20import%20natsorted%0A%20%20%20%20import%20matplotlib.animation%20as%20animation%0A%20%20%20%20%22%22%22%2C%0A%20%20%20%20name%3D%22_%22%0A)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Make%20save_plots%20%3D%20True%20if%20you%20want%20to%20compare%20the%0A%20%20%20%20visual%20results%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(os)%3A%0A%20%20%20%20save_plots%20%3D%20False%0A%20%20%20%20out_put_folder%20%3D%20%22output_3D_test%22%0A%20%20%20%20if%20save_plots%3A%0A%20%20%20%20%20%20%20%20if%20not%20os.path.exists(out_put_folder)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20os.mkdir(out_put_folder)%0A%20%20%20%20%20%20%20%20%20%20%20%20except%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22could%20not%20generate%20output%20folder%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20save_plots%20%3D%20False%0A%20%20%20%20return%20out_put_folder%2C%20save_plots%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%23%23%23%23%23%23%23%23%23%20a%20group%20of%20bars%20shifted%20by%201%20pixel%20to%20the%20each%20dimesion%20the%20second%20frame%20%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%20%20%20%20takes%20~4%20seconds%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20%23%20constructing%20frame%201%20and%20frame%202%0A%20%20%20%20size%20%3D%20(32%2C%2032%2C%2032)%0A%20%20%20%20shape1%20%3D%20np.zeros(size)%0A%20%20%20%20shape2%20%3D%20np.zeros(size)%0A%20%20%20%20return%20shape1%2C%20shape2%0A%0A%0A%40app.cell%0Adef%20_(shape1)%3A%0A%20%20%20%20shape1%5B16%2C%2016%2C%2025%3A27%5D%20%3D%201%0A%20%20%20%20shape1%5B16%2C%2016%2C%207%3A9%5D%20%3D%201%0A%20%20%20%20shape1%5B16%2C%2025%3A27%2C%2016%5D%20%3D%201%0A%20%20%20%20shape1%5B16%2C%207%3A9%2C%2016%5D%20%3D%201%0A%20%20%20%20shape1%5B25%3A27%2C%2016%2C%2016%5D%20%3D%201%0A%20%20%20%20shape1%5B7%3A9%2C%2016%2C%2016%5D%20%3D%201%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(shape2)%3A%0A%20%20%20%20shape2%5B16%2C%2016%2C%2024%3A26%5D%20%3D%201%0A%20%20%20%20shape2%5B16%2C%2016%2C%208%3A10%5D%20%3D%201%0A%20%20%20%20shape2%5B16%2C%2024%3A26%2C%2016%5D%20%3D%201%0A%20%20%20%20shape2%5B16%2C%208%3A10%2C%2016%5D%20%3D%201%0A%20%20%20%20shape2%5B24%3A26%2C%2016%2C%2016%5D%20%3D%201%0A%20%20%20%20shape2%5B8%3A10%2C%2016%2C%2016%5D%20%3D%201%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20window_size%20%3D%20(4%2C%204%2C%204)%0A%20%20%20%20overlap%20%3D%20(3%2C%203%2C%203)%0A%20%20%20%20search_area%20%3D%20(5%2C%205%2C%205)%0A%20%20%20%20return%20overlap%2C%20search_area%2C%20window_size%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20extended_search_area_piv3D%2C%0A%20%20%20%20overlap%2C%0A%20%20%20%20search_area%2C%0A%20%20%20%20shape1%2C%0A%20%20%20%20shape2%2C%0A%20%20%20%20window_size%2C%0A)%3A%0A%20%20%20%20u%2C%20v%2C%20w%2C%20sig2noise%20%3D%20extended_search_area_piv3D(shape1%2C%20shape2%2C%20window_size%3Dwindow_size%2C%20overlap%3Doverlap%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20search_area_size%3Dsearch_area%2C%20subpixel_method%3D'gaussian'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sig2noise_method%3D'peak2peak'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20width%3D2)%0A%20%20%20%20return%20sig2noise%2C%20u%2C%20v%2C%20w%0A%0A%0A%40app.cell%0Adef%20_(quiver_3D%2C%20scatter_3D%2C%20shape1%2C%20shape2%2C%20sig2noise%2C%20u%2C%20v%2C%20w)%3A%0A%20%20%20%20%23%20magic%20command%20not%20supported%20in%20marimo%3B%20please%20file%20an%20issue%20to%20add%20support%0A%20%20%20%20%23%20%25pdb%20%0A%20%20%20%20%23%20displaying%20the%20shapes%20with%203D%20scatter%20plot%0A%20%20%20%20fig1%20%3D%20scatter_3D(shape1%2C%20control%3D%22size%22)%0A%20%20%20%20fig2%20%3D%20scatter_3D(shape2%2C%20control%3D%22size%22)%0A%20%20%20%20%23%203d%20plot%20of%20the%20signal-to-noise%20rations%0A%20%20%20%20fig3%20%3D%20scatter_3D(sig2noise%2C%20control%3D%22size%22)%0A%20%20%20%20%23%203d%20quiver%20plot%20of%20the%20displacement%20field%0A%20%20%20%20fig4%20%3D%20quiver_3D(-u%2C%20v%2C%20w%2C%20cmap%3D%22coolwarm%22%2C%20quiv_args%3D%7B%22arrow_length_ratio%22%3A0.6%7D)%0A%20%20%20%20return%20fig1%2C%20fig2%2C%20fig3%2C%20fig4%0A%0A%0A%40app.cell%0Adef%20_(fig1%2C%20fig2%2C%20fig3%2C%20fig4%2C%20os%2C%20out_put_folder%2C%20save_plots)%3A%0A%20%20%20%20%23%20saving%20the%20plots%0A%20%20%20%20if%20save_plots%3A%0A%20%20%20%20%20%20%20%20fig1.savefig(os.path.join(out_put_folder%2C%20%22displaced_bar_frame1.png%22))%0A%20%20%20%20%20%20%20%20fig2.savefig(os.path.join(out_put_folder%2C%20%22displaced_bar_frame2.png%22))%0A%20%20%20%20%20%20%20%20fig3.savefig(os.path.join(out_put_folder%2C%20%22displaced_bar_sig2noise.png%22))%0A%20%20%20%20%20%20%20%20fig4.savefig(os.path.join(out_put_folder%2C%20%22displaced_bar_deformation_field.png%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20test%20to%20check%20the%20replace_nans_function%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%20%20%20%20takes%20~4%20seconds%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20%23%20ball%20shape%20with%20a%20gap%20of%20nans%20in%20the%20middle%0A%20%20%20%20center%20%3D%20(5%2C%205%2C%205)%0A%20%20%20%20size_1%20%3D%20(10%2C%2010%2C%2010)%0A%20%20%20%20distance%20%3D%20np.linalg.norm(np.subtract(np.indices(size_1).T%2C%20np.asarray(center))%2C%20axis%3Dlen(center))%0A%20%20%20%20arr%20%3D%20np.ones(size_1)%20*%20(distance%20%3C%3D%205)%0A%20%20%20%20hide%20%3D%20arr%20%3D%3D%200%0A%20%20%20%20arr%5B5%3A7%5D%20%3D%20np.nan%0A%20%20%20%20return%20arr%2C%20hide%0A%0A%0A%40app.cell%0Adef%20_(arr%2C%20hide%2C%20np%2C%20replace_nans%2C%20scatter_3D)%3A%0A%20%20%20%20%23%20displaying%20in%203d%20plots.%20Values%20outside%20of%20the%20original%20ball%20are%20hidden%20by%20setting%20to%20nan%0A%20%20%20%20arr_show%20%3D%20arr.copy()%0A%20%20%20%20arr_show%5Bhide%5D%20%3D%20np.nan%0A%20%20%20%20fig9%20%3D%20scatter_3D(arr_show%2C%20size%3D50%2C%20sca_args%3D%7B'alpha'%3A%200.6%7D)%0A%20%20%20%20%23%20replacing%20outliers%0A%20%20%20%20arr_1%20%3D%20replace_nans(arr%2C%20max_iter%3D2%2C%20tol%3D2%2C%20kernel_size%3D2%2C%20method%3D'disk')%0A%20%20%20%20return%20arr_1%2C%20fig9%0A%0A%0A%40app.cell%0Adef%20_(arr_1%2C%20hide%2C%20np%2C%20scatter_3D)%3A%0A%20%20%20%20%23%20displaying%20in%203d%20plots.%20Values%20outside%20of%20the%20original%20ball%20are%20hidden%20by%20setting%20to%20nan%0A%20%20%20%20arr_show_1%20%3D%20arr_1.copy()%0A%20%20%20%20arr_show_1%5Bhide%5D%20%3D%20np.nan%0A%20%20%20%20fig10%20%3D%20scatter_3D(arr_show_1%2C%20size%3D50%2C%20sca_args%3D%7B'alpha'%3A%200.6%7D)%0A%20%20%20%20return%20(fig10%2C)%0A%0A%0A%40app.cell%0Adef%20_(fig10%2C%20fig9%2C%20os%2C%20out_put_folder%2C%20save_plots)%3A%0A%20%20%20%20%23%20saving%20the%20plots%0A%20%20%20%20if%20save_plots%3A%0A%20%20%20%20%20%20%20%20fig9.savefig(os.path.join(out_put_folder%2C%20%22replace_nan_gap.png%22))%0A%20%20%20%20%20%20%20%20fig10.savefig(os.path.join(out_put_folder%2C%20%22replace_nan_filled.png%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20real%20data%20example%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20we%20recorded%20stacks%20of%20collagen%20fibres%20with%20confocal%20microscopy%20in%20reflection%20mode%0A%20%20%20%20%22alive%22%20stack%20contains%20a%20force%20generating%20NK-cell%2C%20marked%20by%20the%20red%20circle%20in%20the%20animation%0A%20%20%20%20%22relaxed%22%20stack%20is%20the%20same%20field%20of%20view%20with%20out%20the%20cell%0A%20%20%20%20download%20the%20data%20at%20https%3A%2F%2Fgithub.com%2Ffabrylab%2F3D_piv_example_data.git%0A%20%20%20%20this%20calculation%20takes%20~%203-4%20minutes%20on%20my%204-core%20Intel%20i5%402.5%20GHz%20Laptop%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20please%20enter%20the%20path%20to%20the%20dataset%20provided%20at%0A%20%20%20%20folder%20%3D%20r%22test_3d%22%0A%20%20%20%20return%20(folder%2C)%0A%0A%0A%40app.cell%0Adef%20_(folder%2C%20os)%3A%0A%20%20%20%20if%20not%20os.path.exists(folder)%3A%20%0A%20%20%20%20%20%20%20%20import%20git%20%0A%20%20%20%20%20%20%20%20repo%20%3D%20git.Repo.clone_from(%22https%3A%2F%2Fgithub.com%2Ffabrylab%2F3D_piv_example_data.git%22%2C%20'.%2Ftest_3d'%2C%20branch%3D'master')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(folder%2C%20os)%3A%0A%20%20%20%20if%20not%20os.path.exists(folder)%3A%0A%20%20%20%20%20%20%20%20raise%20FileNotFoundError(%22path%20to%203d%20piv%20data%20'%25s'%20does%20not%20exists%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22.%20Please%20download%20the%20data%20from%20https%3A%2F%2Fgithub.com%2Ffabrylab%2F3D_piv_example_data.git%22%20%25%20folder)%0A%20%20%20%20%23%20stack%20properties%0A%20%20%20%20%23%20factors%20for%20voxel%20size%0A%20%20%20%20du%20%3D%200.2407%0A%20%20%20%20dv%20%3D%200.2407%0A%20%20%20%20dw%20%3D%201.0071%0A%20%20%20%20%23%20total%20image%20dimension%20for%20x%20y%20z%0A%20%20%20%20image_dim%20%3D%20(123.02%2C%20123.02%2C%20122.86)%0A%20%20%20%20return%20du%2C%20dv%2C%20dw%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20keep%20these%20values%20for%20our%20nk%20cells%20stacks%0A%20%20%20%20win_um%20%3D%2012%20%20%23%20window%20size%20in%20%C2%B5m%0A%20%20%20%20fac_overlap%20%3D%200.3%20%20%23%20overlap%20in%20percent%20of%20the%20window%20size%0A%20%20%20%20signoise_filter%20%3D%201.3%0A%20%20%20%20return%20fac_overlap%2C%20signoise_filter%2C%20win_um%0A%0A%0A%40app.cell%0Adef%20_(du%2C%20dv%2C%20dw%2C%20fac_overlap%2C%20win_um)%3A%0A%20%20%20%20%23%20window%20size%20for%20stacks%20in%20pixel%0A%20%20%20%20window_size_1%20%3D%20(int(win_um%20%2F%20du)%2C%20int(win_um%20%2F%20dv)%2C%20int(win_um%20%2F%20dw))%0A%20%20%20%20overlap_1%20%3D%20(int(fac_overlap%20*%20win_um%20%2F%20du)%2C%20int(fac_overlap%20*%20win_um%20%2F%20dv)%2C%20int(fac_overlap%20*%20win_um%20%2F%20dw))%0A%20%20%20%20search_area_1%20%3D%20(int(win_um%20%2F%20du)%2C%20int(win_um%20%2F%20dv)%2C%20int(win_um%20%2F%20dw))%0A%20%20%20%20return%20overlap_1%2C%20search_area_1%2C%20window_size_1%0A%0A%0A%40app.cell%0Adef%20_(folder%2C%20glob%2C%20natsorted%2C%20np%2C%20os%2C%20plt)%3A%0A%20%20%20%20%23%20load%20tense%20stacks%0A%20%20%20%20images%20%3D%20natsorted(glob.glob(os.path.join(folder%2C%20%22Series001_t22_z*_ch00.tif%22)))%0A%20%20%20%20im_shape%20%3D%20plt.imread(images%5B0%5D).shape%0A%20%20%20%20alive%20%3D%20np.zeros((im_shape%5B0%5D%2C%20im_shape%5B1%5D%2C%20len(images)))%0A%20%20%20%20for%20i%2C%20im%20in%20enumerate(images)%3A%0A%20%20%20%20%20%20%20%20alive%5B%3A%2C%20%3A%2C%20i%5D%20%3D%20plt.imread(im)%0A%20%20%20%20return%20(alive%2C)%0A%0A%0A%40app.cell%0Adef%20_(folder%2C%20glob%2C%20natsorted%2C%20np%2C%20os%2C%20plt)%3A%0A%20%20%20%20%23%20load%20relaxed%20stack%0A%20%20%20%20images_1%20%3D%20natsorted(glob.glob(os.path.join(folder%2C%20'Series003_t05_z*_ch00.tif')))%0A%20%20%20%20im_shape_1%20%3D%20plt.imread(images_1%5B0%5D).shape%0A%20%20%20%20relax%20%3D%20np.zeros((im_shape_1%5B0%5D%2C%20im_shape_1%5B1%5D%2C%20len(images_1)))%0A%20%20%20%20for%20i_1%2C%20im_1%20in%20enumerate(images_1)%3A%0A%20%20%20%20%20%20%20%20relax%5B%3A%2C%20%3A%2C%20i_1%5D%20%3D%20plt.imread(im_1)%0A%20%20%20%20return%20(relax%2C)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20alive%2C%0A%20%20%20%20du%2C%0A%20%20%20%20dv%2C%0A%20%20%20%20dw%2C%0A%20%20%20%20extended_search_area_piv3D%2C%0A%20%20%20%20overlap_1%2C%0A%20%20%20%20relax%2C%0A%20%20%20%20search_area_1%2C%0A%20%20%20%20window_size_1%2C%0A)%3A%0A%20%20%20%20%23%203D%20PIV%0A%20%20%20%20u_1%2C%20v_1%2C%20w_1%2C%20sig2noise_1%20%3D%20extended_search_area_piv3D(relax%2C%20alive%2C%20window_size%3Dwindow_size_1%2C%20overlap%3Doverlap_1%2C%20search_area_size%3Dsearch_area_1%2C%20dt%3D(1%20%2F%20du%2C%201%20%2F%20dv%2C%201%20%2F%20dw)%2C%20subpixel_method%3D'gaussian'%2C%20sig2noise_method%3D'peak2peak'%2C%20width%3D2)%0A%20%20%20%20return%20sig2noise_1%2C%20u_1%2C%20v_1%2C%20w_1%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20u_1%2C%20v_1%2C%20w_1)%3A%0A%20%20%20%20%23%20correcting%20stage%20drift%20between%20the%20field%20of%20views%0A%20%20%20%20u_2%20%3D%20u_1%20-%20np.nanmean(u_1)%0A%20%20%20%20v_2%20%3D%20v_1%20-%20np.nanmean(v_1)%0A%20%20%20%20w_2%20%3D%20w_1%20-%20np.nanmean(w_1)%0A%20%20%20%20return%20u_2%2C%20v_2%2C%20w_2%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20replace_outliers%2C%0A%20%20%20%20sig2noise_1%2C%0A%20%20%20%20sig2noise_val%2C%0A%20%20%20%20signoise_filter%2C%0A%20%20%20%20u_2%2C%0A%20%20%20%20v_2%2C%0A%20%20%20%20w_2%2C%0A)%3A%0A%20%20%20%20%23%20filtering%0A%20%20%20%20mask%20%3D%20sig2noise_val(sig2noise_1%2C%20threshold%3Dsignoise_filter)%0A%20%20%20%20uf%2C%20vf%2C%20wf%20%3D%20replace_outliers(u_2%2C%20v_2%2C%20mask%2C%20w%3Dw_2%2C%20max_iter%3D1%2C%20tol%3D100%2C%20kernel_size%3D2%2C%20method%3D'disk')%0A%20%20%20%20return%20uf%2C%20vf%2C%20wf%0A%0A%0A%40app.cell%0Adef%20_(plt)%3A%0A%20%20%20%20%23%20plotting%0A%20%20%20%20%23%20representation%20of%20the%20image%20stacks%20by%20maximums%20projections.%20The%20red%20circle%20marks%20the%20position%20of%20the%20cell%0A%20%20%20%20def%20update_plot(i%2C%20ims%2C%20ax)%3A%0A%20%20%20%20%20%20%20%20a1%20%3D%20ax.imshow(ims%5Bi%5D)%0A%20%20%20%20%20%20%20%20a2%20%3D%20ax.add_patch(plt.Circle((330%2C%20140)%2C%20100%2C%20color%3D%22red%22%2C%20fill%3DFalse))%0A%20%20%20%20%20%20%20%20return%20%5Ba1%2C%20a2%5D%0A%0A%20%20%20%20return%20(update_plot%2C)%0A%0A%0A%40app.cell%0Adef%20_(alive%2C%20animation%2C%20np%2C%20plt%2C%20relax%2C%20update_plot)%3A%0A%20%20%20%20ims%20%3D%20%5Bnp.max(relax%5B%3A%2C%20%3A%2C%2060%3A%5D%2C%20axis%3D2)%2C%20np.max(alive%5B%3A%2C%20%3A%2C%2060%3A%5D%2C%20axis%3D2)%5D%0A%20%20%20%20fig%20%3D%20plt.figure()%0A%20%20%20%20ax%20%3D%20plt.gca()%0A%20%20%20%20ani%20%3D%20animation.FuncAnimation(fig%2C%20update_plot%2C%202%2C%20interval%3D200%2C%20blit%3DTrue%2C%20repeat_delay%3D0%2C%20fargs%3D(ims%2C%20ax))%0A%20%20%20%20return%20(ims%2C)%0A%0A%0A%40app.cell%0Adef%20_(quiver_3D%2C%20u_2%2C%20v_2%2C%20w_2)%3A%0A%20%20%20%20%23%20unfiltered%203d%20deformation%20field%0A%20%20%20%20fig11%20%3D%20quiver_3D(-u_2%2C%20v_2%2C%20w_2%2C%20quiv_args%3D%7B'length'%3A%202%2C%20'alpha'%3A%200.8%2C%20'linewidth'%3A%201%7D%2C%20filter_def%3D0.1)%0A%20%20%20%20return%20(fig11%2C)%0A%0A%0A%40app.cell%0Adef%20_(quiver_3D%2C%20uf%2C%20vf%2C%20wf)%3A%0A%20%20%20%20%23%20filtered%203d%20deformation%20field%0A%20%20%20%20fig12%20%3D%20quiver_3D(-uf%2C%20vf%2C%20wf%2C%20quiv_args%3D%7B%22length%22%3A%202%2C%20%22alpha%22%3A%200.8%2C%20%22linewidth%22%3A%201%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20filter_def%3D0.1)%0A%20%20%20%20return%20(fig12%2C)%0A%0A%0A%40app.cell%0Adef%20_(fig11%2C%20fig12%2C%20ims%2C%20os%2C%20out_put_folder%2C%20plt%2C%20save_plots)%3A%0A%20%20%20%20%23%20saving%20the%20plots%0A%20%20%20%20if%20save_plots%3A%0A%20%20%20%20%20%20%20%20fig11.savefig(os.path.join(out_put_folder%2C%20%22real_data_unfiltered.png%22))%0A%20%20%20%20%20%20%20%20fig12.savefig(os.path.join(out_put_folder%2C%20%22real_data_filtered.png%22))%0A%0A%20%20%20%20%20%20%20%20%23%20This%20needs%20a%20working%20ImageMagick%20installation%2C%20and%20probably%20works%20only%20on%20linux%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20import%20imageio%0A%20%20%20%20%20%20%20%20%20%20%20%20plt.ioff()%0A%20%20%20%20%20%20%20%20%20%20%20%20f1%20%3D%20plt.figure()%0A%20%20%20%20%20%20%20%20%20%20%20%20plt.imshow(ims%5B0%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20plt.gca().add_artist(plt.Circle((330%2C%20140)%2C%20100%2C%20color%3D%22red%22%2C%20fill%3DFalse))%0A%20%20%20%20%20%20%20%20%20%20%20%20f1.savefig(os.path.join(out_put_folder%2C%22tem1.png%22))%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20f2%20%3D%20plt.figure()%0A%20%20%20%20%20%20%20%20%20%20%20%20plt.imshow(ims%5B1%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20plt.gca().add_artist(plt.Circle((330%2C%20140)%2C%20100%2C%20color%3D%22red%22%2C%20fill%3DFalse))%0A%20%20%20%20%20%20%20%20%20%20%20%20f2.savefig(os.path.join(out_put_folder%2C%22tem2.png%22))%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20i1%20%3D%20plt.imread(os.path.join(out_put_folder%2C%22tem1.png%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20i2%20%3D%20plt.imread(os.path.join(out_put_folder%2C%20%22tem2.png%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20imageio.mimsave(os.path.join(out_put_folder%2C%20%22reaL_data_max_proj.gif%22)%2C%5Bi1%2Ci2%5D%2C%20fps%3D1)%0A%20%20%20%20%20%20%20%20%20%20%20%20os.remove(os.path.join(out_put_folder%2C%22tem1.png%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20os.remove(os.path.join(out_put_folder%2C%22tem2.png%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20plt.ion()%0A%20%20%20%20%20%20%20%20except%20Exception%20as%20e%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print%20(%22failed%20to%20write%20gif%20of%20collagen%20embedded%20cell%3A%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(e)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
460dc198f6793af0909bb39e56c544cf