$ conda install notebook pymt_sedflux
This example explores how to use a BMI implementation using sedflux's subsidence model as an example.
Some magic that allows us to view images within the notebook.
In [1]:
from __future__ import print_function
%matplotlib inline
import matplotlib.pyplot as plt
Import the Subside
class, and instantiate it. In Python, a model with a BMI will have no arguments for its constructor. Note that although the class has been instantiated, it's not yet ready to be run. We'll get to that later!
In [2]:
from pymt import plugins
subside = plugins.Subside()
Even though we can't run our waves model yet, we can still get some information about it. Just don't try to run it. Some things we can do with our model are get the names of the input variables.
In [3]:
subside.output_var_names
Out[3]:
In [4]:
subside.input_var_names
Out[4]:
We can also get information about specific variables. Here we'll look at some info about lithospheric deflections. This is the main input of the Subside model. Notice that BMI components always use CSDMS standard names. With that name we can get information about that variable and the grid that it is on.
OK. We're finally ready to run the model. Well not quite. First we initialize the model with the BMI initialize method. Normally we would pass it a string that represents the name of an input file. For this example we'll pass None, which tells Cem to use some defaults.
In [5]:
config_file, config_folder = subside.setup()
In [6]:
subside.initialize(config_file, dir=config_folder)
In [7]:
subside.var["earth_material_load__pressure"]
Out[7]:
In [8]:
subside.grid[0].node_shape
Out[8]:
Before running the model, let's set an input parameter - the overlying load.
In [9]:
import numpy as np
load = np.zeros((500, 500))
load[250, 250] = 1e3
The main output variable for this model is deflection. In this case, the CSDMS Standard Name is:
"lithosphere__increment_of_elevation"
First we find out which of Subside's grids contains deflection.
In [10]:
subside.var['lithosphere__increment_of_elevation']
Out[10]:
With the grid_id, we can now get information about the grid. For instance, the number of dimension and the type of grid (structured, unstructured, etc.). This grid happens to be uniform rectilinear. If you were to look at the "grid" types for wave height and period, you would see that they aren't on grids at all but instead are scalars.
In [11]:
subside.grid[0]
Out[11]:
Because this grid is uniform rectilinear, it is described by a set of BMI methods that are only available for grids of this type. These methods include:
Allocate memory for the water depth grid and get the current values from cem
.
In [12]:
subside.set_value("earth_material_load__pressure", load)
Out[12]:
In [13]:
subside.update()
In [14]:
dz = subside.get_value('lithosphere__increment_of_elevation')
In [15]:
plt.imshow(dz.reshape((500, 500)))
Out[15]:
In [16]:
load[125, 125] = 2e3
subside.set_value("earth_material_load__pressure", load)
subside.update()
In [18]:
dz = subside.get_value('lithosphere__increment_of_elevation')
plt.imshow(dz.reshape((500, 500)))
plt.colorbar()
Out[18]:
In [ ]:
In [ ]: