Przeglądaj źródła

params in dictionnary

Florian 7 lat temu
rodzic
commit
9fa97dd83b
2 zmienionych plików z 11 dodań i 10 usunięć
  1. 2 2
      plan_gen/plan_gen.py
  2. 9 8
      plan_gen/plan_gen_cli.py

+ 2 - 2
plan_gen/plan_gen.py

@@ -30,8 +30,8 @@ def parse_params(param_str):
     if param_str:
         for key_value_str in param_str.split(','):
             key, value = key_value_str.split('=')
-            if key in ['xmin', 'xmax', 'c', 'w', 'alpha']:
-                dict_params[key] = np.fromstring(str(value), dtype=float, sep=':')
+            if key in ['hc', 'wc']:
+                dict_params[key] = [file for file in value.split(':')]
             else:
                 dict_params[key] = parse_value(value)
     return dict_params

+ 9 - 8
plan_gen/plan_gen_cli.py

@@ -8,14 +8,15 @@ import plan_gen.plan_gen as pg
 if __name__ == '__main__':
 
     # command line arguments
-    if len(sys.argv) != 5:
-        print('usage:', sys.argv[0], '<nb_persons> <input_network> <input_home_clusters> <input_work_clusters>')
-        print('type "" if you don\'t want to use specific clusters')
+    if len(sys.argv) != 2:
+        print('usage:', sys.argv[0], '<params>')
         sys.exit(-1)
-    NB_PERSONS = int(sys.argv[1])
-    INPUT_NETWORK = sys.argv[2]
-    INPUT_HOME_CLUSTERS = sys.argv[3].split(',')
-    INPUT_WORK_CLUSTERS = sys.argv[4].split(',')
+    DICT_PARAMS = pg.parse_params(sys.argv[1])
+
+    NB_PERSONS = DICT_PARAMS['np']
+    INPUT_NETWORK = DICT_PARAMS['nw']
+    INPUT_HOME_CLUSTERS = DICT_PARAMS['hc'] if 'hc' in DICT_PARAMS else ''
+    INPUT_WORK_CLUSTERS = DICT_PARAMS['wc'] if 'wc' in DICT_PARAMS else ''
 
     # get data
     NODES = pg.read_nodes(INPUT_NETWORK)
@@ -29,4 +30,4 @@ if __name__ == '__main__':
     # print XML
     print('<?xml version="1.0" ?>')
     print('<!DOCTYPE plans SYSTEM "http://www.matsim.org/files/dtd/plans_v4.dtd">')
-    print(etree.tostring(PLANS, pretty_print=True).decode('utf-8'))
+    print(etree.tostring(PLANS, pretty_print=True).decode('utf-8'))