From b28e5efeb643a3f941542f4a11db914abbf340d2 Mon Sep 17 00:00:00 2001 From: Michael Milton Date: Fri, 2 Aug 2024 16:09:14 +1000 Subject: [PATCH] Override read_image validator in LatticeData to get the filename --- core/lls_core/models/deskew.py | 9 ++++++--- core/lls_core/models/lattice_data.py | 10 +++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/lls_core/models/deskew.py b/core/lls_core/models/deskew.py index 132c43b6..754d46f7 100644 --- a/core/lls_core/models/deskew.py +++ b/core/lls_core/models/deskew.py @@ -158,9 +158,12 @@ def convert_skew(cls, v: Any): return v @validator("physical_pixel_sizes", pre=True) - def convert_pixels(cls, v: Any): - # Allow the pixel sizes to be specified as a tuple - if isinstance(v, tuple) and len(v) == 3: + def convert_pixels(cls, v: Any, values: dict[Any, Any]): + from aicsimageio.types import PhysicalPixelSizes + if isinstance(v, PhysicalPixelSizes): + return DefinedPixelSizes.from_physical(v) + elif isinstance(v, tuple) and len(v) == 3: + # Allow the pixel sizes to be specified as a tuple return DefinedPixelSizes(Z=v[0], Y=v[1], X=v[2]) return v diff --git a/core/lls_core/models/lattice_data.py b/core/lls_core/models/lattice_data.py index 5bebbd98..dbde3b87 100644 --- a/core/lls_core/models/lattice_data.py +++ b/core/lls_core/models/lattice_data.py @@ -47,12 +47,7 @@ class LatticeData(OutputParams, DeskewParams): ) @root_validator(pre=True) - def use_image_path(cls, values: dict): - # This needs to be a root validator to ensure it runs before the - # reshaping validator. We can't override that either since it's - # a field validator and can't modify save_name - # TODO: separate the image file from the image file path as two separate fields, - # so we don't have to put so much logic here + def read_image(cls, values: dict): from lls_core.types import is_pathlike from pathlib import Path input_image = values.get("input_image") @@ -68,7 +63,8 @@ def use_image_path(cls, values: dict): # Convert a string path to a Path object values["save_dir"] = Path(save_dir) - return values + # Use the Deskew version of this validator, to do the actual image loading + return super().read_image(values) @validator("workflow", pre=True) def parse_workflow(cls, v: Any):