topostats.tracing.splining ========================== .. py:module:: topostats.tracing.splining .. autoapi-nested-parse:: Order single pixel skeletons with or without NodeStats Statistics. .. !! processed by numpydoc !! Attributes ---------- .. autoapisummary:: topostats.tracing.splining.LOGGER Classes ------- .. autoapisummary:: topostats.tracing.splining.splineTrace topostats.tracing.splining.windowTrace Functions --------- .. autoapisummary:: topostats.tracing.splining.measure_contour_length topostats.tracing.splining.measure_end_to_end_distance topostats.tracing.splining.splining_image topostats.tracing.splining.interpolate_between_two_points_distance topostats.tracing.splining.resample_points_regular_interval Module Contents --------------- .. py:data:: LOGGER .. py:class:: splineTrace(topostats_object: topostats.classes.TopoStats, grain: int, molecule: int, spline_step_size: float | None = None, spline_linear_smoothing: float | None = None, spline_circular_smoothing: float | None = None, spline_degree: int | None = None) Smooth the ordered trace via an average of splines. :param topostats_object: TopoStats object with ordered traces calculated for grains and molecules. :type topostats_object: TopoStats :param grain: Grain number to process. :type grain: int :param molecule: Molecule number to process. :type molecule: int :param spline_step_size: Step length in meters to use a coordinate for splining. :type spline_step_size: float :param spline_linear_smoothing: Amount of linear spline smoothing. :type spline_linear_smoothing: float :param spline_circular_smoothing: Amount of circular spline smoothing. :type spline_circular_smoothing: float :param spline_degree: Degree of the spline. Cubic splines are recommended. Even values of k should be avoided especially with a small s-value. :type spline_degree: int .. !! processed by numpydoc !! .. py:attribute:: image .. py:attribute:: mol_ordered_trace .. py:attribute:: mol_is_circular .. py:attribute:: pixel_to_nm_scaling .. py:attribute:: spline_step_size :value: None .. py:attribute:: spline_linear_smoothing :value: None .. py:attribute:: spline_circular_smoothing :value: None .. py:attribute:: spline_degree :value: None .. py:attribute:: tracing_stats .. py:method:: get_splined_traces(fitted_trace: numpy.typing.NDArray) -> numpy.typing.NDArray Get a splined version of the fitted trace - useful for finding the radius of gyration etc. This function actually calculates the average of several splines which is important for getting a good fit on the lower resolution data. :param fitted_trace: Numpy array of the fitted trace. :type fitted_trace: npt.NDArray :returns: Splined (smoothed) array of trace. :rtype: npt.NDArray .. !! processed by numpydoc !! .. py:method:: remove_duplicate_consecutive_tuples(tuple_list: list[tuple | numpy.typing.NDArray]) -> list[tuple] :staticmethod: Remove duplicate consecutive tuples from a list. :param tuple_list: List of tuples or numpy ndarrays to remove consecutive duplicates from. :type tuple_list: list[tuple | npt.NDArray] :returns: List of tuples with consecutive duplicates removed. :rtype: list[Tuple] .. rubric:: Examples For the list of tuples [(1, 2), (1, 2), (1, 2), (2, 3), (2, 3), (3, 4)], this function will return [(1, 2), (2, 3), (3, 4)] .. !! processed by numpydoc !! .. py:method:: run_spline_trace() -> tuple[numpy.typing.NDArray, dict] Pipeline to run the splining smoothing and obtaining smoothing stats. :returns: Tuple of Nx2 smoothed trace coordinates, and smoothed trace statistics. :rtype: tuple[npt.NDArray, dict] .. !! processed by numpydoc !! .. py:class:: windowTrace(topostats_object: topostats.classes.TopoStats, grain: int, molecule: int, rolling_window_size: float | None = None, rolling_window_resampling: bool = False, rolling_window_resample_interval_nm: float = 0.5) Obtain a smoothed trace of a molecule. :param topostats_object: TopoStats object with ordered traces calculated for grains and molecules. :type topostats_object: TopoStats :param grain: Grain number to process. :type grain: int :param molecule: Molecule number to process. :type molecule: int :param rolling_window_size: The length of the rolling window too average over, by default 6.0. :type rolling_window_size: np.float64, optional :param rolling_window_resampling: Whether to resample the rolling window, by default False. :type rolling_window_resampling: bool, optional :param rolling_window_resample_interval_nm: The regular spatial interval (nm) to resample the rolling window, by default 0.5. :type rolling_window_resample_interval_nm: float, optional .. !! processed by numpydoc !! .. py:attribute:: mol_ordered_trace .. py:attribute:: mol_is_circular .. py:attribute:: pixel_to_nm_scaling .. py:attribute:: rolling_window_size .. py:attribute:: rolling_window_resampling :value: False .. py:attribute:: rolling_window_resample_interval_nm :value: 499999999.99999994 .. py:attribute:: tracing_stats .. py:method:: pool_trace_circular(molecule: topostats.classes.Molecule, rolling_window_size: numpy.float64 = 6.0, pixel_to_nm_scaling: float = 1) -> numpy.typing.NDArray[numpy.float64] :staticmethod: Smooth a pixelwise ordered trace of circular molecules via a sliding window. :param molecule: Molecule object with attribute ``.ordered_coords``, the ordered coordinates to be splined. :type molecule: Molecule :param rolling_window_size: The length of the rolling window too average over, by default 6.0. :type rolling_window_size: np.float64, optional :param pixel_to_nm_scaling: The pixel to nm scaling factor, by default 1. :type pixel_to_nm_scaling: float, optional :returns: MxN Smoothed ordered trace coordinates. :rtype: npt.NDArray[np.float64] .. !! processed by numpydoc !! .. py:method:: pool_trace_linear(molecule: topostats.classes.Molecule, rolling_window_size: numpy.float64 = 6.0, pixel_to_nm_scaling: float = 1) -> numpy.typing.NDArray[numpy.float64] :staticmethod: Smooth a pixelwise ordered trace of linear molecules via a sliding window. :param molecule: Molecule object with attribute ``.ordered_coords``, the ordered coordinates to be splined. :type molecule: Molecule :param rolling_window_size: The length of the rolling window too average over, by default 6.0. :type rolling_window_size: np.float64, optional :param pixel_to_nm_scaling: The pixel to nm scaling factor, by default 1. :type pixel_to_nm_scaling: float, optional :returns: MxN Smoothed ordered trace coordinates. :rtype: npt.NDArray[np.float64] .. !! processed by numpydoc !! .. py:method:: run_window_trace() -> tuple[numpy.typing.NDArray, dict] Pipeline to run the rolling window smoothing and obtaining smoothing stats. :returns: Tuple of Nx2 smoothed trace coordinates, and smoothed trace statistics. :rtype: tuple[npt.NDArray, dict] .. !! processed by numpydoc !! .. py:function:: measure_contour_length(splined_trace: numpy.typing.NDArray, mol_is_circular: bool, pixel_to_nm_scaling: float) -> float Contour length for each of the splined traces accounting for whether the molecule is circular or linear. Contour length units are nm. :param splined_trace: The splined trace. :type splined_trace: npt.NDArray :param mol_is_circular: Whether the molecule is circular or not. :type mol_is_circular: bool :param pixel_to_nm_scaling: Scaling factor from pixels to nanometres. :type pixel_to_nm_scaling: float :returns: Length of molecule in nanometres (nm). :rtype: float .. !! processed by numpydoc !! .. py:function:: measure_end_to_end_distance(splined_trace, mol_is_circular, pixel_to_nm_scaling: float) Euclidean distance between the start and end of linear molecules. The hypotenuse is calculated between the start ([0,0], [0,1]) and end ([-1,0], [-1,1]) of linear molecules. If the molecule is circular then the distance is set to zero (0). :param splined_trace: The splined trace. :type splined_trace: npt.NDArray :param mol_is_circular: Whether the molecule is circular or not. :type mol_is_circular: bool :param pixel_to_nm_scaling: Scaling factor from pixels to nanometres. :type pixel_to_nm_scaling: float :returns: Length of molecule in nanometres (nm). :rtype: float .. !! processed by numpydoc !! .. py:function:: splining_image(topostats_object: topostats.classes.TopoStats, method: str | None = None, rolling_window_size: float | None = None, spline_step_size: float | None = None, spline_linear_smoothing: float | None = None, spline_circular_smoothing: float | None = None, spline_degree: int | None = None, rolling_window_resampling: bool | None = None, rolling_window_resample_regular_spatial_interval: float | None = None) -> None Obtain smoothed traces of pixel-wise ordered traces for molecules in an image. :param topostats_object: TopoStats object with ordered traces of grain crops to be splined. :type topostats_object: TopoStats :param method: Method of trace smoothing, options are 'splining' and 'rolling_window'. :type method: str :param rolling_window_size: Length in meters to average coordinates over in the rolling window. :type rolling_window_size: float :param spline_step_size: Step length in meters to use a coordinate for splining. :type spline_step_size: float :param spline_linear_smoothing: Amount of linear spline smoothing. :type spline_linear_smoothing: float :param spline_circular_smoothing: Amount of circular spline smoothing. :type spline_circular_smoothing: float :param spline_degree: Degree of the spline. Cubic splines are recommended. Even values of k should be avoided especially with a small s-value. :type spline_degree: int :param rolling_window_resampling: Whether to resample the rolling window, by default False. :type rolling_window_resampling: bool, optional :param rolling_window_resample_regular_spatial_interval: The regular spatial interval (nm) to resample the rolling window, by default 0.5. :type rolling_window_resample_regular_spatial_interval: float, optional .. !! processed by numpydoc !! .. py:function:: interpolate_between_two_points_distance(point1: numpy.typing.NDArray[numpy.float32], point2: numpy.typing.NDArray[numpy.float32], distance: numpy.float32) -> numpy.typing.NDArray[numpy.float32] Interpolate between two points to create a new point at a set distance between the two. :param point1: The first point. :type point1: npt.NDArray[np.float32] :param point2: The second point. :type point2: npt.NDArray[np.float32] :param distance: The distance to interpolate between the two points. :type distance: np.float32 :returns: The new point at the specified distance between the two points. :rtype: npt.NDArray[np.float32] .. !! processed by numpydoc !! .. py:function:: resample_points_regular_interval(points: numpy.typing.NDArray, interval: float, circular: bool) -> numpy.typing.NDArray Resample a set of points to be at regular spatial intervals. Note: This is NOT intended to be pure interpolation, as interpolated points would not produce uniformly spaced points in cartesian space. :param points: The points to resample. :type points: npt.NDArray :param interval: The distance that all returned points should be apart. :type interval: float :param circular: If True, the first and last points will be connected to form a closed loop. If False, the first and last points will not be connected. :type circular: bool :returns: The resampled points, evenly spaced at the specified interval. :rtype: npt.NDArray .. !! processed by numpydoc !!