Source code for piscat.Trajectory.particle_linking

from __future__ import print_function

import trackpy as tp
from PySide6.QtCore import QObject, Signal
from tqdm.autonotebook import tqdm

from piscat.InputOutput.cpu_configurations import CPUConfigurations


class WorkerSignals(QObject):
    updateProgress = Signal(int)
    result = Signal(object)
    finished = Signal()


[docs]class Linking: def __init__(self): """To obtain the temporal activity of each iPSF, we use the Trackpy packages' algorithm. References ---------- [1] http://soft-matter.github.io/trackpy/v0.4.2/ """ self.cpu = CPUConfigurations()
[docs] def sorting_linking(self, df_PSFs): """This function uses trajectory lengths to sort particles in a dataframe. Parameters ---------- df_PSFs: pandas dataframe The data frame contains PSFs locations(x, y, frame, sigma, particle, ...) Returns ------- total_sort_df_PSFs: pandas dataframe The sort version of data frame contains PSFs locations(x, y, frame, sigma, particle, ...) """ his_all_particles = df_PSFs["particle"].value_counts() index_particles = his_all_particles.index total_sort_df_PSFs = None for index_ in tqdm(index_particles): sort_df_PSFs = df_PSFs.loc[df_PSFs["particle"] == index_] if total_sort_df_PSFs is None: total_sort_df_PSFs = sort_df_PSFs else: total_sort_df_PSFs = total_sort_df_PSFs.append(sort_df_PSFs) return total_sort_df_PSFs
[docs] def trajectory_counter(self, df_PSFs): """ This function counts the number of unique particles in the data frame. Parameters ---------- df_PSFs: pandas dataframe The data frame contains PSFs locations(x, y, frame, sigma, particle,...) Returns ------- unique_list: int Returns the number of particles in data frame """ if df_PSFs.shape[0] != 0: particles_label = df_PSFs["particle"].tolist() unique_list = set(particles_label) return len(unique_list) else: return 0