GridProperty¶
- class petres.grids.GridProperty[source]¶
Bases:
objectRepresent a cell-based property defined on a corner-point grid.
The property stores values per cell with shape
(nk, nj, ni)and provides assignment helpers for constants, random distributions, functions, arrays, and well-based interpolation.- Parameters:
name (str) – Property name (must be unique on the grid).
grid (CornerPointGrid) – Owning grid; used for shape and masking.
values (ndarray or None, optional, default None) – Property values of shape
(nk, nj, ni). IfNone, initialized to NaN.eclipse_keyword (str or None, optional, default None) – Optional Eclipse keyword for export.
description (str or None, optional, default None) – Free-form description.
Notes
Initialization delegates validation and normalization to
__post_init__().Initialize the property and run post-initialization validation.
- Raises:
TypeError – If
nameoreclipse_keywordhas an invalid type.ValueError – If
nameis empty,valuesshape mismatches the grid, oreclipse_keywordresolves to an empty keyword.
- __init__(name, grid, values=None, eclipse_keyword=None, description=None)[source]¶
Initialize the property and run post-initialization validation.
- Raises:
TypeError – If
nameoreclipse_keywordhas an invalid type.ValueError – If
nameis empty,valuesshape mismatches the grid, oreclipse_keywordresolves to an empty keyword.
- grid: CornerPointGrid¶
- __post_init__()[source]¶
Validate and normalize property initialization inputs.
- Raises:
TypeError – If
nameis not a string oreclipse_keywordhas invalid type.ValueError – If
nameis empty,valuesshape mismatches grid shape, oreclipse_keywordresolves to an empty keyword.
- show(*, show_inactive=False, cmap='petres', title='auto', z_scale=1.0, wells=None, **kwargs)[source]¶
Visualize the property in 3D using the grid viewer.
- Parameters:
show_inactive (bool, default False) – Whether to display inactive cells.
cmap (str or None, default DEFAULT_CMAP) – Colormap used for rendering.
title (str or 'auto', default 'auto') – Window title;
'auto'uses the property name.z_scale (float, default 1.0) – Scale factor for the z-axis.
wells (VerticalWell or Sequence[VerticalWell] or None, optional) – Well(s) to plot on top of the grid. Can be a single VerticalWell or a sequence of them. If
None, no wells are plotted.**kwargs (Any) – Forwarded to viewer
add_grid.
Notes
title='auto'expands toProperty: <name>.
- property min: float¶
Return minimum finite property value.
- Returns:
NaN-aware minimum value.
- Return type:
- property max: float¶
Return maximum finite property value.
- Returns:
NaN-aware maximum value.
- Return type:
- property mean: float¶
Return arithmetic mean of finite values.
- Returns:
NaN-aware mean value.
- Return type:
- property median: float¶
Return median of finite values.
- Returns:
NaN-aware median value.
- Return type:
- property std: float¶
Return standard deviation of finite values.
- Returns:
NaN-aware standard deviation.
- Return type:
- fill_normal(mean, std, *, zone=None, include_inactive=True, min=None, max=None, seed=None)[source]¶
Fill target cells with samples from a normal distribution.
- Parameters:
mean (float) – Mean of the normal distribution.
std (float) – Standard deviation of the normal distribution.
zone (str or Zone or None, optional, default None) – Restrict assignment to a zone.
include_inactive (bool, default True) – When False, only active cells are assigned.
min (float, optional, default None) – Minimum value after adding noise (clipping).
max (float, optional, default None) – Maximum value after adding noise (clipping).
seed (int or None, optional, default None) – Seed for reproducible sampling.
- Returns:
Self, for chaining.
- Return type:
- Raises:
ValueError – If
stdis negative.
- apply(func, *, source, zone=None, include_inactive=True)[source]¶
Apply a function to one or more source arrays and store the result.
- Parameters:
func (callable) – Function applied to the resolved source arrays.
source (str | GridProperty | sequence of these) –
Input source(s) for the function.
Supported built-in string sources: - “x” : cell-center x coordinate - “y” : cell-center y coordinate - “depth”, “z” : cell-center depth (positive downward) - “top” : top z of cell - “bottom” : bottom z of cell - “thickness” : cell thickness - “active” : 1 for active cells, 0 for inactive
You may also pass another GridProperty, or a tuple/list mixing them.
zone (str | Zone | None, optional, default None) – Restrict assignment to a zone.
include_inactive (bool, default True) – When False, only active cells are assigned.
- Returns:
Self, for chaining.
- Return type:
Examples
>>> poro.apply(lambda z: 0.32 - 0.00015 * z, source="depth")
>>> perm.apply(lambda p: 1000 * p**3, source=poro)
>>> perm.apply( ... lambda z, p: (1000 * p**3) * np.exp(-z / 3000.0), ... source=("depth", poro), ... )
- Raises:
TypeError – If
funcis not callable orsourcetype is invalid.ValueError – If resolved source dimensions are incompatible or function output shape is unsupported.
- fill(value, *, zone=None, include_inactive=True)[source]¶
Fill target cells with a constant numeric value.
- Parameters:
- Returns:
Self, for chaining.
- Return type:
- Raises:
TypeError – If
valueis not numeric.
- fill_lognormal(mean, std, *, zone=None, include_inactive=True, min=None, max=None, seed=None)[source]¶
Fill target cells with samples from a lognormal distribution.
- Parameters:
mean (float) – Mean in linear space (e.g. permeability mean).
std (float) – Standard deviation in linear space.
zone (str | Zone | None, optional, default None) – Restrict to zone.
include_inactive (bool, default True) – When False, only active cells are assigned.
min (float | None, default None) – Optional lower bound.
max (float | None, default None) – Optional upper bound.
seed (int | None, default None) – Random seed.
Notes
Internally converts linear mean/std to log-space parameters.
- Returns:
Self, for chaining.
- Return type:
- Raises:
ValueError – If
mean <= 0orstd < 0.
- fill_uniform(low, high, *, zone=None, include_inactive=True, seed=None)[source]¶
Fill target cells with samples from a uniform distribution.
- Parameters:
low (float) – Lower bound of the distribution.
high (float) – Upper bound of the distribution (must be
>= low).zone (str or Zone or None, optional, default None) – Restrict assignment to a zone.
include_inactive (bool, default True) – When False, inactive cells are excluded.
seed (int or None, optional, default None) – Seed for reproducible sampling.
- Returns:
Self, for chaining.
- Return type:
- Raises:
ValueError – If
high < low.
- fill_nan(value, *, zone=None, include_inactive=True)[source]¶
Fill
NaNentries with a constant value.
- from_array(values, *, zone=None, include_inactive=True)[source]¶
Assign values from an array, optionally scoped by zone/active mask.
- Parameters:
- Returns:
Self, for chaining.
- Return type:
- Raises:
ValueError – If
valuesshape does not match grid shape.
- from_wells(wells, interpolator, *, source=None, zone=None, location='center', include_inactive=True)[source]¶
Populate this property by interpolating well samples.
- Parameters:
wells (sequence of VerticalWell) – Wells containing property samples.
interpolator (BaseInterpolator) – Interpolator instance with fit(points, values) and predict(query) methods.
source (str | None, optional, default None) – Sample property name to read from wells. Defaults to self.name.
location ({"center", "top", "bottom"}, default "center") – Grid cell location used as interpolation target.
zone (str | Zone | None, optional, default None) – Restrict assignment to a zone.
include_inactive (bool, default True) – When False, only active cells are assigned.
Notes
Interpolation mode is inferred from well sample storage for
source: scalar samples are interpolated in XY (2D), depth-indexed samples are interpolated in XYZ (3D).- Returns:
Self, for chaining.
- Return type:
- Raises:
ValueError – If well sample modes for
sourceare inconsistent, source data is invalid, or interpolator output shape is invalid.TypeError – If
interpolatoris not aBaseInterpolatoror wells contain invalid entries.
- to_grdecl(path)[source]¶
Write property values to a GRDECL file.
- Parameters:
path (str) – Destination file path.
- Raises:
MissingEclipseKeywordError – If this property has no Eclipse keyword.
MissingPropertyValueError – If value export fails due to missing values.