-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.py
More file actions
110 lines (85 loc) · 6.68 KB
/
Copy pathExample.py
File metadata and controls
110 lines (85 loc) · 6.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
Reading slow data and fast data files
========================================
This example shows how to read meta-data and associated sensor data from the
slow and fast data files
"""
# import the module
import DAQData as DQ;
import pandas as pd;
# Centrifuge CGM (UC Davis) data file. Can be slow as well as fast data
Data_File = "./Binary_Data_Files/07122019@121326@154548@64.4rpm.bin";
# Data_File = "./Binary_Data_Files/07122019@121326.bin";
# By default the, 'Extract_Data' parameter is set to be True. If the files are
# very large and only meta data needs to be checked, the data extraction can be
# stooped by setting 'Extract_Data' parameter false. This would increase the
# execution speed but will not read any data
Data_DAQ = DQ.DAQ(Data_File,Extract_Data=True);
#####################################################################################################################
# Read meta data
#####################################################################################################################
# Just use the print statement to print the meta data
# print(Data_DAQ)
# Extracting meta data
FileName = Data_DAQ.FileName; # gets the filename
Sampling_Rate = Data_DAQ.Sampling_Rate; # gets Sampling_Rate
Number_of_Channels = Data_DAQ.Number_of_Channels; # gets number of channels
Number_of_Hardware_Channels = Data_DAQ.Number_of_Hardware_Channels; # gets number of hardware channels
Number_of_Sensors = Data_DAQ.Number_of_Sensors # gets number of Xdcr_Serial Numbers (also referred as sensors)
Channel_List = Data_DAQ.Channel_List; # gets the channel list
Hardware_Channel_List = Data_DAQ.Hardware_Channel_List; # get the hardware channel list
Sensor_List = Data_DAQ.Sensor_List; # gets the sensor list
Number_of_Samples = Data_DAQ.Number_of_Samples; # gets the total number of samples per sensor
Data_Length = Data_DAQ.Data_Length; # gets the total data length in the binary file. Number_of_Samples*Number_of_sensors
ExcelConfig = Data_DAQ.ExcelConfig; # return excel configuration file as a csv string
# print(Number_of_Channels)
# print(ExcelConfig.head())
#####################################################################################################################
# Extract data on demand
#####################################################################################################################
# If the 'Extract_Data' parameter is True, the whole data is already read and extracted and can be easily retrieved as
Sensor_Data = Data_DAQ.Sensor_Data; # 2-D pandas DataFrame with column names (headers) as Channel Names
print(Sensor_Data.head(2)); # shows first 2 rows of the data set
# print(Sensor_Data.shape); # gets the size of the dataset (rows,columns)
# print(Sensor_Data['ICP1-0']) # will retrieve the data for channel no 'ICP1-0'
# print(Sensor_Data.columns) # will show all the header names in the data. It is the same as the Channel List.
# The column names can be renamed to sensor names or any other meaningful names as shown below
Sensor_Data.columns = ["TIME (s)","EAST (g)","WEST (g)","P1_ACC_H2 (g)","P2_ACC_H2 (g)","P1_G1 (lbf)","P1_G2 (lbf)","P1_G3 (lbf)","P1_G4 (lbf)","P1_G5 (lbf)","P1_G6 (lbf)","P1_G7 (lbf)","P1_G8 (lbf)","P2_ACC-V1 (g)","P2_ACC_H1 (g)","4th RING (g)","SOUTH (g)","P1_ACC_H1 (g)","P1_ACC_V1 (g)","NORTH (g)","P2_G1 (lbf)","P2_G2 (lbf)","P2_G3 (lbf)","P2_G4 (lbf)","P2_G5 (lbf)","P2_G6 (lbf)","P2_G7 (lbf)","P2_G8 (lbf)","P1_G9 (lbf)","P2_G9 (lbf)","dummy3","Dummy_2","PPT_5 (kPa)","PPT_3 (kPa)","PPT_9 (kPa)","PPT_1 (kPa)","PPT_8 (kPa)","PPT_6 (kPa)","PPT_2 (kPa)","PPT_7 (kPa)","PPT_5442","PPT_4 (kPa)","PPT_10 (kPa)","PPT_10_Proxy (kPa)","Dummy-127926","ACC_6 (g)","ACC_1 (g)","ACC_3 (g)","ACC_5 (g)","ACC_2 (g)","ACC_7 (g)","ACC_4 (g)","dummy21320","dummy-108849","PT 9F008","P2_LP (mm)","P2_MEM (g)","SM2 (mm)","P1_MEM (g)","P1_LP (mm)","SM1 (mm)","PPT_22 (kPa)","PPT_14 (kPa)","PPT_16 (kPa)","PPT_15 (kPa)","PPT_21 (kPa)","MS5407_115","PPT_18 (kPa)","PPT_20 (kPa)","PPT_19 (kPa)","PPT_12 (kPa)","PPT_1 (kPa)","PPT_11 (kPa)","PPT_17 (kPa)","CPT (lbf)","EXT (lbf)","PLT (lbf)","ACT (mm)"]; # here as an example the channel names 'ICP1-0' is renamed to 'EAST (g)'
print(Sensor_Data.head(2)); # shows first 2 columns of the data with new column names
# print(Sensor_Data['EAST (g)']) # will retrieve the data corresponding to column name 'EAST (g)'. Will give the same result (print(Sensor_Data['ICP1-0'])) has the headers or column names not renames
# If the 'Extract_Data' parameter was initially set to False, the data can be extracted on demand by defining the start and end time
# ..... Time_Data, Sesnor_Data = Data_DAQ.Extract(Start_Time=0, End_Time=10)
# To extract the whole data, set the start time to be 0 and end time to be Number_of_Samples/Sampling_Rate
Data_DAQ = DQ.DAQ(Data_File,Extract_Data=False);
Sensor_Data = Data_DAQ.Extract(Start_Time=0,End_Time=Number_of_Samples/Sampling_Rate);
# note the Sensor_Data now again has the column headers as channel names
# to check print(Sensor_Data.head(2))
# print(Sensor_Data.shape) # would return the same length of data as above
#####################################################################################################################
# Read a particular sensor data and make a plot
#####################################################################################################################
# get the time data
Time_Data = Sensor_Data['TIME'];
# if the headers were changed as in the previous above examples
# it can be extracted as Time_Data = Sensor_Data['TIME (s)'];
# get the sensor data of interest
# extract the data from the Sensor_Data DataFrame
Input_Acceleration = Sensor_Data['ICP1-0'];
# if the headers were changed as in the previous above examples
# it can be extracted as Time_Data = Sensor_Data['EAST (g)'];
# extract the sensor name
Sensor_Name = Data_DAQ.Sensor_List[Data_DAQ.get_Channel_Index(Channel_Name='ICP1-0')];
import matplotlib.pyplot as plt;
plt.figure(figsize=(8,3));
plt.plot(Time_Data,Input_Acceleration,'k',label=Sensor_Name);
plt.legend(loc='best')
plt.grid(axis='both', which='major', ls='-')
plt.grid(axis='both', which='minor', ls='--', alpha=0.4)
plt.minorticks_on()
plt.xlabel('Time [s]')
plt.ylabel('Input Acceleration [g]')
plt.ylim([-10,10])
plt.tight_layout();
plt.show();
# ## The plot function can be alternatively used even for plotting very very large data
# Data_DAQ.Plot(Channel_Name_1='TIME', Channel_Name_2='ICP1-0', ScaleX= 1, OffsetX = 0, ScaleY= 1, OffsetY = 0, Color = 'k');