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

33 statements  

1"An example to show off Breakdowns" 

2import os 

3import pickle 

4from gpkit.breakdowns import Breakdowns 

5 

6# the code to create solar.p is in ./breakdowns/solartest.py 

7path = os.path.dirname(os.path.realpath(__file__)) 

8sol = pickle.load(open(path + os.sep + "solar.p", "rb")) 

9bds = Breakdowns(sol) 

10 

11print("Cost breakdown (you may be familiar with this from solution tables)") 

12print("==============") 

13bds.plot("cost") 

14 

15print("Variable breakdowns (note the two methods of access)") 

16print("===================") 

17varkey, = sol["variables"].keymap[("Mission.FlightSegment.AircraftPerf" 

18 ".AircraftDrag.Poper")] 

19bds.plot(varkey) 

20bds.plot("AircraftPerf.AircraftDrag.MotorPerf.Q") 

21 

22print("Combining the two above by increasing maxwidth") 

23print("----------------------------------------------") 

24bds.plot("AircraftPerf.AircraftDrag.Poper", maxwidth=105) 

25 

26print("Model sensitivity breakdowns (note the two methods of access)") 

27print("============================") 

28bds.plot("model sensitivities") 

29bds.plot("Aircraft") 

30 

31print("Exhaustive variable breakdown traces (and configuration arguments)") 

32print("====================================") 

33# often useful as a reference point when reading traces 

34bds.plot("AircraftPerf.AircraftDrag.Poper", height=12) 

35# includes factors, can be useful for reading traces as well 

36bds.plot("AircraftPerf.AircraftDrag.Poper", showlegend=True) 

37print("\nPermissivity = 2 (the default)") 

38print("----------------") 

39bds.trace("AircraftPerf.AircraftDrag.Poper") 

40print("\nPermissivity = 1 (stops at Pelec = v·i)") 

41print("----------------") 

42bds.trace("AircraftPerf.AircraftDrag.Poper", permissivity=1) 

43 

44# you can also produce Plotly treemaps/icicle plots of your breakdowns 

45fig = bds.treemap("model sensitivities", returnfig=True) 

46fig = bds.icicle("cost", returnfig=True) 

47# uncommenting any of the below makes and shows the plot directly 

48# bds.icicle("model sensitivities") 

49# bds.treemap("cost")