pyemu.utils.geostats
Geostatistics in the PEST(++) realm
Module Contents
Classes
a geostatistical structure object that mimics the behavior of a PEST |
|
2-D unconditional spectral simulation for regular grids |
|
Ordinary Kriging using Pandas and Numpy. |
|
base class for 2-D variograms. |
|
Exponential variogram derived type |
|
Gaussian variogram derived type |
|
Spherical variogram derived type |
Functions
|
read an existing PEST-type structure file into a GeoStruct instance |
Function to instantiate a Vario2d from a PEST-style structure file |
|
function to read information from a PEST-style structure file |
|
|
function to read an SGEMS-type variogram XML file into |
|
function to read a GSLIB point data file into a pandas.DataFrame |
|
read an SGEM experimental variogram into a sequence of |
|
A python replication of the PEST fac2real utility for creating a |
|
function to parse a factor file line. Used by fac2real() |
Attributes
- pyemu.utils.geostats.EPSILON = 1e-07
- class pyemu.utils.geostats.GeoStruct(nugget=0.0, variograms=[], name='struct1', transform='none')
Bases:
object
a geostatistical structure object that mimics the behavior of a PEST geostatistical structure. The object contains variogram instances and (optionally) nugget information.
- Parameters:
nugget (float (optional)) – nugget contribution. Default is 0.0
variograms – ([pyemu.Vario2d] (optional)): variogram(s) associated with this GeoStruct instance. Default is empty list
name (str (optional)) – name to assign the structure. Default is “struct1”.
transform (str (optional)) – the transformation to apply to the GeoStruct. Can be “none” or “log”, depending on the transformation of the property being represented by the GeoStruct. Default is “none”
Example:
v = pyemu.utils.geostats.ExpVario(a=1000,contribution=1.0) gs = pyemu.utils.geostats.GeoStruct(variograms=v,nugget=0.5) gs.plot() # get a covariance matrix implied by the geostruct for three points px = [0,1000,2000] py = [0,0,0] pnames ["p1","p2","p3"] cov = gs.covariance_matrix(px,py,names=pnames)
- property sill
get the sill of the GeoStruct
- Returns:
the sill of the (nested) GeoStruct, including nugget and contribution from each variogram
- Return type:
float
- nugget
the nugget effect contribution
- Type:
float
- variograms
a list of variogram instances
- Type:
[pyemu.utils.geostats.Vario2d]
- transform
the transformation of the GeoStruct. Can be ‘log’ or ‘none’
- Type:
str
- __lt__(other)
Return self<value.
- __gt__(other)
Return self>value.
- same_as_other(other)
compared to geostructs for similar attributes
- Parameters:
other (pyemu.geostats.Geostruct) – the other one
- Returns:
True is the other and self have the same characteristics
- Return type:
same (bool)
- to_struct_file(f)
write a PEST-style structure file
- Parameters:
f (str) – file to write the GeoStruct information in to. Can also be an open file handle
- covariance_matrix(x, y, names=None, cov=None)
build a pyemu.Cov instance from GeoStruct
- Parameters:
x ([floats]) – x-coordinate locations
y ([float]) – y-coordinate locations
names ([str] (optional)) – names of location. If None, cov must not be None. Default is None.
cov (pyemu.Cov) – an existing Cov instance. The contribution of this GeoStruct is added to cov. If cov is None, names must not be None. Default is None
- Returns:
the covariance matrix implied by this GeoStruct for the x,y pairs. cov has row and column names supplied by the names argument unless the “cov” argument was passed.
- Return type:
pyemu.Cov
Note
either “names” or “cov” must be passed. If “cov” is passed, cov.shape must equal len(x) and len(y).
Example:
pp_df = pyemu.pp_utils.pp_file_to_dataframe("hkpp.dat") cov = gs.covariance_matrix(pp_df.x,pp_df.y,pp_df.name) cov.to_binary("cov.jcb")
- covariance(pt0, pt1)
get the covariance between two points implied by the GeoStruct. This is used during the ordinary kriging process to get the RHS
- Parameters:
pt0 ([float]) – xy-pair
pt1 ([float]) – xy-pair
- Returns:
the covariance between pt0 and pt1 implied by the GeoStruct
- Return type:
float
Example:
p1 = [0,0] p2 = [1,1] v = pyemu.geostats.ExpVario(a=0.1,contribution=1.0) gs = pyemu.geostats.Geostruct(variograms=v) c = gs.covariance(p1,p2)
- covariance_points(x0, y0, xother, yother)
Get the covariance between point (x0,y0) and the points contained in xother, yother.
- Parameters:
x0 (float) – x-coordinate
y0 (float) – y-coordinate
xother ([float]) – x-coordinates of other points
yother ([float]) – y-coordinates of other points
- Returns:
a 1-D array of covariance between point x0,y0 and the points contained in xother, yother. len(cov) = len(xother) = len(yother)
- Return type:
numpy.ndarray
Example:
x0,y0 = 1,1 xother = [2,3,4,5] yother = [2,3,4,5] v = pyemu.geostats.ExpVario(a=0.1,contribution=1.0) gs = pyemu.geostats.Geostruct(variograms=v) c = gs.covariance_points(x0,y0,xother,yother)
- plot(**kwargs)
make a cheap plot of the GeoStruct
- Parameters:
**kwargs – (dict) keyword arguments to use for plotting.
- Returns:
the axis with the GeoStruct plot
- Return type:
matplotlib.pyplot.axis
Note
optional arguments include “ax” (an existing axis), “individuals” (plot each variogram on a separate axis), “legend” (add a legend to the plot(s)). All other kwargs are passed to matplotlib.pyplot.plot()
Example:
v = pyemu.geostats.ExpVario(a=0.1,contribution=1.0) gs = pyemu.geostats.Geostruct(variograms=v) gs.plot()
- __str__()
the str representation of the GeoStruct
- Returns:
the string representation of the GeoStruct
- Return type:
str
- class pyemu.utils.geostats.SpecSim2d(delx, dely, geostruct)
Bases:
object
2-D unconditional spectral simulation for regular grids
- Parameters:
delx (numpy.ndarray) – a 1-D array of x-dimension cell centers (or leading/trailing edges). Only the distance between points is important
dely (numpy.ndarray) – a 1-D array of y-dimension cell centers (or leading/trailing edges). Only the distance between points is important
geostruct (pyemu.geostats.Geostruct) – geostatistical structure instance
Example:
v = pyemu.utils.geostats.ExpVario(a=100,contribution=1.0) gs = pyemu.utils.geostats.GeoStruct(variograms=v,nugget=0.5) delx,dely = np.ones(150), np.ones(50) ss = pyemu.utils.geostats.SpecSim2d(delx,dely,gs) arr = np.squeeze(ss.draw_arrays(num_reals=1))*.05 + .08 plt.imshow(arr) plt.colorbar(shrink=.40)
- static grid_is_regular(delx, dely, tol=0.0001)
check that a grid is regular using delx and dely vectors
- Parameters:
delx – numpy.ndarray a 1-D array of x-dimension cell centers (or leading/trailing edges). Only the distance between points is important
dely – numpy.ndarray a 1-D array of y-dimension cell centers (or leading/trailing edges). Only the distance between points is important
tol – float (optional) tolerance to determine grid regularity. Default is 1.0e-4
- Returns:
flag indicating if the grid defined by delx and dely is regular
- Return type:
bool
- initialize()
prepare for spectral simulation.
Note
initialize() prepares for simulation by undertaking the fast FFT on the wave number matrix and should be called if the SpecSim2d.geostruct is changed. This method is called by the constructor.
- draw_arrays(num_reals=1, mean_value=1.0)
draw realizations
- Parameters:
num_reals (int) – number of realizations to generate
mean_value (float) – the mean value of the realizations
- Returns:
a 3-D array of realizations. Shape is (num_reals,self.dely.shape[0],self.delx.shape[0])
- Return type:
numpy.ndarray
Note
log transformation is respected and the returned reals array is in linear space
- grid_par_ensemble_helper(pst, gr_df, num_reals, sigma_range=6, logger=None)
wrapper around SpecSim2d.draw() designed to support PstFromFlopy and PstFrom grid-based parameters
- Parameters:
pst (pyemu.Pst) – a control file instance
gr_df (pandas.DataFrame) – a dataframe listing parval1, pargp, i, j for each grid based parameter
num_reals (int) – number of realizations to generate
sigma_range (float (optional)) – number of standard deviations implied by parameter bounds in control file. Default is 6
logger (pyemu.Logger (optional)) – a logger instance for logging
- Returns:
an untransformed parameter ensemble of realized grid-parameter values
- Return type:
pyemu.ParameterEnsemble
Note
the method processes each unique pargp value in gr_df and resets the sill of self.geostruct by the maximum bounds-implied variance of each pargp. This method makes repeated calls to self.initialize() to deal with the geostruct changes.
- draw_conditional(seed, obs_points, sg, base_values_file, local=True, factors_file=None, num_reals=1, mean_value=1.0, R_factor=1.0)
- Generate a conditional, correlated random field using the Spec2dSim
object, a set of observation points, and a factors file.
The conditional field is made by generating an unconditional correlated random field that captures the covariance in the variogram and conditioning it by kriging a second surface using the value of the random field as observations. This second conditioning surface provides an estimate of uncertainty (kriging error) away from the observation points. At the observation points, the kriged surface is equal to (less nugget effects) the observation. The conditioned correlated field is then generated using: T(x) = Z(x) + [S(x) − S∗(x)] where T(x) is the conditioned simulation, Z(x) is a kriging estimator of the unknown field, S(x) is an unconditioned random field with the same covariance structure as the desired field, and S∗(x) is a kriging estimate of the unconditioned random field using its values at the observation points (pilot points). [S(x) − S∗(x)] is an estimate of the kriging error.
This approach makes T(x) match the observed values at the observation points (x_a, y_z), T(a) = Z(a), and have a structure away from the observation points that follows the variogram used to generate Z, S, and S∗.
- Chiles, J-P, and Delfiner, P., Geostatistics- Modeling Spatial Uncertainty: Wiley,
London, 695 p.
- Parameters:
seed (int) – integer used for random seed. If seed is used as a PEST parameter, then passing the same value for seed will yield the same conditioned random fields. This allows runs to be recreated given an ensemble of seeds.
obs_points (str or dataframe) – locations for observation points. Either filename in pyemupilot point file format: [“name”,”x”,”y”,”zone”,”parval1”] ora dataframe with these columns. Note that parval1 is not used.
base_values_file (str) – filename containing 2d array with the base parameter values from which the random field will depart (Z(x)) above. Values of Z(x) are used for conditioning, not parval1 in the observation point file.
factors_file (str) – name of the factors file generated using the locations of the observation points and the target grid. If None this file will be generated and called conditional_factors.dat; but this is a slow step and should not generally be called for every simulation.
sg – flopy StructuredGrid object
local (boolean) – whether coordinates in obs_points are in local (model) or map coordinates
num_reals (int) – number of realizations to generate
mean_value (float) – the mean value of the realizations
R_factor (float) – a factor to scale the field, sometimes the variation from the geostruct parameters is larger or smaller than desired.
- Returns:
- a 3-D array of realizations. Shape is
(num_reals, self.dely.shape[0], self.delx.shape[0])
- Return type:
numpy.ndarray
Note
- log transformation is respected and the returned reals
array is in arithmetic space
- class pyemu.utils.geostats.OrdinaryKrige(geostruct, point_data)
Bases:
object
Ordinary Kriging using Pandas and Numpy.
- Parameters:
geostruct (GeoStruct) – a pyemu.geostats.GeoStruct to use for the kriging
point_data (pandas.DataFrame) – the conditioning points to use for kriging. point_data must contain columns “name”, “x”, “y”.
Note
if point_data is an str, then it is assumed to be a pilot points file and is loaded as such using pyemu.pp_utils.pp_file_to_dataframe()
If zoned interpolation is used for grid-based interpolation, then point_data must also contain a “zone” column
Example:
import pyemu v = pyemu.utils.geostats.ExpVario(a=1000,contribution=1.0) gs = pyemu.utils.geostats.GeoStruct(variograms=v,nugget=0.5) pp_df = pyemu.pp_utils.pp_file_to_dataframe("hkpp.dat") ok = pyemu.utils.geostats.OrdinaryKrige(gs,pp_df)
- check_point_data_dist(rectify=False)
check for point_data entries that are closer than EPSILON distance - this will cause a singular kriging matrix.
- Parameters:
rectify (bool) – flag to fix the problems with point_data by dropping additional points that are closer than EPSILON distance. Default is False
Note
this method will issue warnings for points that are closer than EPSILON distance
- calc_factors_grid(spatial_reference, zone_array=None, minpts_interp=1, maxpts_interp=20, search_radius=10000000000.0, verbose=False, var_filename=None, forgive=False, num_threads=1)
calculate kriging factors (weights) for a structured grid.
- Parameters:
spatial_reference (flopy.utils.reference.SpatialReference) – a spatial reference that describes the orientation and spatail projection of the the structured grid
zone_array (numpy.ndarray) – an integer array of zones to use for kriging. If not None, then point_data must also contain a “zone” column. point_data entries with a zone value not found in zone_array will be skipped. If None, then all point_data will (potentially) be used for interpolating each grid node. Default is None
minpts_interp (int) – minimum number of point_data entires to use for interpolation at a given grid node. grid nodes with less than minpts_interp point_data found will be skipped (assigned np.NaN). Defaut is 1
maxpts_interp (int) – a given grid node. A larger maxpts_interp will yield “smoother” interplation, but using a large maxpts_interp will slow the (already) slow kriging solution process and may lead to memory errors. Default is 20.
search_radius (float) – point_data entries. Default is 1.0e+10
verbose – (bool): a flag to echo process to stdout during the interpolatino process. Default is False
var_filename (str) – a filename to save the kriging variance for each interpolated grid node. Default is None.
forgive (bool) – flag to continue if inversion of the kriging matrix failes at one or more grid nodes. Inversion usually fails if the kriging matrix is singular, resulting from point_data entries closer than EPSILON distance. If True, warnings are issued for each failed inversion. If False, an exception is raised for failed matrix inversion.
num_threads (int) – number of multiprocessing workers to use to try to speed up kriging in python. Default is 1.
- Returns:
a dataframe with information summarizing the ordinary kriging process for each grid node
- Return type:
pandas.DataFrame
Note
this method calls OrdinaryKrige.calc_factors() this method is the main entry point for grid-based kriging factor generation
Example:
import flopy v = pyemu.utils.geostats.ExpVario(a=1000,contribution=1.0) gs = pyemu.utils.geostats.GeoStruct(variograms=v,nugget=0.5) pp_df = pyemu.pp_utils.pp_file_to_dataframe("hkpp.dat") ok = pyemu.utils.geostats.OrdinaryKrige(gs,pp_df) m = flopy.modflow.Modflow.load("mymodel.nam") df = ok.calc_factors_grid(m.sr,zone_array=m.bas6.ibound[0].array, var_filename="ok_var.dat") ok.to_grid_factor_file("factors.dat")
- _dist_calcs(ix, iy, ptx_array, pty_array, ptnames, sqradius)
private: find nearby points
- _remove_neg_factors()
private function to remove negative kriging factors and renormalize remaining positive factors following the method of Deutsch (1996): https://doi.org/10.1016/0098-3004(96)00005-2
- _cov_points(ix, iy, pt_names)
private: get covariance between points
- _form(pt_names, point_cov, interp_cov)
private: form the kriging equations
- _solve(A, rhs)
- calc_factors(x, y, minpts_interp=1, maxpts_interp=20, search_radius=10000000000.0, verbose=False, pt_zone=None, forgive=False, num_threads=1, idx_vals=None, remove_negative_factors=True)
calculate ordinary kriging factors (weights) for the points represented by arguments x and y
- Parameters:
x ([float]) – x-coordinates to calculate kriging factors for
y (([float]) – y-coordinates to calculate kriging factors for
minpts_interp (int) – minimum number of point_data entires to use for interpolation at a given x,y interplation point. interpolation points with less than minpts_interp point_data found will be skipped (assigned np.NaN). Defaut is 1
maxpts_interp (int) – maximum number of point_data entries to use for interpolation at a given x,y interpolation point. A larger maxpts_interp will yield “smoother” interplation, but using a large maxpts_interp will slow the (already) slow kriging solution process and may lead to memory errors. Default is 20.
search_radius (float) – the size of the region around a given x,y interpolation point to search for point_data entries. Default is 1.0e+10
verbose (bool) – a flag to echo process to stdout during the interpolatino process. Default is False
forgive (bool) – flag to continue if inversion of the kriging matrix failes at one or more interpolation points. Inversion usually fails if the kriging matrix is singular, resulting from point_data entries closer than EPSILON distance. If True, warnings are issued for each failed inversion. If False, an exception is raised for failed matrix inversion.
num_threads (int) – number of multiprocessing workers to use to try to speed up kriging in python. Default is 1.
idx_vals (iterable of int) – optional index values to use in the interpolation dataframe. This is used to set the proper node number in the factors file for unstructured grids.
remove_negative_factors (bool) – option to remove negative Kriging factors, following the method of Deutsch (1996) https://doi.org/10.1016/0098-3004(96)00005-2. Default is True
- Returns:
a dataframe with information summarizing the ordinary kriging process for each interpolation points
- Return type:
pandas.DataFrame
Note
this method calls either OrdinaryKrige.calc_factors_org() or OrdinaryKrige.calc_factors_mp() depending on the value of num_threads
Example:
v = pyemu.utils.geostats.ExpVario(a=1000,contribution=1.0) gs = pyemu.utils.geostats.GeoStruct(variograms=v,nugget=0.5) pp_df = pyemu.pp_utils.pp_file_to_dataframe("hkpp.dat") ok = pyemu.utils.geostats.OrdinaryKrige(gs,pp_df) x = np.arange(100) y = np.ones_like(x) zone_array = y.copy() zone_array[:zone_array.shape[0]/2] = 2 # only calc factors for the points in zone 1 ok.calc_factors(x,y,pt_zone=1) ok.to_grid_factors_file("zone_1.fac",ncol=x.shape[0])
- _calc_factors_org(df, ptx_array, pty_array, ptnames, minpts_interp=1, maxpts_interp=20, search_radius=10000000000.0, verbose=False, pt_zone=None, forgive=False, remove_negative_factors=True)
- _calc_factors_mp(df, ptx_array, pty_array, ptnames, minpts_interp=1, maxpts_interp=20, search_radius=10000000000.0, verbose=False, pt_zone=None, forgive=False, num_threads=1, remove_negative_factors=True)
- static _worker(ptx_array, pty_array, ptnames, point_pairs, inames, idist, ifacts, err_var, full_point_cov, geostruct, epsilon, sqradius, minpts_interp, maxpts_interp, lock)
- to_grid_factors_file(filename, points_file='points.junk', zone_file='zone.junk', ncol=None)
write a PEST-style factors file. This file can be used with the fac2real() method to write an interpolated structured or unstructured array
- Parameters:
filename (str) – factor filename
points_file (str) – points filename to add to the header of the factors file. This is not used by the fac2real() method. Default is “points.junk”
zone_file (str) – zone filename to add to the header of the factors file. This is not used by the fac2real() method. Default is “zone.junk”
ncol (int) – from the spatial reference and should only be passed for unstructured grids - it should be equal to the number of nodes in the current property file. Default is None. Required for unstructured grid models.
Note
this method should be called after OrdinaryKrige.calc_factors_grid() for structured models or after OrdinaryKrige.calc_factors() for unstructured models.
- class pyemu.utils.geostats.Vario2d(contribution, a, anisotropy=1.0, bearing=0.0, name='var1')
Bases:
object
base class for 2-D variograms.
- Parameters:
contribution (float) – sill of the variogram
a (float) – (practical) range of correlation
anisotropy (float, optional) – Anisotropy ratio. Default is 1.0
bearing – (float, optional): angle in degrees East of North corresponding to anisotropy ellipse. Default is 0.0
name (str, optinoal) – name of the variogram. Default is “var1”
Note
This base class should not be instantiated directly as it does not implement an h_function() method.
- property bearing_rads
get the bearing of the Vario2d in radians
- Returns:
the Vario2d bearing in radians
- Return type:
float
- property rotation_coefs
get the rotation coefficents in radians
- Returns:
the rotation coefficients implied by Vario2d.bearing
- Return type:
[float]
- same_as_other(other)
- to_struct_file(f)
write the Vario2d to a PEST-style structure file
- Parameters:
f (str) – filename to write to. f can also be an open file handle.
- inv_h(h)
the inverse of the h_function. Used for plotting
- Parameters:
h (float) – the value of h_function to invert
- Returns:
the inverse of h
- Return type:
float
- plot(**kwargs)
get a cheap plot of the Vario2d
- Parameters:
**kwargs (dict) – keyword arguments to use for plotting
- Returns:
matplotlib.pyplot.axis
Note
optional arguments in kwargs include “ax” (existing matplotlib.pyplot.axis). Other kwargs are passed to matplotlib.pyplot.plot()
- covariance_matrix(x, y, names=None, cov=None)
build a pyemu.Cov instance implied by Vario2d
- Parameters:
x ([float]) – x-coordinate locations
y ([float]) – y-coordinate locations
names ([str]) – names of locations. If None, cov must not be None
cov (pyemu.Cov) – an existing Cov instance. Vario2d contribution is added to cov
place (in) –
- Returns:
the covariance matrix for x, y implied by Vario2d
- Return type:
pyemu.Cov
Note
either names or cov must not be None.
- _specsim_grid_contrib(grid)
- _apply_rotation(dx, dy)
private method to rotate points according to Vario2d.bearing and Vario2d.anisotropy
- covariance_points(x0, y0, xother, yother)
get the covariance between base point (x0,y0) and other points xother,yother implied by Vario2d
- Parameters:
x0 (float) – x-coordinate
y0 (float) – y-coordinate
xother ([float]) – x-coordinates of other points
yother ([float]) – y-coordinates of other points
- Returns:
a 1-D array of covariance between point x0,y0 and the points contained in xother, yother. len(cov) = len(xother) = len(yother)
- Return type:
numpy.ndarray
- covariance(pt0, pt1)
get the covarince between two points implied by Vario2d
- Parameters:
pt0 – ([float]): first point x and y
pt1 – ([float]): second point x and y
- Returns:
covariance between pt0 and pt1
- Return type:
float
- __str__()
get the str representation of Vario2d
- Returns:
string rep
- Return type:
str
- class pyemu.utils.geostats.ExpVario(contribution, a, anisotropy=1.0, bearing=0.0, name='var1')
Bases:
Vario2d
Exponential variogram derived type
- Parameters:
contribution (float) – sill of the variogram
a (float) – (practical) range of correlation
anisotropy (float, optional) – Anisotropy ratio. Default is 1.0
bearing – (float, optional): angle in degrees East of North corresponding to anisotropy ellipse. Default is 0.0
name (str, optinoal) – name of the variogram. Default is “var1”
Example:
v = pyemu.utils.geostats.ExpVario(a=1000,contribution=1.0)
- _h_function(h)
private method exponential variogram “h” function
- class pyemu.utils.geostats.GauVario(contribution, a, anisotropy=1.0, bearing=0.0, name='var1')
Bases:
Vario2d
Gaussian variogram derived type
- Parameters:
contribution (float) – sill of the variogram
a (float) – (practical) range of correlation
anisotropy (float, optional) – Anisotropy ratio. Default is 1.0
bearing – (float, optional): angle in degrees East of North corresponding to anisotropy ellipse. Default is 0.0
name (str, optinoal) – name of the variogram. Default is “var1”
Example:
v = pyemu.utils.geostats.GauVario(a=1000,contribution=1.0)
Note
the Gaussian variogram can be unstable (not invertible) for long ranges.
- _h_function(h)
private method for the gaussian variogram “h” function
- class pyemu.utils.geostats.SphVario(contribution, a, anisotropy=1.0, bearing=0.0, name='var1')
Bases:
Vario2d
Spherical variogram derived type
- Parameters:
contribution (float) – sill of the variogram
a (float) – (practical) range of correlation
anisotropy (float, optional) – Anisotropy ratio. Default is 1.0
bearing – (float, optional): angle in degrees East of North corresponding to anisotropy ellipse. Default is 0.0
name – name of the variogram. Default is “var1”
- _h_function(h)
private method for the spherical variogram “h” function
- pyemu.utils.geostats.read_struct_file(struct_file, return_type=GeoStruct)
read an existing PEST-type structure file into a GeoStruct instance
- Parameters:
struct_file (str) – existing pest-type structure file
return_type (object) – the instance type to return. Default is GeoStruct
- Returns:
list of GeoStruct instances. If only one GeoStruct is in the file, then a GeoStruct is returned
- Return type:
[pyemu.GeoStruct]
Example:
gs = pyemu.utils.geostats.reads_struct_file("struct.dat")
- pyemu.utils.geostats._read_variogram(f)
Function to instantiate a Vario2d from a PEST-style structure file
- pyemu.utils.geostats._read_structure_attributes(f)
function to read information from a PEST-style structure file
- pyemu.utils.geostats.read_sgems_variogram_xml(xml_file, return_type=GeoStruct)
function to read an SGEMS-type variogram XML file into a GeoStruct
- Parameters:
xml_file (str) – SGEMS variogram XML file
return_type (object) – the instance type to return. Default is GeoStruct
- Returns:
GeoStruct
- Return type:
gs
Example:
gs = pyemu.utils.geostats.read_sgems_variogram_xml("sgems.xml")
- pyemu.utils.geostats.gslib_2_dataframe(filename, attr_name=None, x_idx=0, y_idx=1)
function to read a GSLIB point data file into a pandas.DataFrame
- Parameters:
filename (str) – GSLIB file
attr_name (str) – the column name in the dataframe for the attribute. If None, GSLIB file can have only 3 columns. attr_name must be in the GSLIB file header
x_idx (int) – the index of the x-coordinate information in the GSLIB file. Default is 0 (first column)
y_idx (int) – the index of the y-coordinate information in the GSLIB file. Default is 1 (second column)
- Returns:
a dataframe of info from the GSLIB file
- Return type:
pandas.DataFrame
Note
assigns generic point names (“pt0, pt1, etc)
Example:
df = pyemu.utiils.geostats.gslib_2_dataframe("prop.gslib",attr_name="hk")
- pyemu.utils.geostats.load_sgems_exp_var(filename)
read an SGEM experimental variogram into a sequence of pandas.DataFrames
- Parameters:
filename (str) – an SGEMS experimental variogram XML file
- Returns:
a list of pandas.DataFrames of x, y, pairs for each division in the experimental variogram
- Return type:
[pandas.DataFrame]
- pyemu.utils.geostats.fac2real(pp_file=None, factors_file='factors.dat', out_file='test.ref', upper_lim=1e+30, lower_lim=-1e+30, fill_value=1e+30)
A python replication of the PEST fac2real utility for creating a structure grid array from previously calculated kriging factors (weights)
- Parameters:
pp_file (str) – PEST-type pilot points file
factors_file (str) – PEST-style factors file
out_file (str) – filename of array to write. If None, array is returned, else value of out_file is returned. Default is “test.ref”.
upper_lim (float) – maximum interpolated value in the array. Values greater than upper_lim are set to fill_value
lower_lim (float) – minimum interpolated value in the array. Values less than lower_lim are set to fill_value
fill_value (float) – the value to assign array nodes that are not interpolated
- Returns:
if out_file is None
str: if out_file it not None
- Return type:
numpy.ndarray
Example:
pyemu.utils.geostats.fac2real("hkpp.dat",out_file="hk_layer_1.ref")
- pyemu.utils.geostats._parse_factor_line(line)
function to parse a factor file line. Used by fac2real()