-
Notifications
You must be signed in to change notification settings - Fork 5
349 rotation scan now collects OAV snapshots #1443
Conversation
486d71e
to
eed8d74
Compare
c70a6b9
to
a9906a1
Compare
a9906a1
to
488e6b0
Compare
There was a problem hiding this 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( |
There was a problem hiding this comment.
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"
"""Move the aperture into required position, move out the backlight, retract the detector shutter, | ||
and set the attenuator to transmission.""" |
There was a problem hiding this comment.
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 []: |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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, | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
557b073
to
f4402e0
Compare
7ccfcb3
to
326115d
Compare
There was a problem hiding this 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.
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) |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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
69fe5e5
to
a649605
Compare
(#349) refactor rotation_scan_plan to move more things to outside inner plan as per PR comments
…ure unit tests don't accidentally read files from /dls,/dls_sw
8146ce0
to
831618e
Compare
There was a problem hiding this 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.
|
||
|
||
@pytest.fixture(autouse=True) | ||
def patch_open_to_prevent_dls_reads_in_tests(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rtuck99 this is amazing
…#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]>
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:
snapshot_omegas_deg
as an array of up to 4 snapshot angles, andsnapshot_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 ispybsnapshot_omegas_deg
is empty or missing, no snapshots will be acquired and snapshot filenames will be registered in ispyb as specified by theispyb_extras.xtal_snapshots_omega_start
array