Rev Author Line No. Line
4413 kaklik 1 {
2 "metadata": {
3 "name": "",
4423 kaklik 4 "signature": "sha256:2b685229d679e1d41a25fddbfc5abcd92050271aa14c1131a12e709bfacddba1"
4413 kaklik 5 },
6 "nbformat": 3,
7 "nbformat_minor": 0,
8 "worksheets": [
9 {
10 "cells": [
11 {
12 "cell_type": "code",
13 "collapsed": false,
14 "input": [
15 "import h5py\n",
16 "import numpy as np\n",
17 "import matplotlib.pyplot as plt"
18 ],
19 "language": "python",
20 "metadata": {},
21 "outputs": [],
4423 kaklik 22 "prompt_number": 1
4413 kaklik 23 },
24 {
25 "cell_type": "code",
26 "collapsed": false,
27 "input": [
28 "file = h5py.File('test_rps.hdf5', 'r') # 'r' means that hdf5 file is open in read-only mode\n",
29 "dataset = file['RPS01']"
30 ],
31 "language": "python",
32 "metadata": {},
33 "outputs": [],
4423 kaklik 34 "prompt_number": 2
4413 kaklik 35 },
36 {
37 "cell_type": "code",
38 "collapsed": false,
39 "input": [
4417 kaklik 40 "print dataset.value[4,2]"
4413 kaklik 41 ],
42 "language": "python",
43 "metadata": {},
44 "outputs": [
45 {
46 "output_type": "stream",
47 "stream": "stdout",
48 "text": [
4417 kaklik 49 "36.7822\n"
4413 kaklik 50 ]
51 }
52 ],
4423 kaklik 53 "prompt_number": 3
4413 kaklik 54 },
55 {
56 "cell_type": "code",
57 "collapsed": false,
58 "input": [
4417 kaklik 59 "plt.plot( dataset.value[:,0], dataset.value[:,2], color = 'r')\n",
60 "#plt.xlim([1.45415117E9,1.4541513E9])\n",
61 "plt.show()"
4413 kaklik 62 ],
63 "language": "python",
64 "metadata": {},
4417 kaklik 65 "outputs": [],
4423 kaklik 66 "prompt_number": 4
4417 kaklik 67 },
68 {
69 "cell_type": "code",
70 "collapsed": false,
71 "input": [
72 "prev_val= dataset.value[0,2]\n",
73 "n = 0\n",
4422 kaklik 74 "angle = np.zeros((dataset.shape[0]))\n",
4417 kaklik 75 "for i in range(dataset.value.shape[0]):\n",
4423 kaklik 76 " if (dataset.value[i,2] - prev_val) > 300:\n",
4422 kaklik 77 " n -= 1\n",
4417 kaklik 78 " angle[i] = dataset.value[i,2] + n*360\n",
4422 kaklik 79 " prev_val = dataset.value[i,2]\n",
4423 kaklik 80 " elif -(dataset.value[i,2] - prev_val) > 300: # compute angular speed in backward direction.\n",
81 " n += 1\n",
82 " angle[i] = dataset.value[i,2] - n*360\n",
83 " prev_val = dataset.value[i,2]\n",
4422 kaklik 84 " else:\n",
85 " angle[i] = dataset.value[i,2] + n*360\n",
4423 kaklik 86 " prev_val = dataset.value[i,2]\n",
87 " "
4417 kaklik 88 ],
89 "language": "python",
90 "metadata": {},
91 "outputs": [],
4423 kaklik 92 "prompt_number": 57
4417 kaklik 93 },
94 {
4423 kaklik 95 "cell_type": "markdown",
96 "metadata": {},
97 "source": [
98 "Five point difference numerical calculation. Source: http://mathfun528.blogspot.cz/2011/07/numerical-differentiation.html"
99 ]
100 },
101 {
4417 kaklik 102 "cell_type": "code",
103 "collapsed": false,
104 "input": [
4423 kaklik 105 "angle_speed = np.zeros_like(angle)\n",
106 "\n",
107 "for i in range(2,angle.shape[0]-2):\n",
108 " angle_speed[i] = (-angle[i + 2] + 8*angle[i + 1] - 8*angle[i - 1] + angle[i - 2])/12"
109 ],
110 "language": "python",
111 "metadata": {},
112 "outputs": [],
113 "prompt_number": 58
114 },
115 {
116 "cell_type": "code",
117 "collapsed": false,
118 "input": [
4422 kaklik 119 "fig, ax1 = plt.subplots()\n",
120 "\n",
4423 kaklik 121 "ax2 = ax1.twinx()\n",
122 "ax1.set_xlabel('Sample #')\n",
123 "ax1.set_ylabel('Angle')\n",
124 "ax2.set_ylabel('Angular speed')\n",
4422 kaklik 125 "\n",
4423 kaklik 126 "ax1.plot(dataset.value[:,0], angle,'b',dataset.value[:,0], dataset.value[:,2],'r')\n",
127 "ax2.plot(dataset.value[:,0], angle_speed,'g')\n",
4422 kaklik 128 "\n",
129 "plt.show()"
4417 kaklik 130 ],
131 "language": "python",
132 "metadata": {},
4423 kaklik 133 "outputs": [],
134 "prompt_number": 59
4422 kaklik 135 },
136 {
137 "cell_type": "code",
138 "collapsed": false,
4423 kaklik 139 "input": [],
4422 kaklik 140 "language": "python",
141 "metadata": {},
4423 kaklik 142 "outputs": [],
143 "prompt_number": 45
4413 kaklik 144 },
145 {
146 "cell_type": "code",
147 "collapsed": false,
4423 kaklik 148 "input": [],
4422 kaklik 149 "language": "python",
150 "metadata": {},
4423 kaklik 151 "outputs": [],
152 "prompt_number": 45
4422 kaklik 153 },
154 {
155 "cell_type": "code",
156 "collapsed": false,
4423 kaklik 157 "input": [],
4422 kaklik 158 "language": "python",
159 "metadata": {},
4423 kaklik 160 "outputs": [],
161 "prompt_number": 45
4422 kaklik 162 },
163 {
164 "cell_type": "code",
165 "collapsed": false,
4423 kaklik 166 "input": [],
4422 kaklik 167 "language": "python",
168 "metadata": {},
4423 kaklik 169 "outputs": [],
170 "prompt_number": 45
4422 kaklik 171 },
172 {
173 "cell_type": "code",
174 "collapsed": false,
4413 kaklik 175 "input": [],
176 "language": "python",
177 "metadata": {},
4423 kaklik 178 "outputs": [],
179 "prompt_number": 45
180 },
181 {
182 "cell_type": "code",
183 "collapsed": false,
184 "input": [],
185 "language": "python",
186 "metadata": {},
4413 kaklik 187 "outputs": []
188 }
189 ],
190 "metadata": {}
191 }
192 ]
193 }