In this document the basic use of climlab's preconfigured EBM class is shown.
Contents are how to
In [1]:
from __future__ import division, print_function
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import climlab
from climlab import constants as const
The regular path for the EBM class is climlab.model.ebm.EBM
but it can also be accessed through climlab.EBM
An EBM model instance is created through
In [2]:
# model creation
ebm_model = climlab.EBM()
By default many parameters are set during initialization:
num_lat=90, S0=const.S0, A=210., B=2., D=0.55, water_depth=10., Tf=-10, a0=0.3, a2=0.078, ai=0.62, timestep=const.seconds_per_year/90., T0=12., T2=-40
For further details see the climlab documentation.
Many of the input parameters are stored in the following dictionary:
In [3]:
# print model parameters
ebm_model.param
Out[3]:
The model consists of one state variable (surface temperature) and a couple of defined subprocesses.
In [4]:
# print model states and suprocesses
print(ebm_model)
The subprocesses are stored in a dictionary and can be accessed through
In [5]:
# access model subprocesses
ebm_model.subprocess.keys()
Out[5]:
So to access the time type of the Longwave Radiation subprocess for example, type:
In [6]:
# access specific subprocess through dictionary
ebm_model.subprocess['LW'].time_type
Out[6]:
In [7]:
# For interactive convenience, you can also use attribute access for the same thing:
ebm_model.subprocess.LW.time_type
Out[7]:
The model time dictionary shows information about all the time related content and quantities.
In [8]:
# accessing the model time dictionary
ebm_model.time
Out[8]:
To integrate the model forward in time different methods are availible:
In [9]:
# integrate model for a single timestep
ebm_model.step_forward()
The model time step has increased from 0 to 1:
In [10]:
ebm_model.time['steps']
Out[10]:
In [11]:
# integrate model for a 50 days
ebm_model.integrate_days(50.)
In [12]:
# integrate model for two years
ebm_model.integrate_years(1.)
In [13]:
# integrate model until solution converges
ebm_model.integrate_converge()
A couple of interesting model variables are stored in a dictionary named diagnostics
. It has following entries:
In [14]:
ebm_model.diagnostics.keys()
Out[14]:
They can be accessed in two ways:
ebm_model.diagnostics['ASR']
ebm_model.ASR
In [15]:
ebm_model.icelat
Out[15]:
The following code does the plotting for some model variables.
In [16]:
# creating plot figure
fig = plt.figure(figsize=(15,10))
# Temperature plot
ax1 = fig.add_subplot(221)
ax1.plot(ebm_model.lat,ebm_model.Ts)
ax1.set_xticks([-90,-60,-30,0,30,60,90])
ax1.set_xlim([-90,90])
ax1.set_title('Surface Temperature', fontsize=14)
ax1.set_ylabel('(degC)', fontsize=12)
ax1.grid()
# Albedo plot
ax2 = fig.add_subplot(223, sharex = ax1)
ax2.plot(ebm_model.lat,ebm_model.albedo)
ax2.set_title('Albedo', fontsize=14)
ax2.set_xlabel('latitude', fontsize=10)
ax2.set_ylim([0,1])
ax2.grid()
# Net Radiation plot
ax3 = fig.add_subplot(222, sharex = ax1)
ax3.plot(ebm_model.lat, ebm_model.OLR, label='OLR',
color='cyan')
ax3.plot(ebm_model.lat, ebm_model.ASR, label='ASR',
color='magenta')
ax3.plot(ebm_model.lat, ebm_model.ASR-ebm_model.OLR,
label='net radiation',
color='red')
ax3.set_title('Net Radiation', fontsize=14)
ax3.set_ylabel('(W/m$^2$)', fontsize=12)
ax3.legend(loc='best')
ax3.grid()
# Energy Balance plot
net_rad = np.squeeze(ebm_model.net_radiation)
transport = ebm_model.heat_transport_convergence()
ax4 = fig.add_subplot(224, sharex = ax1)
ax4.plot(ebm_model.lat, net_rad, label='net radiation',
color='red')
ax4.plot(ebm_model.lat, transport, label='heat transport',
color='blue')
ax4.plot(ebm_model.lat, net_rad+transport, label='balance',
color='black')
ax4.set_title('Energy', fontsize=14)
ax4.set_xlabel('latitude', fontsize=10)
ax4.set_ylabel('(W/m$^2$)', fontsize=12)
ax4.legend(loc='best')
ax4.grid()
plt.show()
The energy balance is zero at every latitude. That means the model is in equilibrium. Perfect!
The model's state dictionary has following entries:
In [17]:
ebm_model.state.keys()
Out[17]:
Like diagnostics, state variables can be accessed in two ways:
ebm_model.state['Ts']
ebm_model.Ts
These are entirely equivalent:
In [18]:
ebm_model.Ts is ebm_model.state['Ts']
Out[18]:
The global mean of the model's surface temperature can be calculated through
In [19]:
print('The global mean temperature is %.2f deg C.' %climlab.global_mean(ebm_model.Ts))
print('The modeled ice edge is at %.2f deg latitude.' %np.max(ebm_model.icelat))
In [ ]: