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
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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:
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment