Skip to content

Commit

Permalink
add FlexibilityNetwork output file
Browse files Browse the repository at this point in the history
  • Loading branch information
arght committed Jan 15, 2025
1 parent 4588e7d commit 020d9c2
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Change Log
=============

[4.18.2] - 2025-01-15
-----------------------
- [CHANGED] add FlexibilityNetwork output file

[4.18.1] - 2024-12-19
-----------------------
- [CHANGED] add area in MarginalIncrementalVariableCost, MarginalIncrementalGenerator and GenerationIncrementalEmission output files
Expand Down
24 changes: 16 additions & 8 deletions doc/rst/OutputResults.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1143,19 +1143,27 @@ Operational flexibility

File ``oT_Result_FlexibilityDemand.csv``

============ ========== ========== ========== ================================================
============ ========== ========== ========== =====================================================
Identifier Header Description
==================================== ========== ================================================
Period Scenario Load level Demand Demand variation w.r.t. its mean value [MW]
============ ========== ========== ========== ================================================
============ ========== ========== ========== =====================================================
Period Scenario Load level Area Demand per area variation w.r.t. its mean value [MW]
============ ========== ========== ========== =====================================================

File ``oT_Result_FlexibilityPNS.csv``

============ ========== ========== ========== ======================================================
============ ========== ========== ========== ===============================================================
Identifier Header Description
============ ========== ========== ========== ===============================================================
Period Scenario Load level Area Power not served per area variation w.r.t. its mean value [MW]
============ ========== ========== ========== ===============================================================

File ``oT_Result_FlexibilityNetwork.csv``

============ ========== ========== ========== ==================================================================================
Identifier Header Description
==================================== ========== ======================================================
Period Scenario Load level PNS Power not served variation w.r.t. its mean value [MW]
============ ========== ========== ========== ======================================================
============ ========== ========== ========== ==================================================================================
Period Scenario Load level Area Exporting flow from each area to other areas variation w.r.t. its mean value [MW]
============ ========== ========== ========== ==================================================================================

File ``oT_Result_FlexibilityTechnology.csv``

Expand Down
6 changes: 3 additions & 3 deletions doc/rst/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
author = 'Andres Ramos'

# The short X.Y version
version = 'version 4.18.1'
version = 'version 4.18.2'
# The full version, including alpha/beta/rc tags
release = ''

Expand Down Expand Up @@ -84,13 +84,13 @@
#
# html_sidebars = {}
html_theme = 'alabaster'
html_title = 'version 4.18.1'
html_title = 'version 4.18.2'
html_logo = '../img/openTEPES.png'
html_last_updated_fmt = ''
html_show_sphinx = False
html_theme_options = {
'analytics_id': 'UA-515200-2', # Provided by Google in your dashboard
'description': 'version 4.18.1',
'description': 'version 4.18.2',
'body_max_width' : 'none',
'page_width': 'auto',
'font_family': 'Georgia'
Expand Down
2 changes: 1 addition & 1 deletion openTEPES/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
>>> import openTEPES as oT
>>> oT.routine("9n", "C:\\Users\\UserName\\Documents\\GitHub\\openTEPES", "glpk")
"""
__version__ = "4.18.1"
__version__ = "4.18.2"

from .openTEPES_Main import main
from .openTEPES import *
Expand Down
6 changes: 3 additions & 3 deletions openTEPES/openTEPES.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Open Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES) - December 23, 2024
Open Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES) - January 15, 2024
"""

# import dill as pickle
Expand Down Expand Up @@ -39,8 +39,8 @@ def openTEPES_run(DirName, CaseName, SolverName, pIndOutputResults, pIndLogConso
idxDict['y' ] = 1

#%% model declaration
mTEPES = ConcreteModel('Open Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES) - Version 4.18.1 - December 23, 2024')
print( 'Open Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES) - Version 4.18.1 - December 23, 2024', file=open(f'{_path}/openTEPES_version_{CaseName}.log','w'))
mTEPES = ConcreteModel('Open Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES) - Version 4.18.2 - January 15, 2024')
print( 'Open Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES) - Version 4.18.2 - January 15, 2024', file=open(f'{_path}/openTEPES_version_{CaseName}.log','w'))

pIndOutputResults = [j for i,j in idxDict.items() if i == pIndOutputResults][0]
pIndLogConsole = [j for i,j in idxDict.items() if i == pIndLogConsole ][0]
Expand Down
2 changes: 1 addition & 1 deletion openTEPES/openTEPES_Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@
# import pkg_resources
from .openTEPES import openTEPES_run

print('\033[1;32mOpen Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES) - Version 4.18.1 - December 19, 2024\033[0m')
print('\033[1;32mOpen Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES) - Version 4.18.2 - January 15, 2024\033[0m')
print('\033[34m#### Academic research license - for non-commercial use only ####\033[0m \n')

parser = argparse.ArgumentParser(description='Introducing main parameters...')
Expand Down
35 changes: 23 additions & 12 deletions openTEPES/openTEPES_OutputResults.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Open Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES) - December 19, 2024
Open Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES) - January 15, 2025
"""

import time
Expand Down Expand Up @@ -366,10 +366,10 @@ def GenerationOperationResults(DirName, CaseName, OptModel, mTEPES, pIndTechnolo
StartTime = time.time()

# generators to area (n2a)
n2a = defaultdict(list)
for ar,nr in mTEPES.ar*mTEPES.nr:
if (ar,nr) in mTEPES.a2g:
n2a[ar].append(nr)
# n2a = defaultdict(list)
# for ar,nr in mTEPES.ar*mTEPES.nr:
# if (ar,nr) in mTEPES.a2g:
# n2a[ar].append(nr)
g2a = defaultdict(list)
for ar,g in mTEPES.a2g:
g2a[ar].append(g)
Expand Down Expand Up @@ -1451,6 +1451,12 @@ def FlexibilityResults(DirName, CaseName, OptModel, mTEPES):
for gt,g in mTEPES.t2g:
g2t[gt].append(g)

# nodes to area (d2a)
d2a = defaultdict(list)
for ar,nd in mTEPES.ar*mTEPES.nd:
if (nd,ar) in mTEPES.ndar:
d2a[ar].append(nd)

OutputToFile = pd.Series(data=[sum(OptModel.vTotalOutput[p,sc,n,g]() for g in g2t[gt] if (p,g) in mTEPES.pg) for p,sc,n,gt in mTEPES.psngt], index=pd.Index(mTEPES.psngt))
OutputToFile *= 1e3
TechnologyOutput = OutputToFile.loc[:,:,:,:]
Expand All @@ -1470,15 +1476,20 @@ def FlexibilityResults(DirName, CaseName, OptModel, mTEPES):
NetESSTechnologyOutput[p,sc,n,ot] = MeanESSTechnologyOutput[ot] - ESSTechnologyOutput[p,sc,n,ot]
NetESSTechnologyOutput.to_frame(name='MW').reset_index().pivot_table(index=['level_0','level_1','level_2'], columns='level_3', values='MW', aggfunc='sum').rename_axis(['Period', 'Scenario', 'LoadLevel'], axis=0).rename_axis([None], axis=1).to_csv(f'{_path}/oT_Result_FlexibilityTechnologyESS_{CaseName}.csv', sep=',')

MeanDemand = pd.Series(data=[sum(mTEPES.pDemandElec[p,sc,n,nd] for nd in mTEPES.nd) for p,sc,n in mTEPES.psn], index=pd.Index(mTEPES.psn)).mean()
OutputToFile = pd.Series(data=[sum(mTEPES.pDemandElec[p,sc,n,nd] for nd in mTEPES.nd) - MeanDemand for p,sc,n in mTEPES.psn], index=pd.Index(mTEPES.psn))
MeanDemand = pd.Series(data=[sum(mTEPES.pDemandElec[p,sc,n,nd] for nd in d2a[ar]) for p,sc,n,ar in mTEPES.psnar], index=pd.Index(mTEPES.psnar)).groupby(level=3).mean()
OutputToFile = pd.Series(data=[sum(mTEPES.pDemandElec[p,sc,n,nd] for nd in d2a[ar]) - MeanDemand[ar] for p,sc,n,ar in mTEPES.psnar], index=pd.Index(mTEPES.psnar))
OutputToFile *= 1e3
OutputToFile.to_frame(name='MW').reset_index().pivot_table(index=['level_0','level_1','level_2'], columns='level_3', values='MW', aggfunc='sum').rename_axis(['Period', 'Scenario', 'LoadLevel'], axis=0).rename_axis([None], axis=1).to_csv(f'{_path}/oT_Result_FlexibilityDemand_{CaseName}.csv', sep=',')

MeanENS = pd.Series(data=[sum(OptModel.vENS[p,sc,n,nd]() for nd in d2a[ar]) for p,sc,n,ar in mTEPES.psnar], index=pd.Index(mTEPES.psnar)).groupby(level=3).mean()
OutputToFile = pd.Series(data=[sum(OptModel.vENS[p,sc,n,nd]() for nd in d2a[ar]) - MeanENS[ar] for p,sc,n,ar in mTEPES.psnar], index=pd.Index(mTEPES.psnar))
OutputToFile *= 1e3
OutputToFile.to_frame(name='Demand').reset_index().pivot_table(index=['level_0','level_1','level_2']).rename_axis(['Period', 'Scenario', 'LoadLevel'], axis=0).rename_axis([None], axis=1).to_csv(f'{_path}/oT_Result_FlexibilityDemand_{CaseName}.csv', sep=',')
OutputToFile.to_frame(name='MW').reset_index().pivot_table(index=['level_0','level_1','level_2'], columns='level_3', values='MW', aggfunc='sum').rename_axis(['Period', 'Scenario', 'LoadLevel'], axis=0).rename_axis([None], axis=1).to_csv(f'{_path}/oT_Result_FlexibilityPNS_{CaseName}.csv', sep=',')

MeanENS = pd.Series(data=[sum(OptModel.vENS[p,sc,n,nd]() for nd in mTEPES.nd) for p,sc,n in mTEPES.psn], index=pd.Index(mTEPES.psn)).mean()
OutputToFile = pd.Series(data=[sum(OptModel.vENS[p,sc,n,nd]() for nd in mTEPES.nd) - MeanENS for p,sc,n in mTEPES.psn], index=pd.Index(mTEPES.psn))
MeanFlow = pd.Series(data=[sum(OptModel.vFlowElec[p,sc,n,nd,nf,cc]() for nd,nf,cc,af in mTEPES.la*mTEPES.ar if nd in d2a[ar] and nf in d2a[af] and af != ar) for p,sc,n,ar in mTEPES.psnar], index=pd.Index(mTEPES.psnar)).groupby(level=3).mean()
OutputToFile = pd.Series(data=[sum(OptModel.vFlowElec[p,sc,n,nd,nf,cc]() for nd,nf,cc,af in mTEPES.la*mTEPES.ar if nd in d2a[ar] and nf in d2a[af] and af != ar) - MeanFlow[ar] for p,sc,n,ar in mTEPES.psnar], index=pd.Index(mTEPES.psnar))
OutputToFile *= 1e3
OutputToFile.to_frame(name='PNS').reset_index().pivot_table(index=['level_0','level_1','level_2']).rename_axis(['Period', 'Scenario', 'LoadLevel'], axis=0).rename_axis([None], axis=1).to_csv(f'{_path}/oT_Result_FlexibilityPNS_{CaseName}.csv', sep=',')
OutputToFile.to_frame(name='MW').reset_index().pivot_table(index=['level_0','level_1','level_2'], columns='level_3', values='MW', aggfunc='sum').rename_axis(['Period', 'Scenario', 'LoadLevel'], axis=0).rename_axis([None], axis=1).to_csv(f'{_path}/oT_Result_FlexibilityNetwork_{CaseName}.csv', sep=',')

WritingResultsTime = time.time() - StartTime
StartTime = time.time()
Expand Down Expand Up @@ -1879,7 +1890,7 @@ def EconomicResults(DirName, CaseName, OptModel, mTEPES, pIndAreaOutput, pIndPlo
if (nd,re) in mTEPES.n2g:
r2n[nd].append(re)

# generators to area (g2a)
# generators to area (n2a)(g2a)
n2a = defaultdict(list)
for ar,nr in mTEPES.ar*mTEPES.nr:
if (ar,nr) in mTEPES.a2g:
Expand Down

0 comments on commit 020d9c2

Please sign in to comment.