makeGraphInput.py
1.47 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
62
63
import csv, re, sqlite3
import sys
op = ''
if(int(sys.argv[1]) == 1):
op = 'WS'
elif(int(sys.argv[1]) == 2):
op = 'WR'
elif(int(sys.argv[1]) == 3):
op = 'SR'
fy= open("Paredes"+op+"/GraphInputFileW.txt", "w+")
fs= open("Paredes"+op+"/GraphInputFileS.txt", "w+")
fr= open("Paredes"+op+"/GraphInputFileR.txt", "w+")
con = sqlite3.connect("database_modfire.db")
cur = con.cursor()
Filemame = "Paredes"+op+"/pickedSol"
f=open(Filemame,"r")
lines=f.readlines()
result=[]
for line in lines:
MU = line.split(',')[0]
Pr = line.split(',')[1]
cur.execute("SELECT Year, Species, V_thin, V_harv FROM action_external where Id = "+str(MU)+" and Presc = "+str(Pr)+" and (V_thin or V_harv) > 0.0")
result = cur.fetchall()
for i in range(0, len(result)):
year = result[i][0]
act = ''
woodSum = int(result[i][2]) + int(result[i][3])
toWrite = str(MU)+","+str(year)+","+str(result[i][1])+","+str(woodSum)+"\n"
fy.write(toWrite)
cur.execute("SELECT Year, Soilloss FROM action_external where Id = "+str(MU)+" and Presc = "+str(Pr))
result = cur.fetchall()
for i in range(0, len(result)):
year = result[i][0]
toWrite = str(year)+","+str(result[i][1])+"\n"
fs.write(toWrite)
cur.execute("SELECT Year, Perc_r0 FROM action_external where Id = "+str(MU)+" and Presc = "+str(Pr))
result = cur.fetchall()
for i in range(0, len(result)):
year = result[i][0]
toWrite = str(year)+","+str(result[i][1])+"\n"
fr.write(toWrite)
fy.close()
fs.close()
fr.close