The pst_handler
module with pyemu.pst
contains the Pst
class for dealing with pest control files. It relies heavily on pandas
to deal with tabular sections, such as parameters, observations, and prior information. This jupyter notebook shows how to create a control-file object (instantiate the class or make an instance of the class), how to access attributes of the class, and how to call an instance method.
In [13]:
import os
import numpy as np
import pyemu
from pyemu import Pst
A PEST control file is required to make the object, and we need to pass the name of the PEST control file as a parameter to the init method for the class. The class instance (or object) is assigned to the variable p.
In [14]:
pst_name = os.path.join("..", "..", "examples", "henry","pest.pst")
p = Pst(pst_name)
Now all of the relevant parts of the pest control file are attributes of the object. For example, the parameter_data, observation data, and prior information are available as pandas dataframes.
In [15]:
p.parameter_data.head()
Out[15]:
In [16]:
p.observation_data.head()
Out[16]:
In [17]:
p.prior_information.head()
Out[17]:
The client-code can be used to change values in the dataframes that can be written to
a new or updated control file using the write()
method as shown at the end of the notebook.
In [18]:
p.parameter_data.loc['global_k', 'parval1'] = 225
p.parameter_data.head()
Out[18]:
A residual file (.rei
or res
) can also be passed to the resfile
argument at instantiation to enable some simple residual analysis and evaluate if weight adjustments are needed. If resfile = False
, or not supplied, and if the residual file is in the same directory as the pest control file and has the same base name, it will be accessed automatically:
In [19]:
p.res.head()
Out[19]:
The weights can be updated by changing values in the observation dataframe.
In [20]:
p.observation_data.loc['h_obs01_1', 'weight'] = 25.0
p.observation_data.head()
Out[20]:
The Pst
class exposes a method, get()
, to create a new Pst
instance with a subset of parameters and or observations. For example, make a new PEST control-file object using the first 10 entries from the
parameter and observation dataframes. Note this method does not propogate prior information to the new instance:
In [21]:
pnew = p.get(p.par_names[:10],p.obs_names[:10])
pnew.prior_information.head()
Out[21]:
Check the parameter_data and observation_data dataframes for the new object, note that
the updated values for global_k
parval1
and h_obs01_1
weight
are in these dataframes.
In [22]:
pnew.parameter_data.head()
Out[22]:
In [23]:
pnew.observation_data.head()
Out[23]:
The write(filename)
method allows you to write a PEST control file with the current state of the object: that is, make a new PEST control file with the current information contained in an object.
In [24]:
pnew.write("test.pst")