%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.11%22%0A%23%20dependencies%20%3D%20%5B%0A%23%20%20%20%20%20%22marimo%22%2C%0A%23%20%20%20%20%20%22openpiv%3D%3D0.26.3%22%2C%0A%23%20%20%20%20%20%22numpy%22%2C%0A%23%20%20%20%20%20%22matplotlib%22%2C%0A%23%20%20%20%20%20%22scipy%22%2C%0A%23%20%20%20%20%20%22scikit-image%22%2C%0A%23%20%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Test%20case%3A%20test7%0A%0A%20%20%20%20This%20page%20demonstrates%20the%20**test7**%20dataset%2Fcase%20from%20the%20OpenPIV%20examples%20repository.%0A%0A%20%20%20%20%23%23%20What%20this%20case%20is%20for%0A%20%20%20%20-%20Explore%20the%20images%20and%20data%20included%20in%20%60test7%2F%60.%0A%20%20%20%20-%20Learn%20how%20to%20run%20PIV%20on%20this%20case%20and%20what%20to%20look%20for%20(seeding%2C%20displacement%2C%20noise%2C%20masks%2C%20etc.).%0A%20%20%20%20-%20Use%20it%20as%20a%20starting%20point%3A%20adjust%20window%20size%2C%20overlap%2C%20dt%2C%20and%20validation%20for%20your%20needs.%0A%0A%20%20%20%20**%5BOpen%20in%20molab%20(interactive)%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FOpenPIV%2Fopenpiv-python-examples%2Fblob%2Fmain%2Fmarimo_cases%2Ftest7.py)**%0A%0A%20%20%20%20**Files%20(sample)%3A**%20E001_1.tif%2C%20E001_1.tif.txt%2C%20E001_2.tif%0A%0A%20%20%20%20*Note%3A%20when%20running%20in%20molab%2Fcloud%2C%20this%20notebook%20downloads%20the%20case%20files%20from%20GitHub%20automatically.*%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20os%2C%20glob%2C%20urllib.request%0A%20%20%20%20case_name%20%3D%20'test7'%0A%20%20%20%20base_url%20%3D%20'https%3A%2F%2Fraw.githubusercontent.com%2FOpenPIV%2Fopenpiv-python-examples%2Fmain'%20%2B%20%22%2F%22%20%2B%20case_name%0A%20%20%20%20case_files%20%3D%20%5B'E001_1.tif'%2C%20'E001_1.tif.txt'%2C%20'E001_2.tif'%5D%0A%20%20%20%20os.makedirs(case_name%2C%20exist_ok%3DTrue)%0A%20%20%20%20for%20name%20in%20case_files%3A%0A%20%20%20%20%20%20%20%20dest%20%3D%20os.path.join(case_name%2C%20name)%0A%20%20%20%20%20%20%20%20if%20not%20os.path.exists(dest)%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%20urllib.request.urlretrieve(base_url%20%2B%20%22%2F%22%20%2B%20name%2C%20dest)%0A%20%20%20%20%20%20%20%20%20%20%20%20except%20Exception%20as%20e%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22skip%22%2C%20name%2C%20e)%0A%20%20%20%20file_list%20%3D%20sorted(glob.glob(case_name%20%2B%20%22%2F*%22))%0A%20%20%20%20print(%22Files%20in%20case%3A%22)%0A%20%20%20%20for%20fpath%20in%20file_list%5B%3A30%5D%3A%0A%20%20%20%20%20%20%20%20print(%22%20-%22%2C%20os.path.basename(fpath))%0A%20%20%20%20return%20(case_name%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%20Load%20and%20display%20images%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(case_name)%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt1%0A%20%20%20%20from%20openpiv%20import%20tools%0A%20%20%20%20from%20os.path%20import%20join%2C%20exists%0A%20%20%20%20img_a_path%20%3D%20'E001_1.tif'%0A%20%20%20%20img_b_path%20%3D%20'E001_2.tif'%0A%20%20%20%20img_a%20%3D%20tools.imread(join(case_name%2C%20img_a_path))%20if%20img_a_path%20and%20exists(join(case_name%2C%20img_a_path))%20else%20None%0A%20%20%20%20img_b%20%3D%20tools.imread(join(case_name%2C%20img_b_path))%20if%20img_b_path%20and%20exists(join(case_name%2C%20img_b_path))%20else%20None%0A%20%20%20%20if%20img_a%20is%20not%20None%20and%20img_b%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20fig1%2C%20ax1%20%3D%20plt1.subplots(1%2C%202%2C%20figsize%3D(8%2C%204))%0A%20%20%20%20%20%20%20%20ax1%5B0%5D.imshow(img_a%2C%20cmap%3D%22gray%22)%3B%20ax1%5B0%5D.set_title(img_a_path)%0A%20%20%20%20%20%20%20%20ax1%5B1%5D.imshow(img_b%2C%20cmap%3D%22gray%22)%3B%20ax1%5B1%5D.set_title(img_b_path)%0A%20%20%20%20%20%20%20%20display_fig%20%3D%20fig1%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20display_fig%20%3D%20%22No%20image%20pair%20found%20to%20display.%22%0A%20%20%20%20display_fig%0A%20%20%20%20return%20img_a%2C%20img_b%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Run%20PIV%20(basic%20example)%0A%20%20%20%20Adjust%20parameters%20based%20on%20this%20case%3A%20window%20size%2C%20overlap%2C%20search%20area%2C%20and%20%60dt%60.%0A%20%20%20%20-%20**Tip%3A**%20ensure%20particle%20displacement%20is%20~5%E2%80%9310%20px%20between%20frames.%0A%20%20%20%20-%20**Tip%3A**%20inspect%20signal-to-noise%20and%20validate%20outliers.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(img_a%2C%20img_b)%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20from%20openpiv%20import%20pyprocess%0A%20%20%20%20if%20img_a%20is%20not%20None%20and%20img_b%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20u_res%2C%20v_res%2C%20s2n_res%20%3D%20pyprocess.extended_search_area_piv(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20img_a.astype(np.int32)%2C%20img_b.astype(np.int32)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20window_size%3D32%2C%20overlap%3D16%2C%20dt%3D1.0%2C%20search_area_size%3D64%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sig2noise_method%3D%22peak2peak%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22PIV%20computed.%20shape%3A%22%2C%20u_res.shape%2C%20%22finite%3A%22%2C%20int(np.isfinite(u_res).sum()))%0A%20%20%20%20%20%20%20%20%20%20%20%20piv_res%20%3D%20(u_res%2C%20v_res%2C%20s2n_res)%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(%22PIV%20failed%20for%20default%20settings%3A%22%2C%20e)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22Try%20different%20window_size%2Foverlap%2Fsearch_area%20for%20this%20case.%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20piv_res%20%3D%20(None%2C%20None%2C%20None)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20piv_res%20%3D%20(None%2C%20None%2C%20None)%0A%20%20%20%20piv_res%0A%20%20%20%20return%20(piv_res%2C)%0A%0A%0A%40app.cell%0Adef%20_(piv_res)%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt2%0A%20%20%20%20u_r%2C%20v_r%2C%20s2n_r%20%3D%20piv_res%0A%20%20%20%20if%20u_r%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20fig2%2C%20ax2%20%3D%20plt2.subplots()%0A%20%20%20%20%20%20%20%20ax2.quiver(u_r%2C%20v_r)%0A%20%20%20%20%20%20%20%20ax2.invert_yaxis()%0A%20%20%20%20%20%20%20%20ax2.set_title(%22Velocity%20field%20(test7)%22)%0A%20%20%20%20%20%20%20%20out2%20%3D%20fig2%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20out2%20%3D%20%22No%20vector%20field%20to%20plot.%22%0A%20%20%20%20out2%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Notes%20for%20this%20case%0A%20%20%20%20-%20Inspect%20images%20for%20seeding%20density%2C%20illumination%2C%20reflections%2C%20and%20masks.%0A%20%20%20%20-%20Choose%20window%20size%20so%20each%20window%20contains%20enough%20particle%20pairs.%0A%20%20%20%20-%20Validate%20vectors%20(s2n%2C%20median)%20and%20consider%20multi-pass%2Fwindow%20deformation%20for%20gradients.%0A%20%20%20%20-%20Compare%20with%20provided%20reference%20outputs%20in%20this%20folder%20if%20available%20(e.g.%20%60.txt%60%20results).%0A%0A%20%20%20%20Back%20to%20%5Ball%20cases%5D(..%2Fall_cases.html)%20%C2%B7%20%5Bindex%5D(..%2Findex.html)%0A%20%20%20%20%22%22%22)%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
9ecb64d49bb229502422d76a56730805