czbiohub-sf / shrimPy

shrimPy: Smart High-throughput Robust Imaging & Measurement in Python
BSD 3-Clause "New" or "Revised" License
7 stars 1 forks source link

XY and Z drift stabilization; replaces #108 #128

Closed ieivanov closed 3 months ago

ieivanov commented 8 months ago

TODO (01/19/24):

This PR has the code for:

For the XY stabilization, you can use: /hpc/projects/comp.micro/mantis/2023_09_22_A549_0.52NA_illum/3-registration/A549_MitoViewGreen_LysoTracker_W3_FOV5_1_phase.zarr

For Z drift, any of the timelapses: /hpc/projects/comp.micro/mantis/2023_11_01_OpenCell_infection/4-registration/timelapse_7/timelapse_7_phase_registered.zarr

ieivanov commented 8 months ago

@edyoshikun I see that we need to move some functions between /mantis/cli/stabilization and /mantis/analysis/stabilize. Here is the logic I've been using to decide if functions should go in the analysis or cli modules. Functions in analysis operate on numpy arrays. Functions in cli provide wrappers that would read in data (using iohub), apply analysis functions, and save the results. This may not be so clean-cut every time, but we should aim to format the code in a way that would also allow us to analyze data from a python script rather than thru CLI calls.

edyoshikun commented 8 months ago

@ieivanov yes! I actually had changed those in the other branch. I agree with the refactoring to keep separate the functions between the cli and the analysis. We can just wrap the parts of the cli that should be a different stabilize_timelapse() and have the cli call this one.

ieivanov commented 8 months ago

Quick note: calculate_yx_stabilization should use the z indices calculated by calculate_z_drift. If they are not present, then use the focus index of the first time point as we do currently

edyoshikun commented 8 months ago

@ieivanov I added some functions needed to apply stabilization to the config file. Similar to apply_affine the apply_stabilization takes in a config file where we can choose the timepoints and the channels to process. This will allow us to process certain channels within a dataset without modifying the rest. Additionally, I could merge the apply_stabilization_over_time into process_single_position_v2 by appending t_idx to the kwargs if the function needs it. For example, look at apply_stabilization_transform(). This is good because now we could implement any function that applies different conditions per timepoint.

Also, I fixed the channel_name_index to channel_name to match the apply_affine.

ieivanov commented 3 months ago

I am happy with this PR. The Z stabilization is well-tested. The XY stabilization is not used as much and not tested quite as well.