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%20%23%20Ensemble%20correlation%20concept%20using%20OpenPIV%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%20Ensemble%20correlation%20should%20work%20in%20places%20where%20the%20flow%20is%20really%20steady%20and%20repeatable%0A%20%20%20%20or%20could%20be%20phase%20averaged%20in%20the%20sense%20that%20the%20correlation%20map%20in%20a%20single%20interrogation%0A%20%20%20%20window%20represents%20displacements%20from%20a%20statistically%20stationary%20distribution.%0A%0A%20%20%20%20In%20such%20case%2C%20the%20noisy%20position%20of%20the%20correlation%20peak%20is%20due%20to%20randomness%20that%20can%0A%20%20%20%20be%20averaged%20out%20like%20the%20white%20noise%20and%20the%20avergaging%20of%20the%20correlation%20maps%20will%0A%20%20%20%20yield%20a%20high%20quality%20peak%20that%20has%20great%20signal%20to%20noise%20ratio%20and%20close%20to%20Gaussian%0A%0A%20%20%20%20In%20this%20case%20the%20velocity%20estimate%20in%20the%20interrogation%20window%20will%20approach%20the%20mean%0A%20%20%20%20velocity%20value%20at%20that%20location.%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.pyprocess%20import%20*%0A%20%20%20%20from%20openpiv.tools%20import%20*%0A%20%20%20%20%22%22%22%2C%0A%20%20%20%20name%3D%22_%22%0A)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20from%20glob%20import%20glob%0A%0A%20%20%20%20return%20(glob%2C)%0A%0A%0Aapp._unparsable_cell(%0A%20%20%20%20r%22%22%22%0A%20%20%20%20from%20pylab%20import%20*%0A%20%20%20%20%22%22%22%2C%0A%20%20%20%20name%3D%22_%22%0A)%0A%0A%0A%40app.cell%0Adef%20_(glob)%3A%0A%20%20%20%20imlist%20%3D%20glob('..%2Ftest12%2F*.tif')%0A%20%20%20%20imlist.sort()%0A%20%20%20%20print(imlist)%0A%20%20%20%20return%20(imlist%2C)%0A%0A%0A%40app.cell%0Adef%20_(imlist)%3A%0A%20%20%20%20%23%20just%20a%20quick%20look%20at%20the%20data%0A%20%20%20%20from%20openpiv.piv%20import%20simple_piv%0A%20%20%20%20simple_piv(imlist%5B0%5D%2C%20imlist%5B1%5D)%3B%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%20Ensemble%20averaged%20correlation%20using%20FFT%20based%20correlation%20from%20OpenPIV%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fft_correlate_images%2C%20imlist%2C%20imread%2C%20moving_window_array)%3A%0A%20%20%20%20corrs%20%3D%20%5B%5D%0A%20%20%20%20for%20i%2Cj%20in%20zip(imlist%5B%3A%3A2%5D%2Cimlist%5B1%3A%3A2%5D)%3A%0A%20%20%20%20%20%20%20%20%23%20print(i%2Cj)%0A%20%20%20%20%20%20%20%20corrs.append(fft_correlate_images(moving_window_array(imread(i)%2C64%2C32)%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%20moving_window_array(imread(j)%2C64%2C32)%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%20normalized_correlation%3DTrue))%0A%20%20%20%20return%20(corrs%2C)%0A%0A%0A%40app.cell%0Adef%20_(corrs%2C%20np)%3A%0A%20%20%20%20corrs_1%20%3D%20np.array(corrs)%20%20%23%20save%20also%20single%20image%20pair%20correlations%0A%20%20%20%20mean_correlation%20%3D%20corrs_1.mean(axis%3D0)%20%20%23%20ensemble%20average%0A%20%20%20%20return%20corrs_1%2C%20mean_correlation%0A%0A%0A%40app.cell%0Adef%20_(colorbar%2C%20contourf%2C%20mean_correlation)%3A%0A%20%20%20%20%23%20Let's%20compare%20the%20result%20with%20instantaneous%20results%0A%20%20%20%20contourf(mean_correlation%5B23%2C%3A%2C%3A%5D)%0A%20%20%20%20colorbar()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(colorbar%2C%20contourf%2C%20corrs_1%2C%20figure)%3A%0A%20%20%20%20for%20i_1%20in%20range(corrs_1.shape%5B0%5D)%3A%0A%20%20%20%20%20%20%20%20figure()%0A%20%20%20%20%20%20%20%20contourf(corrs_1%5Bi_1%2C%20252%2C%20%3A%2C%20%3A%5D)%0A%20%20%20%20%20%20%20%20colorbar()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(imlist%2C%20imread)%3A%0A%20%20%20%20im%20%3D%20imread(imlist%5B0%5D)%0A%20%20%20%20im.shape%0A%20%20%20%20return%20(im%2C)%0A%0A%0A%40app.cell%0Adef%20_(get_field_shape%2C%20im)%3A%0A%20%20%20%20grid%20%3D%20get_field_shape(im.shape%2Csearch_area_size%3D64%2Coverlap%3D32)%0A%20%20%20%20nrows%2C%20ncols%20%3D%20grid%5B0%5D%2C%20grid%5B1%5D%0A%20%20%20%20return%20ncols%2C%20nrows%0A%0A%0A%40app.cell%0Adef%20_(correlation_to_displacement%2C%20mean_correlation%2C%20ncols%2C%20nrows)%3A%0A%20%20%20%20u%2Cv%20%3D%20correlation_to_displacement(mean_correlation%2C%20nrows%2C%20ncols)%0A%20%20%20%20return%20u%2C%20v%0A%0A%0A%40app.cell%0Adef%20_(get_coordinates%2C%20im)%3A%0A%20%20%20%20x%2Cy%20%3D%20get_coordinates(im.shape%2C%2064%2C%2032)%0A%20%20%20%20return%20x%2C%20y%0A%0A%0A%40app.cell%0Adef%20_(plot%2C%20subplots%2C%20u%2C%20v%2C%20x%2C%20y)%3A%0A%20%20%20%20fig%2C%20ax%20%3D%20subplots(figsize%3D(8%2C8))%0A%20%20%20%20ax.quiver(x%2Cy%2Cu%2Cv%2Cscale%3D80%2Cwidth%3D.003)%0A%20%20%20%20ax.invert_yaxis()%0A%20%20%20%20plot(u.mean(axis%3D1)*80%2B400%2Cy%5B%3A%2C0%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20another%20way%20is%20the%20averaging%20of%20velocity%20fields%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20correlation_to_displacement%2C%0A%20%20%20%20corrs_1%2C%0A%20%20%20%20ncols%2C%0A%20%20%20%20np%2C%0A%20%20%20%20nrows%2C%0A%20%20%20%20plot%2C%0A%20%20%20%20subplots%2C%0A%20%20%20%20x%2C%0A%20%20%20%20y%2C%0A)%3A%0A%20%20%20%20U%20%3D%20%5B%5D%0A%20%20%20%20V%20%3D%20%5B%5D%0A%20%20%20%20for%20i_2%20in%20range(corrs_1.shape%5B0%5D)%3A%0A%20%20%20%20%20%20%20%20tmpu%2C%20tmpv%20%3D%20correlation_to_displacement(corrs_1%5Bi_2%2C%20%3A%2C%20%3A%2C%20%3A%5D%2C%20nrows%2C%20ncols)%0A%20%20%20%20%20%20%20%20U.append(tmpu)%0A%20%20%20%20%20%20%20%20V.append(tmpv)%0A%20%20%20%20%20%20%20%20fig_1%2C%20ax_1%20%3D%20subplots(figsize%3D(6%2C%206))%0A%20%20%20%20%20%20%20%20ax_1.quiver(x%2C%20y%2C%20tmpu%2C%20tmpv%2C%20scale%3D200)%0A%20%20%20%20%20%20%20%20ax_1.invert_yaxis()%0A%20%20%20%20%20%20%20%20plot(tmpu.mean(axis%3D1)%20*%2080%20%2B%20400%2C%20y%5B%3A%2C%200%5D)%0A%20%20%20%20U%20%3D%20np.array(U)%0A%20%20%20%20V%20%3D%20np.array(V)%0A%20%20%20%20meanU%20%3D%20np.mean(U%2C%20axis%3D0)%0A%20%20%20%20meanV%20%3D%20np.mean(V%2C%20axis%3D0)%0A%20%20%20%20return%20meanU%2C%20meanV%0A%0A%0A%40app.cell%0Adef%20_(meanU%2C%20meanV%2C%20plot%2C%20subplots%2C%20x%2C%20y)%3A%0A%20%20%20%20fig_2%2C%20ax_2%20%3D%20subplots(figsize%3D(8%2C%208))%0A%20%20%20%20ax_2.quiver(x%2C%20y%2C%20meanU%2C%20meanV%2C%20scale%3D200)%0A%20%20%20%20ax_2.invert_yaxis()%0A%20%20%20%20plot(meanU.mean(axis%3D1)%20*%2080%20%2B%20400%2C%20y%5B%3A%2C%200%5D)%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
abf5b7601cd9b62e64e7a068572411ab