pyfast_adt.main.tracking ======================== .. py:module:: pyfast_adt.main.tracking Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/pyfast_adt/main/tracking/Detector/index /autoapi/pyfast_adt/main/tracking/KF_custom_models/index /autoapi/pyfast_adt/main/tracking/KalmanFilter/index /autoapi/pyfast_adt/main/tracking/cross_correlation_kalman_filtered/index /autoapi/pyfast_adt/main/tracking/insitu_tracker/index /autoapi/pyfast_adt/main/tracking/objTracking/index /autoapi/pyfast_adt/main/tracking/rigid_body_model/index /autoapi/pyfast_adt/main/tracking/sort_tracker/index Attributes ---------- .. autoapisummary:: pyfast_adt.main.tracking.path1 pyfast_adt.main.tracking.insitu_tracker Classes ------- .. autoapisummary:: pyfast_adt.main.tracking.KalmanFilter pyfast_adt.main.tracking.Tomography_tracker pyfast_adt.main.tracking.Tomography_tracker pyfast_adt.main.tracking.InSituTracker pyfast_adt.main.tracking.MastronardeRigidBody Package Contents ---------------- .. py:class:: KalmanFilter(dt, u_x, u_y, std_acc, x_std_meas, y_std_meas) Bases: :py:obj:`object` .. py:attribute:: dt .. py:attribute:: u .. py:attribute:: x .. py:attribute:: A .. py:attribute:: B .. py:attribute:: H .. py:attribute:: Q .. py:attribute:: R .. py:attribute:: P .. py:method:: predict() .. py:method:: update(z) .. py:class:: Tomography_tracker(images=None, visualization=False, existing_roi=None, dt=0.1, exp_type='continuous') this is the core of the patchworkCC algorithm, main method run the tracking asking the user to selct a ROI to track, and return the tracked positions as a list of tuples (predicted_pos (pure KF), template_match (CC), filtered_pos (CC corrected by KF))) just to clarify: --self.CC_positions is brutally pure CC --self.template_matching_result is CC with on top the patchwork to remove ambiguities --predicted_pos is predicted by pureKF using self.template_matching_result to learn(newton law) (-1 iteration) --filtered_pos is template_matching res. corrected by the KF (CC+newton) == more math the self.support1 contain the tracked positions of all the methods. this method is based on a liner KF at constant velocity where the acceleration act as control input if not overwritten in the init step. to overwrite with another KF model after construct the class should be possible to just assign self.KF to another KF model. if intersted check at the bottom the function self.select_other_KF_model(KF_model = your_model) .. py:attribute:: KF .. py:attribute:: KF_lost_position :value: [] .. py:attribute:: KF_corrected_position :value: [] .. py:attribute:: lost_counter :value: 0 .. py:attribute:: support1 :value: [] .. py:attribute:: series :value: None .. py:attribute:: n :value: None .. py:attribute:: backup_roi :value: None .. py:attribute:: series_support :value: [] .. py:attribute:: support_manual :value: [] .. py:attribute:: exp_type :value: 'continuous' .. py:attribute:: list_templates :value: [] .. py:attribute:: counter_img :value: None .. py:attribute:: visualization :value: False .. py:attribute:: existing_roi :value: None .. py:attribute:: custom_model :value: [False, 'linear_KF_2D', 0] .. py:attribute:: bilateral_d :value: 9 .. py:attribute:: bilateral_sigmacolor :value: 150 .. py:attribute:: bilateral_sigmaspace :value: 150 .. py:method:: main() .. py:method:: user_defined_ROI(img) .. py:method:: plot_single_track(visualization=False) .. py:method:: plot_tracking() .. py:method:: plot_tracking_reevaluation() .. py:method:: save_tracking(datapoints) .. py:method:: draw_circle(event, x, y, flags, param) .. py:method:: plot_result(color=(255, 0, 0)) .. py:method:: manual_tracking(images=None, visualization=False) .. py:method:: display_tracking(images, tracking_dict, method, beam_size_diff=None) .. py:method:: select_other_KF_model(KF_model=None, KF_from_list=None) function to overwrite the KF model used. the KF should be a class with at least 2 functions predict and update to work properly. a custom KF model can be passed in the argument KF_model (a class to construct). otherwise you can use the argument KF_from_list to select an already implemented KF model. the function construct the class for you. as it's builded the experiment up to now the KF model should be using as measurement for the update step only the x,y position obtained from an object detection method. .. py:data:: path1 :value: 'L:\\Marco\\hardware_microscopes\\TecnaiF30\\sergi_track\\Tracking\\Tomography\\Sequential\\18\\clean' .. py:class:: Tomography_tracker(images=None, visualization=False, existing_roi=None, dt=0.1, exp_type='continuous') this is the core of the patchworkCC algorithm, main method run the tracking asking the user to selct a ROI to track, and return the tracked positions as a list of tuples (predicted_pos (pure KF), template_match (CC), filtered_pos (CC corrected by KF))) just to clarify: --self.CC_positions is brutally pure CC --self.template_matching_result is CC with on top the patchwork to remove ambiguities --predicted_pos is predicted by pureKF using self.template_matching_result to learn(newton law) (-1 iteration) --filtered_pos is template_matching res. corrected by the KF (CC+newton) == more math the self.support1 contain the tracked positions of all the methods. this method is based on a liner KF at constant velocity where the acceleration act as control input if not overwritten in the init step. to overwrite with another KF model after construct the class should be possible to just assign self.KF to another KF model. if intersted check at the bottom the function self.select_other_KF_model(KF_model = your_model) .. py:attribute:: KF .. py:attribute:: KF_lost_position :value: [] .. py:attribute:: KF_corrected_position :value: [] .. py:attribute:: lost_counter :value: 0 .. py:attribute:: support1 :value: [] .. py:attribute:: series :value: None .. py:attribute:: n :value: None .. py:attribute:: backup_roi :value: None .. py:attribute:: series_support :value: [] .. py:attribute:: support_manual :value: [] .. py:attribute:: exp_type :value: 'continuous' .. py:attribute:: list_templates :value: [] .. py:attribute:: counter_img :value: None .. py:attribute:: visualization :value: False .. py:attribute:: existing_roi :value: None .. py:attribute:: custom_model :value: [False, 'linear_KF_2D', 0] .. py:attribute:: bilateral_d :value: 9 .. py:attribute:: bilateral_sigmacolor :value: 150 .. py:attribute:: bilateral_sigmaspace :value: 150 .. py:method:: main() .. py:method:: user_defined_ROI(img) .. py:method:: plot_single_track(visualization=False) .. py:method:: plot_tracking() .. py:method:: plot_tracking_reevaluation() .. py:method:: save_tracking(datapoints) .. py:method:: draw_circle(event, x, y, flags, param) .. py:method:: plot_result(color=(255, 0, 0)) .. py:method:: manual_tracking(images=None, visualization=False) .. py:method:: display_tracking(images, tracking_dict, method, beam_size_diff=None) .. py:method:: select_other_KF_model(KF_model=None, KF_from_list=None) function to overwrite the KF model used. the KF should be a class with at least 2 functions predict and update to work properly. a custom KF model can be passed in the argument KF_model (a class to construct). otherwise you can use the argument KF_from_list to select an already implemented KF model. the function construct the class for you. as it's builded the experiment up to now the KF model should be using as measurement for the update step only the x,y position obtained from an object detection method. .. py:class:: InSituTracker(shift=None, tilt_step=5, sim_mode=False, tomo_tracker=None) .. py:attribute:: a :value: [] .. py:attribute:: dt :value: 0.1 .. py:attribute:: tilt_step :value: 5 .. py:attribute:: updated_positions :value: [] .. py:attribute:: updated_positions_2 :value: [] .. py:attribute:: second_iteration :value: False .. py:attribute:: tomo_tracker :value: None .. py:method:: main() .. py:method:: shift_image(image_array, shift) .. py:method:: insitu_obj_detection_sim() .. py:method:: in_situ_run(image, frame_number) .. py:method:: plot_insitu_result() .. py:data:: insitu_tracker .. py:class:: MastronardeRigidBody(folder_path, fit_range, pixelsize_nm, delimiter='\t', plot_intermediate=False, theta_sim_deg=0) .. py:attribute:: folder_path .. py:attribute:: pixelsize_nm .. py:attribute:: pixelsize_um .. py:attribute:: delimiter :value: '\t' .. py:attribute:: plot_intermediate :value: False .. py:attribute:: theta_sim_deg :value: 0 .. py:attribute:: results :value: [] .. py:attribute:: datasets :value: [] .. py:method:: _get_dataset(dataset_index=0) .. py:method:: mastronarde_rot2D(alpha_rad, y0, z0, ys, theta_deg, y_mean) :staticmethod: .. py:method:: mastronarde_point(alpha_rad, y0, z0, ys, theta_deg, y_mean=0.0) Return rotated (y, x) coordinates from Mastronarde model .. py:method:: zheng_point(alpha_rad, y0, z0, ys, theta_deg, y_mean=0.0) .. py:method:: fit_dataset(idx) .. py:method:: fit_single_dataset_from_gui(data_path=None, switch_axis=False) .. py:method:: load_tracking_data_pyfast(path) .. py:method:: plot_intermediate_dataset(alpha, x_ccd, y_ccd, alpha_rad, popt, fname) .. py:method:: run_fits() .. py:method:: compute_linear_fits() .. py:method:: plot_summary(save=True) .. py:method:: plot_trajectories_stacked(dy_offset=1.0, out_path=None, filename='trajectories_all_datasets_stacked.png') Plot stacked rotated XY trajectories with Mastronarde model overlay. Theoretical model is split for positive and negative alpha values and plotted with a small offset to inspect symmetry. .. py:method:: plot_z_scan(alpha_range_deg=np.linspace(-60, 60, 300), out_path=None, filename='plot_z_scan.png') Plot n–z arcs using Mastronarde rigid body model .. py:method:: plot_single_dataset_summary(dataset_index=0, save=False) Summary plots for a SINGLE dataset. .. py:method:: analyze_xy_dynamics(dataset_index=0, n_alpha=500, deg_step=5, out_path=None, scaling=1, original_range=False, deg_markers=False, pixels=True) Analyze velocity and acceleration of projected CCD motion assuming linear relation between tilt angle and time (1 deg = 1 time unit). Markers are placed EXACTLY every `deg_step` degrees. .. py:method:: analyze_xy_dynamics_multiple(deg_step=5, n_alpha=500, scaling=1, original_range=False, deg_markers=False, out_path=None, pixels=True) Analyze XY dynamics for all datasets and compute max velocity & acceleration. Also plots max |v| and |a| vs Z stage (dataset index). Includes the same style as `analyze_xy_dynamics`: - Optional deg markers with text - Velocity & acceleration twin y-axis - Component plots