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