def tracking(
    cells_id,
    cells_id_prev,
    labels,
    V1,
    max_ID,
    match_frac=0.4,
    merge_frac=0.1,
    split_frac=0.1,
    output_splits_merges=False,
):
    """
    This function performs the actual tracking procedure. First the cells are advected,
    then overlapped and finally their IDs are matched. If no match is found, a new ID
    is assigned.
    """
    cells_id_new = cells_id.copy()
    cells_ad = advect(
        cells_id_prev, labels, V1, output_splits_merges=output_splits_merges
    )
    cells_ov, labels, possible_merge_ids = match(
        cells_ad,
        labels,
        output_splits_merges=output_splits_merges,
        split_frac=split_frac,
        match_frac=match_frac,
    )

    splitted_cells = None
    if output_splits_merges:
        splitted_cells = cells_ov[cells_ov.splitted == True]

    newlabels = np.zeros(labels.shape)
    possible_merge_ids_new = {}
    for index, cell in cells_id_new.iterrows():
        if cell.ID == 0 or np.isnan(cell.ID):
            continue
        new_ID = cells_ov[cells_ov.t_ID == cell.ID].ID.values
        if len(new_ID) > 0:
            xx = cells_ov[cells_ov.t_ID == cell.ID].x
            size = []
            for x in xx:
                size.append(len(x))
            biggest = np.argmax(size)
            new_ID = new_ID[biggest]
            cells_id_new.loc[index, "ID"] = new_ID
        else:
            max_ID += 1
            new_ID = max_ID
            cells_id_new.loc[index, "ID"] = new_ID
        newlabels[labels == index + 1] = new_ID
        possible_merge_ids_new[new_ID] = possible_merge_ids[cell.ID]
        del new_ID

    if output_splits_merges:
        # Process possible merges
        for target_id, possible_IDs in possible_merge_ids_new.items():
            merge_ids = []
            for p_id in possible_IDs:
                cell_a = cells_ad[cells_ad.ID == p_id]

                ID_vec = newlabels[cell_a.y.item(), cell_a.x.item()]
                overlap = np.sum(ID_vec == target_id) / len(ID_vec)
                if overlap > merge_frac:
                    merge_ids.append(p_id)

            if len(merge_ids) > 1:
                cell_id = cells_id_new[cells_id_new.ID == target_id].index.item()
                # Merge cells
                cells_id_new.at[cell_id, "merged"] = True
                cells_id_new.at[cell_id, "merged_IDs"] = merge_ids

    return cells_id_new, max_ID, newlabels, splitted_cells
This function performs the actual tracking procedure. First the cells are advected,
then overlapped and finally their IDs are matched. If no match is found, a new ID
is assigned.
pysteps/tracking/tdating.py