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 : import climt In : import matplotlib.pyplot as plt In : import numpy as np # Two new imports In : from sympl import AdamsBashforth In : from datetime import timedelta # Create some components In : radiation = climt.GrayLongwaveRadiation() # Get a state dictionary filled with required quantities # for the components to run In : state = climt.get_default_state([radiation])
We have two new imports,
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 : model_time_step = timedelta(hours=1) In : 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 : 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
Federation once you get used to the workflow.