From 38906c8ffff07fcfeedac987508fa9de2e4aa13a Mon Sep 17 00:00:00 2001 From: Chish36 Date: Tue, 29 Jul 2025 12:28:20 +0100 Subject: [PATCH] Moved quadratic function to utilities file --- .../things/stage_measure.py | 12 +----------- src/openflexure_microscope_server/utilities.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/openflexure_microscope_server/things/stage_measure.py b/src/openflexure_microscope_server/things/stage_measure.py index 82acc5b4..63b2a5eb 100644 --- a/src/openflexure_microscope_server/things/stage_measure.py +++ b/src/openflexure_microscope_server/things/stage_measure.py @@ -13,6 +13,7 @@ import cv2 import json from PIL import Image import time +from ..utilities import quadratic from scipy.optimize import curve_fit from camera_stage_mapping import fft_image_tracking from labthings_fastapi.thing import Thing @@ -30,17 +31,6 @@ CamDep = direct_thing_client_dependency(StreamingPiCamera2, "/camera/") CSMDep = direct_thing_client_dependency(CameraStageMapper, "/camera_stage_mapping/") AutofocusDep = direct_thing_client_dependency(AutofocusThing, "/autofocus/") -def quadratic(x, a, b, c): - """Quadratic function. Used for predicting z. - - :param x: The points at which to evaluate the quadratic. - :param a: The coefficient of x^2. - :param b: The coefficient of x. - :param c: The constant coefficient. - :return: The quadratic, evaluated at each point in ``x`` - """ - return a * x**2 + b * x + c - def generate_move_dicts(fov_perc: int, stream_resolution: list[int], direction: int, factor: float = 1) -> dict[str, float]: """Create a single dictionary of x and y moves for moving in image coordinates. diff --git a/src/openflexure_microscope_server/utilities.py b/src/openflexure_microscope_server/utilities.py index d9debd1e..b5a4bde3 100644 --- a/src/openflexure_microscope_server/utilities.py +++ b/src/openflexure_microscope_server/utilities.py @@ -327,3 +327,14 @@ def _get_version_from_toml(toml_path: str) -> str: except (IOError, ValueError, KeyError): LOGGER.error("Problem opening pyproject.toml") return "Undefined" + +def quadratic(x, a, b, c): + """Quadratic function. Used for predicting z. + + :param x: The points at which to evaluate the quadratic. + :param a: The coefficient of x^2. + :param b: The coefficient of x. + :param c: The constant coefficient. + :return: The quadratic, evaluated at each point in ``x`` + """ + return a * x**2 + b * x + c