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