88
99import numpy as np
1010
11+ import xtgeo
1112from xtgeo .common import XTGeoDialog
1213from xtgeo .common import XTGDescription
13- from xtgeo .common import constants
1414
1515from xtgeo .cube import _cube_import
1616from xtgeo .cube import _cube_export
1717from xtgeo .cube import _cube_utils
1818from xtgeo .cube import _cube_roxapi
1919
20- UNDEF = constants .UNDEF
21- UNDEF_LIMIT = constants .UNDEF_LIMIT
2220
2321xtg = XTGeoDialog ()
2422logger = xtg .functionlogger (__name__ )
@@ -95,9 +93,6 @@ class Cube(object): # pylint: disable=too-many-public-methods
9593 def __init__ (self , * args , ** kwargs ):
9694 """Initiate a Cube instance."""
9795
98- clsname = "{}.{}" .format (type (self ).__module__ , type (self ).__name__ )
99- logger .info (clsname )
100-
10196 self ._filesrc = None
10297 self ._segyfile = None
10398 self ._ilines = None
@@ -117,8 +112,6 @@ def __init__(self, *args, **kwargs):
117112 self ._xlines = np .array (range (1 , 3 + 1 ), dtype = np .int32 )
118113 self ._rotation = 0.0
119114 self ._traceidcodes = np .ones ((5 , 3 ), dtype = np .int32 )
120- self ._undef = UNDEF
121- self ._undef_limit = UNDEF_LIMIT
122115
123116 if len (args ) >= 1 :
124117 fformat = kwargs .get ("fformat" , "guess" )
@@ -565,7 +558,15 @@ def get_xy_value_from_ij(self, iloc, jloc, ixline=False, zerobased=False):
565558 # =========================================================================
566559
567560 def get_randomline (
568- self , fencespec , zmin = None , zmax = None , zincrement = None , sampling = "nearest"
561+ self ,
562+ fencespec ,
563+ zmin = None ,
564+ zmax = None ,
565+ zincrement = None ,
566+ hincrement = None ,
567+ atleast = 5 ,
568+ extend = 2 ,
569+ sampling = "nearest" ,
569570 ):
570571 """Get a randomline from a fence spesification.
571572
@@ -576,13 +577,24 @@ def get_randomline(
576577
577578 The input fencespec is a 2D numpy where each row is X, Y, Z, HLEN,
578579 where X, Y are UTM coordinates, Z is depth/time, and HLEN is a
579- length along the fence.
580+ length along the fence, or a Polygons instance with HLEN present.
581+
582+ It is important that the HLEN array has a constant increment and ideally
583+ a sampling that is less than the Cube resolution.
580584
581585 Args:
582- fencespec (np): 2D numpy with X, Y, Z, HLEN as rows.
586+ fencespec (~np.ndarray or :class:`~xtgeo.xyz.polygons.Polygons`):
587+ 2D numpy with X, Y, Z, HLEN as rows or a xtgeo Polygons() object.
583588 zmin (float): Minimum Z (default is Cube Z minima/origin)
584589 zmax (float): Maximum Z (default is Cube Z maximum)
585- zincrement (float): Sampling, default is Cube ZINC/2
590+ zincrement (float): Sampling vertically, default is Cube ZINC/2
591+ hincrement (float or bool): Resampling horizontally. This applies only
592+ if the fencespec is a Polygons() instance. If None (default),
593+ the distance will be deduced automatically.
594+ atleast (int): Minimum number of horizontal samples (only if
595+ fencespec is a Polygons instance)
596+ extend (int): Extend with extend*hincrement in both ends (only if
597+ fencespec is a Polygons instance)
586598 sampling (str): Algorithm, 'nearest' or 'trilinear' (first is
587599 faster, second is more precise for continuous fields)
588600
@@ -592,16 +604,25 @@ def get_randomline(
592604 Raises:
593605 ValueError: Input fence is not according to spec.
594606
595- """
607+ .. versionadded:: 2.1.0 support for Polygons() as fencespec, and keywords
608+ hincrement, atleast and sampling
596609
610+ """
611+ if not isinstance (fencespec , (np .ndarray , xtgeo .Polygons )):
612+ raise ValueError ("fencespec must be a numpy or a Polygons() object" )
613+ logger .info ("Getting randomline..." )
597614 res = _cube_utils .get_randomline (
598615 self ,
599616 fencespec ,
600617 zmin = zmin ,
601618 zmax = zmax ,
602619 zincrement = zincrement ,
620+ hincrement = hincrement ,
621+ atleast = atleast ,
622+ extend = extend ,
603623 sampling = sampling ,
604624 )
625+ logger .info ("Getting randomline... DONE" )
605626 return res
606627
607628 # =========================================================================
0 commit comments