|
| 1 | +import pytest |
| 2 | +import pandas |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +import load |
| 6 | +import plot |
| 7 | + |
| 8 | + |
| 9 | +def test_velocity_dist_default_key(): |
| 10 | + """Test velocity distribution.""" |
| 11 | + tracking = load.Load("tests/tracking.txt") |
| 12 | + plotObj = plot.Plot(tracking) |
| 13 | + velocityTest = plotObj.velocityDistribution(ids=[0, 1]) |
| 14 | + refData = tracking.getObjects(0) |
| 15 | + a = (np.sqrt(np.diff(refData.xBody.values)**2 + np.diff(refData.yBody.values)**2)) / np.diff(refData.imageNumber.values) |
| 16 | + refData = tracking.getObjects(1) |
| 17 | + b = (np.sqrt(np.diff(refData.xBody.values)**2 + np.diff(refData.yBody.values)**2)) / np.diff(refData.imageNumber.values) |
| 18 | + pooled = np.concatenate((a, b)) |
| 19 | + np.testing.assert_array_equal(pooled, velocityTest[1][0]) |
| 20 | + |
| 21 | + velocityTest = plotObj.velocityDistribution(ids=[0, 1], pooled=False) |
| 22 | + np.testing.assert_array_equal(a, velocityTest[1][0]) |
| 23 | + np.testing.assert_array_equal(b, velocityTest[1][1]) |
| 24 | + |
| 25 | + refData = tracking.getObjectsInFrames(0, indexes=list(range(0, 100))) |
| 26 | + a = (np.sqrt(np.diff(refData.xBody.values)**2 + np.diff(refData.yBody.values)**2)) / np.diff(refData.imageNumber.values) |
| 27 | + velocityTest = plotObj.velocityDistribution(ids=[0], pooled=True, indexes=(0, 100)) |
| 28 | + np.testing.assert_array_equal(a, velocityTest[1][0]) |
| 29 | + |
| 30 | +def test_velocity_dist_head(): |
| 31 | + """Test velocity distribution.""" |
| 32 | + tracking = load.Load("tests/tracking.txt") |
| 33 | + plotObj = plot.Plot(tracking) |
| 34 | + velocityTest = plotObj.velocityDistribution(ids=[0, 1], key="Head") |
| 35 | + refData = tracking.getObjects(0) |
| 36 | + a = (np.sqrt(np.diff(refData.xHead.values)**2 + np.diff(refData.yHead.values)**2)) / np.diff(refData.imageNumber.values) |
| 37 | + refData = tracking.getObjects(1) |
| 38 | + b = (np.sqrt(np.diff(refData.xHead.values)**2 + np.diff(refData.yHead.values)**2)) / np.diff(refData.imageNumber.values) |
| 39 | + pooled = np.concatenate((a, b)) |
| 40 | + np.testing.assert_array_equal(pooled, velocityTest[1][0]) |
| 41 | + |
| 42 | + velocityTest = plotObj.velocityDistribution(ids=[0, 1], pooled=False, key="Head") |
| 43 | + np.testing.assert_array_equal(a, velocityTest[1][0]) |
| 44 | + np.testing.assert_array_equal(b, velocityTest[1][1]) |
| 45 | + |
| 46 | + refData = tracking.getObjectsInFrames(0, indexes=list(range(0, 100))) |
| 47 | + a = (np.sqrt(np.diff(refData.xHead.values)**2 + np.diff(refData.yHead.values)**2)) / np.diff(refData.imageNumber.values) |
| 48 | + velocityTest = plotObj.velocityDistribution(ids=[0], pooled=True, indexes=(0, 100), key="Head") |
| 49 | + np.testing.assert_array_equal(a, velocityTest[1][0]) |
0 commit comments