-
Notifications
You must be signed in to change notification settings - Fork 5
1217 Use event from grid detect to do ispyb deposition #1279
1217 Use event from grid detect to do ispyb deposition #1279
Conversation
20d7c37
to
6a2a0a9
Compare
af06d87
to
de7235f
Compare
6a2a0a9
to
37e8849
Compare
de7235f
to
7864007
Compare
37e8849
to
266070d
Compare
7864007
to
831d8e8
Compare
266070d
to
5b83260
Compare
928fd92
to
88ad151
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! Partly reviewed but ran out of time to go as deep as I wanted, sorry.
Nonetheless, some comments in code. Also, I think with the merge of #1297 some of the code reduces down.
def ispyb_activation_wrapper(parameters, plan_generator): | ||
@bpp.run_decorator( | ||
md={ | ||
"activate_callbacks": ["GridscanISPyBCallback"], | ||
"subplan_name": CONST.PLAN.GRID_DETECT_AND_DO_GRIDSCAN, | ||
"hyperion_internal_parameters": parameters.json(), | ||
} | ||
) | ||
@wraps(plan_generator) | ||
def wrapped(): | ||
return plan_generator | ||
|
||
yield from wrapped() |
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:
def ispyb_activation_wrapper(parameters, plan_generator): | |
@bpp.run_decorator( | |
md={ | |
"activate_callbacks": ["GridscanISPyBCallback"], | |
"subplan_name": CONST.PLAN.GRID_DETECT_AND_DO_GRIDSCAN, | |
"hyperion_internal_parameters": parameters.json(), | |
} | |
) | |
@wraps(plan_generator) | |
def wrapped(): | |
return plan_generator | |
yield from wrapped() | |
def ispyb_activation_wrapper(parameters, plan_generator): | |
return bpp.run_wrapper( | |
plan_generator, | |
md={ | |
"activate_callbacks": ["GridscanISPyBCallback"], | |
"subplan_name": CONST.PLAN.GRID_DETECT_AND_DO_GRIDSCAN, | |
"hyperion_internal_parameters": parameters.json(), | |
}, | |
) |
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.
Nit: I think you could then switch the parameters
and plan_generator
to more closely match the run_wrapper
syntax
) | ||
initial_collection_info = replace( | ||
initial_collection_info, | ||
data_collection_info = replace( |
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: Is this now taking an empty data collection and recreating it from the existing event_sourced_data_collection_info
? Why can't we just use the event_sourced_data_collection_info
itself?
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.
Similar in the ispyb_callback
for xray centring.
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.
yes, I should have spotted this!
grid_scan_info = GridScanInfo( | ||
upper_left_px=numpy.array( | ||
[data["oav_snapshot_top_left_x"], data["oav_snapshot_top_left_y"]] | ||
), | ||
x_steps=data["oav_snapshot_num_boxes_x"], | ||
y_steps=data["oav_snapshot_num_boxes_y"], | ||
# convert pixels back to mm | ||
x_step_size_mm=data["oav_snapshot_box_width"] | ||
* self.params.hyperion_params.ispyb_params.microns_per_pixel_x | ||
/ 1000, | ||
y_step_size_mm=data["oav_snapshot_box_width"] | ||
* self.params.hyperion_params.ispyb_params.microns_per_pixel_y | ||
/ 1000, | ||
) |
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: Is the only reason we need the grid scan info for constructing the comment? It seems messy to make this object here, use it once, then use the same parameters to make a DataCollectionGridInfo
straight after. Could we change construct_comment_for_gridscan
to take a DataCollectionGridInfo
or to just take the parameters it needs then we can get rid of GridScanInfo
?
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 will get rid of it
assert ( | ||
ispyb_ids.data_collection_group_id | ||
), "Attempted to store scan data without a collection group" | ||
assert ( | ||
ispyb_ids.data_collection_ids | ||
), "Attempted to store scan data without a collection" | ||
print(f"OBJECT PASSED IN IS {ispyb_ids}") |
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 assume this is for debugging? Can you remove please? Same with other places in this file.
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.
Doh
self.ispyb_ids, None, [scan_data_info] | ||
) | ||
self._oav_snapshot_event_idx += 1 | ||
pass |
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: What is this pass
doing?
case CONST.DESCRIPTORS.ISPYB_HARDWARE_READ: | ||
self._handle_ispyb_hardware_read(doc) | ||
case CONST.DESCRIPTORS.OAV_SNAPSHOT_TRIGGERED: | ||
self._handle_oav_snapshot_triggered(doc) | ||
case CONST.DESCRIPTORS.ISPYB_TRANSMISSION_FLUX_READ: |
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 do each of these cases have different behavior w.r.t actually updating ispyb?
CONST.DESCRIPTORS.ISPYB_HARDWARE_READ
- doesn't update ispyb at allCONST.DESCRIPTORS.OAV_SNAPSHOT_TRIGGERED
- Updates ispyb inside_handle_oav_snapshot_triggered
CONST.DESCRIPTORS.ISPYB_TRANSMISSION_FLUX_READ
- Updates ispyb outside_handle_ispyb_transmission_flux_read
It seems to me that they should all update ispyb and they should do it in a consistent way
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.
historical reasons really, that's the original underlying behaviour that has always been there.
b5efe47
to
5dd5eb9
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.
Apologies, some more comments in code.
self._sample_barcode, | ||
) | ||
ISPYB_LOGGER.info(f"Recieved ISPYB IDs: {self.ispyb_ids}") | ||
match event_descriptor.get("name"): |
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: Now that these all call the update_deposition
maybe it would be better to have each of these cases return the update and then call the update_deposition
here?
data_collection_info = DataCollectionInfo() | ||
data_collection_info.xtal_snapshot1 = data.get( | ||
"oav_snapshot_last_path_full_overlay" | ||
) | ||
data_collection_info.xtal_snapshot2 = data.get("oav_snapshot_last_path_outer") | ||
data_collection_info.xtal_snapshot3 = data.get("oav_snapshot_last_saved_path") | ||
data_collection_info.n_images = ( | ||
data["oav_snapshot_num_boxes_x"] * data["oav_snapshot_num_boxes_y"] | ||
) |
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.
Nit: We could just do this in the instantiation like _handle_ispyb_hardware_read
:
data_collection_info = DataCollectionInfo(
xtal_snapshot1 = data.get("oav_snapshot_last_path_full_overlay"),
....
)
return "Hyperion rotation scan" | ||
return |
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 function is no longer used, can we remove?
from hyperion.external_interaction.ispyb.data_model import ( | ||
DataCollectionGridInfo, | ||
DataCollectionInfo, | ||
) | ||
from hyperion.external_interaction.ispyb.ispyb_dataclass import Orientation | ||
|
||
|
||
def populate_xz_data_collection_info( |
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 need full_params
?
detector_params, | ||
) -> DataCollectionInfo: | ||
assert ( | ||
detector_params.omega_start is not None | ||
and detector_params.run_number is not None | ||
and ispyb_params is not None | ||
and full_params is not None | ||
), "StoreGridscanInIspyb failed to get parameters" | ||
omega_start = detector_params.omega_start + 90 |
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: We should be able to read the omega from the smargon when we do the pin tip detection, can we make an issue for that?
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.
Have made #1327 but is pin tip detection the right place or should it be done during read_hardware_for_ispyb_pre_collection
?
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.
It can't be done during read_hardware_for_ispyb_pre_collection
because we want the omega for each grid. If we read omega at pre_collection we only get the first grid's omega. We would then have to add the 90 deg in the callback again, which I was trying to avoid. Basically I want the logic of what we're doing to be in the plan, the callback should just be blindly funneling it into ispyb
ScanDataInfo( | ||
data_collection_info=populate_remaining_data_collection_info( | ||
None, | ||
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.
Should: Shouldn't the dcgid
here be the group made above?
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.
we haven't made it yet, we've only populated the DataCollectionGroupInfo
but it hasn't been posted to the database so there's no id, leaving it as none will cause it to be populate during the call to begin_deposition
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.
Ok, that seems a bit convoluted but I guess we can tidy up in #1293
grid_scan_info, | ||
self.params, | ||
self.params.hyperion_params.ispyb_params, | ||
scan_data_infos = [ |
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: Rather than do anything specific upfront could we get away with doing all the specific stuff in _handle_oav_snapshot_triggered
? e.g. this could be something like:
number_of_collections = 2 if self.is_3d_gridscan() else 1
scan_data_infos = [ScanDataInfo(data_collection_info=populate_remaining_data_collection_info(
None,
None,
DataCollectionInfo(
axis_range=0,
axis_end=omega_start,
),
self.params.hyperion_params.detector_params,
self.params.hyperion_params.ispyb_params,
) for range in (number_of_collections)]
Then handle run_number
and omega_start
in _handle_oav_snapshot_triggered
?
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 guess this is a wider question than for this one particular change but given that we are planning to move to ispyb-eye is it better to defer some of our internal changes until that point? At least until it's clearer how start / event documents might map to ispyb-eye calls? Unless you were proposing this with that already in mind.
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.
Sure, happy to park this :)
* Move ispyb callback activation to before grid detect * Fixup all the broken unit tests * Separate descriptor constants from plan names * Move callback activation wrapper to callback module
* Fix system tests * Change comment to be specified as a value instead of a factory
* Remove ispyb params upper_left
* Remove oav_snapshot_callback.py
…ivity_start() and eager create both xy and xz DataCollection, as per PR feedback
Remove GridScanInfo
…ore uniform in ispyb_callback_base.py as per PR review
662c1aa
to
36436f3
Compare
* Remove unused methods and method parameters * Extract common call to update_deposition() from ispyb_callback_base handler methods * Tidy up initialisation of DataCollectionInfo
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! I think this all looks a lot cleaner now
…Source/1217_use_event_from_grid_detect_to_do_ispyb_deposition 1217 Use event from grid detect to do ispyb deposition
Fixes #1217
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: