pyemu.legacy

This module contains legacy, deprecated classes and methods, including PstFromFlopyModel – superseeded by pyemu.utils.PstFrom()

Submodules

Package Contents

Classes

SpatialReference

a class to locate a structured model grid in x-y space.

PstFromFlopyModel

a monster helper class to setup a complex PEST interface around

Functions

kl_setup(num_eig, sr, struct, prefixes[, ...])

setup a karhuenen-Loeve based parameterization for a given

apply_array_pars([arr_par, arr_par_file, chunk_len])

a function to apply array-based multipler parameters.

geostatistical_draws(pst, struct_dict[, num_reals, ...])

construct a parameter ensemble from a prior covariance matrix

_write_df_tpl(filename, df[, sep, tpl_marker, headerlines])

function write a pandas dataframe to a template file.

write_const_tpl(name, tpl_file, suffix[, zn_array, ...])

write a constant (uniform) template file for a 2-D array

write_grid_tpl(name, tpl_file, suffix[, zn_array, ...])

write a grid-based template file for a 2-D array

write_zone_tpl(name, tpl_file[, suffix, zn_array, ...])

write a zone-based template file for a 2-D array

apply_list_pars()

a function to apply boundary condition multiplier parameters.

setup_temporal_diff_obs(pst, ins_file[, out_file, ...])

a helper function to setup difference-in-time observations based on an existing

apply_temporal_diff_obs(config_file)

process an instruction-output file pair and formulate difference observations.

Attributes

wildass_guess_par_bounds_dict

exception pyemu.legacy.PyemuWarning

Bases: Warning

Base class for warning categories.

class pyemu.legacy.SpatialReference(delr=np.array([]), delc=np.array([]), lenuni=2, xul=None, yul=None, xll=None, yll=None, rotation=0.0, proj4_str=None, epsg=None, prj=None, units=None, length_multiplier=None, source=None)

Bases: object

a class to locate a structured model grid in x-y space. Lifted wholesale from Flopy, and preserved here… …maybe slighlty over-engineered for here

Parameters:
  • delr (numpy ndarray) – the model discretization delr vector (An array of spacings along a row)

  • delc (numpy ndarray) – the model discretization delc vector (An array of spacings along a column)

  • lenuni (int) – the length units flag from the discretization package. Default is 2.

  • xul (float) – The x coordinate of the upper left corner of the grid. Enter either xul and yul or xll and yll.

  • yul (float) – The y coordinate of the upper left corner of the grid. Enter either xul and yul or xll and yll.

  • xll (float) – The x coordinate of the lower left corner of the grid. Enter either xul and yul or xll and yll.

  • yll (float) – The y coordinate of the lower left corner of the grid. Enter either xul and yul or xll and yll.

  • rotation (float) – The counter-clockwise rotation (in degrees) of the grid

  • proj4_str (str) – a PROJ4 string that identifies the grid in space. warning: case sensitive!

  • units (string) – Units for the grid. Must be either “feet” or “meters”

  • epsg (int) – EPSG code that identifies the grid in space. Can be used in lieu of proj4. PROJ4 attribute will auto-populate if there is an internet connection(via get_proj4 method). See https://www.epsg-registry.org/ or spatialreference.org

  • length_multiplier (float) – multiplier to convert model units to spatial reference units. delr and delc above will be multiplied by this value. (default=1.)

property ncpl
property xll
property yll
property xul
property yul
property proj4_str
property epsg
property lenuni
property units
property length_multiplier

Attempt to identify multiplier for converting from model units to sr units, defaulting to 1.

property model_length_units
property bounds

Return bounding box in shapely order.

property nrow
property ncol
property attribute_dict
property theta
property xedge
property yedge
property xgrid
property ygrid
property xcenter
property ycenter
property ycentergrid
property xcentergrid
property vertices

Returns a list of vertices for

rotation = 0.0
length_multiplier = 1.0
origin_loc = 'ul'
defaults
lenuni_values
lenuni_text
_parse_units_from_proj4()
static load(namefile=None, reffile='usgs.model.reference')

Attempts to load spatial reference information from the following files (in order): 1) usgs.model.reference 2) NAM file (header comment) 3) SpatialReference.default dictionary

static attribs_from_namfile_header(namefile)
static read_usgs_model_reference_file(reffile='usgs.model.reference')

read spatial reference info from the usgs.model.reference file https://water.usgs.gov/ogw/policy/gw-model/modelers-setup.html

__setattr__(key, value)

Implement setattr(self, name, value).

reset(**kwargs)
_reset()
__eq__(other)

Return self==value.

classmethod from_namfile(namefile, delr=np.array([]), delc=np.array([]))
classmethod from_gridspec(gridspec_file, lenuni=0)
set_spatialreference(xul=None, yul=None, xll=None, yll=None, rotation=0.0)

set spatial reference - can be called from model instance

__repr__()

Return repr(self).

_set_xycentergrid()
_set_xygrid()
static rotate(x, y, theta, xorigin=0.0, yorigin=0.0)

Given x and y array-like values calculate the rotation about an arbitrary origin and then return the rotated coordinates. theta is in degrees.

transform(x, y, inverse=False)

Given x and y array-like values, apply rotation, scale and offset, to convert them from model coordinates to real-world coordinates.

get_extent()

Get the extent of the rotated and offset grid

get_grid_lines()

Get the grid lines as a list

get_xcenter_array()

Return a numpy one-dimensional float array that has the cell center x coordinate for every column in the grid in model space - not offset or rotated.

get_ycenter_array()

Return a numpy one-dimensional float array that has the cell center x coordinate for every row in the grid in model space - not offset of rotated.

get_xedge_array()

Return a numpy one-dimensional float array that has the cell edge x coordinates for every column in the grid in model space - not offset or rotated. Array is of size (ncol + 1)

get_yedge_array()

Return a numpy one-dimensional float array that has the cell edge y coordinates for every row in the grid in model space - not offset or rotated. Array is of size (nrow + 1)

write_gridspec(filename)

write a PEST-style grid specification file

get_vertices(i, j)

Get vertices for a single cell or sequence if i, j locations.

get_rc(x, y)
get_ij(x, y)

Return the row and column of a point or sequence of points in real-world coordinates.

Parameters:
  • x (float) – scalar or sequence of x coordinates

  • y (float) – scalar or sequence of y coordinates

Returns:

tuple of

  • int : row or sequence of rows (zero-based)

  • int : column or sequence of columns (zero-based)

_set_vertices()

Populate vertices for the whole grid

pyemu.legacy.kl_setup(num_eig, sr, struct, prefixes, factors_file='kl_factors.dat', islog=True, basis_file=None, tpl_dir='.')

setup a karhuenen-Loeve based parameterization for a given geostatistical structure.

Parameters:
  • num_eig (int) – the number of basis vectors to retain in the reduced basis

  • sr (flopy.reference.SpatialReference) – a spatial reference instance

  • struct (str) – a PEST-style structure file. Can also be a pyemu.geostats.Geostruct instance.

  • prefixes ([str]) – a list of parameter prefixes to generate KL parameterization for.

  • factors_file (str, optional) – name of the PEST-style interpolation factors file to write (can be processed with FAC2REAL). Default is “kl_factors.dat”.

  • islog (bool, optional) – flag to indicate if the parameters are log transformed. Default is True

  • basis_file (str, optional) – the name of the PEST-style binary (e.g. jco) file to write the reduced basis vectors to. Default is None (not saved).

  • tpl_dir (str, optional) – the directory to write the resulting template files to. Default is “.” (current directory).

Returns:

a dataframe of parameter information.

Return type:

pandas.DataFrame

Note

This is the companion function to helpers.apply_kl()

Example:

m = flopy.modflow.Modflow.load("mymodel.nam")
prefixes = ["hk","vka","ss"]
df = pyemu.helpers.kl_setup(10,m.sr,"struct.dat",prefixes)
pyemu.legacy.apply_array_pars(arr_par='arr_pars.csv', arr_par_file=None, chunk_len=50)

a function to apply array-based multipler parameters.

Parameters:
  • arr_par (str or pandas.DataFrame) – if type str,

  • multipliers. (path to csv file detailing parameter array) – This file can be written by PstFromFlopy.

  • of (if type pandas.DataFrame is Dataframe with columns) –

  • ['mlt_file'

  • 'model_file'

  • optionally ('org_file'] and) –

  • ['pp_file'

  • 'fac_file'].

  • chunk_len (int) – the number of files to process per chunk with multiprocessing - applies to both fac2real and process_ input_files. Default is 50.

Note

Used to implement the parameterization constructed by PstFromFlopyModel during a forward run

This function should be added to the forward_run.py script but can be called on any correctly formatted csv

This function using multiprocessing, spawning one process for each model input array (and optionally pp files). This speeds up execution time considerably but means you need to make sure your forward run script uses the proper multiprocessing idioms for freeze support and main thread handling (PstFrom does this for you).

pyemu.legacy.geostatistical_draws(pst, struct_dict, num_reals=100, sigma_range=4, verbose=True, scale_offset=True, subset=None)

construct a parameter ensemble from a prior covariance matrix implied by geostatistical structure(s) and parameter bounds.

Parameters:
  • pst (pyemu.Pst) – a control file (or the name of control file). The parameter bounds in pst are used to define the variance of each parameter group.

  • struct_dict (dict) – a dict of GeoStruct (or structure file), and list of pilot point template files pairs. If the values in the dict are pd.DataFrames, then they must have an ‘x’,’y’, and ‘parnme’ column. If the filename ends in ‘.csv’, then a pd.DataFrame is loaded, otherwise a pilot points file is loaded.

  • num_reals (int, optional) – number of realizations to draw. Default is 100

  • sigma_range (float) – a float representing the number of standard deviations implied by parameter bounds. Default is 4.0, which implies 95% confidence parameter bounds.

  • verbose (bool, optional) – flag to control output to stdout. Default is True. flag for stdout.

  • scale_offset (bool,optional) – flag to apply scale and offset to parameter bounds when calculating variances - this is passed through to pyemu.Cov.from_parameter_data(). Default is True.

  • subset (array-like, optional) – list, array, set or pandas index defining subset of paramters for draw.

Returns

pyemu.ParameterEnsemble: the realized parameter ensemble.

Note

Parameters are realized by parameter group.

The variance of each parameter is used to scale the resulting geostatistical covariance matrix Therefore, the sill of the geostatistical structures in struct_dict should be 1.0

Example:

pst = pyemu.Pst("my.pst")
sd = {"struct.dat":["hkpp.dat.tpl","vka.dat.tpl"]}
pe = pyemu.helpers.geostatistical_draws(pst,struct_dict=sd}
pe.to_csv("my_pe.csv")
pyemu.legacy._write_df_tpl(filename, df, sep=',', tpl_marker='~', headerlines=None, **kwargs)

function write a pandas dataframe to a template file.

pyemu.legacy.wildass_guess_par_bounds_dict
pyemu.legacy.write_const_tpl(name, tpl_file, suffix, zn_array=None, shape=None, longnames=False)

write a constant (uniform) template file for a 2-D array

Parameters:
  • name (str) – the base parameter name

  • tpl_file (str) – the template file to write

  • zn_array (numpy.ndarray, optional) – an array used to skip inactive cells, and optionally get shape info.

  • shape (tuple) – tuple nrow and ncol. Either zn_array or shape must be passed

  • longnames (bool) – flag to use longer names that exceed 12 chars in length. Default is False.

Returns:

a dataframe with parameter information

Return type:

pandas.DataFrame

Note

This function is used during the PstFrom setup process

pyemu.legacy.write_grid_tpl(name, tpl_file, suffix, zn_array=None, shape=None, spatial_reference=None, longnames=False)

write a grid-based template file for a 2-D array

Parameters:
  • name (str) – the base parameter name

  • tpl_file (str) – the template file to write - include path

  • zn_array (numpy.ndarray, optional) – zone array to identify inactive cells. Default is None

  • shape (tuple, optional) – a length-two tuple of nrow and ncol. Either zn_array or shape must be passed.

  • spatial_reference (flopy.utils.SpatialReference) – a spatial reference instance. If longnames is True, then spatial_reference is used to add spatial info to the parameter names.

  • longnames (bool) – flag to use longer names that exceed 12 chars in length. Default is False.

Returns:

a dataframe with parameter information

Return type:

pandas.DataFrame

Note

This function is used during the PstFrom setup process

Example:

pyemu.helpers.write_grid_tpl("hk_layer1","hk_Layer_1.ref.tpl","gr",
                             zn_array=ib_layer_1,shape=(500,500))
pyemu.legacy.write_zone_tpl(name, tpl_file, suffix='', zn_array=None, shape=None, longnames=False, fill_value='1.0')

write a zone-based template file for a 2-D array

Parameters:
  • name (str) – the base parameter name

  • tpl_file (str) – the template file to write

  • suffix (str) – suffix to add to parameter names. Only used if longnames=True

  • zn_array (numpy.ndarray, optional) – an array used to skip inactive cells, and optionally get shape info. zn_array values less than 1 are given fill_value

  • shape (tuple) – tuple nrow and ncol. Either zn_array or shape must be passed

  • longnames (bool) – flag to use longer names that exceed 12 chars in length. Default is False.

  • fill_value (str) – value to fill locations where zn_array is zero or less. Default is “1.0”.

Returns:

a dataframe with parameter information

Return type:

pandas.DataFrame

Note

This function is used during the PstFrom setup process

pyemu.legacy.apply_list_pars()

a function to apply boundary condition multiplier parameters.

Note

Used to implement the parameterization constructed by PstFromFlopyModel during a forward run

Requires either “temporal_list_pars.csv” or “spatial_list_pars.csv”

Should be added to the forward_run.py script (called programmaticlly by the PstFrom forward run script)

pyemu.legacy.setup_temporal_diff_obs(pst, ins_file, out_file=None, include_zero_weight=False, include_path=False, sort_by_name=True, long_names=True, prefix='dif')

a helper function to setup difference-in-time observations based on an existing set of observations in an instruction file using the observation grouping in the control file

Parameters:
  • pst (pyemu.Pst) – existing control file

  • ins_file (str) – an existing instruction file

  • out_file (str, optional) – an existing model output file that corresponds to the instruction file. If None, ins_file.replace(“.ins”,””) is used

  • include_zero_weight (bool, optional) – flag to include zero-weighted observations in the difference observation process. Default is False so that only non-zero weighted observations are used.

  • include_path (bool, optional) – flag to setup the binary file processing in directory where the hds_file is located (if different from where python is running). This is useful for setting up the process in separate directory for where python is running.

  • sort_by_name (bool,optional) – flag to sort observation names in each group prior to setting up the differencing. The order of the observations matters for the differencing. If False, then the control file order is used. If observation names have a datetime suffix, make sure the format is year-month-day to use this sorting. Default is True

  • long_names (bool, optional) – flag to use long, descriptive names by concating the two observation names that are being differenced. This will produce names that are too long for tradtional PEST(_HP). Default is True.

  • prefix (str, optional) – prefix to prepend to observation names and group names. Default is “dif”.

Returns:

tuple containing

  • str: the forward run command to execute the binary file process during model runs.

  • pandas.DataFrame: a dataframe of observation information for use in the pest control file

Note

This is the companion function of helpers.apply_temporal_diff_obs().

pyemu.legacy.apply_temporal_diff_obs(config_file)

process an instruction-output file pair and formulate difference observations.

Parameters:

config_file (str) – configuration file written by pyemu.helpers.setup_temporal_diff_obs.

Returns:

processed difference observations

Return type:

diff_df (pandas.DataFrame)

Note

Writes config_file.replace(“.config”,”.processed”) output file that can be read with the instruction file that is created by pyemu.helpers.setup_temporal_diff_obs().

This is the companion function of helpers.setup_setup_temporal_diff_obs().

class pyemu.legacy.PstFromFlopyModel(model, new_model_ws, org_model_ws=None, pp_props=[], const_props=[], temporal_bc_props=[], temporal_list_props=[], grid_props=[], grid_geostruct=None, pp_space=None, zone_props=[], pp_geostruct=None, par_bounds_dict=None, sfr_pars=False, temporal_sfr_pars=False, temporal_list_geostruct=None, remove_existing=False, k_zone_dict=None, mflist_waterbudget=True, mfhyd=True, hds_kperk=[], use_pp_zones=False, obssim_smp_pairs=None, external_tpl_in_pairs=None, external_ins_out_pairs=None, extra_pre_cmds=None, extra_model_cmds=None, extra_post_cmds=None, redirect_forward_output=True, tmp_files=None, model_exe_name=None, build_prior=True, sfr_obs=False, spatial_bc_props=[], spatial_list_props=[], spatial_list_geostruct=None, hfb_pars=False, kl_props=None, kl_num_eig=100, kl_geostruct=None)

Bases: object

a monster helper class to setup a complex PEST interface around an existing MODFLOW-2005-family model.

Parameters:
  • model (flopy.mbase) – a loaded flopy model instance. If model is an str, it is treated as a MODFLOW nam file (requires org_model_ws)

  • new_model_ws (str) – a directory where the new version of MODFLOW input files and PEST(++) files will be written

  • org_model_ws (str) – directory to existing MODFLOW model files. Required if model argument is an str. Default is None

  • pp_props ([[str,[int]]]) – pilot point multiplier parameters for grid-based properties. A nested list of grid-scale model properties to parameterize using name, iterable pairs. For 3D properties, the iterable is zero-based layer indices. For example, [“lpf.hk”,[0,1,2,]] would setup pilot point multiplier parameters for layer property file horizontal hydraulic conductivity for model layers 1,2, and 3. For time-varying properties (e.g. recharge), the iterable is for zero-based stress period indices. For example, [“rch.rech”,[0,4,10,15]] would setup pilot point multiplier parameters for recharge for stress period 1,5,11,and 16.

  • const_props ([[str,[int]]]) – constant (uniform) multiplier parameters for grid-based properties. A nested list of grid-scale model properties to parameterize using name, iterable pairs. For 3D properties, the iterable is zero-based layer indices. For example, [“lpf.hk”,[0,1,2,]] would setup constant (uniform) multiplier parameters for layer property file horizontal hydraulic conductivity for model layers 1,2, and 3. For time-varying properties (e.g. recharge), the iterable is for zero-based stress period indices. For example, [“rch.rech”,[0,4,10,15]] would setup constant (uniform) multiplier parameters for recharge for stress period 1,5,11,and 16.

  • temporal_list_props ([[str,[int]]]) – list-type input stress-period level multiplier parameters. A nested list of list-type input elements to parameterize using name, iterable pairs. The iterable is zero-based stress-period indices. For example, to setup multipliers for WEL flux and for RIV conductance, temporal_list_props = [[“wel.flux”,[0,1,2]],[“riv.cond”,None]] would setup multiplier parameters for well flux for stress periods 1,2 and 3 and would setup one single river conductance multiplier parameter that is applied to all stress periods

  • spatial_list_props ([[str,[int]]]) – list-type input for spatial multiplier parameters. A nested list of list-type elements to parameterize using names (e.g. [[“riv.cond”,0],[“wel.flux”,1] to setup up cell-based parameters for each list-type element listed. These multiplier parameters are applied across all stress periods. For this to work, there must be the same number of entries for all stress periods. If more than one list element of the same type is in a single cell, only one parameter is used to multiply all lists in the same cell.

  • grid_props ([[str,[int]]]) – grid-based (every active model cell) multiplier parameters. A nested list of grid-scale model properties to parameterize using name, iterable pairs. For 3D properties, the iterable is zero-based layer indices (e.g., [“lpf.hk”,[0,1,2,]] would setup a multiplier parameter for layer property file horizontal hydraulic conductivity for model layers 1,2, and 3 in every active model cell). For time-varying properties (e.g. recharge), the iterable is for zero-based stress period indices. For example, [“rch.rech”,[0,4,10,15]] would setup grid-based multiplier parameters in every active model cell for recharge for stress period 1,5,11,and 16.

  • sfr_pars (bool) – setup parameters for the stream flow routing modflow package. If list is passed it defines the parameters to set up.

  • sfr_temporal_pars (bool) – flag to include stress-period level spatially-global multipler parameters in addition to the spatially-discrete sfr_pars. Requires sfr_pars to be passed. Default is False

  • grid_geostruct (pyemu.geostats.GeoStruct) – the geostatistical structure to build the prior parameter covariance matrix elements for grid-based parameters. If None, a generic GeoStruct is created using an “a” parameter that is 10 times the max cell size. Default is None

  • pp_space (int) – number of grid cells between pilot points. If None, use the default in pyemu.pp_utils.setup_pilot_points_grid. Default is None

  • zone_props ([[str,[int]]]) – zone-based multiplier parameters. A nested list of zone-based model properties to parameterize using name, iterable pairs. For 3D properties, the iterable is zero-based layer indices (e.g., [“lpf.hk”,[0,1,2,]] would setup a multiplier parameter for layer property file horizontal hydraulic conductivity for model layers 1,2, and 3 for unique zone values in the ibound array. For time-varying properties (e.g. recharge), the iterable is for zero-based stress period indices. For example, [“rch.rech”,[0,4,10,15]] would setup zone-based multiplier parameters for recharge for stress period 1,5,11,and 16.

  • pp_geostruct (pyemu.geostats.GeoStruct) – the geostatistical structure to use for building the prior parameter covariance matrix for pilot point parameters. If None, a generic GeoStruct is created using pp_space and grid-spacing information. Default is None

  • par_bounds_dict (dict) – a dictionary of model property/boundary condition name, upper-lower bound pairs. For example, par_bounds_dict = {“hk”:[0.01,100.0],”flux”:[0.5,2.0]} would set the bounds for horizontal hydraulic conductivity to 0.001 and 100.0 and set the bounds for flux parameters to 0.5 and 2.0. For parameters not found in par_bounds_dict, pyemu.helpers.wildass_guess_par_bounds_dict is used to set somewhat meaningful bounds. Default is None

  • temporal_list_geostruct (pyemu.geostats.GeoStruct) – the geostastical struture to build the prior parameter covariance matrix for time-varying list-type multiplier parameters. This GeoStruct express the time correlation so that the ‘a’ parameter is the length of time that boundary condition multiplier parameters are correlated across. If None, then a generic GeoStruct is created that uses an ‘a’ parameter of 3 stress periods. Default is None

  • spatial_list_geostruct (pyemu.geostats.GeoStruct) – the geostastical struture to build the prior parameter covariance matrix for spatially-varying list-type multiplier parameters. If None, a generic GeoStruct is created using an “a” parameter that is 10 times the max cell size. Default is None.

  • remove_existing (bool) – a flag to remove an existing new_model_ws directory. If False and new_model_ws exists, an exception is raised. If True and new_model_ws exists, the directory is destroyed - user beware! Default is False.

  • k_zone_dict (dict) – a dictionary of zero-based layer index, zone array pairs. e.g. {lay: np.2darray} Used to override using ibound zones for zone-based parameterization. If None, use ibound values greater than zero as zones. Alternatively a dictionary of dictionaries can be passed to allow different zones to be defined for different parameters. e.g. {“upw.hk” {lay: np.2darray}, “extra.rc11” {lay: np.2darray}} or {“hk” {lay: np.2darray}, “rc11” {lay: np.2darray}}

  • use_pp_zones (bool) – a flag to use ibound zones (or k_zone_dict, see above) as pilot point zones. If False, ibound values greater than zero are treated as a single zone for pilot points. Default is False

  • ([[str (external_ins_out_pairs) – a list of observed-simulated PEST-type SMP file pairs to get observations from and include in the control file. Default is []

  • str]] – a list of observed-simulated PEST-type SMP file pairs to get observations from and include in the control file. Default is []

  • ([[str – a list of existing template file, model input file pairs to parse parameters from and include in the control file. Default is []

  • str]] – a list of existing template file, model input file pairs to parse parameters from and include in the control file. Default is []

  • ([[str – a list of existing instruction file, model output file pairs to parse observations from and include in the control file. Default is []

  • str]] – a list of existing instruction file, model output file pairs to parse observations from and include in the control file. Default is []

  • extra_pre_cmds ([str]) – a list of preprocessing commands to add to the forward_run.py script commands are executed with os.system() within forward_run.py. Default is None.

  • redirect_forward_output (bool) – flag for whether to redirect forward model output to text files (True) or allow model output to be directed to the screen (False). Default is True

  • extra_post_cmds ([str]) – a list of post-processing commands to add to the forward_run.py script. Commands are executed with os.system() within forward_run.py. Default is None.

  • tmp_files ([str]) – a list of temporary files that should be removed at the start of the forward run script. Default is [].

  • model_exe_name (str) – binary name to run modflow. If None, a default from flopy is used, which is dangerous because of the non-standard binary names (e.g. MODFLOW-NWT_x64, MODFLOWNWT, mfnwt, etc). Default is None.

  • build_prior (bool) – flag to build prior covariance matrix. Default is True

  • sfr_obs (bool) – flag to include observations of flow and aquifer exchange from the sfr ASCII output file

  • hfb_pars (bool) – add HFB parameters. uses pyemu.gw_utils.write_hfb_template(). the resulting HFB pars have parval1 equal to the values in the original file and use the spatial_list_geostruct to build geostatistical covariates between parameters

  • kl_props ([[str,[int]]]) – karhunen-loeve based multiplier parameters. A nested list of KL-based model properties to parameterize using name, iterable pairs. For 3D properties, the iterable is zero-based layer indices (e.g., [“lpf.hk”,[0,1,2,]] would setup a multiplier parameter for layer property file horizontal hydraulic conductivity for model layers 1,2, and 3 for unique zone values in the ibound array. For time-varying properties (e.g. recharge), the iterable is for zero-based stress period indices. For example, [“rch.rech”,[0,4,10,15]] would setup zone-based multiplier parameters for recharge for stress period 1,5,11,and 16.

  • kl_num_eig (int) – the number of KL-based eigenvector multiplier parameters to use for each KL parameter set. default is 100

  • kl_geostruct (pyemu.geostats.Geostruct) – the geostatistical structure to build the prior parameter covariance matrix elements for KL-based parameters. If None, a generic GeoStruct is created using an “a” parameter that is 10 times the max cell size. Default is None

Note

Setup up multiplier parameters for an existing MODFLOW model.

Does all kinds of coolness like building a meaningful prior, assigning somewhat meaningful parameter groups and bounds, writes a forward_run.py script with all the calls need to implement multiplier parameters, run MODFLOW and post-process.

While this class does work, the newer PstFrom class is a more pythonic implementation

_setup_sfr_obs()

setup sfr ASCII observations

_setup_sfr_pars(par_cols=None, include_temporal_pars=None)

setup multiplier parameters for sfr segment data Adding support for reachinput (and isfropt = 1)

_setup_hfb_pars()

setup non-mult parameters for hfb (yuck!)

_setup_mult_dirs()

setup the directories to use for multiplier parameterization. Directories are make within the PstFromFlopyModel.m.model_ws directory

_setup_model(model, org_model_ws, new_model_ws)

setup the flopy.mbase instance for use with multipler parameters. Changes model_ws, sets external_path and writes new MODFLOW input files

_get_count(name)

get the latest counter for a certain parameter type.

_prep_mlt_arrays()

prepare multipler arrays. Copies existing model input arrays and writes generic (ones) multiplier arrays

_write_u2d(u2d)

write a flopy.utils.Util2D instance to an ASCII text file using the Util2D filename

_write_const_tpl(name, tpl_file, zn_array)

write a template file a for a constant (uniform) multiplier parameter

_write_grid_tpl(name, tpl_file, zn_array)

write a template file a for grid-based multiplier parameters

_grid_prep()

prepare grid-based parameterizations

_pp_prep(mlt_df)

prepare pilot point based parameterization

_kl_prep(mlt_df)

prepare KL based parameterizations

_setup_array_pars()

main entry point for setting up array multipler parameters

_setup_observations()

main entry point for setting up observations

draw(num_reals=100, sigma_range=6, use_specsim=False, scale_offset=True)

draw from the geostatistically-implied parameter covariance matrix

Parameters:
  • num_reals (int) – number of realizations to generate. Default is 100

  • sigma_range (float) – number of standard deviations represented by the parameter bounds. Default is 6.

  • use_specsim (bool) – flag to use spectral simulation for grid-based parameters. Requires a regular grid but is wicked fast. Default is False

  • scale_offset (bool, optional) – flag to apply scale and offset to parameter bounds when calculating variances - this is passed through to pyemu.Cov.from_parameter_data. Default is True.

Note

operates on parameters by groups to avoid having to construct a very large covariance matrix for problems with more the 30K parameters.

uses helpers.geostatitical_draw()

Returns:

The realized parameter ensemble

Return type:

pyemu.ParameterEnsemble

build_prior(fmt='ascii', filename=None, droptol=None, chunk=None, sigma_range=6)

build and optionally save the prior parameter covariance matrix.

Parameters:
  • fmt (str, optional) – the format to save the cov matrix. Options are “ascii”,”binary”,”uncfile”, “coo”. Default is “ascii”. If “none” (lower case string, not None), then no file is created.

  • filename (str, optional) – the filename to save the prior cov matrix to. If None, the name is formed using model nam_file name. Default is None.

  • droptol (float, optional) – tolerance for dropping near-zero values when writing compressed binary. Default is None.

  • chunk (int, optional) – chunk size to write in a single pass - for binary only. Default is None (no chunking).

  • sigma_range (float) – number of standard deviations represented by the parameter bounds. Default is 6.

Returns:

the full prior parameter covariance matrix, generated by processing parameters by groups

Return type:

pyemu.Cov

build_pst(filename=None)

build the pest control file using the parameters and observations.

Parameters:

filename (str) – the filename to save the contorl file to. If None, the name if formed from the model namfile name. Default is None. The control is saved in the PstFromFlopy.m.model_ws directory.

Note

calls pyemu.Pst.from_io_files

calls PESTCHEK

_add_external()

add external (existing) template files and/or instruction files to the Pst instance

write_forward_run()

write the forward run script forward_run.py

Note

This method can be called repeatedly, especially after any changed to the pre- and/or post-processing routines.

_parse_k(k, vals)

parse the iterable from a property or boundary condition argument

_parse_pakattr(pakattr)

parse package-iterable pairs from a property or boundary condition argument

_setup_list_pars()

main entry point for setting up list multiplier parameters

_setup_temporal_list_pars()
_setup_spatial_list_pars()
_list_helper(k, pak, attr, col)

helper to setup list multiplier parameters for a given k, pak, attr set.

_setup_hds()

setup modflow head save file observations for given kper (zero-based stress period index) and k (zero-based layer index) pairs using the kperk argument.

_setup_smp()

setup observations from PEST-style SMP file pairs

_setup_hob()

setup observations from the MODFLOW HOB package

_setup_hyd()

setup observations from the MODFLOW HYDMOD package

_setup_water_budget_obs()

setup observations from the MODFLOW list file for volume and flux water buget information