-
Notifications
You must be signed in to change notification settings - Fork 40
/
breakdowns.py
51 lines (44 loc) · 2.08 KB
/
breakdowns.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
"An example to show off Breakdowns"
import os
import pickle
import pint
from gpkit.breakdowns import Breakdowns
if pint.__version__.split(".") >= ["0", "9"]:
# the code to create solar.p is in ./breakdowns/solartest.py
filepath = os.path.dirname(os.path.realpath(__file__)) + os.sep + "solar.p"
sol = pickle.load(open(filepath, "rb"))
bds = Breakdowns(sol)
print("Cost breakdown (as seen in solution tables)")
print("==============")
bds.plot("cost")
print("Variable breakdowns (note the two methods of access)")
print("===================")
varkey, = sol["variables"].keymap[("Mission.FlightSegment.AircraftPerf"
".AircraftDrag.Poper")]
bds.plot(varkey)
bds.plot("AircraftPerf.AircraftDrag.MotorPerf.Q")
print("Combining the two above by increasing maxwidth")
print("----------------------------------------------")
bds.plot("AircraftPerf.AircraftDrag.Poper", maxwidth=105)
print("Model sensitivity breakdowns (note the two methods of access)")
print("============================")
bds.plot("model sensitivities")
bds.plot("Aircraft")
print("Exhaustive variable breakdown traces (and configuration arguments)")
print("====================================")
# often useful as a reference point when reading traces
bds.plot("AircraftPerf.AircraftDrag.Poper", height=12)
# includes factors, can be useful for reading traces as well
bds.plot("AircraftPerf.AircraftDrag.Poper", showlegend=True)
print("\nPermissivity = 2 (the default)")
print("----------------")
bds.trace("AircraftPerf.AircraftDrag.Poper")
print("\nPermissivity = 1 (stops at Pelec = v·i)")
print("----------------")
bds.trace("AircraftPerf.AircraftDrag.Poper", permissivity=1)
# you can also produce Plotly treemaps/icicle plots of your breakdowns
fig = bds.treemap("model sensitivities", returnfig=True)
fig = bds.icicle("cost", returnfig=True)
# uncommenting any of the below makes and shows the plot directly
# bds.icicle("model sensitivities")
# bds.treemap("cost")