In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import climlab
from climlab import constants as const
In [2]:
# initial state (temperatures)
state = climlab.column_state(num_lev=20, num_lat=1, water_depth=5.)
In [3]:
# Create a parent process
rce = climlab.TimeDependentProcess(state=state)
## Create individual physical process models:
# fixed relative humidity
h2o = climlab.radiation.water_vapor.ManabeWaterVapor(state=state)
# Hard convective adjustment
convadj = climlab.convection.convadj.ConvectiveAdjustment(state=state, adj_lapse_rate=6.5)
# CAM3 radiation with default parameters and interactive water vapor
rad = climlab.radiation.CAM3Radiation(state=state)
rad.q = h2o.q
# Couple the models
rce.add_subprocess('Radiation', rad)
rce.add_subprocess('ConvectiveAdjustment', convadj)
rce.add_subprocess('H2O', h2o)
# Make diagnostic water vapor field easy to access
rce.q = rce.subprocess.H2O.q
In [4]:
print rce
In [5]:
rce.state
Out[5]:
In [6]:
rce.integrate_years(5)
In [7]:
rce.state
Out[7]:
In [8]:
rce.q
Out[8]:
In [9]:
rce.subprocess.Radiation.input
Out[9]:
In [10]:
# initial state (temperatures)
state2 = climlab.column_state(num_lev=20, num_lat=30, water_depth=10.)
In [11]:
# Create a parent process
rcelat = climlab.TimeDependentProcess(state=state2)
## Create individual physical process models:
# seasonal insolation
insol = climlab.radiation.insolation.DailyInsolation(domains=rcelat.Ts.domain)
# fixed relative humidity
h2o = climlab.radiation.water_vapor.ManabeWaterVapor(state=state2)
# Hard convective adjustment
convadj = climlab.convection.convadj.ConvectiveAdjustment(state=state2, adj_lapse_rate=6.5)
# CAM3 radiation with default parameters and interactive water vapor
rad = climlab.radiation.CAM3Radiation(state=state2)
# Couple the insolation and water vapor to radiation process
rad.q = h2o.q
rad.insolation = insol.insolation
# Add all subprocesses to the parent process
rcelat.add_subprocess('Insolation', insol)
rcelat.add_subprocess('Radiation', rad)
rcelat.add_subprocess('ConvectiveAdjustment', convadj)
rcelat.add_subprocess('H2O', h2o)
# Make diagnostic water vapor field easy to access
rcelat.q = rcelat.subprocess.H2O.q
In [12]:
rcelat.integrate_years(5)
In [13]:
rcelat.integrate_years(1)
In [14]:
def plot_temp_section(model, timeave=True):
fig = plt.figure()
ax = fig.add_subplot(111)
if timeave:
field = model.timeave['Tatm'].transpose()
else:
field = model.Tatm.transpose()
cax = ax.contourf(model.lat, model.lev, field)
ax.invert_yaxis()
ax.set_xlim(-90,90)
ax.set_xticks([-90, -60, -30, 0, 30, 60, 90])
fig.colorbar(cax)
In [15]:
plot_temp_section(rcelat)
In [16]:
### Normally we can clone a model with process_like() but it currently fails for compiled Fortran extensions.
#diffmodel = climlab.process_like(rcelat)
In [17]:
# initial state (temperatures)
state3 = climlab.column_state(num_lev=20, num_lat=30, water_depth=10.)
In [18]:
# Create a parent process
diffmodel = climlab.TimeDependentProcess(state=state3)
## Create individual physical process models:
# seasonal insolation
insol = climlab.radiation.insolation.DailyInsolation(domains=diffmodel.Ts.domain)
# fixed relative humidity
h2o = climlab.radiation.water_vapor.ManabeWaterVapor(state=state3)
# Hard convective adjustment
convadj = climlab.convection.convadj.ConvectiveAdjustment(state=state3, adj_lapse_rate=6.5)
# CAM3 radiation with default parameters and interactive water vapor
rad = climlab.radiation.CAM3Radiation(state=state3)
rad.q = h2o.q
rad.insolation = insol.insolation
# Couple the models
diffmodel.add_subprocess('Insolation', insol)
diffmodel.add_subprocess('Radiation', rad)
diffmodel.add_subprocess('ConvectiveAdjustment', convadj)
diffmodel.add_subprocess('H2O', h2o)
# Make diagnostic water vapor field easy to access
diffmodel.q = diffmodel.subprocess.H2O.q
In [19]:
# thermal diffusivity in W/m**2/degC
D = 0.05
# meridional diffusivity in 1/s
K = D / diffmodel.Tatm.domain.heat_capacity[0]
print K
In [20]:
d = climlab.dynamics.diffusion.MeridionalDiffusion(K=K, state={'Tatm': diffmodel.state['Tatm']}, **diffmodel.param)
In [21]:
diffmodel.add_subprocess('diffusion', d)
In [22]:
diffmodel.integrate_years(5)
In [23]:
diffmodel.integrate_years(1)
In [24]:
plot_temp_section(rcelat)
plot_temp_section(diffmodel)
In [25]:
def inferred_heat_transport( energy_in, lat_deg ):
'''Returns the inferred heat transport (in PW) by integrating the net energy imbalance from pole to pole.'''
from scipy import integrate
from climlab import constants as const
lat_rad = np.deg2rad( lat_deg )
return ( 1E-15 * 2 * np.math.pi * const.a**2 * integrate.cumtrapz( np.cos(lat_rad)*energy_in,
x=lat_rad, initial=0. ) )
In [26]:
# Plot the northward heat transport in this model
Rtoa = np.squeeze(diffmodel.timeave['ASR'] - diffmodel.timeave['OLR'])
plt.plot(diffmodel.lat, inferred_heat_transport(Rtoa, diffmodel.lat))
Out[26]:
All the models above use a convective adjustment that simultaneously adjustments Tatm and Ts to the prescribed lapse rate.
We can instead limit the convective adjustment to just the atmosphere. To do this, we just have to change the state variable dictionary in the convective adjustment process.
Then we can invoke process models for sensible and latent heat fluxes that use simple bulk formulae. Tunable parameters for these include drag coefficient and surface wind speed.
In [27]:
# Create a parent process
diffmodel2 = climlab.TimeDependentProcess(state=state3)
## Create individual physical process models:
# seasonal insolation
insol = climlab.radiation.insolation.DailyInsolation(domains=diffmodel2.Ts.domain)
# fixed relative humidity
h2o = climlab.radiation.water_vapor.ManabeWaterVapor(state=state3)
# Hard convective adjustment -- ATMOSPHERE ONLY
convadj = climlab.convection.convadj.ConvectiveAdjustment(state={'Tatm':diffmodel2.state['Tatm']}, adj_lapse_rate=6.5)
# CAM3 radiation with default parameters and interactive water vapor
rad = climlab.radiation.CAM3Radiation(state=state3)
rad.q = h2o.q
rad.insolation = insol.insolation
d = climlab.dynamics.diffusion.MeridionalDiffusion(K=K, state={'Tatm': diffmodel.state['Tatm']})
# Couple the models
diffmodel2.add_subprocess('Insolation', insol)
diffmodel2.add_subprocess('Radiation', rad)
diffmodel2.add_subprocess('ConvectiveAdjustment', convadj)
diffmodel2.add_subprocess('H2O', h2o)
diffmodel2.add_subprocess('diffusion', d)
# Make diagnostic water vapor field easy to access
diffmodel2.q = diffmodel2.subprocess.H2O.q
print diffmodel2
In [28]:
# Now add surface flux processes
# Add surface heat fluxes
shf = climlab.surface.SensibleHeatFlux(state=diffmodel2.state, Cd=0.5E-3)
lhf = climlab.surface.LatentHeatFlux(state=diffmodel2.state, Cd=0.5E-3)
# set the water vapor input field for LHF process
lhf.q = diffmodel2.subprocess.H2O.q
diffmodel2.add_subprocess('SHF', shf)
diffmodel2.add_subprocess('LHF', lhf)
print diffmodel2
In [29]:
diffmodel2.integrate_years(5)
In [30]:
diffmodel2.integrate_years(1)
In [31]:
plot_temp_section(rcelat)
plot_temp_section(diffmodel2)
In [32]:
# Plot the northward heat transport in this model
Rtoa = np.squeeze(diffmodel2.timeave['ASR'] - diffmodel2.timeave['OLR'])
plt.plot(diffmodel2.lat, inferred_heat_transport(Rtoa, diffmodel2.lat))
Out[32]:
In [ ]: