Skip to content

Commit

Permalink
derUtilityCost: Split DER Overview plot into two plots - DER Serving …
Browse files Browse the repository at this point in the history
…Load and Impact to Demand.
  • Loading branch information
astronobri committed Jan 14, 2025
1 parent 0f36c89 commit 8aaa496
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 40 deletions.
4 changes: 4 additions & 0 deletions omf/models/derUtilityCost.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<script type="text/javascript">
$(window).on('pageshow',function(){
Plotly.newPlot('derOverviewData', JSON.parse(allOutputData['derOverviewData']),JSON.parse(allOutputData['derOverviewLayout']));
Plotly.newPlot('newDemandData', JSON.parse(allOutputData['newDemandData']),JSON.parse(allOutputData['newDemandLayout']));
Plotly.newPlot('batteryChargePlotly', JSON.parse(allOutputData['batteryChargeData']), JSON.parse(allOutputData['batteryChargeLayout']));
Plotly.newPlot('thermalBatPowerPlot', JSON.parse(allOutputData['thermalBatPowerPlot']), JSON.parse(allOutputData['thermalBatPowerPlotLayout']) || {});
Plotly.newPlot('resiliencePlotly', JSON.parse(allOutputData['resilienceData']), JSON.parse(allOutputData['resilienceLayout']) || {});
Expand Down Expand Up @@ -271,6 +272,9 @@
<p class="reportTitle" style="page-break-before:always">DER Serving Load Overview</p>
<div id="derOverviewData" class="tightContent" style="width: 1000px; height: 600px;"></div>

<p class="reportTitle" style="page-break-before:always">Impact to Demand</p>
<div id="newDemandData" class="tightContent" style="width: 1000px; height: 600px;"></div>

<p class="reportTitle" style="page-break-before:always">Home Thermal Battery Power Profile</p>
<div id="thermalBatPowerPlot" class="tightContent" style="width: 1000px; height: 600px;"></div>

Expand Down
144 changes: 104 additions & 40 deletions omf/models/derUtilityCost.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def work(modelDir, inputDict):
"""

## DER Overview plot ###################################################################################################################################################################
## DER Serving Load Overview plot ###################################################################################################################################################################
showlegend = True # either enable or disable the legend toggle in the plot
#lineshape = 'linear'
lineshape = 'hv'
Expand Down Expand Up @@ -338,8 +338,9 @@ def work(modelDir, inputDict):
#mode='none',
#fill='tozeroy',
name='Grid Serving Load',
line=dict(color='rgba(192,192,192,1)', width=1),
line_shape=lineshape,
line=dict(color='rgba(0,0,0,0)'), #transparent line (to get around the Plotly default line)
#line_shape=lineshape,
fillcolor='rgba(192,192,192,1)',
stackgroup='one',
showlegend=showlegend))

Expand All @@ -362,23 +363,13 @@ def work(modelDir, inputDict):
#mode='none',
#fill='tozeroy',
name='Home BESS Serving Load',
line=dict(color='rgba(0,137,83,1)', width=1),
line_shape=lineshape,
fillcolor='rgba(0,137,83,1)',
line=dict(color='rgba(0,0,0,0)'), #transparent line (to get around the Plotly default line)
#line_shape=lineshape,
stackgroup='one',
showlegend=showlegend))

fig.add_trace(go.Scatter(x=timestamps,
y=grid_charging_BESS_W,
yaxis='y1',
#mode='none',
name='Additional Load from Home BESS',
#fill='tozeroy',
line=dict(color='rgba(118,196,165,1)', width=1),
line_shape=lineshape,
stackgroup='one',
showlegend=showlegend))

##vbatDispatch (TESS) piece
## vbatDispatch (TESS) piece
if (inputDict['load_type'] != '0') and (int(inputDict['number_devices'])>0): ## Load type 0 corresponds to the "None" option, which disables this vbatDispatch function
fig.add_trace(go.Scatter(x=timestamps,
y = vbat_discharge_component_W,
Expand All @@ -387,50 +378,115 @@ def work(modelDir, inputDict):
#fill='tozeroy',
fillcolor='rgba(127,0,255,1)',
name='Home TESS Serving Load',
line=dict(color='rgba(127,0,255,1)', width=1),
line_shape=lineshape,
#stackgroup='one',
line=dict(color='rgba(0,0,0,0)'), #transparent line (to get around the Plotly default line)
#line_shape=lineshape,
stackgroup='one',
showlegend=showlegend))

fig.add_trace(go.Scatter(x=timestamps,
y = vbat_charge_component_W,
yaxis='y1',
#mode='none',
name='Additional load from Home TESS',
#fill='tozeroy',
line=dict(color='rgba(207,158,255,1)', width=1),
line_shape=lineshape,
#stackgroup='one',
showlegend=showlegend))

## Fossil Generator piece
if 'Generator' in reoptResults:
fig.add_trace(go.Scatter(x=timestamps,
y = generator_W,
yaxis='y1',
mode='none',
fill='tozeroy',
#fill='tozeroy',
fillcolor='rgba(153,0,0,1)',
line=dict(color='rgba(0,0,0,0)'), #transparent line (to get around the Plotly default line)
name='Fossil Generator Serving Load',
stackgroup='one',
showlegend=showlegend))

## Grid charging BESS piece
fig.add_trace(go.Scatter(x=timestamps,
y=grid_charging_BESS_W*-1., ## changed to negative sign to indicate charging behavior
yaxis='y1',
#mode='none',
name='Grid Charging Home BESS',
fill='tozeroy',
fillcolor='rgba(118,196,165,1)',
line=dict(color='rgba(0,0,0,0)'), #transparent line (to get around the Plotly default line)
line_shape=lineshape,
showlegend=showlegend))

## Grid charging TESS piece
fig.add_trace(go.Scatter(x=timestamps,
y = vbat_charge_component_W*-1., ## changed to negative sign to indicate charging behavior
yaxis='y1',
#mode='none',
name='Grid Charging Home TESS',
fill='tozeroy',
fillcolor='rgba(207,158,255,1)',
line=dict(color='rgba(0,0,0,0)'), #transparent line (to get around the Plotly default line)
line_shape=lineshape,
showlegend=showlegend))

## Plot layout
fig.update_layout(
xaxis=dict(title='Timestamp'),
yaxis=dict(title="Power (W)"),
yaxis2=dict(title='degrees Fahrenheit',
overlaying='y',
side='right'
),
legend=dict(
orientation='h',
yanchor='bottom',
y=1.02,
xanchor='right',
x=1
)
)

## NOTE: This opens a window that displays the correct figure with the appropriate patterns.
## For some reason, the slash-mark patterns are not showing up on the OMF page otherwise.
## Eventually we will delete this part.
#fig.show()
#outData['derOverviewHtml'] = fig.to_html(full_html=False)
fig.write_html(pJoin(modelDir, "Plot_DerServingLoadOverview.html"))

## Encode plot data as JSON for showing in the HTML
outData['derOverviewData'] = json.dumps(fig.data, cls=plotly.utils.PlotlyJSONEncoder)
outData['derOverviewLayout'] = json.dumps(fig.layout, cls=plotly.utils.PlotlyJSONEncoder)


## Impact to Demand plot ###################################################################################################################################################################
showlegend = True # either enable or disable the legend toggle in the plot
#lineshape = 'linear'
lineshape = 'hv'

fig = go.Figure()
demand_W = demand * 1000.
new_demand = demand_W + vbat_charge_component_W + grid_charging_BESS_W - BESS_W - vbat_discharge_component_W - generator_W

## Original load piece (minus any vbat or BESS charging aka 'new/additional loads')
fig.add_trace(go.Scatter(x=timestamps,
y = demand_W - BESS_W - vbat_discharge_component_W,
y = demand_W,
yaxis='y1',
mode='none',
name='Original Load',
name='Original Demand',
fill='tozeroy',
fillcolor='rgba(100,200,210,1)',
fillcolor='rgba(81,40,136,1)',
showlegend=showlegend))
## Make original load and its legend name hidden in the plot by default
fig.update_traces(legendgroup='Original Load', visible='legendonly', selector=dict(name='Original Load'))
#fig.update_traces(legendgroup='Original Demand', visible='legendonly', selector=dict(name='Original Demand'))

## New demand piece (minus any vbat or BESS charging aka 'new/additional loads')
fig.add_trace(go.Scatter(x=timestamps,
y = new_demand,
yaxis='y1',
mode='none',
name='New Demand',
fill='tozeroy',
fillcolor='rgba(235, 97, 35, 0.5)',
showlegend=showlegend))
## Make original load and its legend name hidden in the plot by default
#fig.update_traces(legendgroup='New Demand', visible='legendonly', selector=dict(name='New Demand'))

## Plot layout
fig.update_layout(
xaxis=dict(title='Timestamp'),
yaxis=dict(title="Power (W)"),
yaxis2=dict(title='degrees Celsius',
yaxis2=dict(title='degrees Fahrenheit',
overlaying='y',
side='right'
),
Expand All @@ -448,11 +504,19 @@ def work(modelDir, inputDict):
## Eventually we will delete this part.
#fig.show()
#outData['derOverviewHtml'] = fig.to_html(full_html=False)
fig.write_html(pJoin(modelDir, "Plot_DerServingLoadOverview.html"))
fig.write_html(pJoin(modelDir, "Plot_NewDemand.html"))

## Encode plot data as JSON for showing in the HTML
outData['derOverviewData'] = json.dumps(fig.data, cls=plotly.utils.PlotlyJSONEncoder)
outData['derOverviewLayout'] = json.dumps(fig.layout, cls=plotly.utils.PlotlyJSONEncoder)
outData['newDemandData'] = json.dumps(fig.data, cls=plotly.utils.PlotlyJSONEncoder)
outData['newDemandLayout'] = json.dumps(fig.layout, cls=plotly.utils.PlotlyJSONEncoder)









## Create Thermal Battery Power plot object ######################################################################################################################################################
if (inputDict['load_type'] != '0') and (int(inputDict['number_devices'])>0): ## If vbatDispatch is enabled:
Expand Down

0 comments on commit 8aaa496

Please sign in to comment.