Skip to content
Snippets Groups Projects
Commit 3724cbec authored by Olivier Bertrand's avatar Olivier Bertrand
Browse files

Use columns naming from trajectories in database for homogeneity

parent 576f3d35
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ import io
from navipy.scene import is_numeric_array, check_scene
from navipy.maths import constants as mconst
from navipy.trajectories import Trajectory
from navipy.trajectories import posorient_columns
import logging
import numbers
......@@ -552,7 +553,7 @@ class DataBase():
if self.rotation_convention is not None:
posorients = Trajectory()
posorients.from_dataframe(posorient, rotconv=self.__convention)
return posorients
return posorients.astype(float)
@property
def normalisations(self):
......@@ -612,40 +613,27 @@ class DataBase():
# toreturn = toreturn.astype(float)
posorient = None
convention = toreturn.rotconv_id
tuples = posorient_columns(convention)
index = pd.MultiIndex.from_tuples(tuples)
posorient = pd.Series(index=index)
posorient['location']['x'] = toreturn.loc['x']
posorient['location']['y'] = toreturn.loc['y']
posorient['location']['z'] = toreturn.loc['z']
if convention != 'quaternion':
tuples = [('location', 'x'), ('location', 'y'),
('location', 'z'), ('xyz', 'alpha_0'),
('xyz', 'alpha_1'), ('xyz', 'alpha_2')]
index = pd.MultiIndex.from_tuples(tuples,
names=['position',
'orientation'])
posorient = pd.Series(index=index)
posorient['location']['x'] = toreturn.loc['x']
posorient['location']['y'] = toreturn.loc['y']
posorient['location']['z'] = toreturn.loc['z']
posorient[convention]['alpha_0'] = toreturn.loc['q_0']
posorient[convention]['alpha_1'] = toreturn.loc['q_1']
posorient[convention]['alpha_2'] = toreturn.loc['q_2']
posorient.name = toreturn.name
else:
tuples = [('location', 'x'), ('location', 'y'),
('location', 'z'), (convention, 'q_0'),
(convention, 'q_1'), (convention, 'q_2'),
(convention, 'q_3')]
index = pd.MultiIndex.from_tuples(tuples,
names=['position',
'orientation'])
posorient = pd.Series(index=index)
posorient['location']['x'] = toreturn.loc['x']
posorient['location']['y'] = toreturn.loc['y']
posorient['location']['z'] = toreturn.loc['z']
posorient[convention]['q_0'] = toreturn.loc['q_0']
posorient[convention]['q_1'] = toreturn.loc['q_1']
posorient[convention]['q_2'] = toreturn.loc['q_2']
posorient[convention]['q_3'] = toreturn.loc['q_3']
posorient.name = toreturn.name
return posorient
return posorient.astype(float)
def scene(self, posorient=None, rowid=None):
"""Read an image at a given position-orientation or given id of row in the \
......
......@@ -146,27 +146,9 @@ class TestCase(unittest.TestCase):
and checks if the returned entry for rowid 1 is correct
- that it all columns and correct values
"""
conn = sqlite3.connect(self.mydb_filename)
c = conn.cursor()
c.execute(""" SELECT * FROM position_orientation WHERE (rowid=1) """)
rows = c.fetchall()[0]
# working case
tuples = [('location', 'x'), ('location', 'y'),
('location', 'z'), ('xyz', 'alpha_0'),
('xyz', 'alpha_1'), ('xyz', 'alpha_2')]
index = pd.MultiIndex.from_tuples(tuples,
names=['position', 'orientation'])
posorient = pd.Series(index=index)
posorient['location']['x'] = rows[6]
posorient['location']['y'] = rows[7]
posorient['location']['z'] = rows[8]
posorient['xyz']['alpha_0'] = rows[3]
posorient['xyz']['alpha_1'] = rows[5]
posorient['xyz']['alpha_2'] = rows[4]
posorient = self.mydb.posorients.iloc[0, :]
for rowid in [0, -2]:
with self.assertRaises(ValueError):
# print("rowid",rowid)
self.mydb.read_posorient(rowid=rowid)
with self.assertRaises(TypeError):
self.mydb.read_posorient(rowid='T')
......@@ -179,15 +161,7 @@ class TestCase(unittest.TestCase):
for rowid in [1]:
posoriend2 = self.mydb.read_posorient(rowid=rowid)
assert posoriend2['location']['x'] == posorient['location']['x']
assert posoriend2['location']['y'] == posorient['location']['y']
assert posoriend2['location']['z'] == posorient['location']['z']
assert (posoriend2['xyz']['alpha_0'] ==
posorient['xyz']['alpha_0'])
assert (posoriend2['xyz']['alpha_1'] ==
posorient['xyz']['alpha_1'])
assert (posoriend2['xyz']['alpha_2'] ==
posorient['xyz']['alpha_2'])
pd.testing.assert_series_equal(posoriend2, posorient)
def test_scene_id(self):
"""
......@@ -247,7 +221,7 @@ class TestCase(unittest.TestCase):
# incorrect case missing column
posorient2 = posorient.copy()
posorient2.drop(('location', 'x'))
posorient2 = posorient2.drop(('location', 'x'))
with self.assertRaises(Exception):
image = self.mydb.scene(posorient=posorient2)
......@@ -270,7 +244,6 @@ class TestCase(unittest.TestCase):
# not working case empty
posorient2 = pd.Series(index=posorient.index)
with self.assertRaises(Exception):
image = self.mydb.scene(posorient=posorient2)
......
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