Chunk#

class cegalprizm.pythontool.Chunk(i, j, k, backing_object, extent, value_getters, value_setters, value_shapers, value_accessors, value_enumerations, chunk_type: Optional[int] = None, readonly: bool = False, disconnected: bool = False)#

An object allowing manipulation of the data in a Petrel object.

Create a Chunk

Parameters
  • i – The specific i-index, or None to range over all i-values

  • j – The specific j-index, or None to range over all j-values

  • k – The specific k-index, or None to range over all k-values

  • extent (petrellink.primitives.Extent) – The extent of the backing object

  • value_getters – a dict indexed by ChunkType storing value-getting functions (see later)

  • value_setters – a dict indexed by ChunkType storing value-setting functions (see later)

  • value_shapers – a dict indexed by ChunkType storing value-shaping functions (see later)

  • value_accessors – a dict indexed by ChunkType storing value-accessor-creating functions (see later)

  • value_enumerations – a 3-Tuple of booleans indicating which indices this chunk can range over.

  • readonly – is the chunk readonly

  • disconnected – if disconnected, the chunk does not try and send values to its backing object

The functions provided by value_getters are called with with 3 indices (i, j, k) provided by the constructor. Different chunk types can and will ignore some or all of these indices, e.g. a 3d grid generating a k-slice will ignore i and j. Use a lambda to create a function which ignores some of its arguments.

These functions are called with 3 indices and a values objects. See values_getters.

The functions are called with 3 indices and a values object. Different chunk types and backing objects (e.g a DictionaryProperty k-slice) will need to shape the values (which may be a System.Array, a Python list or a numpy.ndarray) etc into the correct data structure to pass to the backing object.

Backing objects storing .NET System.Arrays or numpy.ndarrays demand an indexing object specialized per chunk-type (i.e dimensionality of array). See Chunk.__make_accessor for details.

Different backing objects will enumerate over different indices. For instance, all 3d backing object’s chunks will enumerate over i, j and k (even if one or more of them are constant. Surfaces will only enumerate over i and j, so pass (True, True, False) so the user is not provided a meaningless k-index by the enumerate() method. A 2D Seismic object might only enumerate over i and k, so pass (True, False, True) in this case.

Functions

__init__(i, j, k, backing_object, extent, ...)

Create a Chunk

as_array()

The raw values for the chunk.

as_dataframe()

The values of the chunk as a Pandas dataframe.

clone()

Returns a disconnected clone of the chunk

enumerate()

Returns a generator yielding a tuple of the indices and values

get_rawvalues()

DeprecationWarning: 'get_rawvalues' has been removed.

set(value[, value_column_name])

Sets the values of the chunk

values()

A context-manager object which saves values automatically

Properties

disconnected

Is the chunk disconnected?

i

The i-index of this chunk, or None if chunk ranges over i

j

The j-index of this chunk, or None if chunk ranges over j

k

The k-index of this chunk, or None if chunk ranges over k

object_extent

The extent of the object from which the chunk was created

readonly

The readonly status of this chunk

slice_extent

The extent of this chunk in the i, j and k directions

as_array() numpy.ndarray#

The raw values for the chunk.

Gets the values covered by the chunk as an array, which will be of different dimensionality depending on whether it is a 1d, 2d or 3d chunk. If you change the values in this array, they will not be persisted in the Petrel project immediately. Use the set() method to set the values in a Petrel object.

You can treat a System.Array or numpy.ndarray as an ordinary Python list/iterable, but avoid doing this for maximum performance.

Returns

the raw values for the chunk

Return type

numpy.ndarray (CPython)

Example:

# change one cell in a property
vals = my_property.layer(2).as_array()
vals[2, 5] = 1.23
# my_property is unchanged at this point
my_property.layer(2).set(vals)
# my_property has now been changed.

# assign layer 10's values to layer 11 if they are above 0.5, else set 0
layer10_vals = my_property.layer(10).as_array()
new_vals = [v if v > 0.5 else 0 for v in layer10_vals]
my_property.layer(11).set(new_vals)
# layer 11 has new values.  layer 10 is untouched
as_dataframe() pandas.core.frame.DataFrame#

The values of the chunk as a Pandas dataframe.

clone() cegalprizm.pythontool.chunk.Chunk#

Returns a disconnected clone of the chunk

The returned object has the same values as the original chunk, but it is not connected to any Petrel object. Use the set() method of another compatible chunk to set the values of a Petrel object.

Returns

a disconnected clone of the chunk

Return type

cegalprizm.pythontool.Chunk

enumerate() Iterator[Tuple[int, int, int, Any]]#

Returns a generator yielding a tuple of the indices and values

When the generator is evaluated, it will return tuples of the form (i, j, k, val) where i, j and k are the indices and val is the value at that index.

This method of enumeration is slower than accessing the value array directly (via as_array) but gives the user more information about the order of indexing

Returns

A generator yielding (i, j, k, value) tuples

get_rawvalues() None#

DeprecationWarning: ‘get_rawvalues’ has been removed. Use ‘as_array’ instead

set(value, value_column_name: str = 'Value') None#

Sets the values of the chunk

Use this to immediately set the values of the chunk. If you supply a single value then all the values in the chunk will be set to this value. If you supply another Chunk, then as long as it is compatible (i.e it has has same size and the same ‘undefined value’) this chunk’s values will be set to the other’s. Alternatively, you can supply a list (either flat or nested) or a numpy.ndarray (CPython) of the correct dimensions for the chunk. Alternatively 2, you can supply a Pandas.DataFrame of the correct value count for the chunk (number of rows in input dataframe is same as in the original chunk dataframe). IJK indices in the input dataframe must match IJK indices in the chunk. Optionally specify the value_column_name of the column to be set as chunk values

Parameters

value – the value[s] or another Chunk instance or Pandas.DataFrame

Example:

# copy column i=8, j=10 to column i=1, j=2
colA = my_prop.column(1, 2)
colB = my_prop.column(8, 10)
colA.set(colB)

# set column i=3, j=4 to all 1s
my_prop.column(3, 4).set(1)
values() Iterator[numpy.ndarray]#

A context-manager object which saves values automatically

Use a with-statement to create this object, and then you can set the chunk’s values directly. At the end of the with-statement, the values are sent back to Petrel automatically.

Example:

my_layer = my_property.layer(2)
with my_layer.values() as vals:
    vals[1, 3] = 42
# here, values are saved automatically to Petrel
property disconnected: bool#

Is the chunk disconnected?

Returns

True if the chunk is disconnected

Return type

bool

property i: Union[Tuple[int, int], None, int]#

The i-index of this chunk, or None if chunk ranges over i

property j: Union[Tuple[int, int], None, int]#

The j-index of this chunk, or None if chunk ranges over j

property k: Union[Tuple[int, int], None, int]#

The k-index of this chunk, or None if chunk ranges over k

property object_extent#

The extent of the object from which the chunk was created

Returns

the extent of the object

from which the chunk was created

Return type

cegalprizm.pythontool.Extent

property readonly: bool#

The readonly status of this chunk

Read-only chunks will not allow you to set the rawvalues property. A PythonToolException will be raised upon setting the rawvalues property or upon exit of a values() with-block. However, note that the API does not detect changes to the existing values - it is only upon finally setting them that an error will be raised

Example::

print(my_prop.readonly)
# outputs 'True'
my_prop.column(2, 3).as_array() = [2, 3, 4]
# error is raised
my_prop.column(2, 3).as_array()[88] = 1.33
# no error is raised, but values have not been saved anyway
with my_prop.column(2, 3).values() as vals:
    vals[88] = 1.33 # no error
# error raised here
property slice_extent: cegalprizm.pythontool.primitives.Extent#

The extent of this chunk in the i, j and k directions

Returns

the extent of this chunk

Return type

cegalprizm.pythontool.Extent