From f71bc4e88c0562a8176ce4703673ac4df4f2f0bd Mon Sep 17 00:00:00 2001 From: Talon Chandler Date: Tue, 25 Apr 2023 10:27:32 -0700 Subject: [PATCH] connect background corrections --- recOrder/acq/acquisition_workers.py | 4 +++- recOrder/cli/apply_inverse_transfer_function.py | 6 ++++-- recOrder/cli/settings.py | 15 ++++++++++++--- recOrder/plugin/main_widget.py | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/recOrder/acq/acquisition_workers.py b/recOrder/acq/acquisition_workers.py index 7b66bdd1..5b5e0b97 100644 --- a/recOrder/acq/acquisition_workers.py +++ b/recOrder/acq/acquisition_workers.py @@ -96,7 +96,9 @@ def _generate_transfer_function_config( def _generate_apply_inverse_config(apply_inverse_settings_path, calib_window): birefringence_apply_inverse_settings = ( - settings._BirefringenceApplyInverseSettings() + settings._BirefringenceApplyInverseSettings( + background_path=calib_window.acq_bg_directory + ) ) phase_apply_inverse_settings = settings._PhaseApplyInverseSettings() diff --git a/recOrder/cli/apply_inverse_transfer_function.py b/recOrder/cli/apply_inverse_transfer_function.py index d892a3f5..2b86a745 100644 --- a/recOrder/cli/apply_inverse_transfer_function.py +++ b/recOrder/cli/apply_inverse_transfer_function.py @@ -143,7 +143,7 @@ def apply_inverse_transfer_function_cli( # Resolve background path into array background_path = biref_inverse_dict["background_path"] biref_inverse_dict.pop("background_path") - if background_path is not None: + if background_path != "": cyx_no_sample_data = utils.new_load_background(background_path) _check_background_consistency( cyx_no_sample_data.shape, input_dataset.data.shape @@ -338,8 +338,10 @@ def apply_inverse_transfer_function_cli( **biref_inverse_dict, ) + brightfield_3d = reconstructed_parameters_3d[2] + zyx_phase = phase_thick_3d.apply_inverse_transfer_function( - tczyx_data[time_index, 0], + brightfield_3d, real_potential_transfer_function, imaginary_potential_transfer_function, z_padding=settings.phase_transfer_function_settings.z_padding, diff --git a/recOrder/cli/settings.py b/recOrder/cli/settings.py index d6f0c003..5187954b 100644 --- a/recOrder/cli/settings.py +++ b/recOrder/cli/settings.py @@ -1,3 +1,4 @@ +import os from pydantic import BaseModel, DirectoryPath, validator from typing import Literal, List @@ -110,13 +111,21 @@ class TransferFunctionSettings(BaseModel): class _BirefringenceApplyInverseSettings(BaseModel): - background_path: str = ( - None # I'd DirectoryPath but it's not JSON serializable? - ) + background_path: str = "" remove_estimated_background: bool = False orientation_flip: bool = False orientation_rotate: bool = False + @validator("background_path") + def check_background_path(cls, v): + if v == "": + return v + + raw_dir = r"{}".format(v) + if not os.path.isdir(raw_dir): + raise ValueError(f"{v} is not a existing directory") + return raw_dir + class _PhaseApplyInverseSettings(BaseModel): reconstruction_algorithm: Literal["Tikhonov", "TV"] = "Tikhonov" diff --git a/recOrder/plugin/main_widget.py b/recOrder/plugin/main_widget.py index 985d3b2e..8149a98b 100644 --- a/recOrder/plugin/main_widget.py +++ b/recOrder/plugin/main_widget.py @@ -303,7 +303,7 @@ def __init__(self, napari_viewer: Viewer): self.orientation_offset = False self.pad_z = 0 self.phase_reconstructor = None - self.acq_bg_directory = None + self.acq_bg_directory = "" self.auto_shutter = True self.lca_dac = None self.lcb_dac = None