topostats.tracing.splining#
Order single pixel skeletons with or without NodeStats Statistics.
Attributes#
Classes#
Smooth the ordered trace via an average of splines. |
|
Obtain a smoothed trace of a molecule. |
Functions#
|
Contour length for each of the splined traces accounting for whether the molecule is circular or linear. |
|
Euclidean distance between the start and end of linear molecules. |
|
Obtain smoothed traces of pixel-wise ordered traces for molecules in an image. |
Module Contents#
- topostats.tracing.splining.LOGGER#
- class topostats.tracing.splining.splineTrace(image: numpy.typing.NDArray, mol_ordered_tracing_data: dict, pixel_to_nm_scaling: float, spline_step_size: float, spline_linear_smoothing: float, spline_circular_smoothing: float, spline_degree: int)[source]#
Smooth the ordered trace via an average of splines.
- Parameters:
image (npt.NDArray) – Whole image containing all molecules and grains.
mol_ordered_tracing_data (dict) – Molecule ordered trace dictionary containing Nx2 ordered coords and molecule statistics.
pixel_to_nm_scaling (float) – The pixel to nm scaling factor, by default 1.
spline_step_size (float) – Step length in meters to use a coordinate for splining.
spline_linear_smoothing (float) – Amount of linear spline smoothing.
spline_circular_smoothing (float) – Amount of circular spline smoothing.
spline_degree (int) – Degree of the spline. Cubic splines are recommended. Even values of k should be avoided especially with a small s-value.
- image#
- mol_ordered_trace#
- mol_is_circular#
- pixel_to_nm_scaling#
- spline_step_size#
- spline_linear_smoothing#
- spline_circular_smoothing#
- spline_degree#
- tracing_stats#
- get_splined_traces(fitted_trace: numpy.typing.NDArray) numpy.typing.NDArray [source]#
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.
- Parameters:
fitted_trace (npt.NDArray) – Numpy array of the fitted trace.
- Returns:
Splined (smoothed) array of trace.
- Return type:
npt.NDArray
- static remove_duplicate_consecutive_tuples(tuple_list: list[tuple | numpy.typing.NDArray]) list[tuple] [source]#
Remove duplicate consecutive tuples from a list.
- Parameters:
tuple_list (list[tuple | npt.NDArray]) – List of tuples or numpy ndarrays to remove consecutive duplicates from.
- Returns:
List of tuples with consecutive duplicates removed.
- Return type:
list[Tuple]
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)]
- class topostats.tracing.splining.windowTrace(mol_ordered_tracing_data: dict, pixel_to_nm_scaling: float, rolling_window_size: float)[source]#
Obtain a smoothed trace of a molecule.
- Parameters:
mol_ordered_tracing_data (dict) – Molecule ordered trace dictionary containing Nx2 ordered coords and molecule statistics.
pixel_to_nm_scaling (float, optional) – The pixel to nm scaling factor, by default 1.
rolling_window_size (np.float64, optional) – The length of the rolling window too average over, by default 6.0.
- mol_ordered_trace#
- mol_is_circular#
- pixel_to_nm_scaling#
- rolling_window_size#
- tracing_stats#
- static pool_trace_circular(pixel_trace: numpy.typing.NDArray[numpy.int32], rolling_window_size: numpy.float64 = 6.0, pixel_to_nm_scaling: float = 1) numpy.typing.NDArray[numpy.float64] [source]#
Smooth a pixelwise ordered trace of circular molecules via a sliding window.
- Parameters:
pixel_trace (npt.NDArray[np.int32]) – Nx2 ordered trace coordinates.
rolling_window_size (np.float64, optional) – The length of the rolling window too average over, by default 6.0.
pixel_to_nm_scaling (float, optional) – The pixel to nm scaling factor, by default 1.
- Returns:
MxN Smoothed ordered trace coordinates.
- Return type:
npt.NDArray[np.float64]
- static pool_trace_linear(pixel_trace: numpy.typing.NDArray[numpy.int32], rolling_window_size: numpy.float64 = 6.0, pixel_to_nm_scaling: float = 1) numpy.typing.NDArray[numpy.float64] [source]#
Smooth a pixelwise ordered trace of linear molecules via a sliding window.
- Parameters:
pixel_trace (npt.NDArray[np.int32]) – Nx2 ordered trace coordinates.
rolling_window_size (np.float64, optional) – The length of the rolling window too average over, by default 6.0.
pixel_to_nm_scaling (float, optional) – The pixel to nm scaling factor, by default 1.
- Returns:
MxN Smoothed ordered trace coordinates.
- Return type:
npt.NDArray[np.float64]
- topostats.tracing.splining.measure_contour_length(splined_trace: numpy.typing.NDArray, mol_is_circular: bool, pixel_to_nm_scaling: float) float [source]#
Contour length for each of the splined traces accounting for whether the molecule is circular or linear.
Contour length units are nm.
- Parameters:
splined_trace (npt.NDArray) – The splined trace.
mol_is_circular (bool) – Whether the molecule is circular or not.
pixel_to_nm_scaling (float) – Scaling factor from pixels to nanometres.
- Returns:
Length of molecule in nanometres (nm).
- Return type:
float
- topostats.tracing.splining.measure_end_to_end_distance(splined_trace, mol_is_circular, pixel_to_nm_scaling: float)[source]#
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).
- Parameters:
splined_trace (npt.NDArray) – The splined trace.
mol_is_circular (bool) – Whether the molecule is circular or not.
pixel_to_nm_scaling (float) – Scaling factor from pixels to nanometres.
- Returns:
Length of molecule in nanometres (nm).
- Return type:
float
- topostats.tracing.splining.splining_image(image: numpy.typing.NDArray, ordered_tracing_direction_data: dict, pixel_to_nm_scaling: float, filename: str, method: str, rolling_window_size: float, spline_step_size: float, spline_linear_smoothing: float, spline_circular_smoothing: float, spline_degree: int) tuple[dict, pandas.DataFrame, pandas.DataFrame] [source]#
Obtain smoothed traces of pixel-wise ordered traces for molecules in an image.
- Parameters:
image (npt.NDArray) – Whole image containing all molecules and grains.
ordered_tracing_direction_data (dict) – Dictionary result from the ordered traces.
pixel_to_nm_scaling (float) – Scaling factor from pixels to nanometres.
filename (str) – Name of the image file.
method (str) – Method of trace smoothing, options are ‘splining’ and ‘rolling_window’.
rolling_window_size (float) – Length in meters to average coordinates over in the rolling window.
spline_step_size (float) – Step length in meters to use a coordinate for splining.
spline_linear_smoothing (float) – Amount of linear spline smoothing.
spline_circular_smoothing (float) – Amount of circular spline smoothing.
spline_degree (int) – Degree of the spline. Cubic splines are recommended. Even values of k should be avoided especially with a small s-value.
- Returns:
A spline data dictionary for all molecules, and a grainstats dataframe additions dataframe and molecule statistics dataframe.
- Return type:
tuple[dict, pd.DataFrame, pd.DataFrame]