spateo.io.utils =============== .. py:module:: spateo.io.utils .. autoapi-nested-parse:: IO utility functions. Functions --------- .. autoapisummary:: spateo.io.utils.bin_indices spateo.io.utils.centroids spateo.io.utils.contour_to_geo spateo.io.utils.get_points_props spateo.io.utils.get_label_props spateo.io.utils.get_bin_props spateo.io.utils.in_concave_hull spateo.io.utils.in_convex_hull spateo.io.utils.bin_matrix spateo.io.utils.get_coords_labels Module Contents --------------- .. py:function:: bin_indices(coords: numpy.ndarray, coord_min: float, binsize: int = 50) -> int Take a DNB coordinate, the mimimum coordinate and the binsize, calculate the index of bins for the current coordinate. :param coord: Current x or y coordinate. :type coord: `float` :param coord_min: Minimal value for the current x or y coordinate on the entire tissue slide measured by the spatial transcriptomics. :type coord_min: `float` :param binsize: Size of the bins to aggregate data. :type binsize: `float` :returns: **num** -- The bin index for the current coordinate. :rtype: `int` .. py:function:: centroids(bin_indices: numpy.ndarray, coord_min: float = 0, binsize: int = 50) -> float Take a bin index, the mimimum coordinate and the binsize, calculate the centroid of the current bin. :param bin_ind: The bin index for the current coordinate. :type bin_ind: `float` :param coord_min: Minimal value for the current x or y coordinate on the entire tissue slide measured by the spatial transcriptomics. :type coord_min: `float` :param binsize: Size of the bins to aggregate data. :type binsize: `int` :returns: **num** -- The bin index for the current coordinate. :rtype: `int` .. py:function:: contour_to_geo(contour) Transfer contours to `shapely.geometry` .. py:function:: get_points_props(data: pandas.DataFrame) -> pandas.DataFrame Calculate properties of labeled coordinates. :param data: Pandas Dataframe containing `x`, `y`, `label` columns. :returns: A dataframe with properties and contours indexed by label .. py:function:: get_label_props(labels: numpy.ndarray) -> pandas.DataFrame Measure properties of labeled cell regions. :param labels: cell segmentation label matrix :returns: A dataframe with properties and contours indexed by label .. py:function:: get_bin_props(data: pandas.DataFrame, binsize: int) -> pandas.DataFrame Simulate properties of bin regions. :param data: Pandas dataframe containing binned x, y, and cell labels. There should not be any duplicate cell labels. :param binsize: Bin size used :returns: A dataframe with properties and contours indexed by cell label .. py:function:: in_concave_hull(p: numpy.ndarray, concave_hull: Union[shapely.geometry.Polygon, shapely.geometry.MultiPolygon]) -> numpy.ndarray Test if points in `p` are in `concave_hull` using scipy.spatial Delaunay's find_simplex. :param p: a `Nx2` coordinates of `N` points in `K` dimensions :param concave_hull: A polygon returned from the concave_hull function (the first value). Returns: .. py:function:: in_convex_hull(p: numpy.ndarray, convex_hull: Union[scipy.spatial.Delaunay, numpy.ndarray]) -> numpy.ndarray Test if points in `p` are in `convex_hull` using scipy.spatial Delaunay's find_simplex. :param p: a `NxK` coordinates of `N` points in `K` dimensions :param convex_hull: either a scipy.spatial.Delaunay object or the `MxK` array of the coordinates of `M` points in `K` dimensions for which Delaunay triangulation will be computed. Returns: .. py:function:: bin_matrix(X: Union[numpy.ndarray, scipy.sparse.spmatrix], binsize: int) -> Union[numpy.ndarray, scipy.sparse.csr_matrix] Bin a matrix. :param X: Dense or sparse matrix. :param binsize: Bin size :returns: Dense or spares matrix, depending on what the input was. .. py:function:: get_coords_labels(labels: numpy.ndarray) -> pandas.DataFrame Convert labels into sparse-format dataframe. :param labels: cell segmentation labels matrix. :returns: A DataFrame of columns "x", "y", and "label". The coordinates are relative to the labels matrix.