From 9165f77762a66a5bd706b03b5d51273a250bb53d Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Mon, 25 Apr 2022 11:13:46 +0200 Subject: [PATCH] Use argparse Preparing to introduce an option. --- cost_function.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cost_function.py b/cost_function.py index 663aee50..e8d6e831 100755 --- a/cost_function.py +++ b/cost_function.py @@ -27,8 +27,8 @@ import datetime from numpy import loadtxt import report_graph import util_eddies -import sys import bisect +import argparse def calculate_radii_rossby(start, end, inc, segment, e_overestim, handlers, array_d_init): @@ -76,9 +76,9 @@ def get_SHPC(array_d_ini, date_index): t0 = time.perf_counter() timings = open("timings.txt", "w") - -if len(sys.argv) == 1: - sys.exit("Required arguments: SHPC-directory [SHPC-directory] ...") +parser = argparse.ArgumentParser() +parser.add_argument("SHPC_dir", nargs='+') +args = parser.parse_args() # Grab e_overestim: with open("node_id_param.json") as f: node_id_param = json.load(f) @@ -125,7 +125,7 @@ g.ep['cost_function'] = g.new_ep('float') # Set up the list of SHPC: -handlers = [util_eddies.open_shpc(shpc_dir) for shpc_dir in sys.argv[1:]] +handlers = [util_eddies.open_shpc(shpc_dir) for shpc_dir in args.SHPC_dir] array_d_init = [handler["d_init"] for handler in handlers] # (create the list once and for all) -- GitLab