-
Notifications
You must be signed in to change notification settings - Fork 31
/
example.py
executable file
·84 lines (61 loc) · 2.36 KB
/
example.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
#!/usr/bin/env python
"""
Example script of how I would run the model, the result is not necessarily
sensible...but essentially the Duke experiment.
* Note you don't need to change the parameter values this way, though I think
it is preferable.
This is a wrapper around the C code.
"""
import os
import sys
sys.path.append('../scripts')
import adjust_gday_param_file as ad
__author__ = "Martin De Kauwe"
__version__ = "1.0 (27.02.2015)"
__email__ = "[email protected]"
def ambient_sim(experiment_id, site, treatment, ascii=True):
GDAY_EXE = "../src/gday -p "
# --- FILE PATHS, DIR NAMES ETC --- #
#base_dir = os.getcwd()
param_dir = "params"
met_dir = "met_data"
run_dir = "outputs"
# --- CHANGE PARAM VALUES ON THE FLY --- #
itag = "%s_%s_model_youngforest_%s" % (experiment_id, site, treatment)
otag = "%s_%s_model_simulation_%s" % (experiment_id, site, treatment)
mtag = "%s_met_data_%s_co2.csv" % (site, treatment)
out_fn = "D1GDAY%s%s" + (".csv" if ascii else ".bin")
#import pdb; pdb.set_trace()
out_fn = out_fn % (site, treatment.upper())
out_param_fname = os.path.join(param_dir, otag + ".cfg")
cfg_fname = os.path.join(param_dir, itag + ".cfg")
met_fname = os.path.join(met_dir, mtag)
out_fname = os.path.join(run_dir, out_fn)
replace_dict = {
"out_param_fname": "%s" % (out_param_fname),
"cfg_fname": "%s" % (cfg_fname),
"met_fname": "%s" % (met_fname),
"out_fname": "%s" % (out_fname),
# state
"age": "12.0",
# control
"print_options": "daily",
}
ad.adjust_param_file(cfg_fname, replace_dict)
# --- RUN THE MODEL --- #
os.system(GDAY_EXE + cfg_fname)
# translate output to NCEAS style output
# add this directory to python search path so we can find the scripts!
sys.path.append("scripts")
import translate_GDAY_output_to_NCEAS_format as tr
if ascii:
tr.translate_output(out_fname, met_fname)
else:
tr.translate_output(out_fname, met_fname)
if __name__ == "__main__":
# Ambient
experiment_id = "NCEAS"
site = "DUKE"
treatment="amb"
ascii = True
main(experiment_id, site, treatment, ascii)