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 gpkit.breakdowns import Breakdowns
7if pint.__version__.split(".") >= ["0", "9"]:
8 # the code to create solar.p is in ./breakdowns/solartest.py
9 filepath = os.path.dirname(os.path.realpath(__file__)) + os.sep + "solar.p"
10 sol = pickle.load(open(filepath, "rb"))
11 bds = Breakdowns(sol)
13 print("Cost breakdown (as seen in solution tables)")
14 print("==============")
15 bds.plot("cost")
17 print("Variable breakdowns (note the two methods of access)")
18 print("===================")
19 varkey, = sol["variables"].keymap[("Mission.FlightSegment.AircraftPerf"
20 ".AircraftDrag.Poper")]
21 bds.plot(varkey)
22 bds.plot("AircraftPerf.AircraftDrag.MotorPerf.Q")
24 print("Combining the two above by increasing maxwidth")
25 print("----------------------------------------------")
26 bds.plot("AircraftPerf.AircraftDrag.Poper", maxwidth=105)
28 print("Model sensitivity breakdowns (note the two methods of access)")
29 print("============================")
30 bds.plot("model sensitivities")
31 bds.plot("Aircraft")
33 print("Exhaustive variable breakdown traces (and configuration arguments)")
34 print("====================================")
35 # often useful as a reference point when reading traces
36 bds.plot("AircraftPerf.AircraftDrag.Poper", height=12)
37 # includes factors, can be useful for reading traces as well
38 bds.plot("AircraftPerf.AircraftDrag.Poper", showlegend=True)
39 print("\nPermissivity = 2 (the default)")
40 print("----------------")
41 bds.trace("AircraftPerf.AircraftDrag.Poper")
42 print("\nPermissivity = 1 (stops at Pelec = v·i)")
43 print("----------------")
44 bds.trace("AircraftPerf.AircraftDrag.Poper", permissivity=1)
46 # you can also produce Plotly treemaps/icicle plots of your breakdowns
47 fig = bds.treemap("model sensitivities", returnfig=True)
48 fig = bds.icicle("cost", returnfig=True)
49 # uncommenting any of the below makes and shows the plot directly
50 # bds.icicle("model sensitivities")
51 # bds.treemap("cost")