A Realistic ModelΒΆ

As mentioned before, climt includes some components which returns the a new version of the model state, and some which return just tendencies.

Since tendencies by themselves are not useful for much other than plotting, we need to couple them with numerical integration components to march the model forward in time. Again, we will use the grey radiation scheme as an example.

The following script is used to obtain the temperature profile of the atmosphere if no physical process other than radiation (specifically, grey gas radiation in this example) are present. The temperature profile obtained is called the radiative equilibrium profile.

As before, we will create the radiation component and the model state:

In [1]: import climt

In [2]: import matplotlib.pyplot as plt

In [3]: import numpy as np

# Two new imports
In [4]: from sympl import AdamsBashforth

In [5]: from datetime import timedelta

# Create some components
In [6]: radiation = climt.GrayLongwaveRadiation()

# Get a state dictionary filled with required quantities
# for the components to run
In [7]: state = climt.get_default_state([radiation])

We have two new imports, AdamsBashforth and timedelta. The former is a numerical integrator which will step the model forward in time, and the latter is a standard python module which will be used to represent the time step of the model.

Now, to create the integrator and the timestep:

In [8]: model_time_step = timedelta(hours=1)

In [9]: model = AdamsBashforth([radiation])

We now have a model ready to run! The integrator will return the new model state and any diagnostics that radiation has generated. We can then update the current model state with the new model state and continue to step the model forward in time:

In [10]: for step in range(10):
   ....:     diagnostics, new_state = model(state, model_time_step)
   ....:     ''' Update state with diagnostics.
   ....:     This updated state can be saved if necessary '''
   ....:     state.update(diagnostics)
   ....:     '''Update state quantities'''
   ....:     state.update(new_state)
   ....:     '''Update model time'''
   ....:     state['time'] += model_time_step
   ....:     '''See if the maximum temperature is changing'''
   ....:     print(state['time'], ': ', state['air_temperature'].max().values)
2000-01-01 01:00:00 :  289.96882567458607
2000-01-01 02:00:00 :  289.9377097152726
2000-01-01 03:00:00 :  289.9066289418279
2000-01-01 04:00:00 :  289.8755896761563
2000-01-01 05:00:00 :  289.844584776716
2000-01-01 06:00:00 :  289.81362324988896
2000-01-01 07:00:00 :  289.78269480027757
2000-01-01 08:00:00 :  289.7518063986025
2000-01-01 09:00:00 :  289.72095925683254
2000-01-01 10:00:00 :  289.6901474644026

And voila, we have a model that actually evolves over time! Many example scripts that illustrate standard model configurations used in climate modelling are available in the github repository. These scripts include examples which setup graphics to view the evolution of the model over time.


A more user friendly API called Federation will be available in a later version of climt. However, setting up models is easy enough even without Federation once you get used to the workflow.