add simple CLI directly to package #9

Merged
foefl merged 1 commits from internal_cli into main 2025-10-24 11:04:59 +00:00
5 changed files with 51 additions and 8 deletions

View File

@ -1,6 +1,6 @@
[project] [project]
name = "dopt-sensor-anomalies" name = "dopt-sensor-anomalies"
version = "0.1.1" version = "0.1.2"
description = "anomaly detection for sensor images for quality assurance processes" description = "anomaly detection for sensor images for quality assurance processes"
authors = [ authors = [
{name = "d-opt GmbH", email = "f.foerster@d-opt.com"}, {name = "d-opt GmbH", email = "f.foerster@d-opt.com"},
@ -10,6 +10,9 @@ requires-python = "<3.14,>=3.11"
readme = "README.md" readme = "README.md"
license = {text = "LicenseRef-Proprietary"} license = {text = "LicenseRef-Proprietary"}
[project.scripts]
EKF = "dopt_sensor_anomalies.cli:main"
[build-system] [build-system]
requires = ["pdm-backend", "Cython", "setuptools"] requires = ["pdm-backend", "Cython", "setuptools"]
build-backend = "pdm.backend" build-backend = "pdm.backend"
@ -76,7 +79,7 @@ directory = "reports/coverage"
[tool.bumpversion] [tool.bumpversion]
current_version = "0.1.1" current_version = "0.1.2"
parse = """(?x) parse = """(?x)
(?P<major>0|[1-9]\\d*)\\. (?P<major>0|[1-9]\\d*)\\.
(?P<minor>0|[1-9]\\d*)\\. (?P<minor>0|[1-9]\\d*)\\.

View File

@ -1,3 +1,5 @@
"""main pipeline interface for external calls"""
from dopt_sensor_anomalies import detection from dopt_sensor_anomalies import detection

View File

@ -0,0 +1,33 @@
import argparse
from typing import cast
from dopt_sensor_anomalies import _interface
from dopt_sensor_anomalies.types import CliArgs
def main() -> None:
parser = argparse.ArgumentParser(
description=("simple CLI tool to analyse single sensor images for anomalies")
)
parser.add_argument(
"img_path",
help="file path to the image which is to be analysed",
type=str,
)
parser.add_argument(
"calib_value_x",
help="calibration value in pixels per mcm for x axis",
type=float,
)
parser.add_argument(
"calib_value_y",
help="calibration value in pixels per mcm for y axis",
type=float,
)
args = cast(CliArgs, parser.parse_args())
_interface.sensor_anomalies_detection(
args.img_path,
args.calib_value_x,
args.calib_value_y,
)

View File

@ -25,3 +25,10 @@ class SensorImages(TypedDict):
class DetectionModels(TypedDict): class DetectionModels(TypedDict):
left: Path left: Path
right: Path right: Path
@dc.dataclass()
class CliArgs:
img_path: str
calib_value_x: float
calib_value_y: float

View File

@ -3,7 +3,7 @@ from unittest.mock import patch
import pytest import pytest
from dopt_sensor_anomalies import _csharp_interface, constants, errors from dopt_sensor_anomalies import _interface, constants, errors
@patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "lib") @patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "lib")
@ -15,7 +15,7 @@ def test_sensor_anomalies_detection_FailImagePath(setup_temp_dir):
MESSAGE = "The provided path seems not to exist" MESSAGE = "The provided path seems not to exist"
with pytest.raises(FileNotFoundError, match=MESSAGE): with pytest.raises(FileNotFoundError, match=MESSAGE):
_csharp_interface.sensor_anomalies_detection( _interface.sensor_anomalies_detection(
img_path, pixels_per_metric_X, pixels_per_metric_Y img_path, pixels_per_metric_X, pixels_per_metric_Y
) )
@ -29,7 +29,7 @@ def test_sensor_anomalies_detection_FailElectrodeCount(path_img_with_failure_Ele
MESSAGE = "Number of counted electrodes does not match the" MESSAGE = "Number of counted electrodes does not match the"
with pytest.raises(errors.InvalidElectrodeCount, match=MESSAGE): with pytest.raises(errors.InvalidElectrodeCount, match=MESSAGE):
_csharp_interface.sensor_anomalies_detection( _interface.sensor_anomalies_detection(
img_path, pixels_per_metric_X, pixels_per_metric_Y img_path, pixels_per_metric_X, pixels_per_metric_Y
) )
@ -52,9 +52,7 @@ def test_sensor_anomalies_detection_Success(
pixels_per_metric_X: float = 0.251 pixels_per_metric_X: float = 0.251
pixels_per_metric_Y: float = 0.251 pixels_per_metric_Y: float = 0.251
_csharp_interface.sensor_anomalies_detection( _interface.sensor_anomalies_detection(img_path, pixels_per_metric_X, pixels_per_metric_Y)
img_path, pixels_per_metric_X, pixels_per_metric_Y
)
assert csv_file.exists() assert csv_file.exists()
assert heatmap_file.exists() assert heatmap_file.exists()