From b80b281acf081bc2fa561a7fbdc2a80ed36b1c56 Mon Sep 17 00:00:00 2001
From: "lodenthal@uni-bielefeld.de" <lodenthal@uni-bielefeld.de>
Date: Fri, 11 May 2018 10:06:14 +0300
Subject: [PATCH] changed convention in agent, and repaired flake8

---
 navipy/moving/agent.py      | 15 +++++++++------
 navipy/moving/maths.py      |  7 ++++---
 navipy/moving/test_agent.py | 16 ++++++++--------
 navipy/moving/test_maths.py |  6 +++---
 4 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/navipy/moving/agent.py b/navipy/moving/agent.py
index 2d7f11c..7b30f17 100644
--- a/navipy/moving/agent.py
+++ b/navipy/moving/agent.py
@@ -49,10 +49,9 @@ class DefaultBrain():
 
 
 class AbstractAgent():
-    def __init__(self):
+    def __init__(self, convention='rxyz'):
         self._brain = DefaultBrain()
         self._alter_posorientvel = defaultcallback
-        convention = 'rxyz'
         tuples = [('location', 'x'), ('location', 'y'),
                   ('location', 'z'), (convention, 'alpha_0'),
                   (convention, 'alpha_1'), (convention, 'alpha_2')]
@@ -150,8 +149,10 @@ CyberBeeAgent is a close loop agent and need to be run within blender \
 
     """
 
-    def __init__(self, brain):
-        AbstractAgent.__init__(self)
+    def __init__(self, brain, convention):
+        if convention is None:
+            raise Exception("a convention must be specified")
+        AbstractAgent.__init__(self, convention)
         AbstractAgent._alter_posorientvel = \
             lambda motion_vec: navimomath.next_pos(motion_vec,
                                                    move_mode='free_run')
@@ -175,12 +176,14 @@ GridAgent is a close loop agent here its position is snap to a grid.
 
     """
 
-    def __init__(self, brain,
+    def __init__(self, brain, convention,
                  posorients_queue=None,
                  results_queue=None):
+        if convention is None:
+            raise Exception("convention must be set")
         if (posorients_queue is not None) and (results_queue is not None):
             multiprocessing.Process.__init__(self)
-        AbstractAgent.__init__(self)
+        AbstractAgent.__init__(self, convention)
         self._alter_posorientvel = self.snap_to_grid
         self.brain = brain
         self._posorients_queue = posorients_queue
diff --git a/navipy/moving/maths.py b/navipy/moving/maths.py
index faf8753..55389c7 100644
--- a/navipy/moving/maths.py
+++ b/navipy/moving/maths.py
@@ -53,7 +53,7 @@ def next_pos(motion_vec, move_mode, move_param=None):
         phi = np.arctan2(speed['location']['dy'], speed['location']['dx'])
         radius = np.sqrt(np.sum(speed**2))
         if np.isclose(radius, 0):
-            scaling = 0
+            # scaling = 0
             speed = 0 * speed
         else:
             tuples = [('location', 'dx'), ('location', 'dy'),
@@ -80,10 +80,11 @@ def next_pos(motion_vec, move_mode, move_param=None):
 
             else:
                 deltas['location']['dy'] = 0
-            scaling = 1
+            # scaling = 1
             speed = move_param['grid_spacing'] * deltas
     elif move_mode is 'free_run':
-        scaling = 1  # <=> dt = 1, user need to scale speed in dt units
+        pass
+        # scaling = 1  # <=> dt = 1, user need to scale speed in dt units
     else:
         raise ValueError('grid_mode is not supported')
     toreturn = motion_vec
diff --git a/navipy/moving/test_agent.py b/navipy/moving/test_agent.py
index b951ce6..3319808 100644
--- a/navipy/moving/test_agent.py
+++ b/navipy/moving/test_agent.py
@@ -87,7 +87,7 @@ class TestNavipyMovingAgent(unittest.TestCase):
     # GridAgent
     #
     def test_move_gridagent(self):
-        agent = naviagent.GridAgent(self.brain)
+        agent = naviagent.GridAgent(self.brain, 'rxyz')
         initposorient = None
         with warnings.catch_warnings(record=True):
             initposorient = self.brain.posorients.loc[13, :]
@@ -107,16 +107,16 @@ class TestNavipyMovingAgent(unittest.TestCase):
                                pd.Series(data=1,
                                          index=index)}}
         agent.mode_of_motion = mode_move
-        with warnings.catch_warnings(record=True) as w:
+        with warnings.catch_warnings(record=True):
             agent.move()
         obtained = agent.posorient
         self.assertTrue(np.allclose(
             obtained, initposorient.loc[obtained.index]))
 
     def test_fly_gridagent(self):
-        agent = naviagent.GridAgent(self.brain)
+        agent = naviagent.GridAgent(self.brain, 'rxyz')
         initposorient = None
-        with warnings.catch_warnings(record=True) as w:
+        with warnings.catch_warnings(record=True):
             initposorient = self.brain.posorients.loc[13, :]
         initposovel = pd.Series(data=0,
                                 index=self.__posorient_vel_col)
@@ -145,7 +145,7 @@ class TestNavipyMovingAgent(unittest.TestCase):
 
     def test_init_graphagent(self):
         agent = None
-        with warnings.catch_warnings(record=True) as w:
+        with warnings.catch_warnings(record=True):
             agent = naviagent.GraphAgent(self.brain)
         if version < 2:
             graph_nodes = list(agent.graph.nodes())
@@ -157,7 +157,7 @@ class TestNavipyMovingAgent(unittest.TestCase):
 
     def test_graph_setter(self):
         agent = None
-        with warnings.catch_warnings(record=True) as w:
+        with warnings.catch_warnings(record=True):
             agent = naviagent.GraphAgent(self.brain)
         if version < 2:
             graph_nodes = list(agent.graph.nodes())
@@ -187,7 +187,7 @@ class TestNavipyMovingAgent(unittest.TestCase):
         """
         # Test all node to first
         agent = None
-        with warnings.catch_warnings(record=True) as w:
+        with warnings.catch_warnings(record=True):
             agent = naviagent.GraphAgent(self.brain)
 
         if version < 2:
@@ -254,7 +254,7 @@ class TestNavipyMovingAgent(unittest.TestCase):
         3. Local minima
         """
         agent = None
-        with warnings.catch_warnings(record=True) as w:
+        with warnings.catch_warnings(record=True):
             agent = naviagent.GraphAgent(self.brain)
         # Local maxima
         if version < 2:
diff --git a/navipy/moving/test_maths.py b/navipy/moving/test_maths.py
index 44219dc..75fbc8e 100644
--- a/navipy/moving/test_maths.py
+++ b/navipy/moving/test_maths.py
@@ -116,10 +116,10 @@ class TestNavipyMovingMaths(unittest.TestCase):
         expected_dict[337] = 6
         expected_dict[338] = 7  # equivalent to -22
         tuples2 = [('location', 'x'), ('location', 'y'),
-                  ('location', 'z'), ('location', 'dx'),
-                  ('location', 'dy'), ('location', 'dz')]
+                   ('location', 'z'), ('location', 'dx'),
+                   ('location', 'dy'), ('location', 'dz')]
         index2 = pd.MultiIndex.from_tuples(tuples2,
-                                          names=['position', 'orientation'])
+                                           names=['position', 'orientation'])
 
         for angle, exp_i in expected_dict.items():
             alpha = np.deg2rad(angle)
-- 
GitLab