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

Add tutorials ipyynb

parent bbdb7396
No related branches found
No related tags found
No related merge requests found
......@@ -19,9 +19,7 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../../src/'))
sys.path.insert(0, os.path.abspath('../../src/database/'))
sys.path.insert(0, os.path.abspath('../../tutorials'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
......
This diff is collapsed.
%% Cell type:markdown id: tags:
# Recording animal trajectory
## Conversion to navipy trajectories
### From Matlab to navipy
%% Cell type:code id: tags:
``` python
from scipy.io import loadmat
import numpy as np
import os
from navipy.tools.trajectory import Trajectory
import pkg_resources
# Use the trafile from the resources
# You can adapt this code, by changing trajfile
# with your own trajectory file
trajfile = pkg_resources.resource_filename(
'navipy',
'resources/sample_experiment/Lobecke_JEB_2018/Y101_OBFlight_0001.mat')
csvtrajfile, _ = os.path.splitext(trajfile)
csvtrajfile = csvtrajfile+'.csv'
mymat = loadmat(trajfile)
# matlab files are loaded in a dictionary
# we need to identify, under which key the trajectory has been saved
print(mymat.keys())
key = 'trajectory'
# Arrays are placed in a tupple. We need to access the level
# of the array itself.
mymat = mymat[key][0][0][0]
# The array should be a numpy array, and therefore as the .shape function
# to display the array size:
print(mymat.shape)
# 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)
# 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
# in the trajectory
rotconvention = 'rzyx'
indeces = np.arange(0,mymat.shape[0])
mytraj = Trajectory(rotconv = rotconvention, indeces=indeces)
# We now can assign the values
mytraj.x = mymat[:,0]
mytraj.y = mymat[:,1]
mytraj.z = mymat[:,2]
mytraj.alpha_0 = mymat[:,3]
mytraj.alpha_1 = 0
mytraj.alpha_2 = 0
# We can then save mytraj as csv file for example
mytraj.to_csv(csvtrajfile)
mytraj.head()
```
%% Output
dict_keys(['__header__', '__version__', '__globals__', 'trajectory', 'nests', 'cylinders'])
(7661, 4)
location rzyx
x y z alpha_0 alpha_1 alpha_2
0 3.056519 -214.990482 9.330593 2.79751 0 0
1 4.611665 -215.020314 8.424138 2.80863 0 0
2 4.556650 -214.593236 9.185016 2.81407 0 0
3 4.643091 -213.829769 10.542035 2.82704 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
This diff is collapsed.
......@@ -3,6 +3,8 @@
(called navipy)
"""
from setuptools import setup, find_packages
import glob
import os
excluded = []
......@@ -22,6 +24,18 @@ def create_package_list(base_package):
if not exclude_package(pkg)])
def package_data_files(base_package):
os.chdir(base_package)
filelist = glob.glob(os.path.join('resources',
'*'))
filelist.extend(glob.glob(os.path.join('resources',
'**', '*'),
recursive=True))
os.chdir('../')
print(filelist)
return filelist
setup_dict = {'name': 'navipy',
'version': '0.1',
'author': "Olivier J.N. Bertrand",
......@@ -50,10 +64,7 @@ setup_dict = {'name': 'navipy',
'Pillow',
'tables'],
'package_data': {'navipy':
['resources/*.db',
'resources/*.blend',
'resources/*.csv',
'resources/configs/*.yaml']},
package_data_files("navipy")},
'include_package_data': True,
'entry_points': {
'console_scripts': [
......
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