pyemu.utils.pp_utils

Pilot point support utilities

Module Contents

Functions

setup_pilotpoints_grid([ml, sr, ibound, prefix_dict, ...])

setup a regularly-spaced (gridded) pilot point parameterization

pp_file_to_dataframe(pp_filename)

read a pilot point file to a pandas Dataframe

pp_tpl_to_dataframe(tpl_filename)

read a pilot points template file to a pandas dataframe

pilot_points_from_shapefile(shapename)

read pilot points from shapefile into a dataframe

write_pp_shapfile(pp_df[, shapename])

write pilot points dataframe to a shapefile

write_pp_file(filename, pp_df)

write a pilot points dataframe to a pilot points file

pilot_points_to_tpl(pp_file[, tpl_file, name_prefix])

write a template file for a pilot points file

get_zoned_ppoints_for_vertexgrid(spacing, zone_array, mg)

Generate equally spaced pilot points for active area of DISV type MODFLOW6 grid.

Attributes

PP_FMT

PP_NAMES

pyemu.utils.pp_utils.PP_FMT
pyemu.utils.pp_utils.PP_NAMES = ['name', 'x', 'y', 'zone', 'parval1']
pyemu.utils.pp_utils.setup_pilotpoints_grid(ml=None, sr=None, ibound=None, prefix_dict=None, every_n_cell=4, ninst=1, use_ibound_zones=False, pp_dir='.', tpl_dir='.', shapename='pp.shp', pp_filename_dict={})

setup a regularly-spaced (gridded) pilot point parameterization

Parameters:
  • ml (flopy.mbase, optional) – a flopy mbase dervied type. If None, sr must not be None.

  • sr (flopy.utils.reference.SpatialReference, optional) – a spatial reference use to locate the model grid in space. If None, ml must not be None. Default is None

  • ibound (numpy.ndarray, optional) – the modflow ibound integer array. THis is used to set pilot points only in active areas. If None and ml is None, then pilot points are set in all rows and columns according to every_n_cell. Default is None.

  • prefix_dict (dict) – a dictionary of layer index, pilot point parameter prefix(es) pairs. For example : {0:[“hk,”vk”]} would setup pilot points with the prefix “hk” and “vk” for model layer 1. If None, a generic set of pilot points with the “pp” prefix are setup for a generic nrow by ncol grid. Default is None

  • ninst (int) – Number of instances of pilot_points to set up. e.g. number of layers. If ml is None and prefix_dict is None, this is used to set up default prefix_dict.

  • use_ibound_zones (bool) – a flag to use the greater-than-zero values in the ibound as pilot point zones. If False ,ibound values greater than zero are treated as a single zone. Default is False.

  • pp_dir (str, optional) – directory to write pilot point files to. Default is ‘.’

  • tpl_dir (str, optional) – directory to write pilot point template file to. Default is ‘.’

  • shapename (str, optional) – name of shapefile to write that contains pilot point information. Default is “pp.shp”

  • pp_filename_dict (dict) – optional dict of prefix-pp filename pairs. prefix values must match the values in prefix_dict. If None, then pp filenames are based on the key values in prefix_dict. Default is None

Returns:

a dataframe summarizing pilot point information (same information written to shapename

Return type:

pandas.DataFrame

Example:

m = flopy.modflow.Modflow.load("my.nam")
df = pyemu.pp_utils.setup_pilotpoints_grid(ml=m)
pyemu.utils.pp_utils.pp_file_to_dataframe(pp_filename)

read a pilot point file to a pandas Dataframe

Parameters:

pp_filename (str) – path and name of an existing pilot point file

Returns:

a dataframe with pp_utils.PP_NAMES for columns

Return type:

pandas.DataFrame

Example:

df = pyemu.pp_utils.pp_file_to_dataframe("my_pp.dat")
pyemu.utils.pp_utils.pp_tpl_to_dataframe(tpl_filename)

read a pilot points template file to a pandas dataframe

Parameters:

tpl_filename (str) – path and name of an existing pilot points template file

Returns:

a dataframe of pilot point info with “parnme” included

Return type:

pandas.DataFrame

Notes

Use for processing pilot points since the point point file itself may have generic “names”.

Example:

df = pyemu.pp_utils.pp_tpl_file_to_dataframe("my_pp.dat.tpl")
pyemu.utils.pp_utils.pilot_points_from_shapefile(shapename)

read pilot points from shapefile into a dataframe

Parameters:

shapename (str) – the shapefile name to read.

Notes

requires pyshp

pyemu.utils.pp_utils.write_pp_shapfile(pp_df, shapename=None)

write pilot points dataframe to a shapefile

Parameters:
  • pp_df (pandas.DataFrame) – pilot point dataframe (must include “x” and “y” columns). If pp_df is a string, it is assumed to be a pilot points file and is loaded with pp_utils.pp_file_to_dataframe. Can also be a list of pandas.DataFrames and/or filenames.

  • shapename (str) – the shapefile name to write. If None , pp_df must be a string and shapefile is saved as pp_df +”.shp”

Notes

requires pyshp

pyemu.utils.pp_utils.write_pp_file(filename, pp_df)

write a pilot points dataframe to a pilot points file

Parameters:
  • filename (str) – pilot points file to write

  • pp_df (pandas.DataFrame) – a dataframe that has at least columns “x”,”y”,”zone”, and “value”

pyemu.utils.pp_utils.pilot_points_to_tpl(pp_file, tpl_file=None, name_prefix=None)

write a template file for a pilot points file

Parameters:
  • pp_file – (str): existing pilot points file

  • tpl_file (str) – template file name to write. If None, pp_file`+”.tpl” is used. Default is `None.

  • name_prefix (str) – name to prepend to parameter names for each pilot point. For example, if name_prefix = “hk_”, then each pilot point parameters will be named “hk_0001”,”hk_0002”, etc. If None, parameter names from pp_df.name are used. Default is None.

Returns:

a dataframe with pilot point information (name,x,y,zone,parval1) with the parameter information (parnme,tpl_str)

Return type:

pandas.DataFrame

Example:

pyemu.pp_utils.pilot_points_to_tpl("my_pps.dat",name_prefix="my_pps")
pyemu.utils.pp_utils.get_zoned_ppoints_for_vertexgrid(spacing, zone_array, mg, zone_number=None, add_buffer=True)

Generate equally spaced pilot points for active area of DISV type MODFLOW6 grid.

Parameters:
  • spacing (float) – spacing in model length units between pilot points.

  • zone_array (numpy.ndarray) – the modflow 6 idomain integer array. This is used to set pilot points only in active areas and to assign zone numbers.

  • mg (flopy.discretization.vertexgrid.VertexGrid) – a VertexGrid flopy discretization dervied type.

  • zone_number (int) – zone number

  • add_buffer (boolean) – specifies whether pilot points ar eplaced wihtin a buffer zone of size distance around the zone/active domain

Returns:

a list of tuples with pilot point x and y coordinates

Return type:

list

Example:

get_zoned_ppoints_for_vertexgrid(spacing=100, ib=idomain, mg, zone_number=1, add_buffer=False)