Esempio n. 1
0
def substackTrajectory(trajectory, selection):

    # Get the current positions
    crt_positions = trajectory.positions

    # Make the selection
    crt_positions = crt_positions[crt_positions['frame'].isin(selection)]

    # Remap the frame indices
    old_frames = crt_positions['frame'].unique()
    new_frames = np.arange(old_frames.shape[0])
    convert_dict = dict(zip(old_frames, new_frames))

    # Convert the values
    new_frame_positions = np.copy(crt_positions['frame'].to_numpy())
    for key in convert_dict.keys():
        new_frame_positions[new_frame_positions == key] = convert_dict[key]

    # Replace the trajectory
    new_positions = crt_positions.copy()
    new_positions['frame'] = new_frame_positions

    # Generate the new manager
    new_trajectory = startManager(new_positions)

    return new_trajectory
Esempio n. 2
0
    def getTrajectory(self, trj):

        # Save the trajectory in the class
        self.image_class.trajectory = startManager(trj)

        # Close the progress bar window
        self.close()
        self.scheduler.stackProcessed()
Esempio n. 3
0
def generateTrajectory(positions):

    # Format the pandas dataframe
    positions = positions[['y', 'x']].copy()
    positions['frame'] = [0] * len(positions['x'])
    positions['particle'] = np.arange(len(positions['x']))
    positions.reset_index(drop=True, inplace=True)

    # Initialise the manager
    trajectory = startManager(positions)

    return trajectory
Esempio n. 4
0
    def callLoadTrajectory(self):

        # Check if a tab is open
        if len(self.parent.imageTabDisplay.displayedTabs) > 0:

            # Open the load file browser
            trajectoryFile, _ = qtw.QFileDialog.getOpenFileName(
                self.parent, "Load Trajectory File...", "",
                "Hierarchical Data (*.xml);;All Files (*)")

            # Retrieve the current tab ID
            tab_id = self.parent.imageTabDisplay.currentIndex()

            # Load the trajectory in the session
            if trajectoryFile != "":
                self.parent.imageTabDisplay.displayedTabs[
                    tab_id].image_class.trajectory = startManager(
                        trajectoryFile)

                # Check that the length matches
                n_traj = len(
                    self.parent.imageTabDisplay.displayedTabs[tab_id].
                    image_class.trajectory.positions['frame'].unique())
                n_frames = self.parent.imageTabDisplay.displayedTabs[
                    tab_id].image_class.n_frames

                # Display a warning
                if n_traj != n_frames:
                    warningMessage(
                        "Different Number of Frames",
                        "The number of frames in the image stack and the number of frames in the trajectory do not match. This could lead to issues for displaying the positions of the particles."
                    )

                # Open the trajectory side bar
                self.callTrajectoryManagerDock()

                # Refresh the display
                self.parent.imageTabDisplay.displayedTabs[
                    tab_id].refreshPathList()
                self.parent.imageTabDisplay.displayedTabs[tab_id].displayImage(
                )

        else:
            errorMessageNoImage()
Esempio n. 5
0
    def processTrajectory(self):
        _proceed = True

        # Load the selected trajectory - from file
        if self.fromFileButton.isChecked(
        ) and self.loaded_trajectory is not None:
            self.trajectory = startManager(self.loaded_trajectory)

        # Load the selected trajectory - from image tab
        elif self.fromImageButton.isChecked():
            tab_id = self.parent.imageTabDisplay.currentIndex()
            self.trajectory = self.parent.imageTabDisplay.displayedTabs[
                tab_id].image_class.trajectory

        else:
            _proceed = False

        # Process the loaded trajectory
        if _proceed:

            # Retrieve the scale
            self.space_scale = float(self.spaceScaleEntry.text())
            self.frame_rate = float(self.timeScaleEntry.text())
            self.space_unit = self.spaceUnitEntry.text()

            # Comvert the scale
            micron_per_pixel = getSpaceScale(self.space_scale, self.space_unit)

            # Get the list of paths
            self.path_list = list(self.trajectory.listTracks())

            # Extract the MSDs
            self.lagtime = []
            self.msd = []

            # Get the combined MSD
            crt_lagtime, crt_msd = getMSD(self.trajectory.positions,
                                          micron_per_pixel, self.frame_rate)
            self.lagtime.append(crt_lagtime)
            self.msd.append(crt_msd)

            # Get the individual MSDs
            crt_lagtime, all_msd = getMSD(self.trajectory.positions,
                                          micron_per_pixel,
                                          self.frame_rate,
                                          path_id=self.path_list)

            for i in range(all_msd.shape[1]):
                self.lagtime.append(crt_lagtime)
                self.msd.append(all_msd[:, i])

            # Get all the diffusivity
            self.fits, self.diffusivity, self.diff_err = getDiffusivity(
                self.lagtime, self.msd)

            # Update the display
            self.path_list.insert(0, 'All')
            self.pathSelectionEntry.replaceList(
                [str(x) for x in self.path_list])

            # Update the graph
            self.updateGraph()
            self.saveButton.setEnabled(True)