@@ -20,9 +20,9 @@ def main(argv: list[str] | None = None) -> None:
2020 args = load_parser (argv )
2121 check_cmdargs (args )
2222
23- if args [ " compare" ] :
23+ if args . compare :
2424 print ("\n Compare: Generating common plots to compare results, please wait." )
25- plot_results ({"compare" : args [ " compare" ] })
25+ plot_results ({"compare" : args . compare })
2626 print (f"\n The figures have been written to { os .getcwd ()} /compare/" )
2727 return
2828
@@ -60,7 +60,7 @@ def make_dir(path: str) -> None:
6060 subprocess .run (["mkdir" , "-p" , path ], check = True )
6161
6262
63- def load_parser (argv : list [str ] | None ) -> dict :
63+ def load_parser (argv : list [str ] | None ) -> argparse . Namespace :
6464 """CLI arguments"""
6565 parser = argparse .ArgumentParser (
6666 formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
@@ -167,10 +167,10 @@ def load_parser(argv: list[str] | None) -> dict:
167167 default = "" ,
168168 help = "Region to model (the default '' means the whole system)" ,
169169 )
170- return vars ( parser .parse_known_args (argv )[ 0 ] )
170+ return parser .parse_args (argv )
171171
172172
173- def check_cmdargs (cmdargs : dict [ str , str ] ) -> None :
173+ def check_cmdargs (cmdargs : argparse . Namespace ) -> None :
174174 """Validate command-line arguments and incompatible operations.
175175
176176 The checks cover configuration and output names, spatial resolution,
@@ -187,7 +187,7 @@ def check_cmdargs(cmdargs: dict[str, str]) -> None:
187187 SystemExit
188188 If an argument is invalid or an incompatible combination is requested.
189189 """
190- input_file = cmdargs [ " input" ]
190+ input_file = cmdargs . input
191191 if not input_file :
192192 print ("\n Invalid value for '-i', the input file cannot be empty.\n " )
193193 raise SystemExit (1 )
@@ -197,10 +197,10 @@ def check_cmdargs(cmdargs: dict[str, str]) -> None:
197197 "valid extensions are .toml or .txt.\n "
198198 )
199199 raise SystemExit (1 )
200- if not cmdargs [ " output" ] :
200+ if not cmdargs . output :
201201 print ("\n Invalid value for '-o', the output folder cannot be empty.\n " )
202202 raise SystemExit (1 )
203- resolution = cmdargs [ " resolution" ]
203+ resolution = cmdargs . resolution
204204 try :
205205 resolution_values = [int (value .strip ()) for value in resolution .split ("," )]
206206 except ValueError :
@@ -211,7 +211,7 @@ def check_cmdargs(cmdargs: dict[str, str]) -> None:
211211 "integers separated by commas, e.g., '-r 8,1,5'.\n "
212212 )
213213 raise SystemExit (1 )
214- time = cmdargs [ " time" ]
214+ time = cmdargs . time
215215 try :
216216 time_values = [float (value .strip ()) for value in time .split ("," )]
217217 except ValueError :
@@ -222,15 +222,15 @@ def check_cmdargs(cmdargs: dict[str, str]) -> None:
222222 "separated by commas.\n "
223223 )
224224 raise SystemExit (1 )
225- write = cmdargs [ " write" ]
225+ write = cmdargs . write
226226 try :
227227 write_value = float (write )
228228 except ValueError :
229229 write_value = 0
230230 if write_value <= 0 :
231231 print (f"\n Invalid value '-w { write } ', expected a positive number.\n " )
232232 raise SystemExit (1 )
233- mode = cmdargs [ " mode" ]
233+ mode = cmdargs . mode
234234 has_data = mode == "all" or "data" in mode
235235 data_options = {
236236 "-g" : ("generate" , "performance_sparse" ),
@@ -242,7 +242,7 @@ def check_cmdargs(cmdargs: dict[str, str]) -> None:
242242 invalid_options = [
243243 option
244244 for option , (name , default ) in data_options .items ()
245- if cmdargs [ name ] != default
245+ if getattr ( cmdargs , name ) != default
246246 ]
247247 if invalid_options :
248248 print (
@@ -251,7 +251,7 @@ def check_cmdargs(cmdargs: dict[str, str]) -> None:
251251 "data.\n "
252252 )
253253 raise SystemExit (1 )
254- compare = cmdargs [ " compare" ]
254+ compare = cmdargs . compare
255255 if compare :
256256 compare_options = {
257257 "-i" : ("input" , "input.toml" ),
@@ -267,7 +267,7 @@ def check_cmdargs(cmdargs: dict[str, str]) -> None:
267267 invalid_options = [
268268 option
269269 for option , (name , default ) in compare_options .items ()
270- if cmdargs [ name ] != default
270+ if getattr ( cmdargs , name ) != default
271271 ]
272272 if invalid_options :
273273 print (
0 commit comments