Coverage for docs/source/examples/breakdowns.py: 100%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"An example to show off Breakdowns"
2import os
3import pickle
4import pint
5from packaging import version
6from gpkit.breakdowns import Breakdowns
8if version.parse(pint.__version__) >= version.parse("0.9"):
9 # the code to create solar.p is in ./breakdowns/solartest.py
10 filepath = os.path.dirname(os.path.realpath(__file__)) + os.sep + "solar.p"
11 sol = pickle.load(open(filepath, "rb"))
12 bds = Breakdowns(sol)
14 print("Cost breakdown (as seen in solution tables)")
15 print("==============")
16 bds.plot("cost")
18 print("Variable breakdowns (note the two methods of access)")
19 print("===================")
20 varkey, = sol["variables"].keymap[("Mission.FlightSegment.AircraftPerf"
21 ".AircraftDrag.Poper")]
22 bds.plot(varkey)
23 bds.plot("AircraftPerf.AircraftDrag.MotorPerf.Q")
25 print("Combining the two above by increasing maxwidth")
26 print("----------------------------------------------")
27 bds.plot("AircraftPerf.AircraftDrag.Poper", maxwidth=105)
29 print("Model sensitivity breakdowns (note the two methods of access)")
30 print("============================")
31 bds.plot("model sensitivities")
32 bds.plot("Aircraft")
34 print("Exhaustive variable breakdown traces (and configuration arguments)")
35 print("====================================")
36 # often useful as a reference point when reading traces
37 bds.plot("AircraftPerf.AircraftDrag.Poper", height=12)
38 # includes factors, can be useful for reading traces as well
39 bds.plot("AircraftPerf.AircraftDrag.Poper", showlegend=True)
40 print("\nPermissivity = 2 (the default)")
41 print("----------------")
42 bds.trace("AircraftPerf.AircraftDrag.Poper")
43 print("\nPermissivity = 1 (stops at Pelec = v·i)")
44 print("----------------")
45 bds.trace("AircraftPerf.AircraftDrag.Poper", permissivity=1)
47 # you can also produce Plotly treemaps/icicle plots of your breakdowns
48 fig = bds.treemap("model sensitivities", returnfig=True)
49 fig = bds.icicle("cost", returnfig=True)
50 # uncommenting any of the below makes and shows the plot directly
51 # bds.icicle("model sensitivities")
52 # bds.treemap("cost")