Skip to content

Conversation

@srishtysajeev
Copy link
Contributor

Fixes #1726

Instructions to reviewer on how to test:

  1. Confirm tests work
  2. Review code

Checks for reviewer

  • Would the PR title make sense to a scientist on a set of release notes
  • If a new device has been added does it follow the standards
  • If changing the API for a pre-existing device, ensure that any beamlines using this device have updated their Bluesky plans accordingly
  • Have the connection tests for the relevant beamline(s) been run via dodal connect ${BEAMLINE}

srishtysajeev and others added 22 commits November 25, 2025 18:42
* Proof of concept device manager

* Use fixtures parameter instead of **kwargs

* Expand dependencies

* Pre-optional handling

* 'Working' optional dependencies

* Docs, comments and warnings

* Check for positional only arguments

* Handle connections and support new loader in cli

* Convert adsim to new loading

* Add auto_connect to device manager

* Remove references to connecting from device manager

* DeviceResult wrappers

* Demo adsim

* build_and_connect method

* Multiple manager CLI

* FIXTUEES

* Use device decorator for timeouts

* Type build_and_connect and rely on fixtures for path provider

* mostly reformatting

* Make fixture generators lazy

* Apologise for build_order method

* Return function from fixture decorator

* Add timeout parameter to build_and_connect

* Remove dead comment

* Use set in expand_dependencies to prevent repetition

* Check for duplicate factory names

* Add Ophyd v1 support

* Connect Ophyd v1 devices

* Move device_manager to new module

Instead of burying it amongst the beamlines.

* Remove test code from device_manager module

* Remove debugging and commented code

* Merge connectionspec and connectionparameters

* Add or_raise method to DeviceBuildResult

* Add docstrings

* Use or_raise to handle build errors

* Only set device name if required

* Add TODOs to remove v1 support

* Make v1 device timeout configurable

* Default to waiting for v1 device connection

* Add repr to v1 device factory

* Split DeviceBuildResult devices and connection specs

Makes access to the devices easier and makes it easier to build parameters

* Remove device_type property from factories

* Include fixture overrides in built devices

* Fix duplication in factory repr

* Add initial device_manager tests

* Revert adsim changes for now

* Enough tests to get full coverage

Maybe enough tests to cover basic use

* Create DeviceManager in fixture

* Add test for docstrings

* Reformat tests

* Linting et al

* Support single device manager name in CLI

* Ignore mock type warnings

* Appease pre-commit lints

* Add tests for device manager use in CLI

* Make 'devices' default name for device manager in CLI

* Clean up TODO comments

* Set return_value when creating mocks

* Fix typing in v1_init decorator

* Use ParamSpec when passing through __call__

* Handle or ignore var args

* Update tests

* Rename ignore skip test

* Simplify LazyFixture __getitem__

* Used UserDict as base class for LazyFixtures

* Make pyright happy

* Remove need for type ignore

---------

Co-authored-by: Robert Tuck <robert.tuck@diamond.ac.uk>
* Eiger changes from i04 beamline

* Add test for two eiger stops being called at the same time

* Revert async arming changes

* Fix tests

---------

Co-authored-by: Dominic Oram <dominic.oram@diamond.ac.uk>
* first try

* add trigger function which writes to soft signals

* small changes

* get rid of max pixel location

* add tests - need modifying as made with copilot

* make triggerable for blesky plan

* start to add max-pixel device in i04 (WIP because on beamline)

* Finish adding device to i04.py

* Add changes from beamline testing - from github

* add comment for kernal size

* attemt own tests

* add my tests

* add assert called onece tests

* make changes from Dom's comments

* add greyscale test

* remove print statements in test

* Fix merge issue

---------

Co-authored-by: Dominic Oram <dominic.oram@diamond.ac.uk>
…n as the max pixel device (to blur and convert to greyscale)
@srishtysajeev srishtysajeev requested a review from a team as a code owner December 4, 2025 13:09

# Level is the string description of the zoom level e.g. "1.0x" or "1.0"
self.level = epics_signal_rw(str, f"{prefix}MP:SELECT")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to refactor this to make more concise

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, additionally they don't exist on i03 so we will need to make them optional

Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments mostly reminders to myself


# Level is the string description of the zoom level e.g. "1.0x" or "1.0"
self.level = epics_signal_rw(str, f"{prefix}MP:SELECT")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, additionally they don't exist on i03 so we will need to make them optional

Comment on lines 39 to 41
contour_array = np.array(
[[[10, 10]], [[10, 50]], [[50, 50]], [[50, 10]]], dtype=np.uint8
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: This isn't used, remove

from ophyd_async.core import init_devices

from dodal.devices.i04.beam_centre import CentreEllipseMethod, binary_img

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good tests, I would probably add one that is the whole thing from realistic data through to an actual centre

@DominicOram DominicOram changed the title 1726 beam centre device post testing Add a device that will calculate a beam centre Dec 15, 2025
@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.12%. Comparing base (f919ae5) to head (cfe6770).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1757   +/-   ##
=======================================
  Coverage   99.12%   99.12%           
=======================================
  Files         282      283    +1     
  Lines       10683    10750   +67     
=======================================
+ Hits        10589    10656   +67     
  Misses         94       94           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@olliesilvester olliesilvester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR - only some minor comments


largest_contour = max(contours, key=cv2.contourArea)
if len(largest_contour) < 5:
raise ValueError("Not enough points to fit an ellipse.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: error message could include {largest_contour}

ADDITIONAL_BINARY_THRESH = 20


def convert_image_to_binary(image: np.ndarray):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: Move this function to oav/utils.py


# kernel size describes how many of the neighbouring pixels are used for the blur,
# higher kernal size means more of a blur effect
kernel_size = (7, 7)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: Move this into a constant

arr = await self._convert_to_gray_and_blur()
img_data = await self.array_data.get_value()
arr = convert_to_gray_and_blur(img_data)
max_val = float(np.max(arr)) # np.int64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the # np.int64 comment is saying?


@patch("dodal.devices.i04.beam_centre.CentreEllipseMethod._fit_ellipse")
@patch("dodal.devices.i04.beam_centre.convert_image_to_binary")
async def test_trigger_converts_to_binary_then_finds_ellipse(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think for these types of tests its better to use a parent magic mock so that we can also check the order


@patch("dodal.devices.i04.beam_centre.cv2.threshold")
@patch("dodal.devices.i04.beam_centre.convert_to_gray_and_blur")
async def test_convert_image_to_binary_calls_threshold_twice(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can also check that mock_convert has been called once here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAV Beam Center Device

5 participants