-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargs_parser.py
More file actions
83 lines (74 loc) · 2.69 KB
/
args_parser.py
File metadata and controls
83 lines (74 loc) · 2.69 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
import argparse
def parse_args():
# Initial parsing to get the method
parser = argparse.ArgumentParser(description="Script to generate binarization thresholds.")
parser.add_argument(
'--method',
type=str,
choices=['lpt_x',
'rdm_sampling',
'tgt_sampling',
'rf_classifier',
'mlp_classifier',
'single_fixed_thres',
'mean_pred_thres'
],
required=True,
help="Choose one of the available options: lpt_x, rdm_sampling, tgt_sampling, rf_classifier, mlp_classifier, single_fixed_thres, mean_pred_thres"
)
parser.add_argument(
'--species_set',
type=str,
choices=['iucn', 'snt', 'all', 'custom'],
default='iucn',
help="Choose the species set."
)
parser.add_argument("--model_path", type=str, required=True, help="Model path.")
parser.add_argument("--exp_name", type=str, default='test', help="Experiment name")
# First parse to get the method
args, _ = parser.parse_known_args()
# Conditionally add arguments based on the method
if args.method == 'lpt_x':
parser.add_argument(
'--lpt_level',
type=float,
default=5.0,
help="Specify the level for lpt-x method"
)
elif args.method == 'rdm_sampling':
# Create a mutually exclusive group for raw_number and factor_presences
rdm_group = parser.add_mutually_exclusive_group(required=True)
rdm_group.add_argument(
'--raw_number',
type=int,
default=None,
help="Specify the raw number of absences to generate, e.g. 100, 1000, 10000..."
)
rdm_group.add_argument(
'--factor_presences',
type=float,
default=None,
help="Specify a factor (proportion) of the number of presences to generate absences."
)
elif args.method == 'single_fixed_thres':
parser.add_argument(
'--threshold',
type=float,
default=0.5,
help="Specify the level for the single fixed threshold."
)
# Conditionally add species IDs if species_set is 'custom'
if args.species_set == 'custom':
parser.add_argument(
'--species_ids',
type=int,
nargs='+',
required=True,
help="Specify the species IDs as a list of integers when 'custom' is chosen as the species set."
)
# Parse all arguments including the conditional ones
args = parser.parse_args()
print(args)
return args
if __name__ == "__main__":
args = parse_args()