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

349 rotation scan now collects OAV snapshots #1443

Merged
merged 8 commits into from
Jul 17, 2024

Conversation

rtuck99
Copy link
Contributor

@rtuck99 rtuck99 commented Jun 12, 2024

Addresses the remaining parts of DiamondLightSource/mx-bluesky#388

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

To test:

  1. When supplied with snapshot_omegas_deg as an array of up to 4 snapshot angles, and snapshot_directory in the request parameters to a rotation scan, OAV snapshots will be acquired prior to the rotation scan at the requested angles and deposited in ispyb
  2. If snapshot_omegas_deg is empty or missing, no snapshots will be acquired and snapshot filenames will be registered in ispyb as specified by the ispyb_extras.xtal_snapshots_omega_start array

@rtuck99 rtuck99 force-pushed the 349_create_oav_snapshot_plan branch from 486d71e to eed8d74 Compare June 12, 2024 14:43
@rtuck99 rtuck99 force-pushed the 349_oav_snapshot_plan_part_2 branch from c70a6b9 to a9906a1 Compare June 12, 2024 14:50
@rtuck99 rtuck99 marked this pull request as ready for review June 13, 2024 07:42
@rtuck99 rtuck99 requested review from DominicOram and d-perl June 13, 2024 07:42
Base automatically changed from 349_create_oav_snapshot_plan to main June 13, 2024 11:59
@rtuck99 rtuck99 marked this pull request as draft June 14, 2024 12:46
@rtuck99 rtuck99 marked this pull request as ready for review June 14, 2024 12:50
@rtuck99 rtuck99 force-pushed the 349_oav_snapshot_plan_part_2 branch from a9906a1 to 488e6b0 Compare June 14, 2024 13:29
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, some comments in code.

def setup_sample_environment(
aperture_scatterguard: ApertureScatterguard,
aperture_position_gda_name: AperturePositionGDANames | None,
def begin_sample_environment_setup(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: I think a docstring on here would be good. I think at the moment it would be something like "Do all the sample environment changes that can be done in parallel to oav snapshots"

Comment on lines 36 to 37
"""Move the aperture into required position, move out the backlight, retract the detector shutter,
and set the attenuator to transmission."""
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 docstring is now wrong

return
yield from bps.wait(group=OAV_SNAPSHOT_SETUP_GROUP)
yield from _setup_oav(composite, parameters, oav_parameters)
for omega in parameters.snapshot_omegas_deg or []:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could: Why not default snapshot_omegas_deg to [] in WithSnapshot then it will never be None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did what you suggested but then was reminded why I didn't - pyright complains that it can still be None, which you still need in the type hint in order to allow the parameter to be omitted rather than left empty in the json. So I figured might as well leave the check in there.

yield from bps.wait(group=OAV_SNAPSHOT_SETUP_GROUP)
yield from _setup_oav(composite, parameters, oav_parameters)
for omega in parameters.snapshot_omegas_deg or []:
yield from _take_oav_snapshot(composite, parameters, omega)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: Why does this function take the params? I don't think they're used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume this was on _take_oav_snapshot? I will remove it

Comment on lines 220 to 222
yield from bps.wait("move_gonio_to_start")
if params.take_snapshots:
yield from bps.wait("move_to_rotation_start")
yield from oav_snapshot_plan(composite, params, oav_params)

# Move to start again for rotation scan after snapshots
yield from bps.abs_set(
axis,
motion_values.start_motion_deg,
group="move_to_rotation_start",
wait=True,
)

yield from setup_sample_environment(
composite.aperture_scatterguard,
params.selected_aperture,
composite.backlight,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: Without measuring it I'm not 100% convinced on the optimal order of operations here, except that begin_sample_environment_setup can take ages so that should be first and for the snapshots to be correct we definitely want the x/y/z to be correct and velocity to be at maximum. So as a first pass I would err on reducing the code complexity a bit by moving this earlier. Like I think we could do:

begin_sample_environment_setup(...)
move_x_y_z(...)
move_phi_chi_omega(...)
wait(`move_gonio_to_start`)
set_max_velo
setup_oav_snapshot_plan(...)
oav_snapshot_plan(...)
setup_sample_environment(...)
_rotation_scan_plan()

I think it's good to keep the setup and taking of snapshots separate func calls though as we will probably want to shift them a bit when we get more into optimising.

Copy link
Contributor Author

@rtuck99 rtuck99 Jun 19, 2024

Choose a reason for hiding this comment

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

I made as few changes to the order as I thought necessary. Not quite sure what you want, current order is this:

# These are already first
begin_sample_environment_setup(...)
setup_oav_snapshot_plan(...) # this is first bc AFAIK scatterguard and backlight have no dependencies and no waits but are physical movement therefore take time
move_x_y_z(...)
move_phi_chi_omega(...)

set_max_velo
wait('move_gonio_to_start')

oav_snapshot_plan(...)
setup_sample_environment(...)

So apart from moving set_max_velo and setup_oav_snapshot_plan, there is no difference, apart from other calls you haven't listed? There doesn't seem to be much point in moving setup_oav_snapshot_plan to just before oav_snapshot_plan; you would lose all the benefit of having two separate calls

The only other difference is that all of these are moved out of the _rotation_scan_plan, which I didn't do in order to ensure the events were not disturbed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yh, it's very similar but there are a few differences, like not having to move to start_motion_deg twice, which I don't think you need to do if you put this earlier? I also think moving it out of _rotation_scan_plan is good as it reduces the complexity of the inner plan. What do you mean by ensure the events were not disturbed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed, moving snapshot stuff to outer plan makes things less complicated and should be fine so doing that. We can get away with setting max_velo twice if we have to.

@rtuck99 rtuck99 force-pushed the 349_oav_snapshot_plan_part_2 branch from 557b073 to f4402e0 Compare June 20, 2024 09:22
@rtuck99 rtuck99 requested review from d-perl and DominicOram June 20, 2024 10:35
@rtuck99 rtuck99 force-pushed the 349_oav_snapshot_plan_part_2 branch from 7ccfcb3 to 326115d Compare June 27, 2024 09:35
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. Sorry, a few more comments.

Comment on lines +75 to +83
yield from bps.abs_set(
composite.smargon.omega, omega, group=OAV_SNAPSHOT_SETUP_SHOT
)
time_now = datetime.now()
filename = f"{time_now.strftime('%H%M%S')}_oav_snapshot_{omega:.0f}"
yield from bps.abs_set(composite.oav.snapshot.filename, filename)
yield from bps.trigger(composite.oav.snapshot, group=OAV_SNAPSHOT_GROUP)
yield from bps.wait(group=OAV_SNAPSHOT_GROUP)
yield from bps.abs_set(
composite.oav.snapshot.filename, filename, group=OAV_SNAPSHOT_SETUP_SHOT
)
yield from bps.wait(group=OAV_SNAPSHOT_SETUP_SHOT)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could: mv takes multiple args and waits for them all so you could do this a little more cleanly, if you like:

    time_now = datetime.now()
    filename = f"{time_now.strftime('%H%M%S')}_oav_snapshot_{omega:.0f}"
    yield from bps.mv(
        composite.smargon.omega, omega
        composite.oav.snapshot.filename, filename
    )

Copy link
Contributor

@d-perl d-perl Jun 28, 2024

Choose a reason for hiding this comment

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

they won't be included in any readings for documents in that case though ignore this, obviously sets won't be included in readings anyway

src/hyperion/experiment_plans/rotation_scan_plan.py Outdated Show resolved Hide resolved
src/hyperion/experiment_plans/rotation_scan_plan.py Outdated Show resolved Hide resolved
src/hyperion/experiment_plans/rotation_scan_plan.py Outdated Show resolved Hide resolved
@rtuck99 rtuck99 requested a review from DominicOram July 3, 2024 08:41
@rtuck99 rtuck99 force-pushed the 349_oav_snapshot_plan_part_2 branch 2 times, most recently from 69fe5e5 to a649605 Compare July 3, 2024 09:08
@rtuck99 rtuck99 force-pushed the 349_oav_snapshot_plan_part_2 branch from 8146ce0 to 831618e Compare July 12, 2024 10:44
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. I fixed a linting error but otherwise all good.

@DominicOram DominicOram merged commit 323a1f1 into main Jul 17, 2024
6 checks passed
@DominicOram DominicOram deleted the 349_oav_snapshot_plan_part_2 branch July 17, 2024 15:30


@pytest.fixture(autouse=True)
def patch_open_to_prevent_dls_reads_in_tests():
Copy link
Contributor

Choose a reason for hiding this comment

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

@rtuck99 this is amazing

olliesilvester pushed a commit to olliesilvester/mx-bluesky that referenced this pull request Aug 23, 2024
…#1443)

* (DiamondLightSource/hyperion#349) integrate snapshot plan with main rotation scan plan

* (DiamondLightSource/hyperion#349) additional ispyb system test and fixes/refactor of existing

* (DiamondLightSource/hyperion#349) Response to PR comments
(DiamondLightSource/hyperion#349) refactor rotation_scan_plan to move more things to outside inner plan as per PR comments

* Fix CI failure caused by import of /dls config files.Add check to ensure unit tests don't accidentally read files from /dls,/dls_sw

---------

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.

3 participants