PointSet#

class cegalprizm.pythontool.PointSet(python_petrel_pointset: PointSetGrpc)#

Class representing a point set in Petrel.

** The implementation of point sets is in a preliminary state. Handling large point sets may

fail or be slow. We are working on improving this.

Functions

__init__(python_petrel_pointset)

add_comment(new_comment[, overwrite])

Add a comment to the already existing comments on the PetrelObject, or overwrite the existing comments.

add_point(point)

Adds a point

as_dataframe([indices, start, end, step, ...])

Gets a dataframe with point coordinates and attribute data.

clone(name_of_clone[, copy_values])

Creates a clone of the Petrel object.

delete_point(point)

Deletes a point

retrieve_history()

The Petrel history for the object.

retrieve_stats()

Retrieves a dictionary summarizing the statistics for the object

set_values(data[, create, df_includes_units])

Attribute values are written to Petrel.

values([indices, start, end, step, x_range, ...])

A context manager to use for reading and writing attribute data.

Properties

comments

The comments on the PetrelObject.

crs_wkt

droid

The Petrel Droid (object id or guid) for the object

path

The path of this object in Petrel.

petrel_name

Returns the name of this object in Petrel

points

A list of the cegalprizm.pythontool.PointsetPoint objects making up the pointset

readonly

The read-only status of this object

template

Returns the Petrel template for the object as a string.

add_comment(new_comment: str, overwrite: bool = False) None#

Add a comment to the already existing comments on the PetrelObject, or overwrite the existing comments.

Input:

new_comment: The new comment to add to the PetrelObject. overwrite: Boolean flag to overwrite all existing comments with the new comment. Default is False.

Raises

PythonToolException – if object is read-only

add_point(point: cegalprizm.pythontool.primitives.Point) None#

Adds a point

Adds a single point in displayed world co-ordinates to the pointset. Using this method multiple times will be slower than building up a list of cegalprizm.pythontool.PointsetPoint objects and assigning it to the points() property in one go.

Example:

# slower
mypointset.add_point(Point(100.0, 123.0, 50.3))
mypointset.add_point(Point(102.0, 125.3, 50.2))

# faster
new_points = [Point(100.0, 123.0, 50.3), Point(102.0, 125.3, 50.2)]
mypointset.points = new_points
Parameters

point – the point to add

as_dataframe(indices: Optional[List[int]] = None, start: Optional[int] = None, end: Optional[int] = None, step: Optional[int] = None, x_range: Optional[Union[Tuple[int], Tuple[int, int]]] = None, y_range: Optional[Union[Tuple[int], Tuple[int, int]]] = None, z_range: Optional[Union[Tuple[int], Tuple[int, int]]] = None, max_points: Optional[int] = None, show_units=False) pandas.core.frame.DataFrame#

Gets a dataframe with point coordinates and attribute data.

Example:

With the following code, where pointset is an instance of PointSet, we get a dataframe named df and print the column names

df = pointset.as_dataframe()
print('Columns of the dataframe:', list(df.columns))

Each column of the dataframe represents an attribute or point coordinate. The column names are the names of the attributes. If there are attributes with equal names, these attribute names are given a suffix with a number to make the column names unique.

Example:

With the following code we get data of an attribute named TWT

df = pointset.as_dataframe()
# The values of attribute TWT
twt = df['TWT']
print(twt)

Point sets can be large, and there are several ways of retrieving just a part of the point set from Petrel. The following example shows how to select based on point indices.

Example:

Selecting the attributes for a range of indices from index 10_000 to index 19_999 with step length 10

df = pointset.as_dataframe(start = 10_000, end = 19_999, step = 10)

The step must be a positive integer and end must be larger or equal to start. To select the attributes for some given indices do the following.

df = pointset.as_dataframe(indices = [10, 12, 15, 22])

The values in indices must be monotonically increasing integers.

In the next examples we filter the attributes based on spatial coordinates.

Examples:

Selecting attributes only for points within specified ranges of x, y and z.

df = pointset.as_dataframe(x_range = [10_000, 11_000],
                           y_range = [23_000, 24_000],
                           z_range = [-3_000, 0])

Selecting attributes for points with a range in x, for any values of y and z, but start searching at index 1_000_000 and receiving a maximum number of 200_000 attributes

df = pointset.as_dataframe(x_range = [10_000, 20_000],
                           start = 1_000_000,
                           max_points = 200_000)

Note: As from Petrel 2021 the autogenerated elevation time pointset attribute are named ‘TWT’ instead of previously used ‘TWT auto’ for NEW pointsets.

Parameters
  • indices – A list or tuple of point indices. Values must be monotonically increasing.

  • start – Start index, larger or equal to zero.

  • end – End index.

  • step – The step. Typically used together with start and end.

  • x_range – A list with minimum and maximum point coordinate in x dimension

  • y_range – A list with minimum and maximum point coordinate in y dimension

  • z_range – A list with minimum and maximum point coordinate in z dimension

  • max_points – Maximum number of points in dataframe.

  • show_units – If this flag is set to true the unit symbol of the PointSet attribute will be attached to the DataFrame column name in square brackets.

Returns

A dataframe with points and attributes data.

Return type

Dataframe

clone(name_of_clone: str, copy_values: bool = False) cegalprizm.pythontool.points.PointSet#

Creates a clone of the Petrel object.

The clone is placed in the same collection as the source object. A clone cannot be created with the same name as an existing Petrel object in the same collection.

This is a Python Tool Pro function and is not available when running scripts in the editor integrated in Python Tool or in a workflow.

Parameters
  • path_of_clone – Petrel name of the clone

  • copy_values – Set to True if values shall be copied into the clone. Defaults to False.

Returns

The clone

Return type

PointSet

Raises
  • Exception – If there already exists a Petrel object with the same name

  • ValueError – If name_of_clone is empty or contains slashes

delete_point(point: cegalprizm.pythontool.points.PointsetPoint) None#

Deletes a point

Deletes one point from the pointset. Using this method multiple times will be slower than manipulating a list of cegalprizm.pythontool.PointsetPoint objects and assigning it to the points() property in one go.

Note that cegalprizm.pythontool.PointsetPoint objects are compared by reference, not value. In order to delete a point you must refer to the actual PointsetPoint object you wish to delete:

Example:

# set up the PointSet
new_points = [PointsetPoint(100.0, 123.0, 50.3), PointsetPoint(102.0, 125.3, 50.2)]
mypointset.points = new_points

# delete the second point in a PointSet
# mypointset.delete_point(PointsetPoint(102.0, 125.3, 50.2)) will not work
p = mypointset.points[1]  # the 2nd point
mypointset.delete_point(p)
Parameters

point – the point to delete

retrieve_history() pandas.core.frame.DataFrame#

The Petrel history for the object.

Returns the Petrel history for the object as Pandas dataframe.

Returns

The history of the object as reported by Petrel

Return type

DataFrame

retrieve_stats() Dict[str, str]#

Retrieves a dictionary summarizing the statistics for the object

The statistics are a snapshot of the information in the Statistics page of the Settings panel of the object in the Petrel tree. Both the dict key and value are strings, and may contain punctuation, English phrases or just filler information. Any changes to the dict returned will not be saved or affect anything.

Note: this operation may be slow, since the statistics are ‘live’ - they represent the most up to date information.

Returns

The statistics of the object as reported by Petrel

Return type

dict

set_values(data: pandas.core.frame.DataFrame, create: Optional[List[str]] = None, df_includes_units: bool = False) None#

Attribute values are written to Petrel. The data parameter must be a Pandas Dataframe with a format as returned by the as_dataframe method.

To create a new attributes, list the attribute names in the optional parameter create. The names listed in create must be existing columns in the input dataframe.

Example:

Get the attributes of pointset, add a new column based on the existing column named TWT, and create an attribute in Petrel with the values of this new column.

df = pointset.as_dataframe()
# Creates two new columns
df['TWT adjusted 1'] = 0.95 * df['TWT']
df['TWT adjusted 2'] = 0.97 * df['TWT']
# Create the new attributes in Petrel
pointset.set_values(df, create = ['TWT adjusted 1', 'TWT adjusted 2'])
Raises

PythonToolException – If the name of any of the attributes to create is not a column name in the input dataframe.

Parameters
  • data – A Pandas Dataframe of attributes with format as returned by as_dataframe()

  • create – A list of attribute names to create. Defaults to [].

  • df_includes_units – A flag to indicate that the dataframe columns in the input contains unit values which need to be stripped.

values(indices: Optional[List[int]] = None, start: Optional[int] = None, end: Optional[int] = None, step: Optional[int] = None, x_range: Tuple[int, int] = None, y_range: Tuple[int, int] = None, z_range: Tuple[int, int] = None, max_points: Optional[int] = None) Iterator[pandas.core.frame.DataFrame]#

A context manager to use for reading and writing attribute data. The input parameters are the same as for method as_dataframe.

Example:

Read part of a point set from Petrel and change a value of an attribute called ‘TWT’.

with pointset.values(start = 0, end = 1000) as df:
    df['TWT'][999] = 123.4

At the end of the with block, the content of df is automatically written back to Petrel.

property comments#

The comments on the PetrelObject.

Returns

The comments on the PetrelObject as a string.

Return type

string

property droid: str#

The Petrel Droid (object id or guid) for the object

Returns the Petrel Droid or object id or guid for the object. If not available, will throw a PythonToolException.

This property is planned to be deprecated in favour of a similar but more general id schema in future releases.

Returns

The Petrel Droid of the object

Return type

str

property path: str#

The path of this object in Petrel. Neither the Petrel name nor the path is guaranteed to be unique.

Returns

The path of the Petrel object

Return type

str

property petrel_name: str#

Returns the name of this object in Petrel

property points: List[cegalprizm.pythontool.points.PointsetPoint]#

A list of the cegalprizm.pythontool.PointsetPoint objects making up the pointset

property readonly: bool#

The read-only status of this object

Returns

True if the object is read-only

Return type

bool

property template: str#

Returns the Petrel template for the object as a string. If no template available, will return an empty string.