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

changed convention in agent, and repaired flake8

parent 79919df3
Branches
Tags
No related merge requests found
...@@ -49,10 +49,9 @@ class DefaultBrain(): ...@@ -49,10 +49,9 @@ class DefaultBrain():
class AbstractAgent(): class AbstractAgent():
def __init__(self): def __init__(self, convention='rxyz'):
self._brain = DefaultBrain() self._brain = DefaultBrain()
self._alter_posorientvel = defaultcallback self._alter_posorientvel = defaultcallback
convention = 'rxyz'
tuples = [('location', 'x'), ('location', 'y'), tuples = [('location', 'x'), ('location', 'y'),
('location', 'z'), (convention, 'alpha_0'), ('location', 'z'), (convention, 'alpha_0'),
(convention, 'alpha_1'), (convention, 'alpha_2')] (convention, 'alpha_1'), (convention, 'alpha_2')]
...@@ -150,8 +149,10 @@ CyberBeeAgent is a close loop agent and need to be run within blender \ ...@@ -150,8 +149,10 @@ CyberBeeAgent is a close loop agent and need to be run within blender \
""" """
def __init__(self, brain): def __init__(self, brain, convention):
AbstractAgent.__init__(self) if convention is None:
raise Exception("a convention must be specified")
AbstractAgent.__init__(self, convention)
AbstractAgent._alter_posorientvel = \ AbstractAgent._alter_posorientvel = \
lambda motion_vec: navimomath.next_pos(motion_vec, lambda motion_vec: navimomath.next_pos(motion_vec,
move_mode='free_run') move_mode='free_run')
...@@ -175,12 +176,14 @@ GridAgent is a close loop agent here its position is snap to a grid. ...@@ -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, posorients_queue=None,
results_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): if (posorients_queue is not None) and (results_queue is not None):
multiprocessing.Process.__init__(self) multiprocessing.Process.__init__(self)
AbstractAgent.__init__(self) AbstractAgent.__init__(self, convention)
self._alter_posorientvel = self.snap_to_grid self._alter_posorientvel = self.snap_to_grid
self.brain = brain self.brain = brain
self._posorients_queue = posorients_queue self._posorients_queue = posorients_queue
......
...@@ -53,7 +53,7 @@ def next_pos(motion_vec, move_mode, move_param=None): ...@@ -53,7 +53,7 @@ def next_pos(motion_vec, move_mode, move_param=None):
phi = np.arctan2(speed['location']['dy'], speed['location']['dx']) phi = np.arctan2(speed['location']['dy'], speed['location']['dx'])
radius = np.sqrt(np.sum(speed**2)) radius = np.sqrt(np.sum(speed**2))
if np.isclose(radius, 0): if np.isclose(radius, 0):
scaling = 0 # scaling = 0
speed = 0 * speed speed = 0 * speed
else: else:
tuples = [('location', 'dx'), ('location', 'dy'), tuples = [('location', 'dx'), ('location', 'dy'),
...@@ -80,10 +80,11 @@ def next_pos(motion_vec, move_mode, move_param=None): ...@@ -80,10 +80,11 @@ def next_pos(motion_vec, move_mode, move_param=None):
else: else:
deltas['location']['dy'] = 0 deltas['location']['dy'] = 0
scaling = 1 # scaling = 1
speed = move_param['grid_spacing'] * deltas speed = move_param['grid_spacing'] * deltas
elif move_mode is 'free_run': 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: else:
raise ValueError('grid_mode is not supported') raise ValueError('grid_mode is not supported')
toreturn = motion_vec toreturn = motion_vec
......
...@@ -87,7 +87,7 @@ class TestNavipyMovingAgent(unittest.TestCase): ...@@ -87,7 +87,7 @@ class TestNavipyMovingAgent(unittest.TestCase):
# GridAgent # GridAgent
# #
def test_move_gridagent(self): def test_move_gridagent(self):
agent = naviagent.GridAgent(self.brain) agent = naviagent.GridAgent(self.brain, 'rxyz')
initposorient = None initposorient = None
with warnings.catch_warnings(record=True): with warnings.catch_warnings(record=True):
initposorient = self.brain.posorients.loc[13, :] initposorient = self.brain.posorients.loc[13, :]
...@@ -107,16 +107,16 @@ class TestNavipyMovingAgent(unittest.TestCase): ...@@ -107,16 +107,16 @@ class TestNavipyMovingAgent(unittest.TestCase):
pd.Series(data=1, pd.Series(data=1,
index=index)}} index=index)}}
agent.mode_of_motion = mode_move agent.mode_of_motion = mode_move
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True):
agent.move() agent.move()
obtained = agent.posorient obtained = agent.posorient
self.assertTrue(np.allclose( self.assertTrue(np.allclose(
obtained, initposorient.loc[obtained.index])) obtained, initposorient.loc[obtained.index]))
def test_fly_gridagent(self): def test_fly_gridagent(self):
agent = naviagent.GridAgent(self.brain) agent = naviagent.GridAgent(self.brain, 'rxyz')
initposorient = None initposorient = None
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True):
initposorient = self.brain.posorients.loc[13, :] initposorient = self.brain.posorients.loc[13, :]
initposovel = pd.Series(data=0, initposovel = pd.Series(data=0,
index=self.__posorient_vel_col) index=self.__posorient_vel_col)
...@@ -145,7 +145,7 @@ class TestNavipyMovingAgent(unittest.TestCase): ...@@ -145,7 +145,7 @@ class TestNavipyMovingAgent(unittest.TestCase):
def test_init_graphagent(self): def test_init_graphagent(self):
agent = None agent = None
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True):
agent = naviagent.GraphAgent(self.brain) agent = naviagent.GraphAgent(self.brain)
if version < 2: if version < 2:
graph_nodes = list(agent.graph.nodes()) graph_nodes = list(agent.graph.nodes())
...@@ -157,7 +157,7 @@ class TestNavipyMovingAgent(unittest.TestCase): ...@@ -157,7 +157,7 @@ class TestNavipyMovingAgent(unittest.TestCase):
def test_graph_setter(self): def test_graph_setter(self):
agent = None agent = None
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True):
agent = naviagent.GraphAgent(self.brain) agent = naviagent.GraphAgent(self.brain)
if version < 2: if version < 2:
graph_nodes = list(agent.graph.nodes()) graph_nodes = list(agent.graph.nodes())
...@@ -187,7 +187,7 @@ class TestNavipyMovingAgent(unittest.TestCase): ...@@ -187,7 +187,7 @@ class TestNavipyMovingAgent(unittest.TestCase):
""" """
# Test all node to first # Test all node to first
agent = None agent = None
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True):
agent = naviagent.GraphAgent(self.brain) agent = naviagent.GraphAgent(self.brain)
if version < 2: if version < 2:
...@@ -254,7 +254,7 @@ class TestNavipyMovingAgent(unittest.TestCase): ...@@ -254,7 +254,7 @@ class TestNavipyMovingAgent(unittest.TestCase):
3. Local minima 3. Local minima
""" """
agent = None agent = None
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True):
agent = naviagent.GraphAgent(self.brain) agent = naviagent.GraphAgent(self.brain)
# Local maxima # Local maxima
if version < 2: if version < 2:
......
...@@ -116,10 +116,10 @@ class TestNavipyMovingMaths(unittest.TestCase): ...@@ -116,10 +116,10 @@ class TestNavipyMovingMaths(unittest.TestCase):
expected_dict[337] = 6 expected_dict[337] = 6
expected_dict[338] = 7 # equivalent to -22 expected_dict[338] = 7 # equivalent to -22
tuples2 = [('location', 'x'), ('location', 'y'), tuples2 = [('location', 'x'), ('location', 'y'),
('location', 'z'), ('location', 'dx'), ('location', 'z'), ('location', 'dx'),
('location', 'dy'), ('location', 'dz')] ('location', 'dy'), ('location', 'dz')]
index2 = pd.MultiIndex.from_tuples(tuples2, index2 = pd.MultiIndex.from_tuples(tuples2,
names=['position', 'orientation']) names=['position', 'orientation'])
for angle, exp_i in expected_dict.items(): for angle, exp_i in expected_dict.items():
alpha = np.deg2rad(angle) alpha = np.deg2rad(angle)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment