pyopmnearwell.ml.upscale module#
Functionality to upscale data from an ensemble run on a radial grid to a cartesian grid.
Note: pylint: no-member is disabled, because it complains about the BaseUpscaler
missing instance attributes, which are taken care of by the Upscaler protocol.
pylint: pointless-string-statement is disabled, as it complains an attribute docstring
in the Upscaler protocol.
- class Upscaler(*args, **kwargs)[source]#
Bases:
ProtocolProtocol class for upscalers.
This class is used for typing of abstract attributes of
BaseUpscaler. MyPy will check if subclasses ofBaseUpscalerimplement the following instance attributes:num_timestepsnum_layersnum_zcellsnum_xcellssingle_feature_shape
However, in comparison to missing abstract functions, no runtime error will be raised if they are missing.
See, e.g., https://stackoverflow.com/a/75253719 for an explanation.
- Note: As of now (Python 3.11), each instance method of
BaseUpscaleror a subclass making use of one of the attributes, needs to have its self argumented annotated with
Upscaler. In future python versions it should be possible to useclass BaseUpscaler[Upscaler](ABC):...instead and remove these annotations.
- property num_timesteps: int#
Return the number of simulation time steps.
- Returns:
Result produced by the operation.
- Return type:
- property num_layers: int#
Return the number of geological layers.
- Returns:
Result produced by the operation.
- Return type:
- property num_zcells: int#
Return the number of vertical grid cells.
- Returns:
Result produced by the operation.
- Return type:
- property num_xcells: int#
Return the number of radial grid cells.
- Returns:
Result produced by the operation.
- Return type:
- property single_feature_shape: tuple#
Return the expected shape of one upscaled feature.
- Returns:
Result produced by the operation.
- Return type:
- property angle: float#
Return the angular extent of the cake grid in radians.
- Returns:
Result produced by the operation.
- Return type:
- _abc_impl = <_abc._abc_data object>#
- _is_protocol = True#
- class BaseUpscaler[source]#
Bases:
ABCExtract and upscale data from an array of ensemble data.
This base class provides several methods to extract features from fine-scale radial simulations and upscale to coarse cartesian cells. Depending on the type of data, this is done by averaging/summing/etc. values along all cells that correspond to a coarse cell.
Additionally, the sparsity of the dataset can be increased by taking only some timesteps/horizontal cells.
The upscaled data is usually provided in form of two
np.ndarrays, one for features and one for targets.Subclasses need to implement
__init__and (if needed)create_dsmethods.The feature array will have shape
(num_ensemble_runs, num_timesteps/step_size_t, num_layers, num_xcells/step_size_x, num_features). The target array will have shape(num_ensemble_runs, num_timesteps/step_size_t, num_layers, num_xcells/step_size_x, 1)- Note: All methods assume that all cells have the same height. if this is not the
case, the methods must be overridden.
- abstractmethod create_ds()[source]#
Create the upscaled feature and target dataset.
- Returns:
Result produced by the operation.
- Return type:
Any
- Parameters:
self (Upscaler)
- reduce_data_size(feature, step_size_x=1, step_size_t=1, random=False)[source]#
Reduce the size of the input feature array by selecting elements with a fixed step size.
- Parameters:
feature (np.ndarray) -- The input feature array.
step_size_x (int, optional) -- The step size for the x-axis. Defaults to 1.
step_size_t (int, optional) -- The step size for the t-axis. Defaults to 1.
random (bool, optional) -- If True, select elements randomly instead of using a fixed step size. Defaults to False. Not implemented yet.
self (Upscaler)
- Returns:
The reduced feature array.
- Return type:
np.ndarray
- get_vertically_averaged_values(features, feature_index, disregard_first_xcell=True)[source]#
Average a selected feature over vertical cells within each layer.
- get_radii(radii_file)[source]#
Read radial-cell centers and boundaries for upscaling.
- Parameters:
radii_file (pathlib.Path) -- Grid-coordinate file containing radial boundaries.
self (Upscaler)
- Returns:
Result produced by the operation.
- Return type:
tuple[np.ndarray, np.ndarray]
- get_horizontically_integrated_values(features, cell_center_radii, cell_boundary_radii, feature_index, disregard_first_xcell=True)[source]#
Integrate a vertically averaged feature into equivalent Cartesian blocks.
cartesian block area.
- Parameters:
features (np.ndarray) -- Ensemble feature array.
cell_center_radii (np.ndarray) -- Radii at radial-cell centers.
cell_boundary_radii (np.ndarray) -- Radii at radial-cell boundaries.
feature_index (int) -- Index of the feature to process.
disregard_first_xcell (bool, optional) -- Whether to remove the innermost well cell.
self (Upscaler)
- Returns:
Result produced by the operation.
- Return type:
Any
- get_homogeneous_values(features, feature_index, disregard_first_xcell=True)[source]#
Extract a feature that is homogeneous within each layer.
- get_analytical_PI(permeabilities, cell_heights, radii, well_radius)[source]#
Calculate the single-phase analytical Peaceman productivity index.
- get_analytical_WI(pressures, saturations, permeabilities, temperature, surface_density, radii, well_radius, OPM)[source]#
Calculate a two-phase analytical well index from pressure-dependent fluid properties.
- Parameters:
pressures (np.ndarray) -- Pressure values.
saturations (np.ndarray) -- Non-wetting saturation values.
permeabilities (np.ndarray) -- Permeability values.
temperature (float) -- Fluid temperature.
surface_density (float) -- Reference surface density.
radii (np.ndarray) -- Cell radii.
well_radius (float) -- Wellbore radius.
OPM (pathlib.Path) -- Path to the OPM installation.
self (Upscaler)
- Returns:
Result produced by the operation.
- Return type:
np.ndarray
- get_data_WI(features, pressure_index, inj_rate_index, angle=1.0471975511965976)[source]#
Calculate a data-driven well index from pressure and injection-rate results.
Similar functionality to
ensemble.calculate_WI, but can additionally treat multiple vertical cells in a layer correctly.- Parameters:
- Returns:
Result produced by the operation.
- Return type:
np.ndarray
- _abc_impl = <_abc._abc_data object>#