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

POC: GUI layout for recOrder v1.0.0 #442

Draft
wants to merge 57 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f84063d
draft new main widget layout
ziw-liu Sep 28, 2023
b515d86
remove redundant slider
ziw-liu Sep 29, 2023
954d12c
hack: semi-automated config magicgui
ziw-liu Sep 29, 2023
c95533b
replace typing.List with the builtin generic
ziw-liu Oct 6, 2023
9165057
potential fix for python 3.9
ziw-liu Oct 9, 2023
eecbd6c
watch zarr poc
ziw-liu Oct 9, 2023
f5ed6d5
test watching when writing larger images
ziw-liu Oct 10, 2023
0dbf946
Dynamic layout of reconstruction wizard (#448)
talonchandler Oct 10, 2023
dd0f030
generate example settings with revised model
talonchandler Oct 10, 2023
4f8e24f
skip `reconstruction_settings` during GUI generation
talonchandler Oct 10, 2023
5ce8f82
fix settings tests
talonchandler Oct 10, 2023
194be02
fix roundtrip io tests
talonchandler Oct 10, 2023
278c274
update comput-tf tests and logic
talonchandler Oct 10, 2023
a0759ce
update compute-tf tests
talonchandler Oct 10, 2023
8490c96
update reconstruction
talonchandler Oct 10, 2023
2842834
final tests passing
talonchandler Oct 11, 2023
ef3a4d1
Merge pull request #449 from mehta-lab/revise-settings
talonchandler Oct 11, 2023
8c19e15
unused import
talonchandler Oct 11, 2023
1f8c52a
first steps towards reconstruction button
talonchandler Oct 11, 2023
d16b34f
minimally working GUI -> CLI
talonchandler Oct 11, 2023
6f6c6ae
display results in viewer
talonchandler Oct 11, 2023
2cb8093
annotate types
ziw-liu Oct 11, 2023
0f915a3
save output to a new file path
ziw-liu Oct 11, 2023
f739cc7
Merge pull request #450 from mehta-lab/reconstruct-button
talonchandler Oct 11, 2023
483de87
add in-progress cb
talonchandler Oct 11, 2023
0c6c045
tmp inputs
talonchandler Oct 11, 2023
8124d1e
basic listener
talonchandler Oct 11, 2023
cbe5b25
checkpoint create-then-fill strategy
talonchandler Oct 12, 2023
ffb6c0b
assume finite time points
talonchandler Oct 12, 2023
723957d
setup reconstruction queue
ziw-liu Oct 12, 2023
b82e69c
put tasks in the queue
ziw-liu Oct 12, 2023
2d038ff
Merge branch 'main' into listen-to-zarr
ziw-liu Oct 12, 2023
3cf7b92
fix the queue
ziw-liu Oct 12, 2023
2a0ba12
T and Z sweep acquisition script
talonchandler Oct 12, 2023
025d3f1
integrate with the demo writer
ziw-liu Oct 12, 2023
4976c37
qt slot for callback
ziw-liu Oct 12, 2023
3fd1017
Merge pull request #451 from mehta-lab/listen-to-zarr
talonchandler Oct 12, 2023
81882ac
Merge branch 'v1-gui-layout' into acquire-z-stack
talonchandler Oct 13, 2023
c76b8d0
move the viewing flag forward
ziw-liu Oct 13, 2023
a57d2e9
slow down and acquire from camera
talonchandler Oct 13, 2023
abac294
Merge branch 'v1-gui-layout' into acquire-z-stack
edyoshikun Oct 13, 2023
2fcfa86
quit worker after finished
ziw-liu Oct 13, 2023
1f55613
in-progress testing
edyoshikun Oct 13, 2023
b3b3c16
Merge branch 'acquire-z-stack' of https://github.com/mehta-lab/recOrd…
edyoshikun Oct 13, 2023
feb628e
add pyqtslot
ziw-liu Oct 13, 2023
30b02b1
create array before acquisition
ziw-liu Oct 13, 2023
5241569
fix bug
edyoshikun Oct 13, 2023
96c575e
fix shape
ziw-liu Oct 13, 2023
4bc51ab
xy bug
edyoshikun Oct 13, 2023
8eba361
typo fix
edyoshikun Oct 13, 2023
4f3cb53
put into queue in a separate thread
ziw-liu Oct 13, 2023
984da22
Merge remote-tracking branch 'origin/acquire-z-stack' into acquire-z-…
ziw-liu Oct 13, 2023
f4eab25
attempt to quit worker thread upon close
ziw-liu Oct 13, 2023
629ddc4
quit first
ziw-liu Oct 13, 2023
89686ca
changes during final push to demo
edyoshikun Oct 13, 2023
28b13b2
Merge branch 'acquire-z-stack' of https://github.com/mehta-lab/recOrd…
edyoshikun Oct 13, 2023
160d413
Merge pull request #453 from mehta-lab/acquire-z-stack
talonchandler Nov 1, 2023
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
50 changes: 26 additions & 24 deletions examples/birefringence-and-phase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@ input_channel_names:
- State3
time_indices: all
reconstruction_dimension: 3
birefringence:
transfer_function:
swing: 0.1
apply_inverse:
wavelength_illumination: 0.532
background_path: ''
remove_estimated_background: false
flip_orientation: false
rotate_orientation: false
phase:
transfer_function:
wavelength_illumination: 0.532
yx_pixel_size: 0.325
z_pixel_size: 2.0
z_padding: 0
index_of_refraction_media: 1.3
numerical_aperture_detection: 1.2
numerical_aperture_illumination: 0.5
invert_phase_contrast: false
apply_inverse:
reconstruction_algorithm: Tikhonov
regularization_strength: 0.001
TV_rho_strength: 0.001
TV_iterations: 1
reconstruction_type: Birefringence and Phase
reconstruction_settings:
birefringence_settings:
transfer_function:
swing: 0.1
apply_inverse:
wavelength_illumination: 0.532
background_path: ''
remove_estimated_background: false
flip_orientation: false
rotate_orientation: false
phase_settings:
transfer_function:
wavelength_illumination: 0.532
yx_pixel_size: 0.325
z_pixel_size: 2.0
z_padding: 0
index_of_refraction_media: 1.3
numerical_aperture_detection: 1.2
numerical_aperture_illumination: 0.5
invert_phase_contrast: false
apply_inverse:
reconstruction_algorithm: Tikhonov
regularization_strength: 0.001
TV_rho_strength: 0.001
TV_iterations: 1
3 changes: 2 additions & 1 deletion examples/birefringence.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ input_channel_names:
- State3
time_indices: all
reconstruction_dimension: 3
birefringence:
reconstruction_type: Birefringence
reconstruction_settings:
transfer_function:
swing: 0.1
apply_inverse:
Expand Down
3 changes: 2 additions & 1 deletion examples/fluorescence.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ input_channel_names:
- GFP
time_indices: all
reconstruction_dimension: 3
fluorescence:
reconstruction_type: Fluorescence
reconstruction_settings:
transfer_function:
yx_pixel_size: 0.325
z_pixel_size: 2.0
Expand Down
7 changes: 4 additions & 3 deletions examples/phase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ input_channel_names:
- BF
time_indices: all
reconstruction_dimension: 3
phase:
reconstruction_type: Phase
reconstruction_settings:
transfer_function:
wavelength_illumination: 0.532
yx_pixel_size: 0.325
z_pixel_size: 2.0
z_padding: 0
index_of_refraction_media: 1.3
numerical_aperture_detection: 1.2
numerical_aperture_illumination: 0.5
numerical_aperture_detection: 0.75
numerical_aperture_illumination: 0.55
invert_phase_contrast: false
apply_inverse:
reconstruction_algorithm: Tikhonov
Expand Down
64 changes: 32 additions & 32 deletions recOrder/cli/apply_inverse_transfer_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,21 @@ def get_reconstruction_output_metadata(position_path: Path, config_path: Path):
T, _, Z, Y, X = input_dataset.data.shape

settings = utils.yaml_to_model(config_path, ReconstructionSettings)

# Simplify important settings names
recon_biref = settings.birefringence is not None
recon_phase = settings.phase is not None
recon_fluo = settings.fluorescence is not None
recon_dim = settings.reconstruction_dimension

# Prepare output dataset
channel_names = []
if recon_biref:
if "Birefringence" in settings.reconstruction_type:
channel_names.append("Retardance")
channel_names.append("Orientation")
channel_names.append("BF")
channel_names.append("Pol")
if recon_phase:
if "Phase" in settings.reconstruction_type:
if recon_dim == 2:
channel_names.append("Phase2D")
elif recon_dim == 3:
channel_names.append("Phase3D")
if recon_fluo:
if settings.reconstruction_type == "Fluorescence":
fluor_name = settings.input_channel_names[0]
if recon_dim == 2:
channel_names.append(fluor_name + "_Density2D")
Expand Down Expand Up @@ -125,19 +120,20 @@ def apply_inverse_transfer_function_single_position(
f"time_indices = {time_indices} includes a time index beyond the maximum index of the dataset = {time_ubound}"
)

# Simplify important settings names
recon_biref = settings.birefringence is not None
recon_phase = settings.phase is not None
recon_fluo = settings.fluorescence is not None
recon_dim = settings.reconstruction_dimension

# Prepare birefringence parameters
if settings.birefringence is not None:
if "Birefringence" in settings.reconstruction_type:
# settings.birefringence has more parameters than waveorder needs,
# so this section converts the settings to a dict and separates the
# waveorder parameters (biref_inverse_dict) from the recorder
# parameters (cyx_no_sample_data, and wavelength_illumination)
biref_inverse_dict = settings.birefringence.apply_inverse.dict()
if settings.reconstruction_type == "Birefringence":
biref_inverse_dict = (
settings.reconstruction_settings.apply_inverse.dict()
)
elif settings.reconstruction_type == "Birefringence and Phase":
biref_inverse_dict = (
settings.reconstruction_settings.birefringence_settings.apply_inverse.dict()
)

# Resolve background path into array
background_path = biref_inverse_dict.pop("background_path")
Expand All @@ -157,38 +153,42 @@ def apply_inverse_transfer_function_single_position(
# Prepare the apply_inverse_model_function and its arguments

# [biref only]
if recon_biref and (not recon_phase):
if settings.reconstruction_type == "Birefringence":
echo_headline("Reconstructing birefringence with settings:")
echo_settings(settings.birefringence)
echo_settings(settings.reconstruction_settings)

# Setup parameters for apply_inverse_to_zyx_and_save
apply_inverse_model_function = apply_inverse_models.birefringence
apply_inverse_args = {
"cyx_no_sample_data": cyx_no_sample_data,
"wavelength_illumination": biref_wavelength_illumination,
"recon_dim": recon_dim,
"recon_dim": settings.reconstruction_dimension,
"biref_inverse_dict": biref_inverse_dict,
"transfer_function_dataset": transfer_function_dataset,
}

# [phase only]
if recon_phase and (not recon_biref):
if settings.reconstruction_type == "Phase":
echo_headline("Reconstructing phase with settings:")
echo_settings(settings.phase.apply_inverse)
echo_settings(settings.reconstruction_settings.apply_inverse)

# Setup parameters for apply_inverse_to_zyx_and_save
apply_inverse_model_function = apply_inverse_models.phase
apply_inverse_args = {
"recon_dim": recon_dim,
"settings_phase": settings.phase,
"recon_dim": settings.reconstruction_dimension,
"settings_phase": settings.reconstruction_settings,
"transfer_function_dataset": transfer_function_dataset,
}

# [biref and phase]
if recon_biref and recon_phase:
if settings.reconstruction_type == "Birefringence and Phase":
echo_headline("Reconstructing birefringence and phase with settings:")
echo_settings(settings.birefringence.apply_inverse)
echo_settings(settings.phase.apply_inverse)
echo_settings(
settings.reconstruction_settings.birefringence_settings.apply_inverse
)
echo_settings(
settings.reconstruction_settings.phase_settings.apply_inverse
)

# Setup parameters for apply_inverse_to_zyx_and_save
apply_inverse_model_function = (
Expand All @@ -197,22 +197,22 @@ def apply_inverse_transfer_function_single_position(
apply_inverse_args = {
"cyx_no_sample_data": cyx_no_sample_data,
"wavelength_illumination": biref_wavelength_illumination,
"recon_dim": recon_dim,
"recon_dim": settings.reconstruction_dimension,
"biref_inverse_dict": biref_inverse_dict,
"settings_phase": settings.phase,
"settings_phase": settings.reconstruction_settings.phase_settings,
"transfer_function_dataset": transfer_function_dataset,
}

# [fluo]
if recon_fluo:
if settings.reconstruction_type == "Fluorescence":
echo_headline("Reconstructing fluorescence with settings:")
echo_settings(settings.fluorescence.apply_inverse)
echo_settings(settings.reconstruction_settings.apply_inverse)

# Setup parameters for apply_inverse_to_zyx_and_save
apply_inverse_model_function = apply_inverse_models.fluorescence
apply_inverse_args = {
"recon_dim": recon_dim,
"settings_fluorescence": settings.fluorescence,
"recon_dim": settings.reconstruction_dimension,
"settings_fluorescence": settings.reconstruction_settings,
"transfer_function_dataset": transfer_function_dataset,
}

Expand Down
78 changes: 64 additions & 14 deletions recOrder/cli/compute_transfer_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
output_dirpath,
)
from recOrder.cli.printing import echo_headline, echo_settings
from recOrder.cli.settings import ReconstructionSettings
from recOrder.cli.settings import (
ReconstructionSettings,
PhaseSettings,
BirefringenceSettings,
)
from recOrder.io import utils


def generate_and_save_birefringence_transfer_function(settings, dataset):
def generate_and_save_birefringence_transfer_function(
settings: ReconstructionSettings, dataset
):
"""Generates and saves the birefringence transfer function to the dataset, based on the settings.

Parameters
Expand All @@ -30,13 +36,13 @@ def generate_and_save_birefringence_transfer_function(settings, dataset):
The dataset that will be updated.
"""
echo_headline("Generating birefringence transfer function with settings:")
echo_settings(settings.birefringence.transfer_function)
echo_settings(settings.reconstruction_settings.transfer_function)

# Calculate transfer functions
intensity_to_stokes_matrix = (
inplane_oriented_thick_pol3d.calculate_transfer_function(
scheme=str(len(settings.input_channel_names)) + "-State",
**settings.birefringence.transfer_function.dict(),
**settings.reconstruction_settings.transfer_function.dict(),
)
)
# Save
Expand All @@ -45,7 +51,9 @@ def generate_and_save_birefringence_transfer_function(settings, dataset):
] = intensity_to_stokes_matrix.cpu().numpy()[None, None, None, ...]


def generate_and_save_phase_transfer_function(settings, dataset, zyx_shape):
def generate_and_save_phase_transfer_function(
settings: ReconstructionSettings, dataset, zyx_shape
):
"""Generates and saves the phase transfer function to the dataset, based on the settings.

Parameters
Expand All @@ -57,11 +65,13 @@ def generate_and_save_phase_transfer_function(settings, dataset, zyx_shape):
A tuple of integers specifying the input data's shape in (Z, Y, X) order
"""
echo_headline("Generating phase transfer function with settings:")
echo_settings(settings.phase.transfer_function)
echo_settings(settings.reconstruction_settings.transfer_function)

if settings.reconstruction_dimension == 2:
# Convert zyx_shape and z_pixel_size into yx_shape and z_position_list
settings_dict = settings.phase.transfer_function.dict()
settings_dict = (
settings.reconstruction_settings.transfer_function.dict()
)
settings_dict["yx_shape"] = [zyx_shape[1], zyx_shape[2]]
settings_dict["z_position_list"] = list(
-(np.arange(zyx_shape[0]) - zyx_shape[0] // 2)
Expand Down Expand Up @@ -95,7 +105,7 @@ def generate_and_save_phase_transfer_function(settings, dataset, zyx_shape):
imaginary_potential_transfer_function,
) = phase_thick_3d.calculate_transfer_function(
zyx_shape=zyx_shape,
**settings.phase.transfer_function.dict(),
**settings.reconstruction_settings.transfer_function.dict(),
)
# Save
dataset[
Expand All @@ -108,8 +118,44 @@ def generate_and_save_phase_transfer_function(settings, dataset, zyx_shape):
]


def generate_and_save_birefringence_and_phase_transfer_function(
settings: ReconstructionSettings, dataset, zyx_shape
):
"""Generates and saves the birefringence and phase transfer functions to the dataset, based on the settings.

Parameters
----------
settings: ReconstructionSettings
dataset: NGFF Node
The dataset that will be updated.
zyx_shape : tuple
A tuple of integers specifying the input data's shape in (Z, Y, X) order
"""
phase_only_settings = ReconstructionSettings(
input_channel_names=settings.input_channel_names,
time_indices=settings.time_indices,
reconstruction_dimension=settings.reconstruction_dimension,
reconstruction_type="Phase",
reconstruction_settings=settings.reconstruction_settings.phase_settings,
)
generate_and_save_phase_transfer_function(
phase_only_settings, dataset, zyx_shape
)

biref_only_settings = ReconstructionSettings(
input_channel_names=settings.input_channel_names,
time_indices=settings.time_indices,
reconstruction_dimension=settings.reconstruction_dimension,
reconstruction_type="Birefringence",
reconstruction_settings=settings.reconstruction_settings.birefringence_settings,
)
generate_and_save_birefringence_transfer_function(
biref_only_settings, dataset
)


def generate_and_save_fluorescence_transfer_function(
settings, dataset, zyx_shape
settings: ReconstructionSettings, dataset, zyx_shape
):
"""Generates and saves the fluorescence transfer function to the dataset, based on the settings.

Expand All @@ -122,7 +168,7 @@ def generate_and_save_fluorescence_transfer_function(
A tuple of integers specifying the input data's shape in (Z, Y, X) order
"""
echo_headline("Generating fluorescence transfer function with settings:")
echo_settings(settings.fluorescence.transfer_function)
echo_settings(settings.reconstruction_settings.transfer_function)

if settings.reconstruction_dimension == 2:
raise NotImplementedError
Expand All @@ -131,7 +177,7 @@ def generate_and_save_fluorescence_transfer_function(
optical_transfer_function = (
isotropic_fluorescent_thick_3d.calculate_transfer_function(
zyx_shape=zyx_shape,
**settings.fluorescence.transfer_function.dict(),
**settings.reconstruction_settings.transfer_function.dict(),
)
)
# Save
Expand Down Expand Up @@ -176,15 +222,19 @@ def compute_transfer_function_cli(
)

# Pass settings to appropriate calculate_transfer_function and save
if settings.birefringence is not None:
if settings.reconstruction_type == "Birefringence":
generate_and_save_birefringence_transfer_function(
settings, output_dataset
)
if settings.phase is not None:
elif settings.reconstruction_type == "Phase":
generate_and_save_phase_transfer_function(
settings, output_dataset, zyx_shape
)
if settings.fluorescence is not None:
elif settings.reconstruction_type == "Birefringence and Phase":
generate_and_save_birefringence_and_phase_transfer_function(
settings, output_dataset, zyx_shape
)
elif settings.reconstruction_type == "Fluorescence":
generate_and_save_fluorescence_transfer_function(
settings, output_dataset, zyx_shape
)
Expand Down
Loading