-
Notifications
You must be signed in to change notification settings - Fork 11
/
simple_1param.py
81 lines (67 loc) · 2.36 KB
/
simple_1param.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Copyright (c) 2017, University of Southern Denmark
All rights reserved.
This code is licensed under BSD 2-clause license.
See LICENSE file in the project root for license terms.
"""
import json
import os
import pandas as pd
from modestpy import Estimation
from modestpy.utilities.sysarch import get_sys_arch
if __name__ == "__main__":
"""
This file is supposed to be run from the root directory.
Otherwise the paths have to be corrected.
"""
# DATA PREPARATION ==============================================
# Resources
platform = get_sys_arch()
assert platform, "Unsupported platform type!"
fmu_file = "Simple2R1C_ic_" + platform + ".fmu"
fmu_path = os.path.join("examples", "simple", "resources", fmu_file)
inp_path = os.path.join("examples", "simple", "resources", "inputs.csv")
ideal_path = os.path.join("examples", "simple", "resources", "result.csv")
est_path = os.path.join("examples", "simple", "resources", "est.json")
known_path = os.path.join("examples", "simple", "resources", "known.json")
# Working directory
workdir = os.path.join("examples", "simple", "workdir")
if not os.path.exists(workdir):
os.mkdir(workdir)
assert os.path.exists(workdir), "Work directory does not exist"
# Load inputs
inp = pd.read_csv(inp_path).set_index("time")
# Load measurements (ideal results)
ideal = pd.read_csv(ideal_path).set_index("time")
# Load definition of estimated parameters (name, initial value, bounds)
with open(est_path) as f:
est = json.load(f)
del est["R1"] # We want to estimate only C
del est["R2"] # We want to estimate only C
# Load definition of known parameters (name, value)
with open(known_path) as f:
known = json.load(f)
known["R1"] = 0.1
known["R2"] = 0.25
# MODEL IDENTIFICATION ==========================================
session = Estimation(
workdir,
fmu_path,
inp,
known,
est,
ideal,
lp_n=2,
lp_len=50000,
lp_frame=(0, 50000),
vp=(0, 50000),
ic_param={"Tstart": "T"},
methods=("MODESTGA", "PS"),
ps_opts={"maxiter": 500, "tol": 1e-6},
scipy_opts={},
ftype="RMSE",
default_log=True,
logfile="simple.log",
)
estimates = session.estimate()
err, res = session.validate()