|
11 | 11 | import time
|
12 | 12 | from natsort import natsorted
|
13 | 13 | from pandas import DataFrame
|
14 |
| -#from math import isnan |
15 | 14 |
|
16 | 15 | start = time.clock() # start counting time (optional)
|
17 | 16 |
|
18 |
| -source_left = 'C:\\Users\\Shamir\\Desktop\\Grad\\Participant Study\\Hands_Sorted\\P1\\Left_combined\\' # source folder |
19 |
| -source_right = 'C:\\Users\\Shamir\\Desktop\\Grad\\Participant Study\\Hands_Sorted\\P1\\Right_combined\\' # naturally sort the file list |
20 |
| -destination_left = 'C:\\Users\\Shamir\\Desktop\\Grad\\Participant Study\\Euclidean\\P1\\Left\\' |
21 |
| -destination_right = 'C:\\Users\\Shamir\\Desktop\\Grad\\Participant Study\\Euclidean\\P1\\Right\\' |
| 17 | +source_left = 'C:\\Users\\Shamir\\Desktop\\Grad\\Participant Study\\Hands_Sorted\\P8\\Left_combined\\' # source folder |
| 18 | +source_right = 'C:\\Users\\Shamir\\Desktop\\Grad\\Participant Study\\Hands_Sorted\\P8\\Right_combined\\' # naturally sort the file list |
| 19 | +destination_left = 'C:\\Users\\Shamir\\Desktop\\Grad\\Participant Study\\Euclidean\\P8\\Left Sorted\\' |
| 20 | +destination_right = 'C:\\Users\\Shamir\\Desktop\\Grad\\Participant Study\\Euclidean\\P8\\Right Sorted\\' |
22 | 21 | fileformat = '.csv'
|
23 | 22 |
|
24 | 23 | def Convert2Euclidean(sourcePath, destinationPath):
|
@@ -65,16 +64,19 @@ def Convert2Euclidean(sourcePath, destinationPath):
|
65 | 64 | thirdIndex = j + 2
|
66 | 65 | fourthIndex = j + 3
|
67 | 66 |
|
68 |
| - qr = csvfile.values[i, j] |
69 |
| - qx = csvfile.values[i, secondIndex] |
70 |
| - qy = csvfile.values[i, thirdIndex] |
71 |
| - qz = csvfile.values[i, fourthIndex] |
| 67 | + qr = float(csvfile.values[i, j]) |
| 68 | + qx = float(csvfile.values[i, secondIndex]) |
| 69 | + qy = float(csvfile.values[i, thirdIndex]) |
| 70 | + qz = float(csvfile.values[i, fourthIndex]) |
72 | 71 |
|
73 | 72 |
|
74 | 73 | # Calculate the Euler Angles in degrees (multiplying the radian terms with 180/pi)
|
75 | 74 | #print "reading i, j = ", i, j
|
76 |
| - Alpha = np.arctan ((2*(qr*qx + qy*qz)) / (1 - 2*(np.square(qx) + np.square(qy)))) * 180/np.pi |
77 |
| - |
| 75 | + try: |
| 76 | + Alpha = np.arctan ((2*(qr*qx + qy*qz)) / (1 - 2*(np.square(qx) + np.square(qy)))) * 180/np.pi |
| 77 | + except: |
| 78 | + print 'file, row, col = ', file, i, j |
| 79 | + print qr, qx, qy, qz |
78 | 80 | ## Major bug, possibly due to noise. This test value, given that the condition becomes true, should not be used for actual analysis. Instead, please filter the noise through the modified filter.
|
79 | 81 | test = 2*(qr*qy - qx*qz)
|
80 | 82 | if test < -1.0:
|
@@ -109,7 +111,7 @@ def Convert2Euclidean(sourcePath, destinationPath):
|
109 | 111 | output_list = [] # empty temporary list for next iteration
|
110 | 112 |
|
111 | 113 | output_array = DataFrame(output_array) # convert complete array into a Pandas Dataframe
|
112 |
| - #output_array.to_csv(destinationPath + str(count) + fileformat, header = False, index = False) # write the dataframe to a csv file |
| 114 | + output_array.to_csv(destinationPath + str(count) + fileformat, header = False, index = False) # write the dataframe to a csv file |
113 | 115 | count += 1 # increment file counter
|
114 | 116 | print 'bad Beta values = ', count_errors
|
115 | 117 |
|
|
0 commit comments