Skip to content
Snippets Groups Projects
Commit 29cac28a authored by Luise Odenthal's avatar Luise Odenthal
Browse files

commented test, changed the range for elevation and azimuth and added check...

commented test, changed the range for elevation and azimuth and added check that max difference is samller 2pi;
parent 5db0a620
No related merge requests found
...@@ -8,11 +8,24 @@ import pkg_resources ...@@ -8,11 +8,24 @@ import pkg_resources
class TestCase(unittest.TestCase): class TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
""" loads the database """
self.mydb_filename = pkg_resources.resource_filename( self.mydb_filename = pkg_resources.resource_filename(
'navipy', 'resources/database.db') 'navipy', 'resources/database.db')
self.mydb = database.DataBaseLoad(self.mydb_filename) self.mydb = database.DataBaseLoad(self.mydb_filename)
def test_imagediff_curr(self): def test_imagediff_curr(self):
"""
this test checks the function imdiff works
correctly.
it checks if correct errors are raised for:
- frame containing nans
- frame has wrong dimension
and checks if the returned frame is correct:
- has correct shape
- does not contain nans
- contains only numeric values
"""
curr = self.mydb.scene(rowid=1) curr = self.mydb.scene(rowid=1)
mem = self.mydb.scene(rowid=2) mem = self.mydb.scene(rowid=2)
curr2 = curr.copy() curr2 = curr.copy()
...@@ -39,6 +52,18 @@ class TestCase(unittest.TestCase): ...@@ -39,6 +52,18 @@ class TestCase(unittest.TestCase):
self.assertTrue(is_numeric_array(diff)) self.assertTrue(is_numeric_array(diff))
def test_imagediff_memory(self): def test_imagediff_memory(self):
"""
this test checks the function imagediff works
correctly for the parameter memory.
it checks if correct errors are raised for:
- memory containing nans
- memory has wrong dimension
and checks if the returned frame is correct:
- has correct shape
- does not contain nans
- contains only numeric values
"""
curr = self.mydb.scene(rowid=1) curr = self.mydb.scene(rowid=1)
mem = self.mydb.scene(rowid=2) mem = self.mydb.scene(rowid=2)
mem2 = curr.copy() mem2 = curr.copy()
...@@ -64,6 +89,18 @@ class TestCase(unittest.TestCase): ...@@ -64,6 +89,18 @@ class TestCase(unittest.TestCase):
self.assertTrue(is_numeric_array(diff)) self.assertTrue(is_numeric_array(diff))
def test_rot_imagediff_curr(self): def test_rot_imagediff_curr(self):
"""
this test checks the function imagediff works
correctly for the parameter current.
it checks if correct errors are raised for:
- memory containing nans
- memory has wrong dimension
and checks if the returned frame is correct:
- has correct shape
- does not contain nans
- contains only numeric values
"""
curr = self.mydb.scene(rowid=1) curr = self.mydb.scene(rowid=1)
mem = self.mydb.scene(rowid=2) mem = self.mydb.scene(rowid=2)
curr2 = curr.copy() curr2 = curr.copy()
...@@ -89,6 +126,18 @@ class TestCase(unittest.TestCase): ...@@ -89,6 +126,18 @@ class TestCase(unittest.TestCase):
self.assertTrue(is_numeric_array(diff)) self.assertTrue(is_numeric_array(diff))
def test_rotimagediff_memory(self): def test_rotimagediff_memory(self):
"""
this test checks the function rot_imagediff works
correctly for the parameter memory.
it checks if correct errors are raised for:
- memory containing nans
- memory has wrong dimension
and checks if the returned frame is correct:
- has correct shape
- does not contain nans
- contains only numeric values
"""
curr = self.mydb.scene(rowid=1) curr = self.mydb.scene(rowid=1)
mem = self.mydb.scene(rowid=2) mem = self.mydb.scene(rowid=2)
mem2 = curr.copy() mem2 = curr.copy()
...@@ -114,6 +163,18 @@ class TestCase(unittest.TestCase): ...@@ -114,6 +163,18 @@ class TestCase(unittest.TestCase):
self.assertTrue(is_numeric_array(diff)) self.assertTrue(is_numeric_array(diff))
def test_simple_imagediff_curr(self): def test_simple_imagediff_curr(self):
"""
this test checks the function simple_imagediff works
correctly for the parameter current.
it checks if correct errors are raised for:
- memory containing nans
- memory has wrong dimension
and checks if the returned frame is correct:
- has correct shape
- does not contain nans
- contains only numeric values
"""
curr = self.mydb.scene(rowid=1) curr = self.mydb.scene(rowid=1)
mem = self.mydb.scene(rowid=2) mem = self.mydb.scene(rowid=2)
curr2 = curr.copy() curr2 = curr.copy()
...@@ -141,6 +202,18 @@ class TestCase(unittest.TestCase): ...@@ -141,6 +202,18 @@ class TestCase(unittest.TestCase):
# self.assertTrue(diff.shape[3] == 1) # self.assertTrue(diff.shape[3] == 1)
def test_simple_imagediff_mem(self): def test_simple_imagediff_mem(self):
"""
this test checks the function imagediff works
correctly for the parameter memory.
it checks if correct errors are raised for:
- memory containing nans
- memory has wrong dimension
and checks if the returned frame is correct:
- has correct shape
- does not contain nans
- contains only numeric values
"""
curr = self.mydb.scene(rowid=1) curr = self.mydb.scene(rowid=1)
mem = self.mydb.scene(rowid=2) mem = self.mydb.scene(rowid=2)
mem2 = curr.copy() mem2 = curr.copy()
...@@ -168,6 +241,18 @@ class TestCase(unittest.TestCase): ...@@ -168,6 +241,18 @@ class TestCase(unittest.TestCase):
# self.assertTrue(diff.shape[3] == 1) # self.assertTrue(diff.shape[3] == 1)
def test_diff_optic_flow_memory(self): def test_diff_optic_flow_memory(self):
"""
this test checks the function diff_optic_flow works
correctly for the parameter memory.
it checks if correct errors are raised for:
- memory containing nans
- memory has wrong dimension
and checks if the returned frame is correct:
- has correct shape
- does not contain nans
- contains only numeric values
"""
curr = self.mydb.scene(rowid=1) curr = self.mydb.scene(rowid=1)
mem = self.mydb.scene(rowid=2) mem = self.mydb.scene(rowid=2)
mem2 = curr.copy() mem2 = curr.copy()
...@@ -192,6 +277,18 @@ class TestCase(unittest.TestCase): ...@@ -192,6 +277,18 @@ class TestCase(unittest.TestCase):
self.assertTrue(is_numeric_array(vec)) self.assertTrue(is_numeric_array(vec))
def test_diff_optic_flow_curr(self): def test_diff_optic_flow_curr(self):
"""
this test checks the function diff_optic_flow works
correctly for the parameter current.
it checks if correct errors are raised for:
- memory containing nans
- memory has wrong dimension
and checks if the returned frame is correct:
- has correct shape
- does not contain nans
- contains only numeric values
"""
curr = self.mydb.scene(rowid=1) curr = self.mydb.scene(rowid=1)
mem = self.mydb.scene(rowid=2) mem = self.mydb.scene(rowid=2)
curr2 = curr.copy() curr2 = curr.copy()
......
...@@ -133,12 +133,16 @@ def pcv(place_code, viewing_directions): ...@@ -133,12 +133,16 @@ def pcv(place_code, viewing_directions):
should be 1'.format(place_code.shape[component_dim])) should be 1'.format(place_code.shape[component_dim]))
elevation = viewing_directions[..., __spherical_indeces__['elevation']] elevation = viewing_directions[..., __spherical_indeces__['elevation']]
azimuth = viewing_directions[..., __spherical_indeces__['azimuth']] azimuth = viewing_directions[..., __spherical_indeces__['azimuth']]
# if (np.any(elevation < -np.pi/2) or np.any(elevation > np.pi/2)): if (np.any(elevation < -np.pi/2) or np.any(elevation > np.pi/2)):
if (np.any(elevation < -2*np.pi) or np.any(elevation > 2*np.pi)): # if (np.any(elevation < -2*np.pi) or np.any(elevation > 2*np.pi)):
raise ValueError(" Elevation must be radians in range [-2*pi;2*pi]") raise ValueError(" Elevation must be radians in range [-2*pi;2*pi]")
# if (np.any(azimuth < 0) or np.any(azimuth > np.pi*2)): if (np.max(elevation) - np.min(elevation) > 2 * np.pi):
if (np.any(azimuth < -2*np.pi) or np.any(azimuth > np.pi*2)): raise ValueError(" max difference in elevation must be < 2*pi")
if (np.any(azimuth < -np.pi) or np.any(azimuth > np.pi)):
# if (np.any(azimuth < -2*np.pi) or np.any(azimuth > np.pi*2)):
raise ValueError(" Azimuth must be radians in range [-2*pi;2*pi]") raise ValueError(" Azimuth must be radians in range [-2*pi;2*pi]")
if (np.max(azimuth) - np.min(azimuth) > 2 * np.pi):
raise ValueError(" max difference in azimuth must be < 2*pi")
x, y, z = spherical_to_cartesian(elevation, azimuth, radius=1) x, y, z = spherical_to_cartesian(elevation, azimuth, radius=1)
unscaled_lv = np.zeros((viewing_directions.shape[0], unscaled_lv = np.zeros((viewing_directions.shape[0],
viewing_directions.shape[1], viewing_directions.shape[1],
......
...@@ -375,6 +375,12 @@ class TestCase(unittest.TestCase): ...@@ -375,6 +375,12 @@ class TestCase(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
my_pcv = pcode.pcv(my_scene, testdirections) my_pcv = pcode.pcv(my_scene, testdirections)
testdirections = np.zeros((180, 360, 2))
testdirections[10, 15, 1] = np.pi + 0.001
testdirections[10, 16, 1] = - np.pi - 0.001
with self.assertRaises(ValueError):
my_pcv = pcode.pcv(my_scene, testdirections)
def test_apcv(self): def test_apcv(self):
""" """
this test checks that the correct errors are raised if this test checks that the correct errors are raised if
......
...@@ -26,6 +26,9 @@ def Scale(data, oldmin, oldmax, mini, maxi, ran): ...@@ -26,6 +26,9 @@ def Scale(data, oldmin, oldmax, mini, maxi, ran):
class TestCase(unittest.TestCase): class TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
"""sets up a distance array that is used in some tests,
as well as the velocity and viewing direction frames
"""
distance = np.array([[2.60009956, 2.60009956, 2.60009956], distance = np.array([[2.60009956, 2.60009956, 2.60009956],
[2.60009956, 2.60009956, 2.60009956], [2.60009956, 2.60009956, 2.60009956],
[2.60009956, 2.60009956, 2.60009956]]) [2.60009956, 2.60009956, 2.60009956]])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment