-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteOutput.py
More file actions
61 lines (56 loc) · 1.89 KB
/
Copy pathwriteOutput.py
File metadata and controls
61 lines (56 loc) · 1.89 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
import getGraphProps as gGP
import numpy as np
import os
def genData(fileName):
pathToFile = os.path.realpath(fileName)
f = open(pathToFile, "r")
paramstr = f.readline()
params = {}
f.close()
begin = 0
comma = 1
#create dict from header, based on key=value format in csv
while comma > 0:
comma = paramstr.find(",")
equals = paramstr.find("=")
params[paramstr[begin:equals]] = float(paramstr[equals+1:comma])
paramstr = paramstr[comma+1:]
params[paramstr[begin:equals]] = float(paramstr[equals+1:comma])
for key in params:
if(params[key] % 1 == 0):
params[key] = int(params[key])
data = np.genfromtxt(pathToFile, delimiter=",", skip_header=1)
print params
return params, data
def makeFolder(baseName):
folderCount = 0
newFolder = baseName + str(folderCount) + '/'
while os.path.exists(newFolder):
folderCount = folderCount + 1
newFolder = baseName + str(folderCount) + '/'
os.mkdir(newFolder)
return newFolder
def genFileName(baseName, params, uniqueID=''):
fileName = baseName
for key in params.keys():
fileName = fileName + '_' + key + '_' + str(params[key])
return fileName + '_' + uniqueID
def writeVectorData(data, params, fn):
nData = params['nSteps']/params['dataInterval']
n = params['n']
newFolder = makeFolder('vectData')
fileName = ""
#find y upper and lower limits
for i in range(nData):
fileName = genFileName('vectData', params, str(i)) + ".csv"
f = open(newFolder + fileName, "w")
xs = np.linspace(1,n,n)
ys = fn(data[(i)*n:(i+1)*n,:n])
for i in range(n):
f.write(str(xs[i]) + '\t')
f.write(str(ys[i]) + '\n')
f.close()
if __name__=='__main__':
import sys
params, data = genData(sys.argv[1])
writeVectorData(data, params, gGP.getAdjLeadingEigVect)