Skip to content

Commit

Permalink
Add validation for z range, and loosen the GUI restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
multimeric committed Nov 3, 2023
1 parent 69500a7 commit c09983f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 10 additions & 1 deletion core/lls_core/models/lattice_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,27 @@ def parse_workflow(cls, v: Any):

@validator("crop")
def default_z_range(cls, v: CropParams, values: dict):
# If any part of the z range is missing, assume the user wants all Z indices
if v is None:
return v
with ignore_keyerror():
# Fill in missing parts of the z range with the min/max z values
default_start = 0
default_end = values["input_image"].sizes["Z"]

# Set defaults
if v.z_range is None:
v.z_range = (default_start, default_end)
if v.z_range[0] is None:
v.z_range[0] = default_start
if v.z_range[1] is None:
v.z_range[1] = default_end

# Validate
if v.z_range[1] > default_end:
raise ValueError(f"The z-index endpoint of {v.z_range[1]} is outside the size of the z-axis ({default_end})")
if v.z_range[0] < default_start:
raise ValueError(f"The z-index start of {v.z_range[0]} is outside the size of the z-axis")

return v

@validator("time_range", pre=True, always=True)
Expand Down
1 change: 0 additions & 1 deletion plugin/napari_lattice/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ class CroppingFields(NapariFieldGroup):
value = (0, 1),
options = dict(
min = 0,
max = 1
),
)
errors = field(Label).with_options(label="Errors")
Expand Down

0 comments on commit c09983f

Please sign in to comment.