diff --git a/navipy/database/__init__.py b/navipy/database/__init__.py index e48e7fc04a2f54d7fd69910070984e6899b5b1b6..2affba62d28d0be496b54ff925335cd1c2bfd494 100644 --- a/navipy/database/__init__.py +++ b/navipy/database/__init__.py @@ -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') + raise 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') @@ -463,6 +466,8 @@ database return toreturn def denormalise_image(self, image, cmaxminrange): + if not isinstance(image, np.ndarray): + raise TypeError('image must be np.array') if len(image.shape) != 3: raise Exception('image should be 3D array') if image.shape[2] != len(self.channels): @@ -470,7 +475,7 @@ database number of channels {}'.format( len(self.channels))) if not isinstance(cmaxminrange, pd.Series): - raise Exception('cmaxminrange should be a pandas Series') + raise TypeError('cmaxminrange should be a pandas Series') if cmaxminrange.empty: raise Exception('cmaxminrange must not be empty') for chan_n in self.channels: @@ -517,6 +522,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 +548,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(): diff --git a/navipy/moving/agent.py b/navipy/moving/agent.py index 3a13cc2eb3dac580baa1c90ff26bcb667a34ba9a..6b0225e42c4512fa54fe9eca664435310fe27791 100644 --- a/navipy/moving/agent.py +++ b/navipy/moving/agent.py @@ -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 diff --git a/navipy/moving/test_agent.py b/navipy/moving/test_agent.py index 65f2df4aceccb4a63e83b335fe5a542f89c44fc8..0247b407359794581950d17b79712943844394a7 100644 --- a/navipy/moving/test_agent.py +++ b/navipy/moving/test_agent.py @@ -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])) diff --git a/todo b/todo index 51df4e6d00379601db1e82052674e9e2d9fe3b91..ac8b3a852f9689eab6fd57b47e0fca83053c1fa2 100644 --- a/todo +++ b/todo @@ -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?