Skip to content

Commit

Permalink
Override read_image validator in LatticeData to get the filename
Browse files Browse the repository at this point in the history
  • Loading branch information
multimeric committed Aug 2, 2024
1 parent 420898b commit b28e5ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 6 additions & 3 deletions core/lls_core/models/deskew.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 3 additions & 7 deletions core/lls_core/models/lattice_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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):
Expand Down

0 comments on commit b28e5ef

Please sign in to comment.