-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_inputs.py
More file actions
216 lines (173 loc) · 6.79 KB
/
get_inputs.py
File metadata and controls
216 lines (173 loc) · 6.79 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import os
import numpy as np
from shutil import copyfile
import time
def get_input_frame(outdir,runname):
infile = outdir + runname + '/frame.in'
with open(infile) as f:
lines = [line for line in f]
ztot = float(lines[1].split()[0])
nz = int(lines[2].split()[0])
ttot = float(lines[3].split()[0])
temp = float(lines[4].split()[0])
fdust = float(lines[5].split()[0])
fdust2 = float(lines[6].split()[0])
taudust = float(lines[7].split()[0])
omrain = float(lines[8].split()[0])
zom = float(lines[9].split()[0])
poro = float(lines[10].split()[0])
moistsrf = float(lines[11].split()[0])
zwater = float(lines[12].split()[0])
zdust = float(lines[13].split()[0])
w = float(lines[14].split()[0])
q = float(lines[15].split()[0])
p = float(lines[16].split()[0])
nstep = int(lines[17].split()[0])
rstrt = (lines[18].split()[0])
runid = (lines[20].split()[0])
return ztot,nz,ttot,temp,fdust,fdust2,taudust,omrain,zom,poro,moistsrf,zwater,zdust,w,q,p,nstep,rstrt,runid
def get_input_switches(outdir,runname):
infile = outdir + runname + '/switches.in'
with open(infile) as f:
lines = [line for line in f]
w_scheme = int(lines[1].split()[0])
mix_scheme = int(lines[2].split()[0])
poro_iter = (lines[3].split()[0])
sldmin_lim = (lines[4].split()[0])
display = (lines[5].split()[0])
disp_lim = (lines[6].split()[0])
restart = (lines[7].split()[0])
rough = (lines[8].split()[0])
act_ON = (lines[9].split()[0])
dt_fix = (lines[10].split()[0])
cec_on = (lines[11].split()[0])
dz_fix = (lines[12].split()[0])
close_aq = (lines[13].split()[0])
poro_evol = (lines[14].split()[0])
sa_evol_1 = (lines[15].split()[0])
sa_evol_2 = (lines[16].split()[0])
psd_bulk = (lines[17].split()[0])
psd_full = (lines[18].split()[0])
season = (lines[19].split()[0])
return w_scheme,mix_scheme,poro_iter,sldmin_lim,display,disp_lim,restart,rough,act_ON,dt_fix \
,cec_on,dz_fix,close_aq,poro_evol,sa_evol_1,sa_evol_2,psd_bulk,psd_full,season
def get_input_tracers(outdir,runname):
sld_list = np.genfromtxt(outdir + runname + '/slds.in',dtype='str',skip_header=1)
aq_list = np.genfromtxt(outdir + runname + '/solutes.in',dtype='str',skip_header=1)
gas_list = np.genfromtxt(outdir + runname + '/gases.in',dtype='str',skip_header=1)
exrxn_list = np.genfromtxt(outdir + runname + '/extrxns.in',dtype='str',skip_header=1)
try:
sld_list = list(sld_list)
except:
sld_list = [str(sld_list)]
try:
aq_list = list(aq_list)
except:
aq_list = [aq_list[0]]
try:
gas_list = list(gas_list)
except:
print(gas_list.shape)
gas_list = [str(gas_list)]
try:
exrxn_list = list(exrxn_list)
except:
exrxn_list = [exrxn_list[0]]
return sld_list,aq_list,gas_list,exrxn_list
def get_input_tracer_bounds(**kwargs):
outdir = kwargs.get('outdir', '../scepter_output/')
runname = kwargs.get('runname', 'test_input')
pr_list = kwargs.get('pr_list', [])
rain_list = kwargs.get('rain_list', [])
atm_list = kwargs.get('atm_list', [('pco2',3.16e-4),('po2',0.21),('pnh3',1e-50),('pn2o',1e-50)])
notes = [
'** parent rock wt fraction (e.g., "ab 0.2" in one line and "ka 0.001" in the next) (if not specified assumed 1e-20)'
,'** solute concs. of rain in mol/L (if not specified assumed 1e-20)'
,'** atmospheric composition in atm (if not specified assumed 1 PAL)'
]
pr_list.insert(0,'')
rain_list.insert(0,'')
atm_list.insert(0,'')
values_lists = [
pr_list
,rain_list
,atm_list
]
filenames = [
'parentrock.in'
,'rain.in'
,'atm.in'
]
nn = 3
if not os.path.exists(outdir + runname): os.makedirs(outdir + runname)
for k in range(nn):
values = values_lists[k]
filename = filenames[k]
n = len(values)
input_text = ''
for i in range(n):
if i==0:
input_text += notes[k] + '\n'
else:
try:
input_text += values[i][0] + '\t' + str(values[i][1]) + '\n'
except:
print(n,i,values)
time.sleep(100)
input_file = outdir + runname + '/' + filename
with open(input_file, 'w') as file:
file.write(input_text)
print(input_text)
del pr_list[0]
del rain_list[0]
del atm_list[0]
def get_input_sld_properties(outdir,runname,filename):
infile = outdir + runname + '/' + filename
sld_data_list = []
with open(infile) as f:
cnt2 = 0
for line in f:
if cnt2 ==0:
cnt2 += 1
continue
else:
cnt2 += 1
a = line.split()
tmplist = []
cnt = 0
for item in a:
if cnt ==0: tmplist.append(item)
else: tmplist.append(float(item))
cnt += 1
sld_data_list.append(tmplist)
return sld_data_list
def main():
outdir = '../scepter_output/'
# runname = 'US_cropland_311_sph_N_spintuneup_field'
runname = 'test_Pot7'
ztot,nz,ttot,temp,fdust,fdust2,taudust,omrain,zom,poro,moistsrf,zwater,zdust,w,q,p,nstep,rstrt,runid = get_input_frame(outdir,runname)
print(
ztot,nz,ttot,temp,fdust,fdust2,taudust,omrain,zom,poro,moistsrf,zwater,zdust,w,q,p,nstep,rstrt,runid
)
w_scheme,mix_scheme,poro_iter,sldmin_lim,display,disp_lim,restart,rough,act_ON,dt_fix \
,cec_on,dz_fix,close_aq,poro_evol,sa_evol_1,sa_evol_2,psd_bulk,psd_full,season = get_input_switches(outdir,runname)
print(
w_scheme,mix_scheme,poro_iter,sldmin_lim,display,disp_lim,restart,rough,act_ON,dt_fix
,cec_on,dz_fix,close_aq,poro_evol,sa_evol_1,sa_evol_2,psd_bulk,psd_full,season
)
sld_list,aq_list,gas_list,exrxn_list = get_input_tracers(outdir,runname)
print(
sld_list,aq_list,gas_list,exrxn_list
)
filename = 'cec.in'
sld_data_list = get_input_sld_properties(outdir,runname,filename)
print(
sld_data_list,
sld_data_list[0][1]
)
sld_data_list = get_input_sld_properties('./','data','dust_gbasalt.in')
print(
sld_data_list
)
if __name__ == '__main__':
main()