{
"metadata": {
"name": "",
"signature": "sha256:9453f2d297004717b7b0ab5bb80d8d05d3ff319f7e609fa9565e753aa36cef87"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import h5py\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"file = h5py.File('test_rps.hdf5', 'r') # 'r' means that hdf5 file is open in read-only mode\n",
"dataset = file['RPS01']"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print dataset.value[4,2]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"36.7822\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"plt.plot( dataset.value[:,0], dataset.value[:,2], color = 'r')\n",
"#plt.xlim([1.45415117E9,1.4541513E9])\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"prev_val= dataset.value[0,2]\n",
"n = 0\n",
"angle = np.zeros((dataset.shape[0]))\n",
"for i in range(dataset.value.shape[0]):\n",
" if (dataset.value[i,2] - prev_val) > 300:\n",
" n -= 1\n",
" angle[i] = dataset.value[i,2] + n*360\n",
" prev_val = dataset.value[i,2]\n",
" elif -(dataset.value[i,2] - prev_val) > 300: # compute angular speed in backward direction.\n",
" n += 1\n",
" angle[i] = dataset.value[i,2] - n*360\n",
" prev_val = dataset.value[i,2]\n",
" else:\n",
" angle[i] = dataset.value[i,2] + n*360\n",
" prev_val = dataset.value[i,2]\n",
" "
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Five point difference numerical calculation. Source: http://mathfun528.blogspot.cz/2011/07/numerical-differentiation.html"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"angle_speed = np.zeros_like(angle)\n",
"\n",
"for i in range(2,angle.shape[0]-2):\n",
" angle_speed[i] = (-angle[i + 2] + 8*angle[i + 1] - 8*angle[i - 1] + angle[i - 2])/12"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"fig, ax1 = plt.subplots()\n",
"\n",
"ax2 = ax1.twinx()\n",
"ax1.set_xlabel('Sample #')\n",
"ax1.set_ylabel('Angle')\n",
"ax2.set_ylabel('Angular speed')\n",
"\n",
"ax1.plot(dataset.value[:,0], angle,'b',dataset.value[:,0], dataset.value[:,2],'r')\n",
"ax2.plot(dataset.value[:,0], angle_speed,'g')\n",
"\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print angle"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[ 3.64746094e+01 3.65405273e+01 3.77929688e+01 ..., -1.31529551e+05\n",
" -1.31530452e+05 -1.31528452e+05]\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 45
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 45
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}