-
Notifications
You must be signed in to change notification settings - Fork 2
/
pathdata_processor.py
69 lines (59 loc) · 2 KB
/
pathdata_processor.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
62
63
64
65
66
67
68
69
#!/bin/python
# Python 2.7 standard (but should be agnostic/extensible)
# This is a module that provides useful functions for analysing the data
# produced from the lineage tracking simulations
print("Importing pandas...")
import pandas
print("Done.\nLoading handler functions...")
# Selects all columns from the key file that match a given search key
# and outputs the column numbers
def KeyToCols(targetFile, Key):
KeyFile = pandas.read_csv(targetFile,nrows=1)
ColNums = []
n = 0
# Seek pattern "Key" in target key file
for entry in KeyFile:
# if entry contains 331, print column
if Key in entry:
ColNums.append(n)
n+=1
return ColNums
def StoreKeys(targetFile, Key):
KeyFile = pandas.read_csv(targetFile,nrows=1)
KeyList = []
# Seek pattern "Key" in target key file
for entry in KeyFile:
# if entry contains 331, print column
if Key in entry:
KeyList.append(entry)
return KeyList
# Selects matching columns from a target data file and prints them
def PrintCols(DataFile, ColSelect):
TargetData = pandas.read_csv(DataFile)
ColsFromFile=[]
for i in ColSelect:
ThisCol = TargetData.iloc[:,i]
print(ThisCol.iloc[-1])
ColsFromFile.append(ThisCol)
return ColsFromFile
# Which of these paths are "hits"? And have non-zero probability?
def FindHits(DataFile, ColSelect):
TargetData = pandas.read_csv(DataFile)
HitCols=[]
n = 0
for i in ColSelect:
ThisCol = TargetData.iloc[:,i]
lastProb= ThisCol.iloc[-1]
if (lastProb > 0):
print(lastProb,n)
HitCols.append(n)
n += 1
return HitCols
# Convert this list of column hits into a list of column keys ready to input
# into Mathematica (which numbers arrays from 1):
def MathematicColmHits(ColumHits, ColumKeys):
MathematicaColmHits=[]
for i in ColumHits:
print(ColumKeys[i]+1)
MathematicaColmHits.append(ColumKeys[i]+1)
return MathematicaColmHits