-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcatenateIAvsBTcsvs.py
117 lines (75 loc) · 2.59 KB
/
concatenateIAvsBTcsvs.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 23 14:43:25 2020
@author: marcus
"""
import pandas as pd
from glob import glob
import sys
import numpy as np
#This script is written to collate the data of initial areas vs bursting times
def getvidUID(filename):
numdict = np.arange(1,10).astype(str)
#position ids go from 0 to 63. May be one or two numbers
potid = filename[filename.find('.csv')-2:filename.find('.csv')]
if potid[0]=='_':
uid = potid[0]
#print('single digit position, assigning uid: ', uid)
elif any(numdict==potid[0]):
uid = potid[0]+potid[1]
return uid
def getpervidUID(label):
label = int(label)
label = str(label)
if len(label)==0:
print ('no label given')
return
if len(label) == 1:
label = '00'+label
elif len(label) == 2:
label = '0'+label
return label
def getUID(filename,label):
return getvidUID(filename)+getpervidUID(label)
def getMap(filename,df):
#columntitles should be a pandas dataframe column name array
mapping = {}
columntitles=df.columns.values
for title in columntitles:
label = df[title].iloc[0]
mapping[title]=getUID(filename,label)
return mapping
mapforRownames = {'Unnamed: 0': 'PerVidLabel', 0: 'Size', 0.1: 'Bursting Time'}
if __name__ == '__main__':
debug = True
Anameroot = "Initial_Areas_vs_Bursting_Times_Pos*.csv"
if len(sys.argv) > 1:
dpath = sys.argv[1]
else:
print("Haven't entered directory path as Command Line option")
sys.exit()
if len(sys.argv) > 2:
opath = sys.argv[2]
if debug:
print(opath)
else:
print("Haven't given an output path name pattern as Command Line option")
sys.exit()
Afile_list = glob(dpath+Anameroot)
for i in range(0,len(Afile_list)):
Afile = Afile_list[i]
if i == 0:
df = pd.read_csv(Afile).T
print(df)
mapping0 = getMap(Afile,df)
df = df.rename(columns=mapping0)
else:
dfA = pd.read_csv(Afile).T
mapping = getMap(Afile,dfA)
dfA = dfA.rename(columns =mapping)
#add this dataframe to df
df = pd.concat([df,dfA],axis = 1)
#print(df)
df.rename(mapforRownames)
df.to_csv(dpath+opath)