Skip to content

set_uid

cellseg_gsontools.set_uid(gdf, start_ix=0, id_col='uid', drop=False)

Set a unique identifier column to gdf.

Note

by default sets a running index column to gdf as the uid.

Parameters:

Name Type Description Default
gdf GeoDataFrame

Input Geodataframe.

required
start_ix int, default=0

The starting index of the id column.

0
id_col str, default="uid"

The name of the column that will be used or set to the id.

'uid'
drop bool, default=False

Drop the column after it is added to index.

False

Returns:

Type Description
GeoDataFrame

gpd.GeoDataFrame: The input gdf with a "uid" column added to it.

Examples:

>>> from cellseg_gsontools import set_uid
>>> gdf = set_uid(gdf, drop=True)
Source code in cellseg_gsontools/utils.py
def set_uid(
    gdf: gpd.GeoDataFrame, start_ix: int = 0, id_col: str = "uid", drop: bool = False
) -> gpd.GeoDataFrame:
    """Set a unique identifier column to gdf.

    Note:
        by default sets a running index column to gdf as the uid.

    Parameters:
        gdf (gpd.GeoDataFrame):
            Input Geodataframe.
        start_ix (int, default=0):
            The starting index of the id column.
        id_col (str, default="uid"):
            The name of the column that will be used or set to the id.
        drop (bool, default=False):
            Drop the column after it is added to index.

    Returns:
        gpd.GeoDataFrame:
            The input gdf with a "uid" column added to it.

    Examples:
        >>> from cellseg_gsontools import set_uid
        >>> gdf = set_uid(gdf, drop=True)
    """
    gdf = gdf.copy()
    if id_col not in gdf.columns:
        gdf[id_col] = range(start_ix, len(gdf) + start_ix)

    gdf = gdf.set_index(id_col, drop=drop)

    return gdf