Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Move WarningException and some oav plans to dodal #1423

Merged
merged 10 commits into from
Jun 12, 2024

Conversation

olliesilvester
Copy link
Contributor

@olliesilvester olliesilvester commented May 30, 2024

Fixes dodal #539

Link to dodal PR (if required): #XXX
(remember to update setup.cfg with the dodal commit tag if you need it for tests to pass!)

To test:

  1. Do thing x
  2. Confirm thing y happens

@olliesilvester
Copy link
Contributor Author

It seems like pre_centring_setup_oav and setup_pin_tip_detection_params are a little too specific to also be moved into dodal? I might be wrong though

Copy link
Collaborator

@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.

Great, thanks, one comment but also DiamondLightSource/dodal#589 (comment). I think you're right about not moving more. Wanting to know where the beam is on an OAV image seems generically useful. Doing a centring algorithm on that seems potentially more specific, probably something more for mx_bluesky

@@ -30,7 +28,7 @@ def _fake_grid_detection(
box_size_um: float = 0.0,
):
oav = i03.oav(fake_with_ophyd_sim=True)
smargon = fake_smargon()
smargon = i03.smargon(fake_with_ophyd_sim=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: This isn't equivalent as fake_smargon patched the motors too. Can you use the smargon() in conftest here?

Copy link
Collaborator

@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.

Thanks, couple of comments but basically there.

Comment on lines +17 to +24
def catch_exception_and_warn(
exception_to_catch: Type[Exception],
func: Callable[..., Generator[Msg, None, T]],
*args,
**kwargs,
) -> Generator[Msg, None, T]:
"""A plan wrapper to catch a specific exception and instead raise a WarningException,
so that UDC is not halted
Copy link
Collaborator

Choose a reason for hiding this comment

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

Love this helper function, thank you!

Comment on lines 11 to 13
def dummy_plan():
raise TestException
yield from null
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: If you swap the yield from and the raise then you can remove the type: ignore later on

Comment on lines 11 to 13
def dummy_plan():
raise TestException
yield from null
Copy link
Collaborator

Choose a reason for hiding this comment

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

Must: I think it needs to be yield from null()

@@ -26,11 +28,10 @@ def _fake_grid_detection(
snapshot_dir: str,
grid_width_microns: float = 0,
box_size_um: float = 0.0,
smargon=None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think 2274ac6 is slightly cleaner, feel free to disagree though

Comment on lines 35 to 47
def warn_if_exception_matches(exception: Exception):
if isinstance(exception, exception_to_catch):
raise WarningException(str(exception))
else:
raise

return (
yield from contingency_wrapper(
func(*args, **kwargs),
except_plan=warn_if_exception_matches,
auto_raise=True,
)
)
Copy link
Collaborator

@DominicOram DominicOram Jun 10, 2024

Choose a reason for hiding this comment

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

Should: There's a bit of redundancy here. I think we either need the else raise and then auto_raise=False or no else raise and then auto_raise=True. Both having the else cause and the auto_raise is redundant, which is fine but maybe a little misleading

Copy link
Collaborator

@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.

Great, thank you! Minor comment, take it or leave

@@ -42,6 +42,5 @@ def warn_if_exception_matches(exception: Exception):
yield from contingency_wrapper(
func(*args, **kwargs),
except_plan=warn_if_exception_matches,
auto_raise=True,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: This defaults to True so you still have the redundancy that you had before. Though I'm not too bothered as this protects us against future changes in the default.

Copy link
Contributor Author

@olliesilvester olliesilvester Jun 12, 2024

Choose a reason for hiding this comment

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

I will take it out. I also just realised that warn_if_exception_matches is a plan so it needs a yield from null()

@olliesilvester olliesilvester merged commit c5722de into main Jun 12, 2024
4 checks passed
@olliesilvester olliesilvester deleted the dodal_539_move_setup_oav_utils branch June 12, 2024 13:06
olliesilvester added a commit to olliesilvester/mx-bluesky that referenced this pull request Aug 23, 2024
…/hyperion#1423)

* Move WarningException and some oav plans to dodal

* make wrapper function to raise WarningExceptions from plans

* Simplify xrc tests slightly


---------

Co-authored-by: Dominic Oram <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants