In [1]:
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import cymetric as cym

In [2]:
years = 250
startyear = 1964
tickstep = 25  # years
with cym.dbopen('{0}yr.h5'.format(years)) as db:
    evaler = cym.Evaluator(db)
    agents = evaler.eval('Agents')
    timepower = evaler.eval('TimeSeriesPower')
    blrx = evaler.eval('AgentState_Brightlite_ReactorFacilityInfo')

In [3]:
df = pd.merge(agents[['SimId', 'AgentId', 'Prototype']], timepower, on=['SimId', 'AgentId'])

In [4]:
totpower = df[['Prototype', 'Time', 'Value']].groupby(['Prototype', 'Time']).sum()
prototypes = totpower.index.levels[0]
x = totpower.loc[prototypes[0]]
x.rename(columns={'Value': prototypes[0]}, inplace=True)
x.reset_index(inplace=True)
for ptype in prototypes[1:]:
    col = totpower.loc[ptype]
    col.rename(columns={'Value': ptype}, inplace=True)
    col.reset_index(inplace=True)
    x = pd.merge(x, col, on=['Time'], how='outer')
x.fillna(0.0, inplace=True)
x.sort(columns=['Time'], inplace=True)
x.plot(x='Time', kind='area', figsize=(10, 6))
plt.xticks(range(0, years*12 + 1, tickstep*12), range(startyear, startyear+years+1, tickstep))
plt.ylabel('Generated Power [MWe]')


Out[4]:
<matplotlib.text.Text at 0x7effadcab110>

In [5]:
lwrfr = agents[['AgentId', 'Prototype', 'EnterTime', 'ExitTime']]
mask = lwrfr['Prototype'] == 'FR'
mask = mask | (lwrfr['Prototype'] == 'LWR')
lwrfr = lwrfr[mask]
onoff = pd.merge(lwrfr, blrx[['AgentId', 'generated_power']], on=['AgentId'], how='outer')
onoff.dropna(subset=['Prototype'], inplace=True)
# hack for blrx table
onoff['generated_power'][onoff['generated_power'].isnull() & (onoff['Prototype'] == 'LWR')] = 1000
onoff['generated_power'][onoff['generated_power'].isnull() & (onoff['Prototype'] == 'FR')] = 400

In [6]:
on = onoff[['Prototype', 'EnterTime', 'generated_power']]
#on

In [7]:
totpower = on.groupby(['Prototype', 'EnterTime']).sum()
prototypes = totpower.index.levels[0]
x = totpower.loc[prototypes[0]]
x.rename(columns={'generated_power': prototypes[0]}, inplace=True)
x.reset_index(inplace=True)
for ptype in prototypes[1:]:
    col = totpower.loc[ptype]
    col.rename(columns={'generated_power': ptype}, inplace=True)
    col.reset_index(inplace=True)
    x = pd.merge(x, col, on=['EnterTime'], how='outer')
x.fillna(0.0, inplace=True)
x.sort(columns=['EnterTime'], inplace=True)
x = pd.merge(x, pd.DataFrame({'EnterTime': range(0, years*12 + 1)}), on=['EnterTime'], how='outer')
x.fillna(0.0, inplace=True)
x.sort(columns=['EnterTime'], inplace=True)
x.plot(x='EnterTime', kind='bar', figsize=(18, 6), ylim=(0, 10000), width=15)
plt.xticks(range(0, years*12 + 1, tickstep*12), range(startyear, startyear+years+1, tickstep))
plt.ylabel('Capacity Started [MWe]')


Out[7]:
<matplotlib.text.Text at 0x7effadac35d0>

In [8]:
off = onoff[['Prototype', 'ExitTime', 'generated_power']]

In [9]:
totpower = off.groupby(['Prototype', 'ExitTime']).sum()
prototypes = totpower.index.levels[0]
x = totpower.loc[prototypes[0]]
x.rename(columns={'generated_power': prototypes[0]}, inplace=True)
x.reset_index(inplace=True)
for ptype in prototypes[1:]:
    col = totpower.loc[ptype]
    col.rename(columns={'generated_power': ptype}, inplace=True)
    col.reset_index(inplace=True)
    x = pd.merge(x, col, on=['ExitTime'], how='outer')
x.fillna(0.0, inplace=True)
x.sort(columns=['ExitTime'], inplace=True)
x = pd.merge(x, pd.DataFrame({'ExitTime': range(0, (years+44)*12 + 1)}), on=['ExitTime'], how='outer')
x.fillna(0.0, inplace=True)
x.sort(columns=['ExitTime'], inplace=True)
x.plot(x='ExitTime', kind='bar', figsize=(18, 6), ylim=(0, 10000), width=15)
plt.xticks(range(0, (years+44)*12+1, tickstep*12), range(startyear, startyear+years+1+44, tickstep))
plt.ylabel('Capacity Decommissioned [MWe]')


Out[9]:
<matplotlib.text.Text at 0x7effa4222e50>

In [9]:


In [9]: