In [2]:
%matplotlib inline
from __future__ import division
from ghgforcing import CO2, CH4
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
Define the time axis along which all emissions and calculations take place, from year 0 to 100. The time-step (tstep) is set to 0.01 years to improve the accuracy of calcuations.
In [3]:
tstep = 0.01
time = np.linspace(0, 100, 100/tstep+1)
In [4]:
co2_emission = np.zeros_like(time)
co2_emission[0] = 1
In [5]:
co2_forcing = CO2(co2_emission, time, kind='RF')
The CO2 and CH4 functions return values at 1-year timesteps - 101 values from year 0 to 100. The calculations are done at a default time-step of 0.01 years, but that level of detail seems unnecessary and burdensome for an output.
In [6]:
co2_forcing.size
Out[6]:
Having the outputs on an annual basis makes it really easy to plot.
In [7]:
plt.plot(co2_forcing)
plt.xlabel('Time', size=14)
plt.ylabel('$W \ m^{-2}$', size=14)
Out[7]:
In [9]:
ch4_emission = co2_emission.copy()
In [15]:
ch4_forcing_with = CH4(ch4_emission, time, kind='RF', cc_fb=True)
ch4_forcing_without = CH4(ch4_emission, time, kind='RF',
cc_fb=False, decay=False)
In [19]:
plt.plot(ch4_forcing_with, label = 'Fossil CH$_4$ with cc-fb')
plt.plot(ch4_forcing_without, label = 'Non-fossil CH$_4$ without cc-fb')
plt.xlabel('Time', size=14)
plt.ylabel('$W \ m^{-2}$', size=14)
plt.legend(fontsize=12)
Out[19]:
In [20]:
co2_cont = np.ones_like(time)
co2_cont_rf = CO2(co2_cont, time)
In [21]:
plt.plot(co2_cont_rf)
plt.xlabel('Time', size=14)
plt.ylabel('$W \ m^{-2}$', size=14)
Out[21]:
In [22]:
runs = 500
In [23]:
co2_cont_mc = CO2(co2_cont, time, kind='RF',
runs=runs, full_output=False)
In [24]:
co2_cont_mc.head()
Out[24]:
In [25]:
plt.plot(co2_cont_mc['mean'])
plt.fill_between(x=np.arange(0,101),
y1=co2_cont_mc['+sigma'],
y2=co2_cont_mc['-sigma'],
alpha=0.4)
plt.xlabel('Time', size=14)
plt.ylabel('$W \ m^{-2}$', size=14)
Out[25]:
In [26]:
co2_cont_mc, co2_cont_full = CO2(co2_cont, time, kind='RF',
runs=runs, full_output=True)
The co2_cont_mc results are the same as above
In [27]:
co2_cont_mc.head()
Out[27]:
I'm putting the co2_cont_full into a DataFrame just to make showing some of the results easier.
In [49]:
df = pd.DataFrame(co2_cont_full)
In [51]:
df.loc[:,:200].plot(legend=False, c='b', alpha=0.2)
plt.xlabel('Time', size=14)
plt.ylabel('$W \ m^{-2}$', size=14)
Out[51]:
In [ ]: