Geometric.Linesegment#

Geometric.Linesegment.py

Copyright (c) 2024, SAXS Team, KEK-PF

class Linesegment(x, y, regress_info=None)#

Bases: object

A class representing a line segment defined by linear regression.

slope#

The slope of the line segment.

Type:

float

intercept#

The intercept of the line segment.

Type:

float

std_err#

The standard error of the linear regression.

Type:

float

x#

The x-values of the line segment.

Type:

array-like

y#

The y-values of the line segment, computed as y = slope * x + intercept.

Type:

array-like

center_x#

The center x-value of the line segment.

Type:

float

center_y#

The center y-value of the line segment.

Type:

float

Initialize the Linesegment object. :param x: The x-values of the line segment. :type x: array-like :param y: The y-values of the line segment. :type y: array-like :param regress_info: Precomputed regression information. If None, it will be computed from x and y. :type regress_info: tuple of (slope, intercept, std_err), optional

get_std()#

Get the standard error of the linear regression. :returns: The standard error of the linear regression. :rtype: float

get_y()#

Get the y-values of the line segment. :returns: The y-values of the line segment. :rtype: array-like

get_segments(x, y, breakpoints=None, n_bkps=2)#

Segment the data into line segments using change point detection.

Parameters:
  • x (array-like) – The x-values of the data.

  • y (array-like) – The y-values of the data.

  • breakpoints (list of int, optional) – The breakpoints for segmentation. If None, they will be computed using change point detection.

  • n_bkps (int, optional) – The number of breakpoints to detect if breakpoints is None. Default is 2.

Returns:

A tuple containing the list of breakpoints and the list of Linesegment objects.

Return type:

tuple

plot_segments(x, y, segments, title=None, ax=None)#

Plot the data and the line segments. :param x: The x-values of the data. :type x: array-like :param y: The y-values of the data. :type y: array-like :param segments: The list of line segments to plot. :type segments: list of Linesegment :param title: The title of the plot. If None, no title is set. :type title: str, optional :param ax: The axes to plot on. If None, a new figure and axes are created. :type ax: matplotlib.axes.Axes, optional

to_negative_segments(segments)#

Convert a list of line segments to their negative counterparts.

Parameters:

segments (list of Linesegment) – The list of line segments to convert.

Returns:

The list of negative line segments.

Return type:

list of Linesegment