ReadCSV

Read the csv file with acceloremeter information. Convert the data in file to numpy array and then plot it.


In [63]:
import csv
import numpy as np
import matplotlib.pyplot as plt

Open the CSV file and transform to an array. Also get number of samples


In [71]:
with open('../dataset/PhysicsToolboxSuite/walk_normal_hand_001.csv', 'rb') as csvfile:
    data_reader = csv.reader(csvfile, delimiter = ',')
    
    data = np.asarray(list(data_reader))

Convert data into separate variables (arrays)


In [72]:
timevec_str = data[1:-1,0]
timevec = timevec_str.astype(np.float)

gFx_str = data[1:-1,1]
gFx = gFx_str.astype(np.float)

gFy_str = data[1:-1,2]
gFy = gFy_str.astype(np.float)

gFz_str = data[1:-1,3]
gFz = gFz_str.astype(np.float)

TgF_str = data[1:-1,4]
TgF = TgF_str.astype(np.float)

NumSamples = len(timevec);
TimeDuration = timevec[NumSamples-1] - timevec[0];

In [73]:
msg = 'Number of samples = ' + repr(NumSamples)
print msg

msg = 'Duration of sample = ' + repr(TimeDuration) + ' seconds'
print msg

print ' '
print timevec
print gFx
print gFy
print gFz
print TgF


Number of samples = 2375
Duration of sample = 23.711000000000002 seconds
 
[  1.40000000e-02   1.50000000e-02   1.60000000e-02 ...,   2.36960000e+01
   2.37060000e+01   2.37250000e+01]
[ 0.0049  0.0054  0.0002 ..., -0.1931 -0.1884 -0.1928]
[ 0.1682  0.1559  0.1515 ...,  0.5717  0.5626  0.5469]
[ 1.2113  1.1653  1.1181 ...,  1.0133  1.0651  1.1264]
[ 1.223  1.176  1.128 ...,  1.179  1.219  1.267]

Plotting graphs of variables


In [74]:
fig = plt.figure()
plt.figure(figsize=(16,8))

plt.plot(timevec,TgF,label="TgF")

plt.grid(linestyle='-', linewidth=1)
plt.legend(loc='upper right')
plt.show()

fig = plt.figure()
plt.figure(figsize=(16,8))

plt.plot(timevec,gFx,label="gFx",color="blue")
plt.plot(timevec,gFy,label="gFy",color="red")
plt.plot(timevec,gFz,label="gFz",color="green")

plt.grid(linestyle='-', linewidth=1)
plt.legend(loc='upper right')
plt.show()


<matplotlib.figure.Figure at 0xa3a1470>
<matplotlib.figure.Figure at 0x9685e80>

Explore a range

Visualize an specific range of time


In [75]:
# Parameters to setup
# idx_ini = 0
# idx_end = NumSamples

idx_ini = 0
idx_end = 120

# Extract range
timevec_zoom = timevec[idx_ini:idx_end]

gFx_zoom = gFx[idx_ini:idx_end]

gFy_zoom = gFy[idx_ini:idx_end]

gFz_zoom = gFz[idx_ini:idx_end]

TgF_zoom = TgF[idx_ini:idx_end]

NumSamples_zoom = len(timevec_zoom);
TimeDuration_zoom = timevec[idx_end-1] - timevec[idx_ini];

In [76]:
msg = 'Number of samples of zoom = ' + repr(NumSamples_zoom)
print msg

msg = 'Duration of sample of zoom = ' + repr(TimeDuration_zoom) + ' seconds'
print msg


Number of samples of zoom = 120
Duration of sample of zoom = 1.153 seconds

In [77]:
fig = plt.figure()

plt.figure(figsize=(16,8))
plt.plot(timevec_zoom,TgF_zoom,'b-o',label="TgF")

plt.grid(linestyle='-', linewidth=1)
plt.legend(loc='upper right')
plt.show()

fig = plt.figure()
plt.figure(figsize=(16,8))

plt.plot(timevec_zoom,gFx_zoom,'b-o',label="gFx",color="blue")
plt.plot(timevec_zoom,gFy_zoom,'r-o',label="gFy",color="red")
plt.plot(timevec_zoom,gFz_zoom,'g-o',label="gFz",color="green")

plt.grid(linestyle='-', linewidth=1)
plt.legend(loc='upper right')
plt.show()


<matplotlib.figure.Figure at 0xa7fba20>
<matplotlib.figure.Figure at 0x96702b0>

In [ ]: