Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XY and Z drift stabilization; replaces #108 #128

Merged
merged 142 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 138 commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
b78a3c3
initial commit adding tools for cropping and registering with ants
edyoshikun Sep 22, 2023
6c1ce18
adding lir crop
edyoshikun Sep 26, 2023
0b71192
starting cleanup for registration
edyoshikun Oct 4, 2023
f11874d
converting nan to zero
edyoshikun Oct 5, 2023
1df5d66
ants estimate affine
edyoshikun Oct 24, 2023
b2e38e1
adding config file for estimate_transform
edyoshikun Oct 24, 2023
7819ec4
cleaning up some redundancies
edyoshikun Oct 24, 2023
9fc7df8
fix edge case of input not being float32
edyoshikun Oct 24, 2023
957fc49
channel is an int
edyoshikun Oct 24, 2023
ccde02e
typo in napari add image for vs ants optimzer
edyoshikun Oct 24, 2023
ee1845f
adding utils yaml
edyoshikun Oct 24, 2023
e617ffc
separated the manual estimation from the optimizer
edyoshikun Oct 30, 2023
d019bf6
added ants to numpy and viceversa
edyoshikun Oct 30, 2023
a76d70c
adding input at the end to prevent from closing
edyoshikun Oct 30, 2023
0d39cbe
replacing the reading of .mat to matrix from yaml
edyoshikun Nov 1, 2023
362e7a7
added changes to ants to numpy from Jordaos input
edyoshikun Nov 3, 2023
9d25d1a
cannot have recOrder as dependency given different pycromanager versions
edyoshikun Nov 3, 2023
caa84dc
format
edyoshikun Nov 3, 2023
6d6504a
add test for optimize_affine and update readme
edyoshikun Nov 3, 2023
f2c56fb
adding docstring
edyoshikun Nov 3, 2023
8ed961d
removed the config dependency
edyoshikun Nov 3, 2023
7a7b20d
removing the focus_finding svg
edyoshikun Nov 3, 2023
ac4a5fc
removing the estimate_affine.yml and making flags to choose channels …
edyoshikun Nov 3, 2023
2d13d4d
added comment and code to use scipy.
edyoshikun Nov 3, 2023
58175d0
-ls and -lf to -s and -t
talonchandler Nov 3, 2023
3b9d5eb
document FOCUS_SLICE_ROI_WIDTH
talonchandler Nov 3, 2023
8acad5c
`estimate-source-to-target-affine` -> `estimate-affine`
talonchandler Nov 3, 2023
3fabc8a
standardize `optimize-affine` arguments
talonchandler Nov 3, 2023
52c21ad
cleaner docs
talonchandler Nov 3, 2023
66d8990
update RegistrationSettings
talonchandler Nov 3, 2023
98089b2
fix tests
talonchandler Nov 3, 2023
c34bad0
remove duplicate
talonchandler Nov 3, 2023
a35153f
write indices to output config
talonchandler Nov 3, 2023
36f0b7e
read channels from file
talonchandler Nov 3, 2023
9bfbd20
test fix
talonchandler Nov 4, 2023
2ca449c
echo improvments
talonchandler Nov 4, 2023
5bf0ba0
black
talonchandler Nov 4, 2023
bbbaf97
stabilization draft
edyoshikun Nov 4, 2023
558e0ce
slurm z drift correction
edyoshikun Nov 4, 2023
01b180b
pystackreg
edyoshikun Nov 4, 2023
b6366ea
functions for estimating the z_drift and xy translation over time
edyoshikun Nov 6, 2023
3ea70f7
Merge branch 'registration_v2' of github.com:czbiohub/mantis into sta…
edyoshikun Nov 6, 2023
3e236f9
style
ieivanov Nov 9, 2023
6226786
remove duplicate cli call
ieivanov Nov 9, 2023
9137527
more intuitive manual registration
ieivanov Nov 10, 2023
4f709ba
Merge branch 'main' into registration_v2
ieivanov Nov 10, 2023
d3eb2b2
stabilization cli
edyoshikun Nov 13, 2023
ca75078
patch for deskewing
edyoshikun Nov 13, 2023
70f0c13
fixing CLI calls and docstrings
edyoshikun Nov 14, 2023
4ffe820
addine more comments to doctring
edyoshikun Nov 14, 2023
dcc6e5f
stabilize_timalapse cli typo
edyoshikun Nov 14, 2023
ada50f2
stabilize_timalapse cli typo
edyoshikun Nov 14, 2023
c7fc544
Merge branch 'stabilization' of github.com:czbiohub/mantis into stabi…
edyoshikun Nov 14, 2023
0bd70ae
removing some args in doctring.
edyoshikun Nov 14, 2023
df53a74
testing slurmkit
edyoshikun Nov 15, 2023
cd698d6
fix apply affine example
ieivanov Nov 15, 2023
fdae716
matrix multiplication bugfix
ieivanov Nov 15, 2023
ebc8b04
updating the lir_crop using new registration
edyoshikun Nov 15, 2023
94761c8
adding lir crop to the apply affine and modifying the manual estimati…
edyoshikun Nov 16, 2023
a29811a
convert nans to zeros
edyoshikun Nov 16, 2023
a4d1589
updating the output saving scheme taking zarrs and saving the verbose…
edyoshikun Nov 16, 2023
5a6d59f
Merge branch 'registration_v2' of github.com:czbiohub/mantis into sta…
edyoshikun Nov 17, 2023
0762001
add affine test
edyoshikun Nov 22, 2023
998b714
fixing z-shift error
edyoshikun Nov 22, 2023
903df4d
remove saving intermediate z-shifts
edyoshikun Nov 22, 2023
804b3f9
save to yml
edyoshikun Nov 22, 2023
769d8ff
prototype to change to v2
edyoshikun Dec 5, 2023
548c9a2
fixing the xy drift calculation. refactoring placed xy order instead …
edyoshikun Dec 7, 2023
5be1323
adding option to fill the zeroes with previous value.
edyoshikun Dec 8, 2023
5cad1eb
adding tests
edyoshikun Dec 8, 2023
4ec9f0c
adding one more test
edyoshikun Dec 8, 2023
4562403
adding test for affine
edyoshikun Dec 12, 2023
92d54dc
removed main
edyoshikun Dec 12, 2023
4fd7b6b
fix `apply_affine` docstring
ieivanov Dec 12, 2023
4540956
fixing formatting
edyoshikun Dec 12, 2023
0753c58
remove crop-output from cli args
ieivanov Dec 12, 2023
ef4980f
estimate affine cli docstrings
ieivanov Dec 12, 2023
0e2f8c4
reverting changes to AnalysisSettings model.
edyoshikun Dec 12, 2023
7c3c5f9
optimize_affine cli docstrings
ieivanov Dec 12, 2023
0d30a55
Merge branch 'registration_v2' of github.com:czbiohub/mantis_automati…
ieivanov Dec 12, 2023
ec56140
Revert "reverting changes to AnalysisSettings model."
ieivanov Dec 12, 2023
4172494
fix points layer grid mode bug
ieivanov Dec 14, 2023
7fa9896
fix tests
ieivanov Dec 14, 2023
1a6a59e
add slurmkit
edyoshikun Dec 14, 2023
eb757cb
combining the croping and merging to the apply-affine
edyoshikun Dec 19, 2023
af8dd2e
removing unnecessary prints()
edyoshikun Dec 19, 2023
5325426
add registration and stabilization modules
ieivanov Jan 5, 2024
538ddee
Merge branch 'main' into registration_v2
ieivanov Jan 5, 2024
076f1cb
style
ieivanov Jan 5, 2024
1e8ee8a
flake8
ieivanov Jan 5, 2024
59a762d
Merge branch 'registration_v2' of github.com:czbiohub/mantis into reg…
edyoshikun Jan 5, 2024
6a5f435
Registration refator (#118)
ieivanov Jan 16, 2024
97d2302
removing the source n target shape zyx and testing keep overhang
edyoshikun Jan 16, 2024
ac2dac7
updating estimate affine with previous commit changes
edyoshikun Jan 16, 2024
fde7982
Merge branch 'main' into registration_v2
ieivanov Jan 17, 2024
cfd1116
style
ieivanov Jan 17, 2024
5c7fcf5
Update example_apply_affine_settings.yml
ieivanov Jan 17, 2024
e6ac5f1
Merge branch 'main' into registration_v2
ieivanov Jan 17, 2024
10277c6
refactor registration and stabilization functions
ieivanov Jan 17, 2024
4a54fb7
fixing pytests
edyoshikun Jan 17, 2024
0b45130
more intuitive function names
ieivanov Jan 17, 2024
83292ad
minor refactor of estimane_affine
ieivanov Jan 17, 2024
f358f22
Merge branch 'registration_v2' of https://github.com/czbiohub-sf/shri…
ieivanov Jan 17, 2024
1b78856
bugfix
ieivanov Jan 17, 2024
71eb2c7
fixing the slurmkit files.
edyoshikun Jan 17, 2024
e574675
typo
ieivanov Jan 17, 2024
1957563
cleaner processing of additioanal source channels
ieivanov Jan 18, 2024
d62934a
Merge branch 'registration_v2' of github.com:czbiohub/mantis_automati…
ieivanov Jan 18, 2024
ab6244f
refactor apply_affine job submission
ieivanov Jan 18, 2024
6626aa6
remove position batch processing
ieivanov Jan 19, 2024
9fe9390
temporarily reorder functions
ieivanov Jan 23, 2024
72e07c7
merge registration_v2
ieivanov Jan 23, 2024
8861c71
revert temp reorder functions
ieivanov Jan 23, 2024
8a0f9a6
Merge branch 'main' into stabilization_yml_v2
ieivanov Jan 23, 2024
3327af7
refactor functions
ieivanov Jan 23, 2024
8f10c37
refactor combined matrix calculation
ieivanov Jan 23, 2024
e29d411
refactor z_drift multiprocessing
ieivanov Jan 24, 2024
9064a8b
small refactor + messaging
ieivanov Jan 24, 2024
37588a9
renaming
ieivanov Jan 24, 2024
31591a4
this eliminates stabilization_ove_time_ants by reusing processing_sin…
edyoshikun Jan 29, 2024
186299f
modified the function to process channel indeces and copy over the ot…
edyoshikun Jan 30, 2024
c2ebb4d
remove `analysis/stabilize.py`
ieivanov Feb 8, 2024
9f23924
renaming
ieivanov Feb 8, 2024
8b3f33d
more renaming
ieivanov Feb 8, 2024
f5cb1f6
update docstring
ieivanov Feb 8, 2024
9ecaefa
estimate_xy_stabilization uses the z indices calculated by estimate_z…
ieivanov Feb 9, 2024
4c7a428
style
ieivanov Feb 12, 2024
932004d
rename fields in position_focus.csv
ieivanov Feb 12, 2024
7da1d0f
update z_drift figure save path
ieivanov Feb 12, 2024
9089322
add axis labels
ieivanov Feb 12, 2024
2d2cea2
fixing tests
edyoshikun May 2, 2024
f9edd3a
Merge branch 'stabilization_yml_v2' of github.com:czbiohub/mantis int…
edyoshikun May 2, 2024
fe16f58
fix method='ffill' deprecation issue
ieivanov Jul 1, 2024
051b385
clean up slurmkit examples
ieivanov Jul 1, 2024
13f0d4b
update slurmkit_stabilize example
ieivanov Jul 1, 2024
1983410
fix tests
ieivanov Jul 1, 2024
f9f4829
Merge branch 'main' into stabilization_yml_v2
edyoshikun Jul 2, 2024
b23971d
minor fixes
edyoshikun Jul 2, 2024
79372d3
fix ffill
ieivanov Jul 2, 2024
47a43f1
add back `t_idx` param
ieivanov Jul 2, 2024
468b150
more ffill fix
ieivanov Jul 2, 2024
9ca5060
update apply_transform_to_zyx_and_save_v2 documentation
ieivanov Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions examples/slurmkit_example/slurmkit_stabilize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import datetime
import os
import glob
from slurmkit import SlurmParams, slurm_function, submit_function
from natsort import natsorted
from iohub import open_ome_zarr
from pathlib import Path
from mantis.cli.utils import (
yaml_to_model,
create_empty_hcs_zarr,
process_single_position_v2,
)
from mantis.cli.stabilize import apply_stabilization_transform
import numpy as np
from mantis.analysis.AnalysisSettings import StabilizationSettings

# NOTE: this pipeline uses the focus found on well one for all. Perhaps this should be done per FOV(?)

# io parameters
input_position_dirpaths = "/hpc/projects/comp.micro/mantis/2023_11_08_Opencell_infection_redo/1-recon/OC43_infection_timelapse_3.zarr/*/*/*"
output_dirpath = "/hpc/projects/comp.micro/mantis/2023_11_08_Opencell_infection_redo/3-stabilization/OC43_infection_timelapse_3.zarr"
config_filepath = "/hpc/projects/comp.micro/mantis/2023_11_08_Opencell_infection_redo/3-stabilization/stabilization.yml"

# batch and resource parameters
partition = 'cpu'
cpus_per_task = 5
mem_per_cpu = "4G"
time = 60 # minutes
simultaneous_processes_per_node = 5

# convert to Path
input_position_dirpaths = [Path(p) for p in natsorted(glob.glob(input_position_dirpaths))]
output_dirpath = Path(output_dirpath)
config_filepath = Path(config_filepath)

settings = yaml_to_model(config_filepath, StabilizationSettings)
combined_mats = settings.affine_transform_zyx_list
combined_mats = np.array(combined_mats)

with open_ome_zarr(input_position_dirpaths[0]) as dataset:
T, C, Z, Y, X = dataset.data.shape
channel_names = dataset.channel_names

output_metadata = {
"shape": (T, C, Z, Y, X),
"scale": dataset.scale,
"channel_names": channel_names,
"dtype": np.float32,
}

# Create the output zarr mirroring input_position_dirpaths
create_empty_hcs_zarr(
store_path=output_dirpath,
position_keys=[p.parts[-3:] for p in input_position_dirpaths],
**output_metadata,
)

slurm_out_path = str(os.path.join(output_dirpath.parent, "slurm_output/stabilization-%j.out"))

# prepare slurm parameters
params = SlurmParams(
partition=partition,
cpus_per_task=cpus_per_task,
mem_per_cpu=mem_per_cpu,
time=datetime.timedelta(minutes=time),
output=slurm_out_path,
)

# wrap our utils.process_single_position() function with slurmkit
slurm_process_single_position = slurm_function(process_single_position_v2)
stabilization_function = slurm_process_single_position(
func=apply_stabilization_transform,
list_of_shifts=combined_mats,
time_indices=list(range(T)),
input_channel_idx=None,
output_channel_idx=None,
num_processes=simultaneous_processes_per_node,
)

stabilization_jobs = [
submit_function(
stabilization_function,
slurm_params=params,
input_data_path=in_path,
output_path=output_dirpath,
)
for in_path in input_position_dirpaths
]
20 changes: 20 additions & 0 deletions mantis/analysis/AnalysisSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,23 @@ def check_affine_transform(cls, v):
raise ValueError("The array must contain valid numerical values.")

return v


class StabilizationSettings(MyBaseModel):
stabilization_estimation_channel: str
stabilization_type: Literal["z", "xy", "xyz"]
stabilization_channels: list
affine_transform_zyx_list: list
time_indices: Union[NonNegativeInt, list[NonNegativeInt], Literal["all"]] = "all"

@validator("affine_transform_zyx_list")
def check_affine_transform_list(cls, v):
if not isinstance(v, list):
raise ValueError("affine_transform_list must be a list")

for arr in v:
arr = np.array(arr)
if arr.shape != (4, 4):
raise ValueError("Each element in affine_transform_list must be a 4x4 ndarray")

return v
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stabilization_estimation_channel: "GFP"
stabilization_type: "xyz"
stabilization_channels: ['GFP']
affine_transform_zyx_list: [[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0],[0.0, 0.0, 0.0,1.0]],[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0],[0.0, 0.0, 0.0,1.0]],[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0],[0.0, 0.0, 0.0,1.0]]]
time_indices: 'all'
133 changes: 0 additions & 133 deletions mantis/analysis/stabilize.py

This file was deleted.

Loading
Loading