Resistograph class reference guide

Resistograph data processing module.

This module provides a class to handle resistograph data processing, including reading, preprocessing, and removing global linear trends from the data. It also includes a function to visualize the resistograph data as colored bars on a tomogram image.

class tomotree.resistograph.DrillingPath(file, start=None, end=None, name=None)

Bases: object

A class to represent a drilling path with start and end points.

File is the filename from which to read the resistograph data. All other attributes are optional and default value is None.

Attributes:

startnp.ndarray

Starting coordinates of the drilling path.

endnp.ndarray

Ending coordinates of the drilling path.

filestr

Filename associated with the drilling path.

namestr

Name associated with the drilling path.

datapd.DataFrame

DataFrame containing resistograph data for the drilling path. If the filename is not None in the init, it is read from the file.

Notes:

  • The class uses the dataclass decorator for boilerplate code reduction.

  • All attributes are optional and default to None.

  • The data attribute is initialized to None and can be populated later.

property angle

Calculate the angle of the drilling path in degrees.

Returns:

The angle of the drilling path in degrees.

Return type:

float

data: DataFrame = None
end: ndarray = None
file: str
name: str = None
start: ndarray = None
Parameters:
  • file (str)

  • start (ndarray)

  • end (ndarray)

  • name (str)

class tomotree.resistograph.Resistograph(directory, nan_lower_limit=0, nan_upper_limit=220000, smooth=False, set_min_treshold=0, window_length=201, polyorder=3, drilling_paths=<factory>)

Bases: object

A class to handle resistograph data processing, including reading, preprocessing, and removing global linear trends from the data.

Attributes:

directorystr

Directory containing resistograph data files.

nan_lower_limitint

Number of initial rows to set as NaN.

nan_upper_limitint

Number of rows after which data is set as NaN.

smoothbool

Whether to apply smoothing to the data.

set_min_tresholdint

Minimum threshold for valid data.

window_lengthint

Window length for Savitzky-Golay filter.

polyorderint

Polynomial order for Savitzky-Golay filter.

datapandas.DataFrame

DataFrame containing processed resistograph data.

property data

Property to get the processed resistograph data.

Returns:

The processed resistograph data.

Return type:

pandas.DataFrame

directory: str
drilling_paths: list[DrillingPath]
get_data()

Get the processed resistograph data.

Returns:

The processed resistograph data.

Return type:

pandas.DataFrame

nan_lower_limit: int = 0
nan_upper_limit: int = 220000
polyorder: int = 3
preprocess_data()

Preprocess the resistograph data by applying various transformations.

This method reads the data, sets initial and final rows as NaN, applies smoothing if enabled, and removes values below a minimum threshold.

read_resistograph_data()

Read resistograph data from files in the specified directory and process it.

The method reads all files with the extension .dpa, extracts the data section. The data is stored in a list of DrillingPath objects.

Notes:

  • The method assumes that the files are in CSV format with a specific header.

  • The data section starts after a line containing ‘[DATA]’.

  • The method logs the number of files read and their names.

  • The processed data is stored in the drilling_paths attribute.

remove_global_linear_trend()

Remove the global linear trend from the resistograph data.

This method calculates the linear trend across all columns and subtracts it from the data to normalize the values.

set_min_treshold: int = 0
smooth: bool = False
window_length: int = 201
Parameters:
  • directory (str)

  • nan_lower_limit (int)

  • nan_upper_limit (int)

  • smooth (bool)

  • set_min_treshold (int)

  • window_length (int)

  • polyorder (int)

  • drilling_paths (list[DrillingPath])

tomotree.resistograph.add_resistograph_graphs(resistograph, ax, yshift=100, yscale=20, color='C0', showlabels=False, include_only=None)

Add resistograph graphs to the plot.

Parameters:
  • resistograph (Resistograph) – An object representing the resistograph.

  • ax (matplotlib.axes.Axes) – Axes object to add the graphs to.

  • yshift (int) – Vertical shift for the graphs (default is 100).

  • yscale (int) – Vertical scale for the graphs (default is 20).

  • color (str) – Color for the graphs (default is ‘C0’).

  • showlabels (bool) – Whether to show labels for each drilling path (default is False).

  • include_only (list, optional) – A list of drilling path names to include in the plot. If None, all paths are included.

Returns:

The axes with the resistograph graphs added.

Return type:

matplotlib.axes.Axes

tomotree.resistograph.add_resistograph_to_image(resistograph, ax=None, cax=None, min=100, max=200, zorder=100, columns=None, linewidth=16, ruler_length_cm=20, step=300, showlabels=False, include_only=None, verbose=False, **kwargs)

Plot resistograph data as series of colored bars on the picture with tomogram.

This function visualizes resistograph data by overlaying it as colored bars on a tomogram image. The bars are color-coded based on the resistograph values, and a color bar is added to indicate the value range. Additionally, a scale indicator is drawn on the image.

Parameters:
  • resistograph (Resistograph) – An object representing the resistograph.

  • ax (matplotlib.axes.Axes, optional) – The axes on which to plot the resistograph data. If None, a new figure and axes are created.

  • cax (matplotlib.axes.Axes, optional) – The axes on which to plot the color bar. If None, the color bar is added to the main axes.

  • min (float, optional) – The minimum value for the color normalization. Default is 100.

  • max (float, optional) – The maximum value for the color normalization. Default is 200.

  • zorder (int, optional) – The z-order for the plotted elements. Default is 100.

  • columns (list, optional) – A list of column indices from the DataFrame to plot. If None, all columns are used.

  • linewidth (float, optional) – The width of the colored bars. Default is 16.

  • ruler_length_cm (float, optional) – Length in cm of the ruler (measuring rod) drawn along each drilling path from its start, as alternating red and black 5 cm stripes; only whole stripes are drawn (20 gives 20 cm, 22 gives 20 cm). Default is 20. The former name meter_length is still accepted (deprecated).

  • step (int, optional) – The step size for down-sampling the resistograph data. Default is 300.

  • showlabels (bool, optional) – Whether to show labels for each drilling path. Default is False.

  • include_only (list, optional) – A list of drilling path names to include in the plot. If None, all paths are included.

  • verbose (bool, optional) – Whether to print verbose output. Default is False.

  • **kwargs (dict) – Additional keyword arguments for customization.

Returns:

ax – The axes with the plotted resistograph data.

Return type:

matplotlib.axes.Axes

Notes

  • The function assumes that the tomogram nodes are numbered sequentially and that their coordinates are accessible via the get_node_by_number method.

  • The scale indicator is drawn at the bottom-left corner of the plot, with labels “5cm” and “10cm”.

  • Missing or NaN values in the resistograph data are ignored during plotting.

tomotree.resistograph.auto_drilling_paths(resistograph, tomo)

Paths from the midpoint between neighbouring sensors (i, i+1) to the pith.

Sets the paths of resistograph and returns them as a dict.

tomotree.resistograph.plot_rolling_mean_std(df, column, window, center=False, show_std_band=True, n=2)

Vykreslí data, klouzavý průměr a směrodatnou odchylku.

Parameters:
  • df (pandas.DataFrame) – Vstupní data

  • column (str) – Název sloupce s daty

  • window (int) – Velikost klouzavého okna

  • center (bool, default False) – Zda centrovat okno

  • show_std_band (bool, default True) – Zda vykreslit pásmo ±1σ

tomotree.resistograph.plot_savgol_mean_std(df, column, window, polyorder=2, show_std_band=True, n=2)

Vykreslí data, Savitzky-Golay vyhlazení a pásmo ±nσ (σ počítána z reziduí v klouzavém okně).

Parameters:
  • df (pandas.DataFrame) – Vstupní data

  • column (str) – Název sloupce s daty

  • window (int) – Délka okna (musí být liché číslo)

  • polyorder (int, default 2) – Řád polynomu Savitzky-Golay filtru

  • show_std_band (bool, default True) – Zda vykreslit pásmo ±nσ

  • n (int, default 2) – Násobek směrodatné odchylky

tomotree.resistograph.set_drilling_paths(resistograph, paths)

Set start and end of drilling paths from {name: {'start': xy, 'end': xy}}.