{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# running tests instead of pytest" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# %load ../../test/test_process.py\n", "try:\n", " from openpiv.process import extended_search_area_piv as piv\n", "except ImportError:\n", " from openpiv.pyprocess import extended_search_area_piv as piv\n", "import numpy as np\n", "\n", "\n", "from skimage.util import random_noise\n", "from skimage import img_as_ubyte\n", "\n", "import warnings\n", "\n", "threshold = 0.1\n", "\n", "def dist(u,shift):\n", " return np.mean(np.abs(u-shift))\n", "\n", "def create_pair(image_size=32, u = 3, v = 2):\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", "\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=32)\n", " u, v = piv(frame_a, frame_b, window_size=32)\n", " assert(dist(u,3) < threshold)\n", " assert(dist(v,-2) < threshold)\n", "\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", "\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, window_size=16, \n", " search_area_size=32, overlap=0)\n", "\n", " assert((dist(u,3)+dist(v,-2)) < 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, window_size=16, \n", " search_area_size=32, overlap=8)\n", " assert((dist(u,3)+dist(v,-2)) < 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(frame_a,frame_b,window_size=16,\n", " search_area_size=32, sig2noise_method='peak2peak')\n", " assert((dist(u,3)+dist(v,-2)) < 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,\n", " 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,3)+dist(v,-2)) < 2*threshold)\n", " \n", "def test_piv_vs_extended_search():\n", " \"\"\" test of the simplest PIV run \"\"\"\n", " try:\n", " import openpiv.process\n", " import openpiv.pyprocess\n", " frame_a, frame_b = create_pair()\n", " u,v = openpiv.process.extended_search_area_piv(frame_a,frame_b,\n", " window_size=32)\n", " u1,v1 = openpiv.pyprocess.extended_search_area_piv(frame_a, frame_b, \n", " window_size=32,\n", " search_area_size=32,\n", " dt=1,overlap=0)\n", "\n", " assert(np.allclose(u,u1))\n", " assert(np.allclose(v,v1))\n", " except ImportError:\n", " raise warning(\" Probably Cython or a compiler was not installed, failed to import process \")\n", "\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:openpiv-3d] *", "language": "python", "name": "conda-env-openpiv-3d-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.7" } }, "nbformat": 4, "nbformat_minor": 4 }