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

Merge branch 'develop' of gitlab.ub.uni-bielefeld.de:olivier.bertrand/navipy into develop

parents 37802b5a d7816f3a
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Recording animal trajectory # Recording animal trajectory
# Conversion to navipy trajectories # Conversion to navipy trajectories
### From Matlab to navipy ### From Matlab to navipy
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from scipy.io import loadmat from scipy.io import loadmat
import numpy as np import numpy as np
import os import os
from navipy.tools.trajectory import Trajectory from navipy.tools.trajectory import Trajectory
trajfile = '../navipy/resources/sample_experiment/Lobecke_JEB_2018/Y101_OBFlight_0001.mat' trajfile = '../navipy/resources/sample_experiment/Lobecke_JEB_2018/Y101_OBFlight_0001.mat'
csvtrajfile, _ = os.path.splitext(trajfile) csvtrajfile, _ = os.path.splitext(trajfile)
csvtrajfile = csvtrajfile+'.csv' csvtrajfile = csvtrajfile+'.csv'
mymat = loadmat(trajfile) mymat = loadmat(trajfile)
# matlab files are loaded in a dictionary # matlab files are loaded in a dictionary
# we need to identify, under which key the trajectory has been saved # we need to identify, under which key the trajectory has been saved
print(mymat.keys()) print(mymat.keys())
key = 'trajectory' key = 'trajectory'
# Arrays are placed in a tupple. We need to access the level # Arrays are placed in a tupple. We need to access the level
# of the array itself. # of the array itself.
mymat = mymat[key][0][0][0] mymat = mymat[key][0][0][0]
# The array should be a numpy array, and therefore as the .shape function # The array should be a numpy array, and therefore as the .shape function
# to display the array size: # to display the array size:
print(mymat.shape) print(mymat.shape)
# In this example the array has 7661 rows and 4 columns # In this example the array has 7661 rows and 4 columns
# the columns are: x,y,z, yaw. Therefore pitch and roll were assumed to be constant (here null) # the columns are: x,y,z, yaw. Therefore pitch and roll were assumed to be constant (here null)
# We can therefore init a trajectory with the convention for rotation # We can therefore init a trajectory with the convention for rotation
# often yaw-pitch-roll (i.e. 'rzyx') and with indeces the number of sampling points we have # often yaw-pitch-roll (i.e. 'rzyx') and with indeces the number of sampling points we have
# in the trajectory # in the trajectory
rotconvention = 'rzyx' rotconvention = 'rzyx'
indeces = np.arange(0,mymat.shape[0]) indeces = np.arange(0,mymat.shape[0])
mytraj = Trajectory(rotconv = rotconvention, indeces=indeces) mytraj = Trajectory(rotconv = rotconvention, indeces=indeces)
# We now can assign the values # We now can assign the values
mytraj.x = mymat[:,0] mytraj.x = mymat[:,0]
mytraj.y = mymat[:,1] mytraj.y = mymat[:,1]
mytraj.z = mymat[:,2] mytraj.z = mymat[:,2]
mytraj.alpha_0 = mymat[:,3] mytraj.alpha_0 = mymat[:,3]
mytraj.alpha_1 = 0 mytraj.alpha_1 = 0
mytraj.alpha_2 = 0 mytraj.alpha_2 = 0
# We can then save mytraj as csv file for example # We can then save mytraj as csv file for example
mytraj.to_csv(csvtrajfile) mytraj.to_csv(csvtrajfile)
mytraj.head() mytraj.head()
``` ```
%% Output %% Output
dict_keys(['__header__', '__version__', '__globals__', 'trajectory', 'nests', 'cylinders']) dict_keys(['__header__', '__version__', '__globals__', 'trajectory', 'nests', 'cylinders'])
(7661, 4) (7661, 4)
location rzyx location rzyx
x y z alpha_0 alpha_1 alpha_2 x y z alpha_0 alpha_1 alpha_2
0 3.056519 -214.990482 9.330593 2.79751 0 0 0 3.056519 -214.990482 9.330593 2.79751 0 0
1 4.611665 -215.020314 8.424138 2.80863 0 0 1 4.611665 -215.020314 8.424138 2.80863 0 0
2 4.556650 -214.593236 9.185016 2.81407 0 0 2 4.556650 -214.593236 9.185016 2.81407 0 0
3 4.643091 -213.829769 10.542035 2.82704 0 0 3 4.643091 -213.829769 10.542035 2.82704 0 0
4 4.647302 -214.431592 7.461187 2.82896 0 0 4 4.647302 -214.431592 7.461187 2.82896 0 0
%% Cell type:markdown id: tags:
### From csv to navipy
Navipy can read csv files with 7 columns and a two line headers
<table>
<tr>
<td>location</td>
<td>location</td>
<td>location</td>
<td>rzyx</td>
<td>rzyx</td>
<td>rzyx</td>
</tr>
<tr>
<td>x</td>
<td>y</td>
<td>z</td>
<td>alpha_0</td>
<td>alpha_1</td>
<td>alpha_2</td>
</tr>
</table>
But you may have csv file with a different format.
Here we are going to show, how to convert your csv file format to the one required by navipy
......
...@@ -162,7 +162,7 @@ ...@@ -162,7 +162,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.5" "version": "3.6.3"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
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