In [1]:
from coad.plexos2hdf5 import plexos2hdf5 
import numpy as np
import json
import networkx as nx
import tdsvis
import pandas as pd
import re

tdsvis.offline()
In [2]:
def json_to_networkx(filename):
    """ Converts a json file into nx graph + pos """
    data = json.loads(open(filename).read())
    

    g = nx.DiGraph()
    for node in data['nodes']:
        g.add_node(node['name'], data=node)
        
    for edge in data['edges']:
        g.add_edge(edge['source'], edge['target'])
        
    pos = { x['name']: (x['x'], x['y']) for x in data['pos']}
    
    return g, pos


g, pos = json_to_networkx("data/system/rts.json")
In [3]:
def read_rts(filename):
    df = pd.read_csv(filename)
    df = df.rename(columns={"Unnamed: 0": 'timestamp'})
    df = df.rename(columns={"x": 'timestamp'})
    df['timestamp'] = pd.to_datetime(df['timestamp'])
    df.set_index('timestamp', inplace=True)
    
    return df

Reading in PLEXOS solution data

In [4]:
RT_Solution_zip = "data/pcm/Model Interesting Week RT Solution/Model Interesting Week RT Solution.zip"
RT_Solution = plexos2hdf5(RT_Solution_zip)

DA_Solution_zip = "data/pcm/Model Interesting Week DA Solution/Model Interesting Week DA Solution.zip"
DA_Solution = plexos2hdf5(DA_Solution_zip)

Generating dataframes from HDF5 PLEXOS solution

Generators RT

In [5]:
generator_list=list(RT_Solution["/Generator"])
print generator_list
print len(generator_list)

index= pd.date_range('2024-07-14 00:00:00','2024-7-20 23:55:00', freq='5min')

df_commitment=pd.DataFrame(data=0,index=index,columns=[])
count=0
for i in generator_list:
    
    if str(i)[-1]=='d':
        
        df_commitment[str(i)]=list(RT_Solution["/Generator/" +str(i)+ "/Units Generating/period_0/phase_4"])
    else:
        if count<10:
            gen_name='gen_'+ '0'+ str(count)
            df_commitment[gen_name]=list(RT_Solution["/Generator/" +str(i)+ "/Units Generating/period_0/phase_4"])
        else:
            gen_name='gen_'+ str(count)
            df_commitment[gen_name]=list(RT_Solution["/Generator/" +str(i)+ "/Units Generating/period_0/phase_4"])
        count=count+1   


df_commitment=df_commitment['2024-07-14 00:00:00':'2024-7-14 23:55:00']

df_commitment.head()
[u'101_1', u'101_2', u'101_3', u'101_4', u'102_1', u'102_2', u'102_3', u'102_4', u'107_1', u'113_1', u'113_2', u'113_3', u'113_4', u'114_1', u'115_1', u'115_2', u'115_3', u'116_1', u'118_1', u'121_1', u'122_1', u'122_2', u'122_3', u'122_4', u'122_5', u'122_6', u'122_wind', u'123_1', u'123_2', u'123_3', u'123_4', u'123_5', u'201_1', u'201_2', u'201_3', u'201_4', u'202_1', u'202_2', u'202_3', u'202_4', u'207_1', u'207_2', u'213_1', u'213_2', u'213_3', u'214_1', u'215_1', u'215_2', u'215_3', u'215_4', u'215_5', u'216_1', u'218_1', u'221_1', u'222_1', u'222_2', u'222_3', u'222_4', u'222_5', u'222_6', u'223_1', u'223_2', u'223_3', u'223_4', u'223_5', u'223_6', u'301_1', u'301_2', u'301_3', u'301_4', u'302_1', u'302_2', u'302_3', u'302_4', u'303_wind', u'307_1', u'307_2', u'309_wind', u'313_1', u'314_1', u'315_1', u'315_2', u'315_3', u'315_4', u'315_5', u'315_6', u'315_7', u'315_8', u'316_1', u'317_wind', u'318_1', u'321_1', u'322_1', u'322_2', u'322_3', u'322_4', u'322_5', u'322_6', u'323_1', u'323_2']
100
Out[5]:
gen_00 gen_01 gen_02 gen_03 gen_04 gen_05 gen_06 gen_07 gen_08 gen_09 ... gen_86 gen_87 gen_88 gen_89 gen_90 gen_91 gen_92 gen_93 gen_94 gen_95
2024-07-14 00:00:00 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 ... 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0
2024-07-14 00:05:00 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 ... 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0
2024-07-14 00:10:00 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 ... 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0
2024-07-14 00:15:00 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 ... 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0
2024-07-14 00:20:00 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 ... 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0

5 rows × 100 columns

In [6]:
generator_list=list(RT_Solution["/Generator"])
index= pd.date_range('2024-07-14 00:00:00','2024-7-20 23:55:00', freq='5min')

df_real_power_gen=pd.DataFrame(data=0,index=index,columns=[])
count=0
for i in generator_list:
    
    if str(i)[-1]=='d':
        
        df_real_power_gen[str(i)]=list(RT_Solution["/Generator/" +str(i)+ "/Generation/period_0/phase_4"])
    else:
        if count<10:
            gen_name='gen_'+ '0'+ str(count)
            df_real_power_gen[gen_name]=list(RT_Solution["/Generator/" +str(i)+ "/Generation/period_0/phase_4"])
        else:
            gen_name='gen_'+ str(count)
            df_real_power_gen[gen_name]=list(RT_Solution["/Generator/" +str(i)+ "/Generation/period_0/phase_4"])
        count=count+1 
    
df_real_power_gen=df_real_power_gen['2024-07-14 00:00:00':'2024-7-14 23:55:00']

df_real_power_gen.head()
Out[6]:
gen_00 gen_01 gen_02 gen_03 gen_04 gen_05 gen_06 gen_07 gen_08 gen_09 ... gen_86 gen_87 gen_88 gen_89 gen_90 gen_91 gen_92 gen_93 gen_94 gen_95
2024-07-14 00:00:00 0.0 0.0 45.333333 45.333333 0.0 0.0 45.333333 45.343889 0.0 0.0 ... 0.0 0.0 26.7 26.7 26.7 26.7 0.0 0.0 0.0 0.0
2024-07-14 00:05:00 0.0 0.0 43.177111 45.333333 0.0 0.0 45.333333 45.333333 0.0 0.0 ... 0.0 0.0 31.6 31.6 31.6 31.6 0.0 0.0 0.0 0.0
2024-07-14 00:10:00 0.0 0.0 50.444444 50.444444 0.0 0.0 45.333333 45.333333 0.0 0.0 ... 0.0 0.0 31.6 31.6 31.6 31.6 0.0 0.0 0.0 0.0
2024-07-14 00:15:00 0.0 0.0 50.444444 50.444444 0.0 0.0 50.444444 45.333333 0.0 0.0 ... 0.0 0.0 32.9 32.9 32.9 32.9 0.0 0.0 0.0 0.0
2024-07-14 00:20:00 0.0 0.0 45.588889 45.333333 0.0 0.0 50.444444 45.333333 0.0 0.0 ... 0.0 0.0 33.5 33.5 33.5 33.5 0.0 0.0 0.0 0.0

5 rows × 100 columns

In [7]:
max_wind={'309_wind':159.999756,'317_wind':769.274353,'303_wind':847.488953,'122_wind':715.493347}

df_real_power_gen_norm=df_real_power_gen.copy()
gens_not_found=[]
for i in df_real_power_gen_norm.columns:
    try:
        rating=g.node[str(i)].get('data').get('Pmax')
        df_real_power_gen_norm[str(i)]=df_real_power_gen_norm[str(i)]/float(rating)
    except KeyError:
        #df_real_line_flow_norm=df_real_line_flow_norm.drop(str(i), 1)
        gens_not_found.append(i)
        rating=max_wind[str(i)]
        df_real_power_gen_norm[str(i)]=df_real_power_gen_norm[str(i)]/float(rating)
        
        
        
print  gens_not_found    
df_real_power_gen_norm.head()
['122_wind', '303_wind', '309_wind', '317_wind']
Out[7]:
gen_00 gen_01 gen_02 gen_03 gen_04 gen_05 gen_06 gen_07 gen_08 gen_09 ... gen_86 gen_87 gen_88 gen_89 gen_90 gen_91 gen_92 gen_93 gen_94 gen_95
2024-07-14 00:00:00 0.0 0.0 0.596491 0.596491 0.0 0.0 0.596491 0.596630 0.0 0.0 ... 0.0 0.0 0.534 0.534 0.534 0.534 0.0 0.0 0.0 0.0
2024-07-14 00:05:00 0.0 0.0 0.568120 0.596491 0.0 0.0 0.596491 0.596491 0.0 0.0 ... 0.0 0.0 0.632 0.632 0.632 0.632 0.0 0.0 0.0 0.0
2024-07-14 00:10:00 0.0 0.0 0.663743 0.663743 0.0 0.0 0.596491 0.596491 0.0 0.0 ... 0.0 0.0 0.632 0.632 0.632 0.632 0.0 0.0 0.0 0.0
2024-07-14 00:15:00 0.0 0.0 0.663743 0.663743 0.0 0.0 0.663743 0.596491 0.0 0.0 ... 0.0 0.0 0.658 0.658 0.658 0.658 0.0 0.0 0.0 0.0
2024-07-14 00:20:00 0.0 0.0 0.599854 0.596491 0.0 0.0 0.663743 0.596491 0.0 0.0 ... 0.0 0.0 0.670 0.670 0.670 0.670 0.0 0.0 0.0 0.0

5 rows × 100 columns

Generators DA

In [8]:
generator_list=list(DA_Solution["/Generator"])
index= pd.date_range('2024-07-14 00:00:00','2024-7-20 23:00:00', freq='H')

df_commitment_DA=pd.DataFrame(data=0,index=index,columns=[])
count=0
for i in generator_list:
    
    if str(i)[-1]=='d':
        
        df_commitment_DA[str(i)]=list(DA_Solution["/Generator/" +str(i)+ "/Units Generating/period_0/phase_4"])
    else:
        if count<10:
            gen_name='gen_'+ '0'+ str(count)
            df_commitment_DA[gen_name]=list(DA_Solution["/Generator/" +str(i)+ "/Units Generating/period_0/phase_4"])
        else:
            gen_name='gen_'+ str(count)
            df_commitment_DA[gen_name]=list(DA_Solution["/Generator/" +str(i)+ "/Units Generating/period_0/phase_4"])
        count=count+1   


#df_commitment=df_commitment['2024-07-14 00:00:00':'2024-7-15 00:00:00']

df_commitment_DA=df_commitment_DA.resample('5min').ffill()
df_commitment_DA=df_commitment_DA['2024-07-14 00:00:00':'2024-7-14 23:55:00']
df_commitment_DA.head()
Out[8]:
gen_00 gen_01 gen_02 gen_03 gen_04 gen_05 gen_06 gen_07 gen_08 gen_09 ... gen_86 gen_87 gen_88 gen_89 gen_90 gen_91 gen_92 gen_93 gen_94 gen_95
2024-07-14 00:00:00 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 ... 0.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0
2024-07-14 00:05:00 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 ... 0.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0
2024-07-14 00:10:00 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 ... 0.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0
2024-07-14 00:15:00 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 ... 0.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0
2024-07-14 00:20:00 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 ... 0.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0

5 rows × 100 columns

In [9]:
generator_list=list(DA_Solution["/Generator"])
index= pd.date_range('2024-07-14 00:00:00','2024-7-20 23:00:00', freq='H')

df_real_power_gen_DA=pd.DataFrame(data=0,index=index,columns=[])
count=0
for i in generator_list:
    
    if str(i)[-1]=='d':
        
        df_real_power_gen_DA[str(i)]=list(DA_Solution["/Generator/" +str(i)+ "/Generation/period_0/phase_4"])
    else:
        if count<10:
            gen_name='gen_'+ '0'+ str(count)
            df_real_power_gen_DA[gen_name]=list(DA_Solution["/Generator/" +str(i)+ "/Generation/period_0/phase_4"])
        else:
            gen_name='gen_'+ str(count)
            df_real_power_gen_DA[gen_name]=list(DA_Solution["/Generator/" +str(i)+ "/Generation/period_0/phase_4"])
        count=count+1 

        

df_real_power_gen_DA=df_real_power_gen_DA.resample('5min').ffill()
df_real_power_gen_DA=df_real_power_gen_DA['2024-07-14 00:00:00':'2024-7-14 23:55:00']

df_real_power_gen_DA.head()
Out[9]:
gen_00 gen_01 gen_02 gen_03 gen_04 gen_05 gen_06 gen_07 gen_08 gen_09 ... gen_86 gen_87 gen_88 gen_89 gen_90 gen_91 gen_92 gen_93 gen_94 gen_95
2024-07-14 00:00:00 0.0 0.0 60.666667 60.666667 0.0 0.0 60.666667 60.666667 0.0 0.0 ... 0.0 248.133333 26.7 26.7 26.7 26.7 0.0 0.0 0.0 0.0
2024-07-14 00:05:00 0.0 0.0 60.666667 60.666667 0.0 0.0 60.666667 60.666667 0.0 0.0 ... 0.0 248.133333 26.7 26.7 26.7 26.7 0.0 0.0 0.0 0.0
2024-07-14 00:10:00 0.0 0.0 60.666667 60.666667 0.0 0.0 60.666667 60.666667 0.0 0.0 ... 0.0 248.133333 26.7 26.7 26.7 26.7 0.0 0.0 0.0 0.0
2024-07-14 00:15:00 0.0 0.0 60.666667 60.666667 0.0 0.0 60.666667 60.666667 0.0 0.0 ... 0.0 248.133333 26.7 26.7 26.7 26.7 0.0 0.0 0.0 0.0
2024-07-14 00:20:00 0.0 0.0 60.666667 60.666667 0.0 0.0 60.666667 60.666667 0.0 0.0 ... 0.0 248.133333 26.7 26.7 26.7 26.7 0.0 0.0 0.0 0.0

5 rows × 100 columns

In [10]:
max_wind={'309_wind':159.999756,'317_wind':769.274353,'303_wind':847.488953,'122_wind':715.493347}

df_real_power_gen_norm_DA=df_real_power_gen_DA.copy()
gens_not_found=[]
for i in df_real_power_gen_norm_DA.columns:
    try:
        rating=g.node[str(i)].get('data').get('Pmax')
        df_real_power_gen_norm_DA[str(i)]=df_real_power_gen_norm_DA[str(i)]/float(rating)
    except KeyError:
        #df_real_line_flow_norm=df_real_line_flow_norm.drop(str(i), 1)
        gens_not_found.append(i)
        rating=max_wind[str(i)]
        df_real_power_gen_norm_DA[str(i)]=df_real_power_gen_norm_DA[str(i)]/float(rating)
        
        
        
print  gens_not_found    
df_real_power_gen_norm_DA.head()
['122_wind', '303_wind', '309_wind', '317_wind']
Out[10]:
gen_00 gen_01 gen_02 gen_03 gen_04 gen_05 gen_06 gen_07 gen_08 gen_09 ... gen_86 gen_87 gen_88 gen_89 gen_90 gen_91 gen_92 gen_93 gen_94 gen_95
2024-07-14 00:00:00 0.0 0.0 0.798246 0.798246 0.0 0.0 0.798246 0.798246 0.0 0.0 ... 0.0 0.698967 0.534 0.534 0.534 0.534 0.0 0.0 0.0 0.0
2024-07-14 00:05:00 0.0 0.0 0.798246 0.798246 0.0 0.0 0.798246 0.798246 0.0 0.0 ... 0.0 0.698967 0.534 0.534 0.534 0.534 0.0 0.0 0.0 0.0
2024-07-14 00:10:00 0.0 0.0 0.798246 0.798246 0.0 0.0 0.798246 0.798246 0.0 0.0 ... 0.0 0.698967 0.534 0.534 0.534 0.534 0.0 0.0 0.0 0.0
2024-07-14 00:15:00 0.0 0.0 0.798246 0.798246 0.0 0.0 0.798246 0.798246 0.0 0.0 ... 0.0 0.698967 0.534 0.534 0.534 0.534 0.0 0.0 0.0 0.0
2024-07-14 00:20:00 0.0 0.0 0.798246 0.798246 0.0 0.0 0.798246 0.798246 0.0 0.0 ... 0.0 0.698967 0.534 0.534 0.534 0.534 0.0 0.0 0.0 0.0

5 rows × 100 columns

Lines RT

In [19]:
line_list=list(RT_Solution["/Line"])
index=pd.date_range('2024-07-14 00:00:00','2024-7-20 23:55:00', freq='5min')

df_real_line_flow=pd.DataFrame(data=0,index=index,columns=[])

for i in line_list:
    if str(i)[-1]==2:
        continue 
        
    else:
        duplicate=str(i)[:-1] + '2'
        line_name='branch_' + str(i)[:-2]
        if duplicate in line_list:
            line_1=np.array(list(RT_Solution["/Line/"+str(i)+"/Flow/period_0/phase_4"]))
            line_2=np.array(list(RT_Solution["/Line/"+duplicate+"/Flow/period_0/phase_4"]))
            df_real_line_flow[line_name]=line_1+line_2
        else:
            df_real_line_flow[line_name]=list(RT_Solution["/Line/"+str(i)+"/Flow/period_0/phase_4"])
            
df_real_line_flow=df_real_line_flow['2024-07-14 00:00:00':'2024-7-14 23:55:00']

df_real_line_flow.head()
Out[19]:
branch_101_102 branch_101_103 branch_101_105 branch_102_104 branch_102_106 branch_103_109 branch_103_124 branch_104_109 branch_105_110 branch_106_110 ... branch_316_319 branch_317_318 branch_317_322 branch_318_223 branch_318_321 branch_319_320 branch_320_323 branch_321_322 branch_323_325 branch_325_121
2024-07-14 00:00:00 16.271712 -23.918739 47.292220 25.862161 35.261931 63.975334 -172.929862 -9.096996 13.750325 -28.987333 ... 82.217960 263.780882 -13.855716 41.352152 90.186836 10.338732 -40.492988 -92.944284 -368.552152 -368.552152
2024-07-14 00:05:00 15.491096 -25.014726 46.338075 25.023851 34.703245 63.795575 -174.970302 -10.397482 12.352742 -30.395422 ... 83.550264 257.466701 -22.798121 45.757682 80.507019 12.236264 -38.195736 -103.601879 -362.057682 -362.057682
2024-07-14 00:10:00 20.590230 -21.631027 49.559159 27.546209 36.674196 62.888229 -171.803467 -8.337300 15.130387 -29.273874 ... 82.978601 249.616690 -23.420410 39.102097 80.679645 12.407653 -37.498873 -102.979590 -358.102097 -358.102097
2024-07-14 00:15:00 17.874433 -20.184000 50.987087 28.969710 37.788957 62.861559 -170.064506 -6.804746 16.662947 -27.958692 ... 78.780764 240.881115 -26.338156 33.113231 78.458727 8.495606 -41.208815 -105.261844 -362.913231 -362.913231
2024-07-14 00:20:00 13.483744 -22.448538 47.857543 26.653025 35.878322 61.972110 -171.136438 -8.996800 13.652981 -29.640275 ... 83.225967 234.010527 -28.562902 36.410048 68.805427 13.220248 -36.286559 -105.437098 -354.310048 -354.310048

5 rows × 109 columns

In [12]:
df_real_line_flow_norm=df_real_line_flow.copy()
branches_not_found=[]
for i in df_real_line_flow_norm.columns:
    try:
        rating=g.node[str(i)].get('data').get('rateA')
        df_real_line_flow_norm[str(i)]=df_real_line_flow_norm[str(i)]/float(rating)
    except KeyError:
        df_real_line_flow_norm=df_real_line_flow_norm.drop(str(i), 1)
        branches_not_found.append(i)
        
print  branches_not_found    
df_real_line_flow_norm.head() 
['branch_113_316']
Out[12]:
branch_101_102 branch_101_103 branch_101_105 branch_102_104 branch_102_106 branch_103_109 branch_103_124 branch_104_109 branch_105_110 branch_106_110 ... branch_316_319 branch_317_318 branch_317_322 branch_318_223 branch_318_321 branch_319_320 branch_320_323 branch_321_322 branch_323_325 branch_325_121
2024-07-14 00:00:00 0.092981 -0.136679 0.270241 0.147784 0.201497 0.365573 -0.432325 -0.051983 0.078573 -0.165642 ... 0.164436 0.527562 -0.027711 0.082704 0.180374 0.020677 -0.080986 -0.185889 -0.510460 -0.737104
2024-07-14 00:05:00 0.088521 -0.142941 0.264789 0.142993 0.198304 0.364546 -0.437426 -0.059414 0.070587 -0.173688 ... 0.167101 0.514933 -0.045596 0.091515 0.161014 0.024473 -0.076391 -0.207204 -0.501465 -0.724115
2024-07-14 00:10:00 0.117658 -0.123606 0.283195 0.157407 0.209567 0.359361 -0.429509 -0.047642 0.086459 -0.167279 ... 0.165957 0.499233 -0.046841 0.078204 0.161359 0.024815 -0.074998 -0.205959 -0.495986 -0.716204
2024-07-14 00:15:00 0.102140 -0.115337 0.291355 0.165541 0.215937 0.359209 -0.425161 -0.038884 0.095217 -0.159764 ... 0.157562 0.481762 -0.052676 0.066226 0.156917 0.016991 -0.082418 -0.210524 -0.502650 -0.725826
2024-07-14 00:20:00 0.077050 -0.128277 0.273472 0.152303 0.205019 0.354126 -0.427841 -0.051410 0.078017 -0.169373 ... 0.166452 0.468021 -0.057126 0.072820 0.137611 0.026440 -0.072573 -0.210874 -0.490734 -0.708620

5 rows × 108 columns

Lines DA

In [13]:
line_list=list(DA_Solution["/Line"])
index=pd.date_range('2024-07-14 00:00:00','2024-7-20 23:00:00', freq='H')

df_real_line_flow_DA=pd.DataFrame(data=0,index=index,columns=[])

for i in line_list:
    if str(i)[-1]==2:
        continue 
        
    else:
        duplicate=str(i)[:-1] + '2'
        line_name='branch_' + str(i)[:-2]
        if duplicate in line_list:
            line_1=np.array(list(DA_Solution["/Line/"+str(i)+"/Flow/period_0/phase_4"]))
            line_2=np.array(list(DA_Solution["/Line/"+duplicate+"/Flow/period_0/phase_4"]))
            df_real_line_flow_DA[line_name]=line_1+line_2
        else:
            df_real_line_flow_DA[line_name]=list(DA_Solution["/Line/"+str(i)+"/Flow/period_0/phase_4"])

df_real_line_flow_DA=df_real_line_flow_DA.resample('5min').ffill()
df_real_line_flow_DA=df_real_line_flow_DA['2024-07-14 00:00:00':'2024-7-14 23:55:00']

df_real_line_flow_DA.head()
Out[13]:
branch_101_102 branch_101_103 branch_101_105 branch_102_104 branch_102_106 branch_103_109 branch_103_124 branch_104_109 branch_105_110 branch_106_110 ... branch_316_319 branch_317_318 branch_317_322 branch_318_223 branch_318_321 branch_319_320 branch_320_323 branch_321_322 branch_323_325 branch_325_121
2024-07-14 00:00:00 16.009729 -18.227008 60.103454 35.390101 44.968014 64.90715 -188.879421 -8.082951 18.392823 -34.928407 ... 174.016907 263.822418 -23.714913 154.659589 -41.061066 92.363679 34.61996 -83.085087 -251.326256 -251.326256
2024-07-14 00:05:00 16.009729 -18.227008 60.103454 35.390101 44.968014 64.90715 -188.879421 -8.082951 18.392823 -34.928407 ... 174.016907 263.822418 -23.714913 154.659589 -41.061066 92.363679 34.61996 -83.085087 -251.326256 -251.326256
2024-07-14 00:10:00 16.009729 -18.227008 60.103454 35.390101 44.968014 64.90715 -188.879421 -8.082951 18.392823 -34.928407 ... 174.016907 263.822418 -23.714913 154.659589 -41.061066 92.363679 34.61996 -83.085087 -251.326256 -251.326256
2024-07-14 00:15:00 16.009729 -18.227008 60.103454 35.390101 44.968014 64.90715 -188.879421 -8.082951 18.392823 -34.928407 ... 174.016907 263.822418 -23.714913 154.659589 -41.061066 92.363679 34.61996 -83.085087 -251.326256 -251.326256
2024-07-14 00:20:00 16.009729 -18.227008 60.103454 35.390101 44.968014 64.90715 -188.879421 -8.082951 18.392823 -34.928407 ... 174.016907 263.822418 -23.714913 154.659589 -41.061066 92.363679 34.61996 -83.085087 -251.326256 -251.326256

5 rows × 109 columns

In [14]:
df_real_line_flow_norm_DA=df_real_line_flow_DA.copy()
branches_not_found=[]
for i in df_real_line_flow_norm_DA.columns:
    try:
        rating=g.node[str(i)].get('data').get('rateA')
        df_real_line_flow_norm_DA[str(i)]=df_real_line_flow_norm_DA[str(i)]/float(rating)
    except KeyError:
        df_real_line_flow_norm_DA=df_real_line_flow_norm_DA.drop(str(i), 1)
        branches_not_found.append(i)
        
print  branches_not_found    
df_real_line_flow_norm_DA.head() 
['branch_113_316']
Out[14]:
branch_101_102 branch_101_103 branch_101_105 branch_102_104 branch_102_106 branch_103_109 branch_103_124 branch_104_109 branch_105_110 branch_106_110 ... branch_316_319 branch_317_318 branch_317_322 branch_318_223 branch_318_321 branch_319_320 branch_320_323 branch_321_322 branch_323_325 branch_325_121
2024-07-14 00:00:00 0.091484 -0.104154 0.343448 0.202229 0.25696 0.370898 -0.472199 -0.046188 0.105102 -0.199591 ... 0.348034 0.527645 -0.04743 0.309319 -0.082122 0.184727 0.06924 -0.16617 -0.348097 -0.502653
2024-07-14 00:05:00 0.091484 -0.104154 0.343448 0.202229 0.25696 0.370898 -0.472199 -0.046188 0.105102 -0.199591 ... 0.348034 0.527645 -0.04743 0.309319 -0.082122 0.184727 0.06924 -0.16617 -0.348097 -0.502653
2024-07-14 00:10:00 0.091484 -0.104154 0.343448 0.202229 0.25696 0.370898 -0.472199 -0.046188 0.105102 -0.199591 ... 0.348034 0.527645 -0.04743 0.309319 -0.082122 0.184727 0.06924 -0.16617 -0.348097 -0.502653
2024-07-14 00:15:00 0.091484 -0.104154 0.343448 0.202229 0.25696 0.370898 -0.472199 -0.046188 0.105102 -0.199591 ... 0.348034 0.527645 -0.04743 0.309319 -0.082122 0.184727 0.06924 -0.16617 -0.348097 -0.502653
2024-07-14 00:20:00 0.091484 -0.104154 0.343448 0.202229 0.25696 0.370898 -0.472199 -0.046188 0.105102 -0.199591 ... 0.348034 0.527645 -0.04743 0.309319 -0.082122 0.184727 0.06924 -0.16617 -0.348097 -0.502653

5 rows × 108 columns

Busses

In [15]:
bus_list=list(RT_Solution["/Node"])

    
index=pd.date_range('2024-07-14 00:00:00','2024-7-20 23:55:00', freq='5min')

df_bus_voltage=pd.DataFrame(data=0,index=index,columns=bus_list)

for i in bus_list:
   
    df_bus_voltage[str(i)]=list(RT_Solution["/Node/"+str(i)+"/Voltage/period_0/phase_4"])
    df_bus_voltage=df_bus_voltage.rename(columns={str(i):'bus_'+ str(i)})
    
df_bus_voltage=df_bus_voltage['2024-07-14 00:00:00':'2024-7-14 23:55:00']

df_bus_voltage.head()
Out[15]:
bus_101 bus_102 bus_103 bus_104 bus_105 bus_106 bus_107 bus_108 bus_109 bus_110 ... bus_316 bus_317 bus_318 bus_319 bus_320 bus_321 bus_322 bus_323 bus_324 bus_325
2024-07-14 00:00:00 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 ... 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0
2024-07-14 00:05:00 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 ... 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0
2024-07-14 00:10:00 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 ... 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0
2024-07-14 00:15:00 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 ... 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0
2024-07-14 00:20:00 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 138.0 ... 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0 230.0

5 rows × 73 columns

In [16]:
bus_list=list(RT_Solution["/Node"])
index=pd.date_range('2024-07-14 00:00:00','2024-7-20 23:55:00', freq='5min')

df_bus_real_demand=pd.DataFrame(data=0,index=index,columns=bus_list)

for i in bus_list:
   
    df_bus_real_demand[str(i)]=list(RT_Solution["/Node/"+str(i)+"/Load/period_0/phase_4"])
    df_bus_real_demand=df_bus_real_demand.rename(columns={str(i):'bus_'+ str(i)})
    
df_bus_real_demand=df_bus_real_demand['2024-07-14 00:00:00':'2024-7-14 23:55:00']

df_bus_real_demand.head()
Out[16]:
bus_101 bus_102 bus_103 bus_104 bus_105 bus_106 bus_107 bus_108 bus_109 bus_110 ... bus_316 bus_317 bus_318 bus_319 bus_320 bus_321 bus_322 bus_323 bus_324 bus_325
2024-07-14 00:00:00 51.021474 45.824842 85.035789 34.959158 33.541895 64.249263 59.052632 80.784 82.673684 92.122105 ... 39.712281 0.0 132.241895 71.879228 50.831719 0.0 0.0 0.0 0.0 0.0
2024-07-14 00:05:00 51.696000 46.430667 86.160000 35.421333 33.985333 65.098667 59.833333 81.852 83.766667 93.340000 ... 39.400000 0.0 131.202000 71.314000 50.432000 0.0 0.0 0.0 0.0 0.0
2024-07-14 00:10:00 52.370526 47.036491 87.284211 35.883509 34.428772 65.948070 60.614035 82.920 84.859649 94.557895 ... 38.989474 0.0 129.834947 70.570947 49.906526 0.0 0.0 0.0 0.0 0.0
2024-07-14 00:15:00 52.211368 46.893544 87.018947 35.774456 34.324140 65.747649 60.429825 82.668 84.601754 94.270526 ... 38.831579 0.0 129.309158 70.285158 49.704421 0.0 0.0 0.0 0.0 0.0
2024-07-14 00:20:00 52.029474 46.730175 86.715789 35.649825 34.204561 65.518596 60.219298 82.380 84.307018 93.942105 ... 38.677193 0.0 128.795053 70.005719 49.506807 0.0 0.0 0.0 0.0 0.0

5 rows × 73 columns

Visualizing dataframes with TDSVIS

RTS System

In [17]:
network = tdsvis.network(g, pos=pos, table=True, color='power flow', scale=2, width=400,
                         legend=False, node_size={'bus': 2, 'line': 0.25, 'gen': 0.5})

va_line = tdsvis.line(df_bus_real_demand, color='lightgrey', 
                   scale=1.5, xlab="Time", ylab='Real Power Demand',
                   margin={'top': 10, 'left': 60, 'right': 10, 'bottom': 50})

vb_line = tdsvis.line(df_real_power_gen, color='lightgrey', 
                   scale=1.5, xlab="Time", ylab='Real Power Generation',
                   margin={'top': 10, 'left': 60, 'right': 10, 'bottom': 50})

vc_line = tdsvis.line(df_real_line_flow, color='lightgrey', 
                   scale=1.5, xlab="Time", ylab='Real Power Flow', emit='power flow',
                   margin={'top': 10, 'left': 60, 'right': 10, 'bottom': 50})

#tdsvis.plot([network, vm_line, va_line], emit=True, title="Bus data as a function of time")
tdsvis.plot([network, va_line,vb_line,vc_line], emit=True, title="RTS System Over Time")

RTS System Over of Time

keyvalue
Real Power DemandTimeJul 1403 AM06 AM09 AM12 PM03 PM06 PM09 PMMon 15020406080100120140160180200220240260280300
Real Power GenerationTimeJul 1403 AM06 AM09 AM12 PM03 PM06 PM09 PMMon 15050100150200250300350400450500550600650
Real Power FlowTimeJul 1403 AM06 AM09 AM12 PM03 PM06 PM09 PMMon 15-500-400-300-200-1000100200300400

Normalized RTS Sytem

In [26]:
network = tdsvis.network(g, pos=pos, table=True, color='power flow', scale=2, width=400,
                         legend=False, node_size={'bus': 2, 'line': 0.25, 'gen': 0.5})

va_line = tdsvis.line(df_bus_real_demand, color='lightgrey', 
                   scale=1.5, xlab="Time", ylab='Real Power Demand',
                   margin={'top': 10, 'left': 60, 'right': 10, 'bottom': 50})

vb_line = tdsvis.line(df_real_power_gen_norm, color='lightgrey', 
                   scale=1.5, xlab="Time", ylab='Real Power Generation',
                   margin={'top': 10, 'left': 60, 'right': 10, 'bottom': 50})

vc_line = tdsvis.line(df_real_line_flow_norm, color='lightgrey', 
                   scale=1.5, xlab="Time", ylab='Real Power Flow', emit='power flow',
                   margin={'top': 10, 'left': 60, 'right': 10, 'bottom': 50})

#tdsvis.plot([network, vm_line, va_line], emit=True, title="Bus data as a function of time")
tdsvis.plot([network, va_line,vb_line,vc_line], emit=True, title="Normalized RTS System Over Time")

Normalized RTS System Over Time

keyvalue
Real Power DemandTimeJul 1403 AM06 AM09 AM12 PM03 PM06 PM09 PMMon 15020406080100120140160180200220240260280300
Real Power GenerationTimeJul 1403 AM06 AM09 AM12 PM03 PM06 PM09 PMMon 150.00.10.20.30.40.50.60.70.80.91.0
Real Power FlowTimeJul 1403 AM06 AM09 AM12 PM03 PM06 PM09 PMMon 15-1.0-0.8-0.6-0.4-0.20.00.20.40.60.81.0

RTS System Generation

In [34]:
network = tdsvis.network(g, pos=pos, table=True, color='power generation', scale=2, width=400,
                         legend=False, node_size={'bus': 2, 'line': 0.25, 'gen': 0.5})

va_line = tdsvis.line(df_real_power_gen, color='lightgrey', 
                   scale=1.5, xlab="Time", ylab='Real Power Generation', emit='power generation',
                   margin={'top': 10, 'left': 60, 'right': 10, 'bottom': 50})
vs_line = tdsvis.line(df_real_power_gen_DA, color='lightgrey', 
                   scale=1.5, xlab="Time", ylab='DA Real Power Generation',
                   margin={'top': 10, 'left': 60, 'right': 10, 'bottom': 50})

vm_line = tdsvis.line(df_commitment_DA, color='lightgrey', 
                   scale=1.5, xlab="Time", ylab='DA Generator Commitment', 
                   margin={'top': 10, 'left': 60, 'right': 10, 'bottom': 50})

tdsvis.plot([network, vm_line, vs_line,va_line], emit=True, title="Generator Data Over Time")

Generator Data Over Time

keyvalue
DA Generator CommitmentTimeJul 1403 AM06 AM09 AM12 PM03 PM06 PM09 PMMon 150.00.10.20.30.40.50.60.70.80.91.0
DA Real Power GenerationTimeJul 1403 AM06 AM09 AM12 PM03 PM06 PM09 PMMon 15050100150200250300350400450500550600650
Real Power GenerationTimeJul 1403 AM06 AM09 AM12 PM03 PM06 PM09 PMMon 15050100150200250300350400450500550600650