-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTP_prePanels.py
72 lines (69 loc) · 2.94 KB
/
STP_prePanels.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
#!/usr/bin/env python3
import re
import sys
import subprocess
from os import path, system
from datetime import datetime
from itertools import product
import MoNeT_MGDrivE as monet
import STP_aux as aux
import STP_functions as fun
(USR, AOI, REL, LND) = ('dsk', 'HLT', '106', 'SPA')
# (USR, AOI, REL, LND) = (sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
FIC = ('0000000000', '0100000000')
(PT_ROT, PT_IMG, PT_DTA, PT_PRE, PT_OUT, PT_MTR) = aux.selectPath(USR, LND, REL)
monet.makeFolder(path.join(PT_IMG, 'panels'))
###############################################################################
# Template layout
###############################################################################
template = path.join(PT_IMG, REL+'_template.svg')
with open(template, 'r') as file :
filedata = file.read()
###############################################################################
# Replacements
###############################################################################
PTRN = 'E_{}_{}_{}_{}_{}-{}'
# Find original ids -----------------------------------------------------------
p = re.compile('E_.*png', re.IGNORECASE)
pats = re.findall(p, filedata)
img_org = list({i[:-8] for i in pats})
print(img_org)
# Replacement ids -------------------------------------------------------------
uids = fun.getExperimentsIDSets(path.join(PT_IMG, 'preTraces/'), skip=-1)
uids[2] = uids[2][1:] # Delete the zero releases entry
expSets = set(list(product(*uids[1:-1])))
print(expSets)
###############################################################################
# Iterate
###############################################################################
tS = datetime.now()
monet.printExperimentHead(PT_ROT, PT_IMG, tS, 'UCIMI PrePanels '+AOI)
(xpNum, digs) = monet.lenAndDigits(expSets)
i = 0
exp = sorted(list(expSets))[-18]
for (i, exp) in enumerate(sorted(list(expSets))):
monet.printProgress(i+1, xpNum, digs)
# Get exp ids -------------------------------------------------------------
(i_rer, i_ren, i_rsg, i_fic, i_gsv) = exp
fn = PTRN.format(i_rer, i_ren, i_rsg, 'X', i_gsv, AOI)
# print(fn)
img_new = (
PTRN.format(i_rer, i_ren, i_rsg, FIC[0], i_gsv, AOI),
PTRN.format(i_rer, i_ren, i_rsg, FIC[1], i_gsv, AOI)
)
# Replace and export SVG --------------------------------------------------
fd = filedata.replace(img_org[0], img_new[0])
fd = fd.replace(img_org[1], img_new[1])
with open(path.join(path.join(PT_IMG, fn+'.svg')), "w") as text_file:
text_file.write(fd)
###########################################################################
# Export PNG from SVG
###########################################################################
cmd = [
'inkscape',
'--export-type=png',
'--export-dpi=300',
path.join(PT_IMG, fn+'.svg'),
'--export-filename='+path.join(PT_IMG, 'panels', fn)
]
subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)