In this document the basic use of climlab's preconfigured EBM class is shown.
Contents are how to
In [1]:
# import header
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import climlab
from climlab import constants as const
from climlab.domain.field import global_mean
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]:
The model time dictionary shows information about all the time related content and quantities.
In [7]:
# accessing the model time dictionary
ebm_model.time
Out[7]:
To integrate the model forward in time different methods are availible:
In [8]:
# integrate model for a single timestep
ebm_model.step_forward()
The model time step has increased from 0 to 1:
In [9]:
ebm_model.time['steps']
Out[9]:
In [10]:
# integrate model for a 50 days
ebm_model.integrate_days(50.)
In [11]:
# integrate model for two years
ebm_model.integrate_years(1.)
In [12]:
# 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 [13]:
ebm_model.diagnostics.keys()
Out[13]:
They can be accessed respecively to the keys through ebm_model.diagnostics['ASR']
. Most of them can be also accessed directly as model attributes like:
In [14]:
ebm_model.icelat
Out[14]:
The following code does the plotting for some model variables.
In [15]:
# 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_xlabel('latitude')
ax1.set_ylabel('surface temperature (degC)', fontsize=12)
ax1.grid()
# Albedo plot
ax2 = fig.add_subplot(223, sharex = ax1)
ax2.plot(ebm_model.lat,ebm_model.albedo)
ax2.set_ylabel('albedo', fontsize=12)
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_ylabel('radiation (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_ylabel('energy (W/m$^2$)', fontsize=12)
ax4.legend(loc='best')
ax4.grid()
plt.show()
The model's state dictionary has following entries:
In [16]:
ebm_model.state.keys()
Out[16]:
So the surface temperature can usually be accessed through ebm_model.state['Ts']
but is also availible as a model attribute: ebm_model.Ts
The global mean of the model's surface temperature can be calculated through
In [17]:
# calculate global mean temperature
global_mean(ebm_model.Ts)
Out[17]:
Note that in the header the global_mean
method has been imported!
In [18]:
print 'The global mean temperature is %s degC with a model ice edge at %s deg.' \
%(np.round(global_mean(ebm_model.Ts),2), np.max(ebm_model.icelat))