-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblink_adjust_NEW.py
50 lines (42 loc) · 1.42 KB
/
blink_adjust_NEW.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
'''
change 13 frames of a blink in 1 frame
USAGE: python blink_adjust.py -d file_name.py
'''
import argparse
import pandas as pd
import copy
from pandas import read_csv
AP = argparse.ArgumentParser()
AP.add_argument("-d", "--data", required=True,
help="data to be changed")
ARGS = vars(AP.parse_args())
DATA = pd.read_csv(ARGS["data"], sep=",", index_col=0)
FRAME_LIST = list(DATA.index)
BLINK_LIST = list(DATA.blink)
#sostituisco 0.0 o 1.0 sparsi
for n in range(len(BLINK_LIST)):
#trovo il primo 1.0
if BLINK_LIST[n]==1.0:
i = copy.deepcopy(n)
#correggi 1.0 isolati: se è un 1.0 singolo o doppio diventa 0.0
if sum(BLINK_LIST[i:i+15])<=4.0:
BLINK_LIST[i]=0.0
else:
#correggi 0.0 isolati: se ci sono 0.0 singoli o doppi appena dopo diventano 1.0
while (sum(BLINK_LIST[i:i+15])>4.0):
BLINK_LIST[i+1]=1.0
i+=1
#ora costruisco singoli 1.0 corrispondenti al blink
for n in range(len(BLINK_LIST)):
#trovo il primo 1.0
if BLINK_LIST[n]==1.0:
i = copy.deepcopy(n)
while (BLINK_LIST[i+1]==1.0):
BLINK_LIST[i+1]=0.0
i+=1
#scala gli 1.0 di 8 frame
BLINK_LIST=[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]+BLINK_LIST[:len(BLINK_LIST)-8]
BLINK_LIST = pd.DataFrame(BLINK_LIST, index=FRAME_LIST)
BLINK_LIST.index.name='frame'
BLINK_LIST.columns = ['blink']
BLINK_LIST.to_csv("results_prova2.csv")