Wells

Wells

class Wells(node=None, **kwargs)[source]

Wells component.

Contains wells and groups in a single tree structure, wells attributes and preprocessing actions.

Parameters

node (WellSegment, optional) – Root node for well’s tree.

add_null_results_column(segment, column, fill_with=0.0)[source]

Add a dummy column to results if it is absent.

Parameters
  • segment

  • column (str) – Column name to add

  • fill_with (float) – Value to fill the column

Returns

wells

Return type

Wells

add_welltrack(segment, grid)[source]

Reconstruct welltrack from COMPDAT table.

To connect the end point of the current segment with the start point of the next segment we find a set of segments with nearest start point and take a segment with the lowest depth. Works fine for simple trajectories only. :param grid: Grid parameters. :type grid: Grid class instance

Returns

comp – Wells component with WELLTRACK attribute added.

Return type

Wells

apply(func, attr, *args, inplace=False, **kwargs)

Apply function to attributes.

Parameters
  • func (callable) – A function to apply. Must accept data as its first argument.

  • attr (str, array-like) – Attributes to get data from.

  • args (misc) – Any additional positional arguments to func.

  • kwargs (misc) – Any additional named arguments to func.

Returns

output – Transformed component.

Return type

BaseComponent

apply_perforations(segment, current_date=None)[source]

Open or close perforation intervals for given time interval.

Parameters
Returns

comp – Wells component with an updated blocks_info attribute which contains: - projections of welltrack in grid blocks - MD values for corresponding grid blocks - ratio of perforated part of the well for each grid block.

Return type

Wells

property attributes

Array of attributes.

blocks_ravel(grid)[source]

Transforms block coordinates into 1D representation.

blocks_to_spatial(grid)[source]

Transforms block coordinates into 3D representation.

calculate_cf(segment, rock, grid, beta=1, units='METRIC', cf_aggregation='sum', **kwargs)[source]

Calculate connection factor values for each grid block of a segment.

Parameters
  • rock (Rock class instance) – Rock component of geological model.

  • grid (Grid class instance) – Rock component of geological model.

  • segment (WellSegment class instance) – Well’s node.

  • beta (list or ndarray) – Additional multiplicator for productivity index of well.

  • conversion_const (float) – Сonversion factor for field units.

Returns

comp – Wells component with a ‘CF’ columns in a blocks_info attribute.

Return type

Wells

property class_name

Name of the component.

compute_events(segment, grid, attr='EVENTS')[source]

Make events from WCONPROD and WCONINJE if present.

Parameters
  • grid (Grid) – Grid component.

  • attr (str, optional) – Attribute name for events. Default to ‘EVENTS’.

Returns

wells – Wells with an event attribute added.

Return type

Wells

copy()[source]

Returns a deepcopy. Cached properties are not copied.

property cum_rates

Cumulative rates over all wells.

del_state(*args)

State remover.

drop(names)[source]

Detach nodes by names.

Parameters

names (str, array-like) – Nodes to be detached.

Returns

out – Wells without detached nodes.

Return type

Wells

drop_empty_groups(logger=None)[source]

Drop groups without wells in descendants.

drop_incomplete(logger=None)[source]

Drop nodes with missing ‘WELLTRACK’ and ‘PERF’.

Parameters

logger (logger, optional) – Logger for messages.

Returns

wells – Wells without incomplete nodes.

Return type

Wells

drop_outside(keep_ancestors=False, logger=None)[source]

Drop nodes with missing ‘BLOCKS’ (outside of the grid).

Parameters
  • keep_ancestors (bool) – Keep all ancestors segments for a segment with nonempty ‘BLOCKS’. Setting True might result in segments with empty ‘BLOCKS’, e.g. if a parent has no ‘BLOCKS’ but a child has nonempty ‘BLOCKS’. If False, welltracks may be discontinued. Default False.

  • logger (logger, optional) – Logger for messages.

Returns

wells – Wells without outside nodes.

Return type

Wells

dump(path, **kwargs)

Dump attributes into file.

Parameters
  • path (str) – Path to output file.

  • kwargs (dict, optional) – Any kwargs for dump method.

Returns

comp – BaseComponent unchanged.

Return type

BaseComponent

static dump_array_ascii(buffer, array, header=None, fmt='%f', compressed=True)

Writes array-like data into an ASCII buffer.

Parameters
  • buffer (buffer-like) –

  • array (1d, array-like) – Array to be saved

  • header (str, optional) – String to be written line before the array

  • fmt (str or sequence of strs, optional) – Format to be passed into numpy.savetxt function. Default to ‘%f’.

  • compressed (bool) – If True, uses compressed typing style

empty_like()

Get an empty component with the same state and the structure of embedded BaseComponents (if any).

property event_dates

List of dates with any event in main branches.

filter_blocks_with_perm(segment, permeab)[source]

Delete blocks with zero permeability.

get_wellblocks(segment, grid, logger=None, **kwargs)[source]

Calculate grid blocks for the tree of wells.

Parameters
  • grid (class instance) – Basic grid class.

  • kwargs (misc) – Any additional named arguments to append.

Returns

comp – Wells component with calculated grid blocks and well in block projections.

Return type

Wells

glob(name)[source]

Return instances at name supporting wildcards.

group(node_names, group_name)[source]

Group nodes in a new group attached to root.

Parameters
  • node_names (array-like) – Array of nodes to be grouped.

  • group_name (str) – Name of a new group.

Returns

out – Wells with a new group added.

Return type

Wells

property history_dates

List of dates with any history in main branches.

init_state(**kwargs)

Init state attributes.

items()

Returns pairs of attribute’s names and data.

keys()

Array of attributes.

load(path_or_buffer, **kwargs)

Load data from a file or buffer.

Parameters
  • path_or_buffer (str of string buffer) – Source to read data from.

  • **kwargs (dict, optional) – Any kwargs to be passed to load method.

Returns

comp – BaseComponent with loaded attributes.

Return type

BaseComponent

property main_branches

List of main branches names.

property names

List of well names.

randomize_events(segment, additive=False, clip=None, equality_condition=None, **kwargs)[source]

Add random values to events or fill with new random values.

Parameters
  • kwargs (dict) – A dict of {keyword: sampler} pairs. A keyword should be one of event keywords. A sampler should be callable that accepts parameter size (number of samples to generate).

  • additive (bool) – If True, add random value to existing one. If False, substitute existing value with a new random. Default to False.

  • clip ((2, ), tuple) – If not None, apply clip with given min and max values.

  • equality_condition (dict, None) – If not None, randomize only those events that satisfy df[k] == v for all (k, v) from equality_condition.items()

Returns

wells – Wells with randomized events.

Return type

Wells

ravel(attr=None, order='F', inplace=True)

Ravel attributes where applicable assuming by default Fortran order.

Parameters
  • attr (str, array of str) – Attribute to ravel.

  • order (str) – Numpy reshape order. Default to ‘F’.

  • inplace (bool) – If True, ravel is made inplace, return BaseComponent. Else, return raveled attribute.

Returns

out

Return type

BaseComponent if inplace else raveled attribute itself.

render_tree()[source]

Print tree structure.

reshape(attr, newshape, order='C', inplace=True)

Reshape numpy.ndarray attributes.

Parameters
  • attr (str, array of str) – Attribute to be reshaped.

  • newshape (tuple) – New shape.

  • order (str) – Numpy reshape order. Default to ‘C’.

  • inplace (bool) – If True, reshape is made inplace, return BaseComponent. Else, return reshaped attribute.

Returns

output

Return type

BaseComponent if inplace else reshaped attribute itself.

property resolver

Tree resolver.

property result_dates

List of dates with any result in main branches.

results_to_events(segment, grid, production_mode='BHPT', attr='EVENTS', drop_duplicates=True)[source]

Make events from results.

Parameters
  • grid (Grid) – Grid component.

  • production_mode (str, 'BHPT' or 'LPT'. Default to 'BHPT'.) – Control mode for production wells.

  • attr (str, optional) – Attribute name for events. Default to ‘EVENTS’.

  • drop_duplicates (bool, optional) – Drop repeated events. Default to True.

Returns

wells – Wells with an event attribute added.

Return type

Wells

property root

Tree root.

set_state(**kwargs)

State setter.

show_blocks_dynamics(timesteps=None, wellnames=None, figsize=(16, 6))[source]

Plot liquid or gas rates and pvt props for a chosen block of a chosen well segment on two separate axes.

Parameters
  • timesteps (list of Timestamps) – Dates at which rates were calculated.

  • wellnames (array-like) – List of wells to plot.

  • figsize (tuple) – Figsize for two axes plots.

show_rates(timesteps=None, wellnames=None, wells2=None, labels=None, figsize=(16, 6))[source]

Plot total or cumulative liquid and gas rates for a chosen node including branches.

Parameters
  • timesteps (list of Timestamps) – Dates at which rates were calculated.

  • wellnames (array-like) – List of wells to show.

  • figsize (tuple) – Figsize for two axes plots.

  • wells2 (Wells) – Target model to compare with.

show_rates2(timesteps=None, wellnames=None, wells2=None, labels=None, figsize=(16, 6))[source]

Plot total or cumulative liquid and gas rates for a chosen node including branches on two separate axes.

Parameters
  • timesteps (list of Timestamps) – Dates at which rates were calculated.

  • wellnames (array-like) – List of wells to show.

  • figsize (tuple) – Figsize for two axes plots.

  • wells2 (Wells) – Target model to compare with.

show_wells(figsize=None, c='r', **kwargs)[source]

Return 3D visualization of wells.

Parameters
  • figsize (tuple) – Output figsize.

  • c (str) – Line color, default red.

  • kwargs (misc) – Any additional kwargs for plot.

split_perforations(segment)[source]

Split well perforations in a way that each perforation correspond to one specific cell.

Parameters

segment (WellSegment) – Well node

Returns

Wells component with updated perforations.

Return type

Wells

property state

Get state.

property total_rates

Total rates over all wells.

update(wellsdata, mode='w', **kwargs)[source]

Update tree nodes with new wellsdata. If node does not exists, it will be attached to root.

Parameters
  • wellsdata (dict) – Keys are well names, values are dicts with well attributes.

  • mode (str, optional) – If ‘w’, write new data. If ‘a’, try to append new data. Default to ‘w’.

  • kwargs (misc) – Any additional named arguments to append.

Returns

out – Wells with updated attributes.

Return type

Wells

update_wpi_mult(segment, mults)[source]

Update WPI multipliers.

Parameters
  • segment (WellSegment) – Well node

  • mults (pandas.DataFrame) – Multiplyers to be updated. A table with following columns – I: – J: – K: indices – MULT correspnding multipliers

Returns

Wells component with updated WPI multipliers in perf tables.

Return type

Wells

values()

Returns a generator of attribute’s data.

WellSegment

class WellSegment(*args, parent=None, children=None, name=None, is_group=False, **kwargs)[source]

Well’s node.

Parameters
  • name (str, optional) – Node’s name.

  • is_group (bool, optional) – Should a node represet a group of wells. Default to False.

is_group

Indicator of a group.

Type

bool

is_main_branch

Indicator of a main branch.

Type

bool

name

Node’s name.

Type

str

fullname

Node’s full name from root.

Type

str

all_perforated_blocks(t=None)[source]

List of perforated blocks for current node and all its descendants.

property ancestors

All parent nodes and their parent nodes.

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> udo.ancestors
()
>>> marc.ancestors
(Node('/Udo'),)
>>> lian.ancestors
(Node('/Udo'), Node('/Udo/Marc'))
property anchestors

All parent nodes and their parent nodes - see ancestors.

The attribute anchestors is just a typo of ancestors. Please use ancestors. This attribute will be removed in the 3.0.0 release.

apply(func, attr, *args, inplace=False, **kwargs)

Apply function to attributes.

Parameters
  • func (callable) – A function to apply. Must accept data as its first argument.

  • attr (str, array-like) – Attributes to get data from.

  • args (misc) – Any additional positional arguments to func.

  • kwargs (misc) – Any additional named arguments to func.

Returns

output – Transformed component.

Return type

BaseComponent

apply_perforations(current_date=None)[source]

Open or close perforation intervals for given time interval.

Parameters
Returns

segment – Segment with a blocks_info attribute that contains: - projections of welltrack in grid blocks - MD values for corresponding grid blocks - ratio of perforated part of the well for each grid block.

Return type

WellSegment

property attributes

Array of attributes.

calculate_cf(rock, grid, beta=1, units='METRIC', cf_aggregation='sum')[source]

Calculate connection factor values for each grid block of a segment.

Parameters
  • rock (Rock) – Rock component of geological model.

  • grid (Grid) – Rock component of geological model.

  • segment (WellSegment) – Well’s node.

  • beta (list or ndarray) – Additional multiplicator for productivity index of well.

  • units (str, 'METRIC' or 'FIELD') – Field units.

  • cf_aggregation (str, 'sum' or 'eucl') – The way of aggregating cf projection (‘sum’ - sum, ‘eucl’ - Euclid norm).

Returns

segment – Segment with a blocks_info attribute extended with calculated connection factor values for all segment blocks.

Return type

WellSegment

property children

All child nodes.

>>> from anytree import Node
>>> n = Node("n")
>>> a = Node("a", parent=n)
>>> b = Node("b", parent=n)
>>> c = Node("c", parent=n)
>>> n.children
(Node('/n/a'), Node('/n/b'), Node('/n/c'))

Modifying the children attribute modifies the tree.

Detach

The children attribute can be updated by setting to an iterable.

>>> n.children = [a, b]
>>> n.children
(Node('/n/a'), Node('/n/b'))

Node c is removed from the tree. In case of an existing reference, the node c does not vanish and is the root of its own tree.

>>> c
Node('/c')

Attach

>>> d = Node("d")
>>> d
Node('/d')
>>> n.children = [a, b, d]
>>> n.children
(Node('/n/a'), Node('/n/b'), Node('/n/d'))
>>> d
Node('/n/d')

Duplicate

A node can just be the children once. Duplicates cause a TreeError:

>>> n.children = [a, b, d, a]
Traceback (most recent call last):
    ...
anytree.node.exceptions.TreeError: Cannot add node Node('/n/a') multiple times as child.
property class_name

Name of the component.

copy()[source]

Returns a deepcopy. Cached properties are not copied.

property cum_rates

Cumulative rates for the current node and all its branches.

del_state(*args)

State remover.

property depth

Number of edges to the root Node.

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> udo.depth
0
>>> marc.depth
1
>>> lian.depth
2
property descendants

All child nodes and all their child nodes.

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> loui = Node("Loui", parent=marc)
>>> soe = Node("Soe", parent=lian)
>>> udo.descendants
(Node('/Udo/Marc'), Node('/Udo/Marc/Lian'), Node('/Udo/Marc/Lian/Soe'), Node('/Udo/Marc/Loui'))
>>> marc.descendants
(Node('/Udo/Marc/Lian'), Node('/Udo/Marc/Lian/Soe'), Node('/Udo/Marc/Loui'))
>>> lian.descendants
(Node('/Udo/Marc/Lian/Soe'),)
drop(attr)

Drop an attribute.

dump(path, **kwargs)

Dump attributes into file.

Parameters
  • path (str) – Path to output file.

  • kwargs (dict, optional) – Any kwargs for dump method.

Returns

comp – BaseComponent unchanged.

Return type

BaseComponent

static dump_array_ascii(buffer, array, header=None, fmt='%f', compressed=True)

Writes array-like data into an ASCII buffer.

Parameters
  • buffer (buffer-like) –

  • array (1d, array-like) – Array to be saved

  • header (str, optional) – String to be written line before the array

  • fmt (str or sequence of strs, optional) – Format to be passed into numpy.savetxt function. Default to ‘%f’.

  • compressed (bool) – If True, uses compressed typing style

empty_like()

Get an empty component with the same state and the structure of embedded BaseComponents (if any).

property fullname

Full name from root.

property height

Number of edges on the longest path to a leaf Node.

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> udo.height
2
>>> marc.height
1
>>> lian.height
0
init_state(**kwargs)

Init state attributes.

property is_group

Check that node is a group of wells.

property is_leaf

Node has no children (External Node).

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> udo.is_leaf
False
>>> marc.is_leaf
False
>>> lian.is_leaf
True
property is_main_branch

Check that node in a main well’s branch.

property is_root

Node is tree root.

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> udo.is_root
True
>>> marc.is_root
False
>>> lian.is_root
False
items()

Returns pairs of attribute’s names and data.

iter_path_reverse()

Iterate up the tree from the current node.

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> for node in udo.iter_path_reverse():
...     print(node)
Node('/Udo')
>>> for node in marc.iter_path_reverse():
...     print(node)
Node('/Udo/Marc')
Node('/Udo')
>>> for node in lian.iter_path_reverse():
...     print(node)
Node('/Udo/Marc/Lian')
Node('/Udo/Marc')
Node('/Udo')
keys()

Array of attributes.

property leaves

Tuple of all leaf nodes.

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> loui = Node("Loui", parent=marc)
>>> lazy = Node("Lazy", parent=marc)
>>> udo.leaves
(Node('/Udo/Marc/Lian'), Node('/Udo/Marc/Loui'), Node('/Udo/Marc/Lazy'))
>>> marc.leaves
(Node('/Udo/Marc/Lian'), Node('/Udo/Marc/Loui'), Node('/Udo/Marc/Lazy'))
load(path_or_buffer, **kwargs)

Load data from a file or buffer.

Parameters
  • path_or_buffer (str of string buffer) – Source to read data from.

  • **kwargs (dict, optional) – Any kwargs to be passed to load method.

Returns

comp – BaseComponent with loaded attributes.

Return type

BaseComponent

property name

Node’s name.

property parent

Parent Node.

On set, the node is detached from any previous parent node and attached to the new node.

>>> from anytree import Node, RenderTree
>>> udo = Node("Udo")
>>> marc = Node("Marc")
>>> lian = Node("Lian", parent=marc)
>>> print(RenderTree(udo))
Node('/Udo')
>>> print(RenderTree(marc))
Node('/Marc')
└── Node('/Marc/Lian')

Attach

>>> marc.parent = udo
>>> print(RenderTree(udo))
Node('/Udo')
└── Node('/Udo/Marc')
    └── Node('/Udo/Marc/Lian')

Detach

To make a node to a root node, just set this attribute to None.

>>> marc.is_root
False
>>> marc.parent = None
>>> marc.is_root
True
property path

Path of this Node.

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> udo.path
(Node('/Udo'),)
>>> marc.path
(Node('/Udo'), Node('/Udo/Marc'))
>>> lian.path
(Node('/Udo'), Node('/Udo/Marc'), Node('/Udo/Marc/Lian'))
perforated_blocks(t=None)[source]

List of perforated blocks for current node.

perforated_indices(t=None)[source]

Mask indicating perforated blocks.

ravel(attr=None, order='F', inplace=True)

Ravel attributes where applicable assuming by default Fortran order.

Parameters
  • attr (str, array of str) – Attribute to ravel.

  • order (str) – Numpy reshape order. Default to ‘F’.

  • inplace (bool) – If True, ravel is made inplace, return BaseComponent. Else, return raveled attribute.

Returns

out

Return type

BaseComponent if inplace else raveled attribute itself.

reshape(attr, newshape, order='C', inplace=True)

Reshape numpy.ndarray attributes.

Parameters
  • attr (str, array of str) – Attribute to be reshaped.

  • newshape (tuple) – New shape.

  • order (str) – Numpy reshape order. Default to ‘C’.

  • inplace (bool) – If True, reshape is made inplace, return BaseComponent. Else, return reshaped attribute.

Returns

output

Return type

BaseComponent if inplace else reshaped attribute itself.

property root

Tree Root Node.

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> udo.root
Node('/Udo')
>>> marc.root
Node('/Udo')
>>> lian.root
Node('/Udo')
separator = '/'
set_state(**kwargs)

State setter.

property siblings

Tuple of nodes with the same parent.

>>> from anytree import Node
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> loui = Node("Loui", parent=marc)
>>> lazy = Node("Lazy", parent=marc)
>>> udo.siblings
()
>>> marc.siblings
()
>>> lian.siblings
(Node('/Udo/Marc/Loui'), Node('/Udo/Marc/Lazy'))
>>> loui.siblings
(Node('/Udo/Marc/Lian'), Node('/Udo/Marc/Lazy'))
property state

Get state.

property total_rates

Total rates for the current node and all its branches.

values()

Returns a generator of attribute’s data.