forked from DSSAT/pythia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpythia.py
65 lines (58 loc) · 2.53 KB
/
pythia.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
import datetime
import logging
import os
import pythia.config
import pythia.dssat
import pythia.analytics
import pythia.io
import pythia.peerless
import pythia.plugin
logging.getLogger("pythia_app")
logging.basicConfig(level=logging.INFO, filename="pythia.log", filemode="w")
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("config", help="JSON configuration file to run")
parser.add_argument("--all", action="store_true", help="Run all the steps in pythia")
parser.add_argument(
"--export-runlist",
action="store_true",
help="Export a list of all the directories to be run",
)
parser.add_argument("--setup", action="store_true", help="Setup DSSAT run structure and files")
parser.add_argument("--run-dssat", action="store_true", help="Run DSSAT over the run structure")
parser.add_argument(
"--analyze", action="store_true", help="Run the analysis for the DSSAT runs"
)
parser.add_argument(
"--clean-work-dir", action="store_true", help="Clean the work directory prior to run"
)
args = parser.parse_args()
if not args.config:
parser.print_help()
else:
config = pythia.config.load_config(args.config)
if args is None or not config:
print("Invalid configuration file")
else:
logging.info("Pythia started: %s", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
if args.clean_work_dir:
print("Cleaning the work directory")
if os.path.exists(config["workDir"]):
import shutil
shutil.rmtree(config["workDir"])
config["exportRunlist"] = args.export_runlist
plugins = pythia.plugin.load_plugins(config, {})
config = pythia.plugin.run_plugin_functions(
pythia.plugin.PluginHook.post_config, plugins, full_config=config
)
if args.all or args.setup:
print("Setting up points and directory structure")
pythia.peerless.execute(config, plugins)
if args.all or args.run_dssat:
print("Running DSSAT over the directory structure")
pythia.dssat.execute(config, plugins)
if args.all or args.analyze:
print("Running simple analytics over DSSAT directory structure")
pythia.analytics.execute(config, plugins)
logging.info("Pythia completed: %s", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))