11
11
from .postprocessing import get_imports , get_plot_data , filter_by_zone
12
12
13
13
14
- def plot_dispatch (demand , plotdata , level = None , curtailment = None , rng = None ,
14
+ def plot_dispatch (demand , plotdata , level = None , curtailment = None , shedload = None , rng = None ,
15
15
alpha = None , figsize = (13 , 6 )):
16
16
"""
17
17
Function that plots the dispatch data and the reservoir level as a cumulative sum
@@ -20,6 +20,7 @@ def plot_dispatch(demand, plotdata, level=None, curtailment=None, rng=None,
20
20
:param plotdata: Pandas Dataframe with the data to be plotted. Negative columns should be at the beginning. Output of the function GetPlotData
21
21
:param level: Optional pandas series with an aggregated reservoir level for the considered zone.
22
22
:param curtailment: Optional pandas series with the value of the curtailment
23
+ :param shedload: Optional pandas series with the value of the shed load
23
24
:param rng: Indexes of the values to be plotted. If undefined, the first week is plotted
24
25
"""
25
26
import matplotlib .patches as mpatches
@@ -34,7 +35,7 @@ def plot_dispatch(demand, plotdata, level=None, curtailment=None, rng=None,
34
35
raise ValueError ()
35
36
elif rng [0 ] < plotdata .index [0 ] or rng [0 ] > plotdata .index [- 1 ] or rng [- 1 ] < plotdata .index [0 ] or rng [- 1 ] > \
36
37
plotdata .index [- 1 ]:
37
- logging .warn ('Plotting range is not properly defined, considering the first simulated week' )
38
+ logging .warning ('Plotting range is not properly defined, considering the first simulated week' )
38
39
pdrng = plotdata .index [:min (len (plotdata ) - 1 , 7 * 24 )]
39
40
else :
40
41
pdrng = rng
@@ -127,12 +128,32 @@ def plot_dispatch(demand, plotdata, level=None, curtailment=None, rng=None,
127
128
axes [1 ].yaxis .label .set_fontsize (12 )
128
129
line_SOC = mlines .Line2D ([], [], color = 'black' , alpha = alpha , label = 'Reservoir' , linestyle = ':' )
129
130
131
+ if isinstance (shedload , pd .Series ):
132
+ if not shedload .index .equals (demand .index ):
133
+ logging .error ('The shedload time series must have the same index as the demand' )
134
+ sys .exit (1 )
135
+ reduced_demand = demand - shedload
136
+ axes [0 ].plot (pdrng , reduced_demand [pdrng ], color = 'k' , alpha = alpha , linestyle = 'dashed' )
137
+ line_shedload = mlines .Line2D ([], [], color = 'black' , alpha = alpha , label = 'Shed Load' , linestyle = 'dashed' )
138
+
130
139
line_demand = mlines .Line2D ([], [], color = 'black' , label = 'Load' )
131
- plt .legend (handles = [line_demand ] + patches [::- 1 ], loc = 4 )
132
- if level is None :
133
- plt .legend (handles = [line_demand ] + patches [::- 1 ], loc = 4 )
140
+ # plt.legend(handles=[line_demand] + patches[::-1], loc=4)
141
+
142
+ if shedload is None and level is None :
143
+ plt .legend (handles = [line_demand ] + patches [::- 1 ], loc = 4 , bbox_to_anchor = (1.2 , 1.3 ))
144
+ if shedload is None :
145
+ plt .legend (handles = [line_demand ] + [line_SOC ] + patches [::- 1 ], loc = 4 , bbox_to_anchor = (1.2 , 1.3 ))
146
+ elif level is None :
147
+ plt .legend (handles = [line_demand ] + [line_shedload ] + patches [::- 1 ], loc = 4 , bbox_to_anchor = (1.2 , 1.3 ))
148
+ axes [0 ].fill_between (demand .index , demand , reduced_demand , facecolor = "none" , hatch = "X" , edgecolor = "k" ,
149
+ linestyle = 'dashed' )
134
150
else :
135
- plt .legend (title = 'Dispatch for ' + demand .name [1 ], handles = [line_demand ] + [line_SOC ] + patches [::- 1 ], loc = 4 )
151
+ plt .legend (title = 'Dispatch for ' + demand .name [1 ], handles = [line_demand ] + [line_shedload ] + [line_SOC ] +
152
+ patches [::- 1 ], loc = 4 , bbox_to_anchor = (1.2 , 1.3 ))
153
+ axes [0 ].fill_between (demand .index , demand , reduced_demand , facecolor = "none" , hatch = "X" , edgecolor = "k" ,
154
+ linestyle = 'dashed' )
155
+
156
+ plt .subplots_adjust (right = 0.8 )
136
157
plt .show ()
137
158
138
159
@@ -249,6 +270,7 @@ def plot_energy_zone_fuel(inputs, results, PPindicators):
249
270
demand = inputs ['param_df' ]['Demand' ]['DA' ].sum () / 1E6
250
271
ax .barh (demand , left = ax .get_xticks () - 0.4 , width = [0.8 ] * len (demand ), height = ax .get_ylim ()[1 ] * 0.005 , linewidth = 2 ,
251
272
color = 'k' )
273
+ plt .show ()
252
274
return ax
253
275
254
276
@@ -324,16 +346,23 @@ def plot_zone(inputs, results, z='', rng=None, rug_plot=True):
324
346
# if 'OutputShedLoad' in results:
325
347
if 'OutputShedLoad' in results and z in results ['OutputShedLoad' ]:
326
348
shed_load = results ['OutputShedLoad' ][z ] / 1000 # GW
349
+ shed_load = pd .Series (shed_load , index = demand .index ).fillna (0 )
327
350
else :
328
351
shed_load = pd .Series (0 , index = demand .index ) / 1000 # GW
329
352
diff = (sum_generation - demand + shed_load ).abs ()
330
353
if diff .max () > 0.01 * demand .max ():
331
354
logging .critical ('There is up to ' + str (
332
355
diff .max () / demand .max () * 100 ) + '% difference in the instantaneous energy balance of zone ' + z )
333
356
334
- if 'OutputCurtailedPower' in results and z in results ['OutputCurtailedPower' ]:
357
+ if 'OutputCurtailedPower' in results and z in results ['OutputCurtailedPower' ] \
358
+ and 'OutputShedLoad' in results and z in results ['OutputShedLoad' ]:
359
+ curtailment = results ['OutputCurtailedPower' ][z ] / 1000 # GW
360
+ plot_dispatch (demand , plotdata , level , curtailment = curtailment , shedload = shed_load , rng = rng )
361
+ elif 'OutputCurtailedPower' in results and z in results ['OutputCurtailedPower' ]:
335
362
curtailment = results ['OutputCurtailedPower' ][z ] / 1000 # GW
336
363
plot_dispatch (demand , plotdata , level , curtailment = curtailment , rng = rng )
364
+ elif 'OutputShedLoad' in results and z in results ['OutputShedLoad' ]:
365
+ plot_dispatch (demand , plotdata , level , shedload = shed_load , rng = rng )
337
366
else :
338
367
plot_dispatch (demand , plotdata , level , rng = rng )
339
368
0 commit comments