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

debuged some test functions in the moving part, and made it can be used with...

debuged some test functions in the moving part, and made it can be used with different networkx versions now
parent 99a55355
No related branches found
No related tags found
No related merge requests found
......@@ -110,10 +110,16 @@ It creates three sql table on initialisation.
raise TypeError('filename should be a string')
if not isinstance(channels, list):
raise TypeError('nb_channel should be a list or np array')
"""for c in channels:
if not c in ['R','G','B','D']:
raise ValueError('channels
must be either R,G,B or D (Distance)')"""
for c in channels:
if c is None:
raise ValueError('channels\
must not be None')
if c is np.nan:
raise ValueError('channels\
must not be of nan value')
if isinstance(c, list) or isinstance(c, np.ndarray):
raise ValueError('channels\
must be single value')
self.filename = filename
self.channels = channels
self.normalisation_columns = list()
......@@ -343,8 +349,6 @@ database
return posorient
def read_posorient(self, posorient=None, rowid=None):
if not isinstance(posorient, pd.Series):
('posorient should be a pandas Series')
if posorient is not None:
if not isinstance(posorient, pd.Series):
raise TypeError('posorient should be a pandas Series')
......@@ -364,16 +368,17 @@ database
raise ValueError('missing index alpha_2')
if np.any(pd.isnull(posorient)):
raise ValueError('posorient must not contain nan')
if not isinstance(rowid, int):
raise TypeError('rowid must be an integer')
if rowid <= 0:
raise ValueError('rowid must be greater zero')
if rowid is np.nan:
raise ValueError('rowid must not be nan')
if rowid is not None:
if not isinstance(rowid, int):
raise TypeError('rowid must be an integer')
if rowid <= 0:
raise ValueError('rowid must be greater zero')
if rowid is np.nan:
raise ValueError('rowid must not be nan')
if (posorient is None) and (rowid is None):
Exception('posorient and rowid can not be both None')
Exception('posorient and rowid can not be both None')
if posorient is not None:
rowid = self.get_posid(posorient)
rowid = self.get_posid(posorient)
# Read images
tablename = 'position_orientation'
toreturn = pd.read_sql_query(
......@@ -399,8 +404,6 @@ database
:rtype: numpy.ndarray
"""
if not isinstance(posorient, pd.Series):
('posorient should be a pandas Series')
if posorient is not None:
if not isinstance(posorient, pd.Series):
raise TypeError('posorient should be a pandas Series')
......@@ -517,6 +520,7 @@ class DataBaseSave(DataBase):
DataBase.__init__(self, filename, channels=channels)
self.arr_dtype = arr_dtype
@property
def create(self):
"""use to decide weather to alter the database or not
return True because we will need
......@@ -542,9 +546,9 @@ class DataBaseSave(DataBase):
def insert_replace(self, tablename, params):
if not isinstance(tablename, str):
raise ValueError('table are named by string')
raise TypeError('table are named by string')
if not isinstance(params, dict):
raise ValueError('params should be dictionary columns:val')
raise TypeError('params should be dictionary columns:val')
params_list = list()
columns_str = ''
for key, val in params.items():
......
......@@ -10,6 +10,8 @@ import inspect
from navipy.database import DataBaseLoad
import navipy.moving.maths as navimomath
version = float(nx.__version__)
def defaultcallback(*args, **kwargs):
"""default call back"""
......@@ -309,7 +311,11 @@ class GraphAgent():
results_edges = []
posorients_queue = JoinableQueue()
results_queue = Queue()
for node in self._graph.nodes:
if version < 2:
graph_nodes = list(self._graph.nodes())
else:
graph_nodes = list(self._graph.nodes)
for node in graph_nodes:
posorients_queue.put(self._graph.nodes[node]['posorient'])
# Start ndatabase loader
......@@ -341,7 +347,11 @@ class GraphAgent():
self.check_single_target()
def check_single_target(self):
for node in self._graph.nodes:
if version < 2:
graph_nodes = list(self._graph.nodes())
else:
graph_nodes = list(self._graph.nodes)
for node in graph_nodes:
# not connected -> loop not ran
for count, _ in enumerate(self._graph.neighbors(node)):
# count == 0 -> connected to one node
......
......@@ -10,6 +10,8 @@ import pkg_resources
import unittest
version = float(nx.__version__)
class TestNavipyMovingAgent(unittest.TestCase):
......@@ -89,13 +91,20 @@ class TestNavipyMovingAgent(unittest.TestCase):
def test_init_graphagent(self):
agent = naviagent.GraphAgent(self.mydb_filename)
self.assertEqual(sorted(agent.graph.nodes),
if version < 2:
graph_nodes = list(agent.graph.nodes())
else:
graph_nodes = list(agent.graph.nodes)
self.assertEqual(sorted(graph_nodes),
sorted(list(self.mydb.posorients.index)),
'Init of graph failed. Node missmatch')
def test_graph_setter(self):
agent = naviagent.GraphAgent(self.mydb_filename)
graph_nodes = list(agent.graph.nodes)
if version < 2:
graph_nodes = list(agent.graph.nodes())
else:
graph_nodes = list(agent.graph.nodes)
graph_edges = list()
for gnode in graph_nodes[1:]:
graph_edges.append((gnode, graph_nodes[0]))
......@@ -121,7 +130,10 @@ class TestNavipyMovingAgent(unittest.TestCase):
# Test all node to first
agent = naviagent.GraphAgent(self.mydb_filename)
graph_nodes = list(agent.graph.nodes)
if version < 2:
graph_nodes = list(agent.graph.nodes())
else:
graph_nodes = list(agent.graph.nodes)
graph_edges = list()
for gnode in graph_nodes[1:]:
graph_edges.append((gnode, graph_nodes[0]))
......@@ -183,7 +195,10 @@ class TestNavipyMovingAgent(unittest.TestCase):
"""
agent = naviagent.GraphAgent(self.mydb_filename)
# Local maxima
graph_nodes = list(agent.graph.nodes)
if version < 2:
graph_nodes = list(agent.graph.nodes())
else:
graph_nodes = list(agent.graph.nodes)
graph_edges = list()
graph_edges.append((graph_nodes[0],
graph_nodes[1]))
......
......@@ -16,28 +16,19 @@ should be replaced by
def posorients(self)
Need to propagate the changes through all the code (see rendering / processing / moving )
------------------------------------------------------
0004: Change every assert by a if () raise TypeError/IOError/KeyError/...
- present in processing
- present in database
Should be done, but maybe I missed something?
------------------------------------------------------
0005: Write test function for raise Error
- for every raise error create a test function, checking that the error is correctly thrown (see moving/test_agent for inspiration)
------------------------------------------------------
0006: Improve comparing/__init__.py
- Change comment in simple_image_diff
- call simple_image_diff in imagediff. you can then remove all the assert (that should be raise Error at that point) from imagediff
- Add comment to diff_optic_flow / add reference to article.
- rename capitalised variable A,ATA, and b as longer variable name [future PEP8 will forbid this]
also should be done. But I did not add any more checks to the moving part, shall I check for additional possible checks?
------------------------------------------------------
0007: Improve cyber_bee so that every getter and setter are properties
0008: Improve bee_sampling so that every getter and setter are properties
--------------------------------------------------------------------
0009: can the last dimension (4) of the place-code be greater 1? (should be 1)
Yes it can, see apcv a [1x1x1x3] array
0010: what is the image in the database? must it be transformed to a a scene?
The image is an image, and distance the distance. I added scene as a join image+distance array
now we do not have a read_image function in database anymore, is it supposed to be like this?
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