Skip to content

Commit b11c7fe

Browse files
committed
Used for participant study sets
1 parent 94a1c82 commit b11c7fe

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

convert2euclidean.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
import time
1212
from natsort import natsorted
1313
from pandas import DataFrame
14-
#from math import isnan
1514

1615
start = time.clock() # start counting time (optional)
1716

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\\'
2221
fileformat = '.csv'
2322

2423
def Convert2Euclidean(sourcePath, destinationPath):
@@ -65,16 +64,19 @@ def Convert2Euclidean(sourcePath, destinationPath):
6564
thirdIndex = j + 2
6665
fourthIndex = j + 3
6766

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])
7271

7372

7473
# Calculate the Euler Angles in degrees (multiplying the radian terms with 180/pi)
7574
#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
7880
## 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.
7981
test = 2*(qr*qy - qx*qz)
8082
if test < -1.0:
@@ -109,7 +111,7 @@ def Convert2Euclidean(sourcePath, destinationPath):
109111
output_list = [] # empty temporary list for next iteration
110112

111113
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
113115
count += 1 # increment file counter
114116
print 'bad Beta values = ', count_errors
115117

0 commit comments

Comments
 (0)