diff --git a/estimate_electricity_cost_by_technology_from_population.py b/estimate_electricity_cost_by_technology_from_population.py index 3faa19e..c1ab542 100644 --- a/estimate_electricity_cost_by_technology_from_population.py +++ b/estimate_electricity_cost_by_technology_from_population.py @@ -34,7 +34,8 @@ from infrastructure_planning.electricity.report import ( save_total_lines, save_total_map, save_total_points, save_total_report_by_location, save_total_summary_by_grid_mv_line, - save_total_summary_by_location, save_total_summary_by_technology) + save_total_summary_by_location, save_total_summary_by_technology, + FULL_KEYS) from estimate_grid_mv_line_budget_in_meters import ( add_arguments_for_estimate_population) @@ -296,4 +297,4 @@ save_total_map, # save_total_graph, wash_total_folder, - ], x) + ], x.parse_args().__dict__, FULL_KEYS) diff --git a/infrastructure_planning/macros.py b/infrastructure_planning/macros.py index d040748..3912f91 100644 --- a/infrastructure_planning/macros.py +++ b/infrastructure_planning/macros.py @@ -8,7 +8,7 @@ from invisibleroads_macros.disk import ( make_enumerated_folder_for, make_folder, remove_safely) from invisibleroads_macros.geometry import flip_geometry_coordinates -from invisibleroads_macros.iterable import merge_dictionaries +from invisibleroads_macros.iterable import merge_dictionaries, sort_dictionary from invisibleroads_macros.math import divide_safely from invisibleroads_macros.table import normalize_column_name from networkx import Graph, write_gpickle @@ -46,10 +46,10 @@ def cycle_edges(self): yield node1_id, node2_id, edge_d -def load_and_run(normalization_functions, main_functions, argument_parser): - args = argument_parser.parse_args() - g = load_arguments(args.__dict__) - save_arguments(g, __file__) +def load_and_run( + normalization_functions, main_functions, arguments, keys): + g = load_arguments(arguments) + save_arguments(g, __file__, keys) try: g = load_files(g) g = normalize_arguments(normalization_functions, g) @@ -75,7 +75,7 @@ def load_arguments(value_by_key): return g -def save_arguments(g, script_path): +def save_arguments(g, script_path, keys): d = g.copy() target_folder = d.pop('target_folder') if not target_folder: @@ -89,10 +89,14 @@ def save_arguments(g, script_path): shutil.copy(v, join(arguments_folder, file_name)) # Make the reference point to the local copy d[k] = file_name + # Sort arguments using keys + d = sort_dictionary(d, keys) # Save global arguments as JSON - json.dump(d, open(join(arguments_folder, 'arguments.json'), 'w')) + target_file = open(join(arguments_folder, 'arguments.json'), 'w') + json.dump(d, target_file, indent=4, separators=(',', ': ')) # Save global arguments as CSV - csv_writer = csv.writer(open(join(arguments_folder, 'arguments.csv'), 'w')) + target_file = open(join(arguments_folder, 'arguments.csv'), 'w') + csv_writer = csv.writer(target_file) for x in d.items(): csv_writer.writerow(x)