@@ -18,7 +18,7 @@ def plot_dispatch(demand, plotdata, level=None, curtailment=None, shedload=None,
18
18
19
19
:param demand: Pandas Series with the demand curve
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
- :param level: Optional pandas series with an aggregated reservoir level for the considered zone.
21
+ :param level: Optional pandas series/dataframe with an (dis) aggregated reservoir level for the considered zone.
22
22
:param curtailment: Optional pandas series with the value of the curtailment
23
23
:param shedload: Optional pandas series with the value of the shed load
24
24
:param rng: Indexes of the values to be plotted. If undefined, the first week is plotted
@@ -75,22 +75,50 @@ def plot_dispatch(demand, plotdata, level=None, curtailment=None, shedload=None,
75
75
76
76
fig .suptitle ('Power dispatch for zone ' + demand .name [1 ])
77
77
78
+ # Define labels, patches and colors
78
79
labels = []
79
80
patches = []
80
81
colorlist = []
81
82
82
- # # Plot negative values:
83
+ # Plot reservoir levels (either separated or as one value)
84
+ if level is not None :
85
+ if isinstance (level , pd .DataFrame ):
86
+ cols_lvl = level .columns .tolist ()
87
+ sumplot_lev = level [cols_lvl [0 :]].cumsum (axis = 1 )
88
+ sumplot_lev ['zero' ] = 0
89
+ sumplot_lev = sumplot_lev [['zero' ] + sumplot_lev .columns [:- 1 ].tolist ()]
90
+ print ('Its dataframe' )
91
+ for j in range (len (sumplot_lev .columns ) - 1 ):
92
+ col3 = sumplot_lev .columns [j ]
93
+ col4 = sumplot_lev .columns [j + 1 ]
94
+ rez_color = commons ['colors' ][col4 ]
95
+ rez_hatch = commons ['hatches' ][col4 ]
96
+ axes [1 ].fill_between (pdrng , sumplot_lev .loc [pdrng , col3 ], sumplot_lev .loc [pdrng , col4 ],
97
+ facecolor = rez_color , alpha = alpha , hatch = rez_hatch )
98
+ labels .append (col4 )
99
+ patches .append (mpatches .Patch (facecolor = rez_color , alpha = alpha , hatch = rez_hatch , label = col4 ))
100
+ colorlist .append (rez_color )
101
+ elif isinstance (level , pd .Series ):
102
+ # Create right axis:
103
+ axes [1 ].plot (pdrng , level [pdrng ], color = 'k' , alpha = alpha , linestyle = ':' )
104
+ axes [1 ].fill_between (pdrng , 0 , level [pdrng ],
105
+ facecolor = commons ['colors' ]['WAT' ], alpha = .3 )
106
+ axes [1 ].set_ylabel ('Level [TWh]' )
107
+ axes [1 ].yaxis .label .set_fontsize (12 )
108
+ line_SOC = mlines .Line2D ([], [], color = 'black' , alpha = alpha , label = 'Reservoir' , linestyle = ':' )
109
+
110
+ # Plot negative values:
83
111
for j in range (idx_zero ):
84
112
col1 = sumplot_neg .columns [j ]
85
113
col2 = sumplot_neg .columns [j + 1 ]
86
114
color = commons ['colors' ][col2 ]
87
115
hatch = commons ['hatches' ][col2 ]
88
116
axes [0 ].fill_between (pdrng , sumplot_neg .loc [pdrng , col1 ], sumplot_neg .loc [pdrng , col2 ], facecolor = color ,
89
- alpha = alpha ,
90
- hatch = hatch )
91
- labels .append (col1 )
92
- patches .append (mpatches .Patch (facecolor = color , alpha = alpha , hatch = hatch , label = col2 ))
93
- colorlist .append (color )
117
+ alpha = alpha , hatch = hatch )
118
+ if col2 not in labels :
119
+ labels .append (col1 )
120
+ patches .append (mpatches .Patch (facecolor = color , alpha = alpha , hatch = hatch , label = col2 ))
121
+ colorlist .append (color )
94
122
95
123
# Plot Positive values:
96
124
for j in range (len (sumplot_pos .columns ) - 1 ):
@@ -118,16 +146,6 @@ def plot_dispatch(demand, plotdata, level=None, curtailment=None, shedload=None,
118
146
axes [0 ].set_ylabel ('Power [GW]' )
119
147
axes [0 ].yaxis .label .set_fontsize (12 )
120
148
121
- if level is not None :
122
- # Create right axis:
123
- axes [1 ].plot (pdrng , level [pdrng ], color = 'k' , alpha = alpha , linestyle = ':' )
124
- axes [1 ].fill_between (pdrng , 0 , level [pdrng ],
125
- facecolor = commons ['colors' ]['WAT' ], alpha = .3 )
126
-
127
- axes [1 ].set_ylabel ('Level [TWh]' )
128
- axes [1 ].yaxis .label .set_fontsize (12 )
129
- line_SOC = mlines .Line2D ([], [], color = 'black' , alpha = alpha , label = 'Reservoir' , linestyle = ':' )
130
-
131
149
if isinstance (shedload , pd .Series ):
132
150
if not shedload .index .equals (demand .index ):
133
151
logging .error ('The shedload time series must have the same index as the demand' )
@@ -296,7 +314,7 @@ def plot_zone_capacities(inputs, plot=True):
296
314
PowerCapacity = PowerCapacity [cols ]
297
315
if plot :
298
316
colors = [commons ['colors' ][tech ] for tech in PowerCapacity .columns ]
299
- ax = PowerCapacity .plot (kind = "bar" , figsize = (12 , 8 ), stacked = True , color = colors , alpha = 1.0 , legend = 'reverse' ,
317
+ ax = PowerCapacity .plot (kind = "bar" , figsize = (12 , 8 ), stacked = True , color = colors , alpha = 0.8 , legend = 'reverse' ,
300
318
title = 'Installed capacity per zone (the horizontal lines indicate the peak demand)' )
301
319
ax .set_ylabel ('Capacity [MW]' )
302
320
demand = inputs ['param_df' ]['Demand' ]['DA' ].max ()
@@ -326,10 +344,22 @@ def plot_zone(inputs, results, z='', rng=None, rug_plot=True):
326
344
327
345
plotdata = get_plot_data (inputs , results , z ) / 1000 # GW
328
346
347
+ aggregation = False
329
348
if 'OutputStorageLevel' in results :
330
- levels = filter_by_zone (results ['OutputStorageLevel' ], inputs , z ) / 1E6 # TWh
331
- level = filter_by_storage (levels , inputs , StorageSubset = 's' )
332
- level = level .sum (axis = 1 )
349
+ lev = filter_by_zone (results ['OutputStorageLevel' ], inputs , z ) / 1E6 # TWh
350
+ level = filter_by_storage (lev , inputs , StorageSubset = 's' )
351
+ levels = pd .DataFrame (index = results ['OutputStorageLevel' ].index ,columns = inputs ['sets' ]['t' ])
352
+ for t in ['HDAM' ,'HPHS' ,'BEVS' ,'BATS' ]:
353
+ temp = filter_by_tech (level ,inputs ,t )
354
+ levels [t ] = temp .sum (axis = 1 )
355
+ levels .dropna (axis = 1 ,inplace = True )
356
+ for col in levels .columns :
357
+ if levels [col ].max () == 0 and levels [col ].min () == 0 :
358
+ del levels [col ]
359
+ if aggregation is True :
360
+ level = level .sum (axis = 1 )
361
+ else :
362
+ level = levels
333
363
else :
334
364
level = pd .Series (0 , index = results ['OutputPower' ].index )
335
365
@@ -358,14 +388,14 @@ def plot_zone(inputs, results, z='', rng=None, rug_plot=True):
358
388
if 'OutputCurtailedPower' in results and z in results ['OutputCurtailedPower' ] \
359
389
and 'OutputShedLoad' in results and z in results ['OutputShedLoad' ]:
360
390
curtailment = results ['OutputCurtailedPower' ][z ] / 1000 # GW
361
- plot_dispatch (demand , plotdata , level , curtailment = curtailment , shedload = shed_load , rng = rng )
391
+ plot_dispatch (demand , plotdata , level , curtailment = curtailment , shedload = shed_load , rng = rng , alpha = 0.8 )
362
392
elif 'OutputCurtailedPower' in results and z in results ['OutputCurtailedPower' ]:
363
393
curtailment = results ['OutputCurtailedPower' ][z ] / 1000 # GW
364
- plot_dispatch (demand , plotdata , level , curtailment = curtailment , rng = rng )
394
+ plot_dispatch (demand , plotdata , level , curtailment = curtailment , rng = rng , alpha = 0.8 )
365
395
elif 'OutputShedLoad' in results and z in results ['OutputShedLoad' ]:
366
- plot_dispatch (demand , plotdata , level , shedload = shed_load , rng = rng )
396
+ plot_dispatch (demand , plotdata , level , shedload = shed_load , rng = rng , alpha = 0.8 )
367
397
else :
368
- plot_dispatch (demand , plotdata , level , rng = rng )
398
+ plot_dispatch (demand , plotdata , level , rng = rng , alpha = 0.8 )
369
399
370
400
# Generation plot:
371
401
if rug_plot :
0 commit comments