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