Skip to content

Commit

Permalink
BUG: fix issue with get_randomline when using Polygons (equinor#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnatt authored Nov 30, 2023
1 parent 8775d00 commit 1ead811
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
19 changes: 10 additions & 9 deletions src/xtgeo/grid3d/_grid3d_fence.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ def get_randomline(

_update_tmpvars(self)

if hincrement is None and isinstance(fencespec, Polygons):
logger.info("Estimate hincrement from Polygons instance...")
if hincrement is not None and not isinstance(hincrement, (float, int)):
raise TypeError("'hincrement' can only be a number or None")

if isinstance(fencespec, Polygons):
fencespec = _get_randomline_fence(self, fencespec, hincrement, atleast, nextend)
logger.info("Estimate hincrement from Polygons instance... DONE")

logger.info("Get property...")
if isinstance(prop, str):
Expand Down Expand Up @@ -149,22 +150,22 @@ def _update_tmpvars(self: Grid, force: bool = False) -> None:
def _get_randomline_fence(
self: Grid,
polygon: Polygons,
hincrement: float | int | None,
distance: float | int | None,
atleast: int,
nextend: int,
) -> np.ndarray:
"""Compute a resampled fence from a Polygons instance."""
if hincrement is None:
if distance is None:
logger.debug("Estimate fence distance from grid resolution...")
geom = self.get_geometrics()

avgdxdy = 0.5 * (geom[10] + geom[11])
distance = 0.5 * avgdxdy
else:
distance = hincrement
logger.debug("Estimate fence distance from grid resolution... DONE")

logger.info("Getting fence from a Polygons instance...")
logger.debug("Getting fence from a Polygons instance...")
fspec = polygon.get_fence(
distance=distance, atleast=atleast, nextend=nextend, asnumpy=True
)
logger.info("Getting fence from a Polygons instance... DONE")
logger.debug("Getting fence from a Polygons instance... DONE")
return fspec
19 changes: 9 additions & 10 deletions src/xtgeo/grid3d/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2651,7 +2651,7 @@ def get_randomline(
zmin: float | None = None,
zmax: float | None = None,
zincrement: float = 1.0,
hincrement: float | bool | None = None,
hincrement: float | None = None,
atleast: int = 5,
nextend: int = 2,
) -> tuple[float, float, float, float, np.ndarray]:
Expand All @@ -2667,8 +2667,8 @@ def get_randomline(
If input fencspec is a numpy 2D, it is important that the HLEN array
has a constant increment and ideally a sampling that is less than the
Grid resolution. If a Polygons() instance, this is automated if hincrement is
None, and ignored if hincrement is False.
Grid resolution. If a Polygons() instance, this will be automated if
hincrement is None.
Args:
fencespec (:obj:`~numpy.ndarray` or :class:`~xtgeo.xyz.polygons.Polygons`):
Expand All @@ -2678,14 +2678,13 @@ def get_randomline(
zmin (float): Minimum Z (default is Grid Z minima/origin)
zmax (float): Maximum Z (default is Grid Z maximum)
zincrement (float): Sampling vertically, default is 1.0
hincrement (float or bool): Resampling horizontally. This applies only
hincrement (float): Resampling horizontally. This applies only
if the fencespec is a Polygons() instance. If None (default),
the distance will be deduced automatically. If False, then it assumes
the Polygons can be used as-is.
atleast (int): Minimum number of horizontal samples (only if
fencespec is a Polygons instance and hincrement != False)
nextend (int): Extend with nextend * hincrement in both ends (only if
fencespec is a Polygons instance and hincrement != False)
the distance will be deduced automatically.
atleast (int): Minimum number of horizontal samples This applies
only if the fencespec is a Polygons() instance.
nextend (int): Extend with nextend * hincrement in both ends.
This applies only if the fencespec is a Polygons() instance.
Returns:
A tuple: (hmin, hmax, vmin, vmax, ndarray2d)
Expand Down

0 comments on commit 1ead811

Please sign in to comment.