Beispiel #1
0
def test_adams_bashforth_requires_same_timestep(mock_prognostic_call):
    """Test that the Asselin filter is being correctly applied"""
    mock_prognostic_call.return_value = ({'air_temperature': 0.}, {})
    state = {'air_temperature': 273.}
    time_stepper = AdamsBashforth([MockPrognostic()])
    state = time_stepper.__call__(state, timedelta(seconds=1.))
    try:
        time_stepper.__call__(state, timedelta(seconds=2.))
    except ValueError:
        pass
    except Exception as err:
        raise err
    else:
        raise AssertionError(
            'AdamsBashforth must require timestep to be constant')
Beispiel #2
0

def plot_function(fig, state):
    ax = fig.add_subplot(1, 1, 1)
    ax.plot(
        state['air_temperature'].values.flatten(),
        state['air_pressure'].values.flatten(), '-o')
    ax.axes.invert_yaxis()
    ax.set_yscale('log')
    ax.set_ylim(1e5, 100.)
    ax.set_xlabel('Kelvin')
    ax.set_ylabel('Pa')
    ax.set_title('Radiative equilibrium in a Grey Gas atmosphere')


monitor = PlotFunctionMonitor(plot_function)
diagnostic = Frierson06LongwaveOpticalDepth()
radiation = GrayLongwaveRadiation()
time_stepper = AdamsBashforth([radiation])
timestep = timedelta(hours=4)

state = get_default_state([radiation, diagnostic])

for i in range(6*7*4*10):
    state.update(diagnostic(state))
    diagnostics, new_state = time_stepper.__call__(state, timestep)
    state.update(diagnostics)
    if i % 5 == 0:
        monitor.store(state)
    state.update(new_state)