-
Notifications
You must be signed in to change notification settings - Fork 2
/
countDatapoints.py
61 lines (42 loc) · 2.14 KB
/
countDatapoints.py
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
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 23 19:35:25 2015
@author: Shamir
"""
import pandas
import os
from natsort import natsorted
from math import isnan
source_left = 'C:\\Users\\Shamir\\Desktop\\Grad\\Participant Study\\Euclidean\\P1\\Left\\'
source_right = 'C:\\Users\\Shamir\\Desktop\\Grad\\Participant Study\\Euclidean\\P1\\Right\\'
fileformat = '.csv'
def CountData(sourcePath):
"""
This function counts the total number of datapoints contained in an entire folder
input parameter : sourcePath; it takes the path of the directory where the files are stored for processing.
"""
count = 0
filelist = os.listdir(sourcePath) # list all the files in the folder
filelist = natsorted(filelist) # naturally sort the file list; this fixes the problem of having improper file order in the list
for file in range(len(filelist)):
csvfile = pandas.read_csv(sourcePath + filelist[file], header = None) # read csv file
csvfile.values[1:] = csvfile.values[1:].astype(float) # convert all strings to floats; ignore header columns
num_rows = len(csvfile) # number of rows in the file
num_columns = len(csvfile.values[0]) # number of columns in the file
for i in range(1, num_rows):
for j in range(0, num_columns):
datapoint = csvfile.values[i,j]
if isnan(datapoint) == True:
continue
else:
count += 1
return count
totalDatapoints = 0
datapoints = CountData(source_left)
print 'datapoints_left = ', datapoints
totalDatapoints += datapoints
datapoints = CountData(source_right)
print 'datapoints_right = ', datapoints
totalDatapoints += datapoints
print 'total number of datapoints = ', totalDatapoints
print 'total number of coordinates = ', totalDatapoints/3.0