{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from openpiv.pyprocess import extended_search_area_piv as piv\n", "\n", "import numpy as np\n", "\n", "\n", "from skimage.util import random_noise\n", "from skimage import img_as_ubyte\n", "\n", "threshold = 0.1\n", "shift_u = -5\n", "shift_v = 4\n", "\n", "\n", "def dist(u, shift):\n", " return np.mean(np.abs(u - shift))\n", "\n", "def create_pair(image_size=32, u=shift_u, v=shift_v):\n", " \"\"\" creates a pair of images with a roll/shift \"\"\"\n", " frame_a = np.zeros((image_size, image_size))\n", " frame_a = random_noise(frame_a)\n", " frame_a = img_as_ubyte(frame_a)\n", " # note rolling positive vertical +2 means we create\n", " # negative vertical velocity as our origin is at 0,0\n", " # bottom left corner, and the image is rolled from the\n", " # top left corner\n", "\n", " frame_b = np.roll(np.roll(frame_a, u, axis=1), v, axis=0)\n", " return frame_a.astype(np.int32), frame_b.astype(np.int32)\n", "\n", "def test_piv():\n", " \"\"\"test of the simplest PIV run\n", " default window_size = 32\n", " \"\"\"\n", " frame_a, frame_b = create_pair(image_size=64)\n", " u, v = piv(frame_a, frame_b, window_size=64)\n", " print(u,v)\n", " assert dist(u, shift_u) < threshold\n", " assert dist(v, -shift_v) < threshold\n", "\n", "def test_piv_smaller_window():\n", " \"\"\" test of the search area larger than the window \"\"\"\n", " frame_a, frame_b = create_pair(image_size=32, u=-3, v=-2)\n", " u, v = piv(frame_a, frame_b, window_size=16, search_area_size=32)\n", " assert dist(u, -3) < threshold\n", " assert dist(v, 2) < threshold\n", "\n", "def test_extended_search_area():\n", " \"\"\" test of the extended area PIV with larger image \"\"\"\n", " frame_a, frame_b = create_pair(image_size=64)\n", " u, v = piv(frame_a, frame_b,\n", " window_size=16, search_area_size=32, overlap=0)\n", "\n", " assert (dist(u, shift_u) + dist(v, -shift_v)) < 2 * threshold\n", "\n", "def test_extended_search_area_overlap():\n", " \"\"\" test of the extended area PIV with different overlap \"\"\"\n", " frame_a, frame_b = create_pair(image_size=64)\n", " u, v = piv(frame_a, frame_b,\n", " window_size=16, search_area_size=32, overlap=8)\n", " assert (dist(u, shift_u) + dist(v, -shift_v)) < 2 * threshold\n", "\n", "def test_extended_search_area_sig2noise():\n", " \"\"\" test of the extended area PIV with sig2peak \"\"\"\n", " frame_a, frame_b = create_pair(image_size=64)\n", " u, v, s2n = piv(\n", " frame_a,\n", " frame_b,\n", " window_size=16,\n", " search_area_size=32,\n", " sig2noise_method=\"peak2peak\",\n", " )\n", " assert (dist(u, shift_u) + dist(v, -shift_v)) < 2 * threshold\n", "\n", "def test_process_extended_search_area():\n", " \"\"\" test of the extended area PIV from Cython \"\"\"\n", " frame_a, frame_b = create_pair(image_size=64)\n", " u, v = piv(frame_a, frame_b, window_size=16, search_area_size=32, dt=1, overlap=0)\n", " # assert(np.max(np.abs(u[:-1,:-1]-3)+np.abs(v[:-1,:-1]+2)) <= 0.3)\n", " assert (dist(u, shift_u) + dist(v, -shift_v)) < 2 * threshold" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:windef] *", "language": "python", "name": "conda-env-windef-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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }