Skip to content

Commit

Permalink
MAINT: Use specs instead of user input
Browse files Browse the repository at this point in the history
  • Loading branch information
jwboth committed Jun 16, 2024
1 parent b4b386d commit d7e2801
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/darsia/assistants/crop_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def __init__(self, img: darsia.Image, **kwargs) -> None:
self.finalized_prompt_input = False
"""Flag controlling whether the user has entered the width and height."""

self.width = None
self.width = kwargs.get("width", None)
"""Identified width of the box."""

self.height = None
self.height = kwargs.get("height", None)
"""Identified height of the box."""

def _reset(self) -> None:
Expand All @@ -65,8 +65,10 @@ def __call__(self) -> dict:

# Ask user to enter width and height into prompt
if not self.finalized_prompt_input:
self.width = float(input("Enter width of box: "))
self.height = float(input("Enter height of box: "))
if self.width is None:
self.width = float(input("Enter width of box: "))
if self.height is None:
self.height = float(input("Enter height of box: "))
self.finalized_prompt_input = True

# Define a dictionary for input of the 'crop' option of CurvatureCorrection
Expand Down Expand Up @@ -96,7 +98,10 @@ def _print_info(self) -> None:
# ! ---- Automatic mode ---- ! #

def from_image(
self, color: Union[list[float], np.ndarray], width: float, height: float
self,
color: Union[list[float], np.ndarray],
width: Optional[float],
height: Optional[float],
) -> dict:
"""Run the assistant in automatic mode.
Expand All @@ -119,8 +124,12 @@ def from_image(
self.pts = self._find_marks(color)

# Define width and height of the box
self.width = width
self.height = height
if self.width is None:
assert width is not None, "Width not provided"
self.width = width
if self.height is None:
assert height is not None, "Height not provided"
self.height = height

# Define a dictionary for input of the 'crop' option of CurvatureCorrection
config = self._define_config()
Expand Down

0 comments on commit d7e2801

Please sign in to comment.