Esempio n. 1
0
def test_float():
    '''Check that we can step forward the model after setting the state
    variable with an ndarray of integers through 2 different methods'''
    from climlab.domain import initial
    from climlab.domain.field import Field
    state = initial.surface_state()
    sfc = climlab.domain.zonal_mean_surface(num_lat=4)
    state.Ts = Field([10, 15, 15, 10], domain=sfc)
    m = climlab.EBM(state=state)
    m.step_forward()
    k = climlab.EBM(num_lat=4)
    k.set_state('Ts', Field([10, 15, 15, 10], domain=k.domains['Ts']))
    k.step_forward()
Esempio n. 2
0
def test_moist_EBM_creation():
    '''See if we can swap a moist diffusion module for the dry diffusion
    and just step forward once.'''
    m = climlab.EBM()
    m.remove_subprocess('diffusion')
    diff = climlab.dynamics.MeridionalMoistDiffusion(state=m.state,
                                                     timestep=m.timestep)
    m.add_subprocess('diffusion', diff)
    m.step_forward()
    assert hasattr(m, 'heat_transport')
Esempio n. 3
0
def test_albedo():
    '''Check that we can integrate forward a model after changing the albedo
    subprocess and get the expected icelat'''
    import numpy as np
    m = climlab.EBM()
    m.add_subprocess('albedo',
                     climlab.surface.ConstantAlbedo(state=m.state, **m.param))
    m.integrate_years(1)
    assert m.icelat == None
    m.add_subprocess(
        'albedo', climlab.surface.StepFunctionAlbedo(state=m.state, **m.param))
    m.integrate_years(1)
    assert np.all(m.icelat == np.array([-70., 70.]))
    assert np.all(m.icelat == m.subprocess.albedo.subprocess.iceline.icelat)
Esempio n. 4
0
def test_analytical():
    '''Check to see if the the numerical solution converges to the analytical
    steady-state solution of the simple EBM with constant albedo'''
    param = {
        'a0': 0.3,
        'a2': 0.,
        'ai': 0.3,
        's2': -0.48,
        'S0': 1360.,
        'A': 210.,
        'B': 2.,
        'D': 0.55,
        'Tf': -1000.,  # effectively makes albedo constant
    }
    m = climlab.EBM(**param)
    m.integrate_years(5)
    Tnumerical = np.squeeze(m.Ts)
    delta = param['D'] / param['B']
    x = np.sin(np.deg2rad(m.lat))
    Tanalytical = ((1 - param['a0']) * param['S0'] / 4 *
                   (1 + param['s2'] * P2(x) /
                    (1 + 6 * delta)) - param['A']) / param['B']
    assert Tnumerical == pytest.approx(Tanalytical, abs=2E-2)
import climlab
import matplotlib.pyplot as plt

# creating & integrating model
model = climlab.EBM()
model.step_forward()

# plot
fig = plt.figure( figsize=(6,4))
ax = fig.add_subplot(111)

ax.plot(model.lat, model.inferred_heat_transport())

ax.set_title('inferred heat transport')
ax.set_xlabel('latitude')
ax.set_xticks([-90,-60,-30,0,30,60,90])
ax.set_ylabel('energy (PW)')
plt.axhline(linewidth=2, color='grey', linestyle='dashed')
plt.show()