-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangeFileContent.py
50 lines (38 loc) · 1.57 KB
/
ChangeFileContent.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
import argparse
import os
import pandas as pd
def ChangeFileContent(store, prior, exp, model_name=None):
needToClose = False
if isinstance(store, str):
needToClose = True
store = pd.HDFStore(store, "a")
if isinstance(prior, str):
prior = pd.read_csv(prior, index_col=0)
if isinstance(exp, str):
exp = pd.read_csv(exp, index_col=0)
config = store.get_storer("PriorAndConfig").attrs.my_attribute
if prior is not None:
prior = prior.T
prior[prior.columns.difference(["Type"])] = prior[
prior.columns.difference(["Type"])
].astype("float")
store["PriorAndConfig"] = prior
store.get_storer("PriorAndConfig").attrs.my_attribute = config
if model_name is not None:
config['name'] = model_name
store.get_storer("PriorAndConfig").attrs.my_attribute = config
if exp is not None:
store["Exp_Y"] = exp.loc["Values"].astype("float")
store["Exp_YErr"] = exp.loc["Errors"].astype("float")
if needToClose:
store.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="This script changes the prior and experimental values of an already trained config file")
parser.add_argument(
"store",
help="Location of the already existing config file")
parser.add_argument("--prior", help="Location of parameter priors", default=None)
parser.add_argument("--exp", help="Location of the experimental result", default=None)
args = vars(parser.parse_args())
ChangeFileContent(**args)