Working with PRMS parameters¶
This tutorial shows how to access, edit, remove, and add new PRMS parameters and packages to a GSFLOW model using pyGSFLOW
[1]:
# Package import
import os
import gsflow
import numpy as np
load a demonstration model¶
[2]:
model_ws = os.path.join("..", "..", "data", "sagehen", "gsflow")
[3]:
control_file = os.path.join(model_ws, "saghen_new_cont.control")
gsf = gsflow.GsflowModel.load_from_file(control_file)
Control file is loaded
Working on loading PRMS model ...
Prms model loading ...
------------------------------------
Reading parameter file : saghen_new_par_0.params
------------------------------------
Warning: ncascade data type will be infered from data supplied
Warning: ncascdgw data type will be infered from data supplied
Warning: ndays data type will be infered from data supplied
Warning: ndepl data type will be infered from data supplied
Warning: ndeplval data type will be infered from data supplied
Warning: nevap data type will be infered from data supplied
Warning: ngw data type will be infered from data supplied
Warning: ngwcell data type will be infered from data supplied
Warning: nhru data type will be infered from data supplied
Warning: nhrucell data type will be infered from data supplied
Warning: nlake data type will be infered from data supplied
Warning: nlake_hrus data type will be infered from data supplied
Warning: nmonths data type will be infered from data supplied
Warning: nobs data type will be infered from data supplied
Warning: nrain data type will be infered from data supplied
Warning: nreach data type will be infered from data supplied
Warning: nsegment data type will be infered from data supplied
Warning: nsnow data type will be infered from data supplied
Warning: nsol data type will be infered from data supplied
Warning: nssr data type will be infered from data supplied
Warning: nsub data type will be infered from data supplied
Warning: ntemp data type will be infered from data supplied
Warning: one data type will be infered from data supplied
------------------------------------
Reading parameter file : saghen_new_par_1.params
------------------------------------
------------------------------------
Reading parameter file : saghen_new_par_2.params
------------------------------------
------------------------------------
Reading parameter file : saghen_new_par_3.params
------------------------------------
PRMS model loaded ...
Working on loading MODFLOW files ....
loading iuzfbnd array...
loading irunbnd array...
loading vks array...
loading eps array...
loading thts array...
stress period 1:
loading finf array...
stress period 2:
MODFLOW files are loaded ...
Accessing the PrmsParameters object¶
The PrmsParameters object allows the user to access data from PRMS parameter files.
[4]:
params = gsf.prms.parameters
Getting a list all of the model parameters¶
The parameters_list
method returns all parameter names in the PrmsParameters object
[5]:
param_names = params.parameters_list
Getting parameter values from the PrmsParameters object¶
The get_values()
method returns a numpy array of parameter values for PRMS parameters
[6]:
ssr2gw = params.get_values("ssr2gw_rate")
Adjusting parameter values¶
The set_values()
method allows the user to adjust a PRMS parameter value
[7]:
ssr2gw = params.get_values("ssr2gw_rate")
ssr2gw *= 0.8
params.set_values("ssr2gw_rate", ssr2gw)
[7]:
array([0., 0., 0., ..., 0., 0., 0.])
Removing a parameter¶
The remove_record()
method allows the user to remove a parameter from the PrmsParameters object.
[8]:
params.remove_record("ssr2gw_rate")
Adding a new parameter¶
The add_record()
method allows the user to add new parameters to the PrmsParameters object
add_record()
parameters include
name
: (str) parameter namevalues
: (np.array, list) numpy array or list of parameter valuesdimensions
: (list) 2 dimensional list that defines 1) the dimension name and 2) the dimension sizedatatype
: (int) PRMS data typefilename
: (str) Optional parameter that allows the user to set which PRMS parameter file a given parameter is written to. Default is None which writes to the parameter file that contains the PRMS dimensions block.
[9]:
nhru = gsf.mf.nrow * gsf.mf.ncol
ssr2gw = np.random.random(nhru)
params.add_record("ssr2gw_rate",
ssr2gw,
dimensions=[["nhru", nhru]],
datatype=3)