{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# test find_subpixel_position" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from pylab import *\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from openpiv.pyprocess import find_first_peak, find_second_peak, find_subpixel_peak_position\n", "from openpiv.pyprocess import extended_search_area_piv, correlate_windows\n", "from scipy.ndimage import shift\n", "from scipy.ndimage.filters import gaussian_filter" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from test_process import create_pair" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.random.randn(32,32)\n", "a = gaussian_filter(a,.5)\n", "\n", "u0 = 2.8 # to the right\n", "v0 = -5.3 # downwards\n", "\n", "b = shift(a,(-v0, u0),mode='wrap')\n", "plt.imshow(b)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "u,v = extended_search_area_piv(a,b,window_size=32)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[-0.00271353]] [[0.01545332]]\n" ] } ], "source": [ "print(u-u0,v-v0)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "corr = correlate_windows(a,b)# + correlate_windows(c,d)\n", "from scipy.ndimage.filters import gaussian_filter\n", "\n", "corr = gaussian_filter(corr,1.5)\n", "\n", "x,y = np.meshgrid(np.arange(corr.shape[0]),np.arange(corr.shape[1]))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "x1, y1, p1 = find_first_peak(corr)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "x2, y2, p2 = find_second_peak(corr)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "(i,j) = find_subpixel_peak_position(corr)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from mpl_toolkits.mplot3d import Axes3D\n", "fig = plt.figure(figsize=(10,10))\n", "ax = fig.add_subplot(111, projection='3d')\n", "ax.plot_surface(x,y,corr);\n", "ax.scatter(j,i,p1,'o',color='r')" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(26,\n", " 28,\n", " 60.07128420968547,\n", " 23,\n", " 28,\n", " 20.830743171795604,\n", " 25.74341384564399,\n", " 28.189462289160172)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x1,y1,p1,x2,y2,p2,i,j " ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6.256586154356011" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "32-i" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.810537710839828" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "32-j" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:bospiv]", "language": "python", "name": "conda-env-bospiv-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" } }, "nbformat": 4, "nbformat_minor": 4 }