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