spateo.io.utils

IO utility functions.

Functions

bin_indices(→ int)

Take a DNB coordinate, the mimimum coordinate and the binsize, calculate the index of bins for the current

centroids(→ float)

Take a bin index, the mimimum coordinate and the binsize, calculate the centroid of the current bin.

contour_to_geo(contour)

Transfer contours to shapely.geometry

get_points_props(→ pandas.DataFrame)

Calculate properties of labeled coordinates.

get_label_props(→ pandas.DataFrame)

Measure properties of labeled cell regions.

get_bin_props(→ pandas.DataFrame)

Simulate properties of bin regions.

in_concave_hull(→ numpy.ndarray)

Test if points in p are in concave_hull using scipy.spatial Delaunay's find_simplex.

in_convex_hull(→ numpy.ndarray)

Test if points in p are in convex_hull using scipy.spatial Delaunay's find_simplex.

bin_matrix(→ Union[numpy.ndarray, scipy.sparse.csr_matrix])

Bin a matrix.

get_coords_labels(→ pandas.DataFrame)

Convert labels into sparse-format dataframe.

Module Contents

spateo.io.utils.bin_indices(coords: numpy.ndarray, coord_min: float, binsize: int = 50) int[source]

Take a DNB coordinate, the mimimum coordinate and the binsize, calculate the index of bins for the current coordinate.

Parameters:
coord float

Current x or y coordinate.

coord_min float

Minimal value for the current x or y coordinate on the entire tissue slide measured by the spatial transcriptomics.

binsize float

Size of the bins to aggregate data.

Returns:

num – The bin index for the current coordinate.

Return type:

int

spateo.io.utils.centroids(bin_indices: numpy.ndarray, coord_min: float = 0, binsize: int = 50) float[source]

Take a bin index, the mimimum coordinate and the binsize, calculate the centroid of the current bin.

Parameters:
bin_ind float

The bin index for the current coordinate.

coord_min float

Minimal value for the current x or y coordinate on the entire tissue slide measured by the spatial transcriptomics.

binsize int

Size of the bins to aggregate data.

Returns:

num – The bin index for the current coordinate.

Return type:

int

spateo.io.utils.contour_to_geo(contour)[source]

Transfer contours to shapely.geometry

spateo.io.utils.get_points_props(data: pandas.DataFrame) pandas.DataFrame[source]

Calculate properties of labeled coordinates.

Parameters:
data

Pandas Dataframe containing x, y, label columns.

Returns:

A dataframe with properties and contours indexed by label

spateo.io.utils.get_label_props(labels: numpy.ndarray) pandas.DataFrame[source]

Measure properties of labeled cell regions.

Parameters:
labels

cell segmentation label matrix

Returns:

A dataframe with properties and contours indexed by label

spateo.io.utils.get_bin_props(data: pandas.DataFrame, binsize: int) pandas.DataFrame[source]

Simulate properties of bin regions.

Parameters:
data

Pandas dataframe containing binned x, y, and cell labels. There should not be any duplicate cell labels.

binsize

Bin size used

Returns:

A dataframe with properties and contours indexed by cell label

spateo.io.utils.in_concave_hull(p: numpy.ndarray, concave_hull: shapely.geometry.Polygon | shapely.geometry.MultiPolygon) numpy.ndarray[source]

Test if points in p are in concave_hull using scipy.spatial Delaunay’s find_simplex.

Parameters:
p

a Nx2 coordinates of N points in K dimensions

concave_hull

A polygon returned from the concave_hull function (the first value).

Returns:

spateo.io.utils.in_convex_hull(p: numpy.ndarray, convex_hull: scipy.spatial.Delaunay | numpy.ndarray) numpy.ndarray[source]

Test if points in p are in convex_hull using scipy.spatial Delaunay’s find_simplex.

Parameters:
p

a NxK coordinates of N points in K dimensions

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:

spateo.io.utils.bin_matrix(X: numpy.ndarray | scipy.sparse.spmatrix, binsize: int) numpy.ndarray | scipy.sparse.csr_matrix[source]

Bin a matrix.

Parameters:
X

Dense or sparse matrix.

binsize

Bin size

Returns:

Dense or spares matrix, depending on what the input was.

spateo.io.utils.get_coords_labels(labels: numpy.ndarray) pandas.DataFrame[source]

Convert labels into sparse-format dataframe.

Parameters:
labels

cell segmentation labels matrix.

Returns:

A DataFrame of columns “x”, “y”, and “label”. The coordinates are relative to the labels matrix.