-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_groimp_task.py
70 lines (60 loc) · 1.7 KB
/
generate_groimp_task.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
#!/usr/bin/env python3
from __future__ import annotations
from pathlib import Path
from jinja2 import Template
PLANT_TYPES = [
"dicot1",
"dicot2",
"cheno",
"at",
"cereal",
"grass",
"hemp",
"weed",
"sunflower",
"maize",
"quinoa",
"tulip",
"pea",
"soy",
"faba",
"basil",
]
if __name__ == "__main__":
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument(
"--groimp_path",
type=Path,
default=Path(__file__).parent / "groimp",
help="GroIMP folder path.",
)
parser.add_argument(
"--groimp_output_path",
type=Path,
default=Path(__file__).parent / "generated_groimp",
help="GroIMP output path.",
)
parser.add_argument(
"--crop_type",
type=str,
default="maize",
choices=PLANT_TYPES,
help="Crop type to generate task.",
)
args = parser.parse_args()
parameter_template = Template(Path("templates/parameters.rgg.template").read_text(encoding="utf-8"))
output_folder: Path = args.groimp_output_path
highest_run_number = 1
for sub_output_folder in output_folder.glob(f"{args.crop_type}_*/"):
try:
highest_run_number = max(highest_run_number, int(sub_output_folder.name.split("_")[1]))
except ValueError:
pass
run_output_folder = (output_folder / f"{args.crop_type}_{highest_run_number+1:03}").resolve()
run_output_folder.mkdir()
parameter_file: Path = args.groimp_path / "parameters.rgg"
parameter_file.write_text(
parameter_template.render(output_path=run_output_folder, crop_type=args.crop_type),
encoding="utf-8",
)