logio.dynamic_time_warping package
Submodules
logio.dynamic_time_warping.DTW module
- logio.dynamic_time_warping.DTW.dtw(x, y, dist='euclidean', window_type='none', window_size=None, step_pattern='symmetric2', dist_only=False, open_begin=False, open_end=False)[source]
Perform dynamic time warping (dtw).
A Dynamic Programming algorithm to correlate well logs and to find the minimum-cost or “best” match.
- Parameters
x (1D or 2D array (sample * feature)) – Query log.
y (1D or 2D array (sample * feature)) – Reference log.
dist (string or callable) – Define how to calclulate pair-wise distance between x and y. If a string given, it will be interpreted as metric argument of
scipy.spatial.distance. If callable that defines metric between two samples, it will be used to compute distance matrix.window_type (string) – Window type to use. If “sakoechiba” given, Sakoechiba window will be used. If “itakura” given, Itakura window will be used.
window_size (int) – Window size to use for Sakoechiba window.
step_pattern (string) – Step pattern to use.
dist_only (bool) – Whether or not to obtain warping path. If true, only alignment distance will be calculated.
open_begin (bool) – Whether or not perform open-ended alignment at the starting point of query log. If true, partial alignment will be performed.
open_end (bool) – Whether or not perform open-ended alignment at the end point of query log. If true, partial alignment will be performed.
- Returns
Result obj.
- Return type
- logio.dynamic_time_warping.DTW.dtw_from_distance_matrix(X, window_type='none', window_size=None, step_pattern='symmetric2', dist_only=False, open_begin=False, open_end=False)[source]
Perform dtw based correlation using pre-computed pair-wise distance matrix.
- Parameters
X (2D array) – Pre-computed pair-wise distance matrix.
others – see
dtw()function.
- Returns
Result obj.
- Return type
- logio.dynamic_time_warping.DTW.dtw_low(X, window, pattern, dist_only=False, open_begin=False, open_end=False)[source]
Low-level dtw interface.
- Parameters
X (2D array) – Pair-wise distance matrix.
window (window.BaseWindow object) – window object.
pattern (step_pattern.BasePattern object) – step pattern object.
others – see
dtw()function.
- Returns
Result obj.
- Return type
logio.dynamic_time_warping.backtrack module
Backtracking implementation.
logio.dynamic_time_warping.cost module
Cost matrix computation.
logio.dynamic_time_warping.distance module
logio.dynamic_time_warping.dtwPlot module
DTW plotting functions
- logio.dynamic_time_warping.dtwPlot.AlignmentPlot(alignment_vector, query_index='Query Log index', reference_index='Reference Log index', **kwargs)[source]
Plotting of dynamic time warp results: annotated warping function
Details Display the query and reference well logs and their warping curve, arranged for visual inspection. The query log is plotted in the bottom panel, with indices growing rightwards and values upwards. Reference log is in the left panel, indices growing upwards and values leftwards.
- logio.dynamic_time_warping.dtwPlot.ThreeWayPlot(alignment_vector, query=None, reference=None, match_indices=None, match_col='gray', query_label='Query log index', reference_label='Reference log index', **kwargs)[source]
Plotting of dynamic time warp results: annotated warping function
Details Display the query and reference well logs and their warping curve, arranged for visual inspection. The query log is plotted in the bottom panel, with indices growing rightwards and values upwards. Reference log is in the left panel, indices growing upwards and values leftwards.
- Parameters
alignment_vector (object) – an alignment result, object of class DtwResult
query (Series) – query log (log of considerable interest)
reference (Series) – log from another well, which we intend to correlate or align with the query log.
query_label – label for the query axis
reference_label – label for the reference axis
match_indices – indices for which to draw a visual guide
... – additional arguments, used for the warping curve
- Returns
axes
- Return type
figure axes
logio.dynamic_time_warping.result module
- class logio.dynamic_time_warping.result.DtwResult(cumsum_matrix, path, window, pattern)[source]
Bases:
objectResult of Dynamic time warping.
- cumsum_matrix
Alignment matrix
- Type
2d array
- window
window constraints
- Type
2d array
- pattern
Alignment pattern
- Type
2d array
- get_warping_path(target="query"):
Get warping path.
- plot_window():
visualize window
- plot_cumsum_matrix():
plot heatmap of cumsum_matrix
- plot_path(with_="cum"):
plot alignment path; warp function/curve
- plot_pattern():
Plot alignment pattern
- dtw_plot(query=None,reference=None, type=None,**kwargs):
Plot dynamic time warp results using specific type plot.
- plot_aligned_logs(query=None,reference=None):
plot optimal aligment of both logs.
- dtw_plot(query=None, reference=None, type=None, **kwargs)[source]
Plot dynamic time warp results by displaying alignment contained in
DtwResultobject.Details Various plotting styles are available, passing strings to the
typeargument (may be abbreviated):alignmentplots the warping curve inalignment_vector;threewayvis-a-vis inspection of the timeseries and their warping curve;see [dtwPlot.ThreeWayPlot()]
Additional parameters are passed to the plotting functions: use with care.
- Parameters
query – log from another well, which we intend to correlate or align with the reference log
reference – reference log (log of considerable interest)
xlab (str) – label for the query axis
ylab (str) – label for the reference axis
type (str) – general style for the plot, see below
... – additional arguments, passed to plotting functions
- get_warping_path(target='query')[source]
Get warping path.
- Parameters
target (string, "query" or "reference") – Specify the target to be warped.
- Returns
warping_index – Warping index.
- Return type
1D array
- plot_aligned_logs(query=None, reference=None)[source]
Plot query log such that it is locally stretched and/or compressed in order to achieve the best possible match to the reference.
- Parameters
query (array, DataFrame or Series) – log from another well, which we intend to correlate or align with the reference log.
reference (array, DataFrame or Series) – well log used as reference point for correlation.
logio.dynamic_time_warping.step_pattern module
- class logio.dynamic_time_warping.step_pattern.Asymmetric[source]
Bases:
BasePattern- label = 'asymmetric'
- normalize_guide = 'N'
- pattern_info = [{'indices': [(-1, 0), (0, 0)], 'weights': [1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, 0)], 'weights': [1]}]
- class logio.dynamic_time_warping.step_pattern.AsymmetricP0[source]
Bases:
BasePattern- label = 'asymmetricP0'
- normalize_guide = 'N'
- pattern_info = [{'indices': [(0, -1), (0, 0)], 'weights': [0]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, 0), (0, 0)], 'weights': [1]}]
- class logio.dynamic_time_warping.step_pattern.AsymmetricP05[source]
Bases:
BasePattern- label = 'asymmetricP05'
- normalize_guide = 'N'
- pattern_info = [{'indices': [(-1, -3), (0, -2), (0, -1), (0, 0)], 'weights': [0.3333333333333333, 0.3333333333333333, 0.3333333333333333]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [0.5, 0.5]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [1, 1]}, {'indices': [(-3, -1), (-2, 0), (-1, 0), (0, 0)], 'weights': [1, 1, 1]}]
- class logio.dynamic_time_warping.step_pattern.AsymmetricP1[source]
Bases:
BasePattern- label = 'asymmetricP1'
- normalize_guide = 'N'
- pattern_info = [{'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [0.5, 0.5]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [1, 1]}]
- class logio.dynamic_time_warping.step_pattern.AsymmetricP2[source]
Bases:
BasePattern- label = 'asymmetricP2'
- normalize_guide = 'N'
- pattern_info = [{'indices': [(-2, -3), (-1, -2), (0, -1), (0, 0)], 'weights': [0.6666666666666666, 0.6666666666666666, 0.6666666666666666]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-3, -2), (-2, -1), (-1, 0), (0, 0)], 'weights': [1, 1, 1]}]
- class logio.dynamic_time_warping.step_pattern.BasePattern[source]
Bases:
objectStep pattern base class. A
BasePatternobject lists the transitions allowed while searching for the minimum-distance path.Methods
Plot_normalize_get_array__repr__prints a user-readable description of the recurrence equation defined by the given pattern.- property is_normalizable
- class logio.dynamic_time_warping.step_pattern.Mori2006[source]
Bases:
BasePattern- label = 'mori2006'
- normalize_guide = 'M'
- pattern_info = [{'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [2, 1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [3]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [3, 3]}]
- class logio.dynamic_time_warping.step_pattern.Symmetric1[source]
Bases:
BasePattern- label = 'symmetric1'
- normalize_guide = 'none'
- pattern_info = [{'indices': [(-1, 0), (0, 0)], 'weights': [1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(0, -1), (0, 0)], 'weights': [1]}]
- class logio.dynamic_time_warping.step_pattern.Symmetric2[source]
Bases:
BasePattern- label = 'symmetric2'
- normalize_guide = 'N+M'
- pattern_info = [{'indices': [(-1, 0), (0, 0)], 'weights': [1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [2]}, {'indices': [(0, -1), (0, 0)], 'weights': [1]}]
- class logio.dynamic_time_warping.step_pattern.SymmetricP0[source]
Bases:
Symmetric2Same as symmetric2 pattern.
- label = 'symmetricP05'
- class logio.dynamic_time_warping.step_pattern.SymmetricP05[source]
Bases:
BasePattern- label = 'symmetricP05'
- normalize_guide = 'N+M'
- pattern_info = [{'indices': [(-1, -3), (0, -2), (0, -1), (0, 0)], 'weights': [2, 1, 1]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [2, 1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [2]}, {'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [2, 1]}, {'indices': [(-3, -1), (-2, 0), (-1, 0), (0, 0)], 'weights': [2, 1, 1]}]
- class logio.dynamic_time_warping.step_pattern.SymmetricP1[source]
Bases:
BasePattern- label = 'symmetricP1'
- normalize_guide = 'N+M'
- pattern_info = [{'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [2, 1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [2]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [2, 1]}]
- class logio.dynamic_time_warping.step_pattern.SymmetricP2[source]
Bases:
BasePattern- label = 'symmetricP2'
- normalize_guide = 'N+M'
- pattern_info = [{'indices': [(-3, -2), (-2, -1), (-1, 0), (0, 0)], 'weights': [2, 2, 1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [2]}, {'indices': [(-2, -3), (-1, -2), (0, -1), (0, 0)], 'weights': [2, 2, 1]}]
- class logio.dynamic_time_warping.step_pattern.TypeIIIc[source]
Bases:
BasePattern- label = 'typeIIIc'
- normalize_guide = 'N'
- pattern_info = [{'indices': [(-1, -2), (0, 0)], 'weights': [1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [1, 1]}, {'indices': [(-2, -2), (-1, 0), (0, 0)], 'weights': [1, 1]}]
- class logio.dynamic_time_warping.step_pattern.TypeIIa[source]
Bases:
BasePattern- label = 'typeIIa'
- normalize_guide = 'none'
- pattern_info = [{'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, 0)], 'weights': [1]}, {'indices': [(-2, -1), (0, 0)], 'weights': [1]}]
- class logio.dynamic_time_warping.step_pattern.TypeIIb[source]
Bases:
BasePattern- label = 'typeIIb'
- normalize_guide = 'none'
- pattern_info = [{'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, 0)], 'weights': [2]}, {'indices': [(-2, -1), (0, 0)], 'weights': [2]}]
- class logio.dynamic_time_warping.step_pattern.TypeIIc[source]
Bases:
BasePattern- label = 'typeIIc'
- normalize_guide = 'none'
- pattern_info = [{'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, 0)], 'weights': [1]}, {'indices': [(-2, -1), (0, 0)], 'weights': [2]}]
- class logio.dynamic_time_warping.step_pattern.TypeIId[source]
Bases:
BasePattern- label = 'typeIId'
- normalize_guide = 'N+M'
- pattern_info = [{'indices': [(-1, -1), (0, 0)], 'weights': [2]}, {'indices': [(-1, -2), (0, 0)], 'weights': [3]}, {'indices': [(-2, -1), (0, 0)], 'weights': [3]}]
- class logio.dynamic_time_warping.step_pattern.TypeIVc[source]
Bases:
BasePattern- label = 'typeIVc'
- normalize_guide = 'N'
- pattern_info = [{'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, 0)], 'weights': [1]}, {'indices': [(-1, -3), (0, 0)], 'weights': [1]}, {'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [1, 1]}, {'indices': [(-2, -2), (-1, 0), (0, 0)], 'weights': [1, 1]}, {'indices': [(-2, -3), (-1, 0), (0, 0)], 'weights': [1, 1]}, {'indices': [(-3, -1), (-2, 0), (-1, 0), (0, 0)], 'weights': [1, 1, 1]}, {'indices': [(-3, -2), (-2, 0), (-1, 0), (0, 0)], 'weights': [1, 1, 1]}, {'indices': [(-3, -3), (-2, 0), (-1, 0), (0, 0)], 'weights': [1, 1, 1]}]
- class logio.dynamic_time_warping.step_pattern.TypeIa[source]
Bases:
BasePattern- label = 'typeIa'
- normalize_guide = 'none'
- pattern_info = [{'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [1, 0]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [1, 0]}]
- class logio.dynamic_time_warping.step_pattern.TypeIas[source]
Bases:
BasePattern- label = 'typeIas'
- normalize_guide = 'none'
- pattern_info = [{'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [0.5, 0.5]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [0.5, 0.5]}]
- class logio.dynamic_time_warping.step_pattern.TypeIb[source]
Bases:
BasePattern- label = 'typeIb'
- normalize_guide = 'none'
- pattern_info = [{'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [1, 1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [1, 1]}]
- class logio.dynamic_time_warping.step_pattern.TypeIbs[source]
Bases:
BasePattern- label = 'typeIbs'
- normalize_guide = 'none'
- pattern_info = [{'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [1, 1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [1, 1]}]
- class logio.dynamic_time_warping.step_pattern.TypeIc[source]
Bases:
BasePattern- label = 'typeIc'
- normalize_guide = 'N'
- pattern_info = [{'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [1, 1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [1, 0]}]
- class logio.dynamic_time_warping.step_pattern.TypeIcs[source]
Bases:
BasePattern- label = 'typeIcs'
- normalize_guide = 'N'
- pattern_info = [{'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [1, 1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [1]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [0.5, 0.5]}]
- class logio.dynamic_time_warping.step_pattern.TypeId[source]
Bases:
BasePattern- label = 'typeId'
- normalize_guide = 'N+M'
- pattern_info = [{'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [2, 1]}, {'indices': [(-1, -1), (0, 0)], 'weights': [2]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [2, 1]}]
- class logio.dynamic_time_warping.step_pattern.TypeIds[source]
Bases:
BasePattern- label = 'typeIds'
- normalize_guide = 'N+M'
- pattern_info = [{'indices': [(-2, -1), (-1, 0), (0, 0)], 'weights': [1.5, 1.5]}, {'indices': [(-1, -1), (0, 0)], 'weights': [2]}, {'indices': [(-1, -2), (0, -1), (0, 0)], 'weights': [1.5, 1.5]}]
- class logio.dynamic_time_warping.step_pattern.Unitary[source]
Bases:
BasePattern- label = 'unitary'
- normalize_guide = 'N'
- pattern_info = [{'indices': [(-1, -1), (0, 0)], 'weights': [1]}]
- class logio.dynamic_time_warping.step_pattern.UserStepPattern(pattern_info, normalize_guide)[source]
Bases:
BasePattern- label = 'user defined step pattern'
logio.dynamic_time_warping.window module
- class logio.dynamic_time_warping.window.BaseWindow[source]
Bases:
objectBase class on which the desired window constraint is built upon. The warping window intuitively controls the amount of distortion allowed when comparing a pair of well logs.
Generally they are two types of wapring windows: 1. Sakoechiba’s Window implemented in SakoechibaWindow class. 2. Itakura’s Window implemented in ItakuraWindow class.
- plot():
Visualize window (constraint)..
- class logio.dynamic_time_warping.window.ItakuraWindow(len_x, len_y)[source]
Bases:
BaseWindowA class for the Itakura window warping constraint.
- _gen_window(len_x, len_y):
Generates the window constraint matrix.
- label = 'itakura window'
- class logio.dynamic_time_warping.window.NoWindow(len_x, len_y)[source]
Bases:
BaseWindowNo window class.
- _gen_window(len_x, len_y):
Generates the window constraint matrix.
- label = 'no window'
- class logio.dynamic_time_warping.window.SakoechibaWindow(len_x, len_y, size)[source]
Bases:
BaseWindowSakoechiba window warping constraint.
- _gen_window(len_x, len_y, size):
Generates the window constraint matrix.
- label = 'sakoechiba window'
- class logio.dynamic_time_warping.window.UserWindow(len_x, len_y, win_func, *args, **kwargs)[source]
Bases:
BaseWindowA class for user defined window constraints.
Option for a user defined window is implemented in UserWindow class. The user window defined must be a function that returns a boolean.
- win_func
Any function which returns bool.
- Type
callable
- \*args, \*\*kwargs
Arguments for win_func
- _gen_window(len_x, len_y, win_func, \*args, \*\*kwargs):
Generates the window constraint matrix.
- label = 'user defined window'