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.
-
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
-
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
-
apply_perforations
(segment, current_date=None)[source]¶ Open or close perforation intervals for given time interval.
- Parameters
segment (WellSegment) – Well’s node.
current_date (pandas.Timestamp, optional) – Final date to open new perforations.
- 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
-
property
attributes
¶ Array of attributes.
-
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
-
property
class_name
¶ Name of the component.
-
compute_events
(segment, grid, attr='EVENTS')[source]¶ Make events from WCONPROD and WCONINJE if present.
-
property
cum_rates
¶ Cumulative rates over all wells.
-
del_state
(*args)¶ State remover.
-
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
-
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
-
dump
(path, **kwargs)¶ Dump attributes into file.
- Parameters
- Returns
comp – BaseComponent unchanged.
- Return type
-
static
dump_array_ascii
(buffer, array, header=None, fmt='%f', compressed=True)¶ Writes array-like data into an ASCII buffer.
- Parameters
-
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.
-
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
-
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
-
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
-
ravel
(attr=None, order='F', inplace=True)¶ Ravel attributes where applicable assuming by default Fortran order.
-
reshape
(attr, newshape, order='C', inplace=True)¶ Reshape numpy.ndarray attributes.
- Parameters
- 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
- Returns
wells – Wells with an event attribute added.
- Return type
-
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.
-
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.
-
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
-
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
- Returns
out – Wells with updated attributes.
- Return type
-
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
-
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
-
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
-
apply_perforations
(current_date=None)[source]¶ Open or close perforation intervals for given time interval.
- Parameters
segment (WellSegment) – Well’s node.
current_date (pandas.Timestamp) – Final date to open new perforations.
- 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
-
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
-
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.
-
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
- Returns
comp – BaseComponent unchanged.
- Return type
-
static
dump_array_ascii
(buffer, array, header=None, fmt='%f', compressed=True)¶ Writes array-like data into an ASCII buffer.
- Parameters
-
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
-
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'))
-
ravel
(attr=None, order='F', inplace=True)¶ Ravel attributes where applicable assuming by default Fortran order.
-
reshape
(attr, newshape, order='C', inplace=True)¶ Reshape numpy.ndarray attributes.
- Parameters
- 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.