@@ -542,12 +542,35 @@ def graph_state_of_charge(tools):
542542 df ["StateOfCharge" ] /= 1e6
543543 df ["OnlineEnergyCapacityMWh" ] /= 1e6
544544
545- # Determine information for the label
546- y_axis_lim = df ["OnlineEnergyCapacityMWh" ].max ()
547- offset = y_axis_lim * 0.05
548- df ["label_position" ] = df ["OnlineEnergyCapacityMWh" ] + offset
549- df ["label" ] = df ["OnlineEnergyCapacityMWh" ].round (decimals = 2 )
545+ # Add information regarding the diurnal cycle to the dataframe
546+ # Find the difference between the min and max for every day of the year
547+ group = df .groupby (
548+ ["period" , "scenario_name" , tools .pd .Grouper (freq = "D" , key = "datetime" )]
549+ )["StateOfCharge" ]
550+ daily_size = (group .max () - group .min ()).reset_index ()
551+ # Find the mean between the difference of the min and max
552+ daily_size = (
553+ daily_size .groupby (["period" , "scenario_name" ], as_index = False )
554+ .mean ()
555+ .reset_index ()
556+ )
557+ # Add the mean to the dataframe under the name DiurnalCycle
558+ df = df .merge (
559+ daily_size .rename ({"StateOfCharge" : "DiurnalCycle" }, axis = 1 ),
560+ on = ["period" , "scenario_name" ],
561+ how = "left" ,
562+ )
563+
564+ # Determine information for the labels
565+ y_axis_max = df ["OnlineEnergyCapacityMWh" ].max ()
566+ label_offset = y_axis_max * 0.05
550567 label_x_pos = df ["datetime" ].median ()
568+ # For the max label
569+ df ["label_position" ] = df ["OnlineEnergyCapacityMWh" ] + label_offset
570+ df ["label" ] = df ["OnlineEnergyCapacityMWh" ].round (decimals = 2 )
571+ # For the diurnal cycle label
572+ df ["diurnal_label" ] = df ["DiurnalCycle" ].round (decimals = 2 )
573+ df ["diurnal_label_pos" ] = df ["DiurnalCycle" ] + label_offset
551574
552575 # Plot with plotnine
553576 pn = tools .pn
@@ -565,6 +588,15 @@ def graph_state_of_charge(tools):
565588 fontweight = "light" ,
566589 size = "10" ,
567590 )
591+ + pn .geom_hline (
592+ pn .aes (yintercept = "DiurnalCycle" ), linetype = "dashed" , color = "red"
593+ )
594+ + pn .geom_text (
595+ pn .aes (label = "diurnal_label" , x = label_x_pos , y = "diurnal_label_pos" ),
596+ fontweight = "light" ,
597+ size = "10" ,
598+ color = "red" ,
599+ )
568600 )
569601
570602 tools .save_figure (by_scenario_and_period (tools , plot , num_periods ).draw ())
0 commit comments