CerePressPlot

Takes one ForceTimeStampXXXX.csv file and plots a grid of F v T, F v P, and P v T.

  • csv file imported as dataframe for pandas
  • note that the column headers in the CerePress csv file contain spaces

Manipulations

  • compensated force is converted to grams force
  • position is zeroed out
  • time is zeroed out and converted to seconds
  • average force is calculated using rolling centered average (n=19)

Plot features

  • 3 plots saved to one html file
  • Custom hover tool to show x,y data

To Do

  • batch process files
  • maybe include image frame for each time index

In [1]:
import numpy as np
import pandas as pd
from bokeh.layouts import gridplot
from bokeh.plotting import figure, show
from bokeh.io import output_notebook, output_file
from bokeh.models import HoverTool

In [2]:
output_notebook()
output_file("ForceTimeStampPlot.html")


Loading BokehJS ...

In [3]:
df=pd.read_csv('ForceTimestamp20160713_051922.csv')

In [4]:
df.head(5)


Out[4]:
Function Raw Force Resting Force offset Compensated Force External Analog Input Position milliseconds
0 Seeking initial Contact 1851 1852 -1 0 30.000475 1468387163947
1 Seeking initial Contact 1860 1852 8 0 30.001965 1468387163953
2 Seeking initial Contact 1859 1852 7 0 30.004246 1468387163958
3 Seeking initial Contact 1858 1852 6 0 30.007521 1468387163964
4 Seeking initial Contact 1850 1852 -2 0 30.011786 1468387163970

In [6]:
timezero = df.loc[0,' milliseconds']

df['Time']= (df[' milliseconds']-timezero) / 1000

In [7]:
df.columns


Out[7]:
Index(['Function', 'Raw Force', ' Resting Force offset', ' Compensated Force',
       ' External Analog Input', ' Position', ' milliseconds', 'Time'],
      dtype='object')

In [8]:
df.head(5)


Out[8]:
Function Raw Force Resting Force offset Compensated Force External Analog Input Position milliseconds Time
0 Seeking initial Contact 1851 1852 -1 0 30.000475 1468387163947 0.000
1 Seeking initial Contact 1860 1852 8 0 30.001965 1468387163953 0.006
2 Seeking initial Contact 1859 1852 7 0 30.004246 1468387163958 0.011
3 Seeking initial Contact 1858 1852 6 0 30.007521 1468387163964 0.017
4 Seeking initial Contact 1850 1852 -2 0 30.011786 1468387163970 0.023

In [10]:
forceconversion = 35  # counts per gram

df['Force'] = df[' Compensated Force'] / forceconversion

In [12]:
positionzero = df.loc[0,' Position']

df['Position'] = df[' Position']-positionzero

In [13]:
df.head(5)


Out[13]:
Function Raw Force Resting Force offset Compensated Force External Analog Input Position milliseconds Time Force Position
0 Seeking initial Contact 1851 1852 -1 0 30.000475 1468387163947 0.000 -0.028571 0.000000
1 Seeking initial Contact 1860 1852 8 0 30.001965 1468387163953 0.006 0.228571 0.001490
2 Seeking initial Contact 1859 1852 7 0 30.004246 1468387163958 0.011 0.200000 0.003771
3 Seeking initial Contact 1858 1852 6 0 30.007521 1468387163964 0.017 0.171429 0.007046
4 Seeking initial Contact 1850 1852 -2 0 30.011786 1468387163970 0.023 -0.057143 0.011311

In [14]:
df['AverageForce'] = df['Force'].rolling(center=True,window=19).mean()
df.fillna(value=0)


Out[14]:
Function Raw Force Resting Force offset Compensated Force External Analog Input Position milliseconds Time Force Position AverageForce
0 Seeking initial Contact 1851 1852 -1 0 30.000475 1468387163947 0.000 -0.028571 0.000000 0.000000
1 Seeking initial Contact 1860 1852 8 0 30.001965 1468387163953 0.006 0.228571 0.001490 0.000000
2 Seeking initial Contact 1859 1852 7 0 30.004246 1468387163958 0.011 0.200000 0.003771 0.000000
3 Seeking initial Contact 1858 1852 6 0 30.007521 1468387163964 0.017 0.171429 0.007046 0.000000
4 Seeking initial Contact 1850 1852 -2 0 30.011786 1468387163970 0.023 -0.057143 0.011311 0.000000
5 Seeking initial Contact 1860 1852 8 0 30.017740 1468387163976 0.029 0.228571 0.017265 0.000000
6 Seeking initial Contact 1838 1852 -14 0 30.023891 1468387163982 0.035 -0.400000 0.023417 0.000000
7 Seeking initial Contact 1862 1852 10 0 30.030935 1468387163987 0.040 0.285714 0.030460 0.000000
8 Seeking initial Contact 1866 1852 14 0 30.038874 1468387163993 0.046 0.400000 0.038399 0.000000
9 Seeking initial Contact 1861 1852 9 0 30.047504 1468387163998 0.051 0.257143 0.047029 0.102256
10 Seeking initial Contact 1833 1852 -19 0 30.057228 1468387164004 0.057 -0.542857 0.056753 0.067669
11 Seeking initial Contact 1861 1852 9 0 30.067844 1468387164010 0.063 0.257143 0.067369 0.078195
12 Seeking initial Contact 1866 1852 14 0 30.080744 1468387164016 0.069 0.400000 0.080269 0.090226
13 Seeking initial Contact 1871 1852 19 0 30.093641 1468387164022 0.075 0.542857 0.093166 0.114286
14 Seeking initial Contact 1867 1852 15 0 30.107334 1468387164027 0.080 0.428571 0.106859 0.109774
15 Seeking initial Contact 1865 1852 13 0 30.121622 1468387164033 0.086 0.371429 0.121147 0.099248
16 Seeking initial Contact 1857 1852 5 0 30.135511 1468387164039 0.092 0.142857 0.135036 0.084211
17 Seeking initial Contact 1844 1852 -8 0 30.151287 1468387164045 0.098 -0.228571 0.150812 0.048120
18 Seeking initial Contact 1827 1852 -25 0 30.165873 1468387164051 0.104 -0.714286 0.165398 0.057143
19 Seeking initial Contact 1828 1852 -24 0 30.179764 1468387164057 0.110 -0.685714 0.179289 0.049624
20 Seeking initial Contact 1867 1852 15 0 30.193655 1468387164062 0.115 0.428571 0.193180 0.120301
21 Seeking initial Contact 1867 1852 15 0 30.208040 1468387164069 0.122 0.428571 0.207565 0.147368
22 Seeking initial Contact 1874 1852 22 0 30.223518 1468387164074 0.127 0.628571 0.223043 0.174436
23 Seeking initial Contact 1847 1852 -5 0 30.237707 1468387164080 0.133 -0.142857 0.237232 0.127820
24 Seeking initial Contact 1853 1852 1 0 30.251499 1468387164086 0.139 0.028571 0.251024 0.067669
25 Seeking initial Contact 1828 1852 -24 0 30.265390 1468387164091 0.144 -0.685714 0.264915 0.039098
26 Seeking initial Contact 1838 1852 -14 0 30.279676 1468387164098 0.151 -0.400000 0.279202 0.034586
27 Seeking initial Contact 1872 1852 20 0 30.295353 1468387164103 0.156 0.571429 0.294878 0.087218
28 Seeking initial Contact 1856 1852 4 0 30.309046 1468387164109 0.162 0.114286 0.308571 0.189474
29 Seeking initial Contact 1880 1852 28 0 30.322937 1468387164114 0.167 0.800000 0.322462 0.207519
... ... ... ... ... ... ... ... ... ... ... ...
1508 Moving to start position 1827 1852 -25 0 30.525839 1468387173559 9.612 -0.714286 0.525364 -0.300752
1509 Moving to start position 1835 1852 -17 0 30.503614 1468387173568 9.621 -0.485714 0.503139 -0.273684
1510 Moving to start position 1852 1852 0 0 30.480000 1468387173576 9.629 0.000000 0.479525 -0.227068
1511 Moving to start position 1867 1852 15 0 30.457973 1468387173584 9.637 0.428571 0.457499 -0.242105
1512 Moving to start position 1832 1852 -20 0 30.436245 1468387173592 9.645 -0.571429 0.435770 -0.267669
1513 Moving to start position 1839 1852 -13 0 30.412729 1468387173601 9.654 -0.371429 0.412254 -0.248120
1514 Moving to start position 1847 1852 -5 0 30.390009 1468387173610 9.663 -0.142857 0.389534 -0.237594
1515 Moving to start position 1845 1852 -7 0 30.368080 1468387173618 9.671 -0.200000 0.367605 -0.273684
1516 Moving to start position 1823 1852 -29 0 30.346352 1468387173626 9.679 -0.828571 0.345877 -0.302256
1517 Moving to start position 1823 1852 -29 0 30.323631 1468387173635 9.688 -0.828571 0.323156 -0.300752
1518 Moving to start position 1852 1852 0 0 30.301506 1468387173643 9.696 0.000000 0.301031 -0.288722
1519 Moving to start position 1872 1852 20 0 30.277891 1468387173652 9.705 0.571429 0.277416 -0.255639
1520 Moving to start position 1854 1852 2 0 30.255964 1468387173660 9.713 0.057143 0.255489 -0.311278
1521 Moving to start position 1824 1852 -28 0 30.233837 1468387173668 9.721 -0.800000 0.233362 -0.321805
1522 Moving to start position 1847 1852 -5 0 30.212009 1468387173676 9.729 -0.142857 0.211535 -0.266165
1523 Moving to start position 1858 1852 6 0 30.188496 1468387173685 9.738 0.171429 0.188021 -0.233083
1524 Moving to start position 1847 1852 -5 0 30.165972 1468387173693 9.746 -0.142857 0.165497 -0.218045
1525 Moving to start position 1826 1852 -26 0 30.143549 1468387173702 9.755 -0.742857 0.143074 -0.237594
1526 Moving to start position 1818 1852 -34 0 30.119934 1468387173711 9.764 -0.971429 0.119459 -0.216541
1527 Moving to start position 1835 1852 -17 0 30.099197 1468387173719 9.772 -0.485714 0.098722 -0.181955
1528 Moving to start position 1857 1852 5 0 30.080248 1468387173727 9.780 0.142857 0.079773 -0.181955
1529 Moving to start position 1815 1852 -37 0 30.062685 1468387173736 9.789 -1.057143 0.062210 0.000000
1530 Moving to start position 1860 1852 8 0 30.046810 1468387173745 9.798 0.228571 0.046335 0.000000
1531 Moving to start position 1869 1852 17 0 30.033714 1468387173753 9.806 0.485714 0.033239 0.000000
1532 Moving to start position 1861 1852 9 0 30.023197 1468387173762 9.815 0.257143 0.022722 0.000000
1533 Moving to start position 1857 1852 5 0 30.013969 1468387173771 9.824 0.142857 0.013494 0.000000
1534 Moving to start position 1832 1852 -20 0 30.007521 1468387173779 9.832 -0.571429 0.007046 0.000000
1535 Moving to start position 1837 1852 -15 0 30.003155 1468387173787 9.840 -0.428571 0.002680 0.000000
1536 Moving to start position 1846 1852 -6 0 30.000574 1468387173796 9.849 -0.171429 0.000099 0.000000
1537 Moving to start position 1852 1852 0 0 29.999979 1468387173804 9.857 0.000000 -0.000496 0.000000

1538 rows × 11 columns


In [15]:
TOOLS = 'box_zoom,wheel_zoom,pan,crosshair,reset'

hover1 = HoverTool(
        tooltips=[
            ("index", "$index"),
            ("(x,y)", "($x, $y)"),
        ]
    )
hover2 = HoverTool(
        tooltips=[
            ("index", "$index"),
            ("(x,y)", "($x, $y)"),
        ]
    )
hover3 = HoverTool(
        tooltips=[
            ("index", "$index"),
            ("(x,y)", "($x, $y)"),
        ]
    )

p1 = figure(title="Force vs. Time", toolbar_location = 'above', tools=[TOOLS,hover1])
p1.grid.grid_line_alpha=0.3
p1.xaxis.axis_label = 'Time [s]'
p1.yaxis.axis_label = 'Force [g]'
p1.line(df['Time'],df['Force'], color="firebrick", alpha=0.3, line_width=2)
p1.line(df['Time'],df['AverageForce'], color="navy", alpha=0.8, line_width=2)

p2 = figure(title="Force vs. Position", toolbar_location = 'above', tools=[TOOLS,hover2])
p2.grid.grid_line_alpha=0.3
p2.xaxis.axis_label = 'Position [mm]'
p2.yaxis.axis_label = 'Force [g]'
p2.line(df['Position'],df['Force'], color="firebrick", alpha=0.3, line_width=2)
p2.line(df['Position'],df['AverageForce'], color="navy", alpha=0.8, line_width=2)

p3 = figure(title="Position vs. Time", toolbar_location = 'right', tools=[TOOLS,hover3])
p3.grid.grid_line_alpha=0.3
p3.xaxis.axis_label = 'Time [s]'
p3.yaxis.axis_label = 'Position [mm]'
p3.line(df['Time'],df['Position'])

grid = gridplot([p1,p2],[p3,None], merge_tools=False)

show(grid)



In [ ]: