forked from darcamo/pyphysim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombine_results.py
51 lines (40 loc) · 1.58 KB
/
combine_results.py
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
#!/usr/bin/env python
"""
Script that reads two files with saved SimulationResults and combine
them into a new SimulationResults which is saved to a new file.
"""
import argparse
from pyphysim.simulations.results import (SimulationResults,
combine_simulation_results)
from pyphysim.util.misc import replace_dict_values
def main():
"""Main function of the script.
"""
parser = argparse.ArgumentParser()
parser.add_argument('first',
help="The name of the first SimulationResults file.")
parser.add_argument('second',
help="The name of the second SimulationResults file.")
parser.add_argument(
'output',
help=("The name that will be used to save the combined "
"SimulationResults file."),
nargs='?')
args = parser.parse_args()
first = SimulationResults.load_from_file(args.first)
second = SimulationResults.load_from_file(args.second)
union = combine_simulation_results(first, second)
if args.output is None:
output = replace_dict_values(first.original_filename,
union.params.parameters,
filename_mode=True)
else:
output = args.output
if output == args.first or output == args.second:
raise RuntimeError(
"output filename must be different from the filename of either"
" of the two SimulationResults.")
# Finally save to the output file
union.save_to_file(output)
if __name__ == '__main__':
main()