@@ -502,7 +502,21 @@ def register_grid_square(
502502 grid_square .y_location = grid_square_params .y_location
503503 grid_square .x_stage_position = grid_square_params .x_stage_position
504504 grid_square .y_stage_position = grid_square_params .y_stage_position
505+ if _transport_object :
506+ _transport_object .do_update_grid_square (grid_square .id , grid_square_params )
505507 except Exception :
508+ if _transport_object :
509+ dcg = db .exec (
510+ select (DataCollectionGroup )
511+ .where (DataCollectionGroup .session_id == session_id )
512+ .where (DataCollectionGroup .tag == grid_square_params .tag )
513+ ).one ()
514+ gs_ispyb_response = _transport_object .do_insert_grid_square (
515+ dcg .atlas_id , gsid , grid_square_params
516+ )
517+ else :
518+ # mock up response so that below still works
519+ gs_ispyb_response = {"success" : False , "return_value" : None }
506520 secured_grid_square_image_path = secure_filename (grid_square_params .image )
507521 if (
508522 secured_grid_square_image_path
@@ -512,6 +526,11 @@ def register_grid_square(
512526 else :
513527 jpeg_size = (0 , 0 )
514528 grid_square = GridSquare (
529+ id = (
530+ gs_ispyb_response ["return_value" ]
531+ if gs_ispyb_response ["success" ]
532+ else None
533+ ),
515534 name = gsid ,
516535 session_id = session_id ,
517536 tag = grid_square_params .tag ,
@@ -552,16 +571,13 @@ def register_foil_hole(
552571 db = murfey_db ,
553572):
554573 try :
555- gsid = (
556- db .exec (
557- select (GridSquare )
558- .where (GridSquare .tag == foil_hole_params .tag )
559- .where (GridSquare .session_id == session_id )
560- .where (GridSquare .name == gs_name )
561- )
562- .one ()
563- .id
564- )
574+ gs = db .exec (
575+ select (GridSquare )
576+ .where (GridSquare .tag == foil_hole_params .tag )
577+ .where (GridSquare .session_id == session_id )
578+ .where (GridSquare .name == gs_name )
579+ ).one ()
580+ gsid = gs .id
565581 except NoResultFound :
566582 log .debug (
567583 f"Foil hole { sanitise (str (foil_hole_params .name ))} could not be registered as grid square { sanitise (str (gs_name ))} was not found"
@@ -572,21 +588,53 @@ def register_foil_hole(
572588 jpeg_size = Image .open (secured_foil_hole_image_path ).size
573589 else :
574590 jpeg_size = (0 , 0 )
575- foil_hole = FoilHole (
576- name = foil_hole_params .name ,
577- session_id = session_id ,
578- grid_square_id = gsid ,
579- x_location = foil_hole_params .x_location ,
580- y_location = foil_hole_params .y_location ,
581- x_stage_position = foil_hole_params .x_stage_position ,
582- y_stage_position = foil_hole_params .y_stage_position ,
583- readout_area_x = foil_hole_params .readout_area_x ,
584- readout_area_y = foil_hole_params .readout_area_y ,
585- thumbnail_size_x = foil_hole_params .thumbnail_size_x or jpeg_size [0 ],
586- thumbnail_size_y = foil_hole_params .thumbnail_size_y or jpeg_size [1 ],
587- pixel_size = foil_hole_params .pixel_size ,
588- image = secured_foil_hole_image_path ,
589- )
591+ try :
592+ foil_hole = db .exec (
593+ select (FoilHole )
594+ .where (FoilHole .name == foil_hole_params .name )
595+ .where (FoilHole .grid_square_id == gsid )
596+ .where (FoilHole .session_id == session_id )
597+ ).one ()
598+ foil_hole .x_location = foil_hole_params .x_location
599+ foil_hole .y_location = foil_hole_params .y_location
600+ foil_hole .x_stage_position = foil_hole_params .x_stage_position
601+ foil_hole .y_stage_position = foil_hole_params .y_stage_position
602+ foil_hole .readout_area_x = foil_hole_params .readout_area_x
603+ foil_hole .readout_area_y = foil_hole_params .readout_area_y
604+ foil_hole .thumbnail_size_x = foil_hole_params .thumbnail_size_x or jpeg_size [0 ]
605+ foil_hole .thumbnail_size_y = foil_hole_params .thumbnail_size_y or jpeg_size [1 ]
606+ foil_hole .pixel_size = foil_hole_params .pixel_size
607+ if _transport_object :
608+ _transport_object .do_update_foil_hole (
609+ foil_hole .id , gs .thumbnail_size_x / gs .readout_area_x , foil_hole_params
610+ )
611+ except Exception :
612+ if _transport_object :
613+ fh_ispyb_response = _transport_object .do_insert_foil_hole (
614+ gsid .id , gs .thumbnail_size_x / gs .readout_area_x , foil_hole_params
615+ )
616+ else :
617+ fh_ispyb_response = {"success" : False , "return_value" : None }
618+ foil_hole = FoilHole (
619+ id = (
620+ fh_ispyb_response ["return_value" ]
621+ if fh_ispyb_response ["success" ]
622+ else None
623+ ),
624+ name = foil_hole_params .name ,
625+ session_id = session_id ,
626+ grid_square_id = gsid ,
627+ x_location = foil_hole_params .x_location ,
628+ y_location = foil_hole_params .y_location ,
629+ x_stage_position = foil_hole_params .x_stage_position ,
630+ y_stage_position = foil_hole_params .y_stage_position ,
631+ readout_area_x = foil_hole_params .readout_area_x ,
632+ readout_area_y = foil_hole_params .readout_area_y ,
633+ thumbnail_size_x = foil_hole_params .thumbnail_size_x or jpeg_size [0 ],
634+ thumbnail_size_y = foil_hole_params .thumbnail_size_y or jpeg_size [1 ],
635+ pixel_size = foil_hole_params .pixel_size ,
636+ image = secured_foil_hole_image_path ,
637+ )
590638 db .add (foil_hole )
591639 db .commit ()
592640 db .close ()
@@ -1128,6 +1176,7 @@ async def request_spa_preprocessing(
11281176 "image_number" : proc_file .image_number ,
11291177 "microscope" : get_microscope (),
11301178 "mc_uuid" : murfey_ids [0 ],
1179+ "foil_hole_id" : foil_hole_id ,
11311180 "ft_bin" : proc_params ["motion_corr_binning" ],
11321181 "fm_dose" : proc_params ["dose_per_frame" ],
11331182 "gain_ref" : proc_params ["gain_ref" ],
@@ -1377,15 +1426,30 @@ def register_dc_group(
13771426 ).all ():
13781427 dcg_murfey [0 ].atlas = dcg_params .atlas
13791428 dcg_murfey [0 ].sample = dcg_params .sample
1429+ dcg_murfey [0 ].atlas_pixel_size = dcg_params .atlas_pixel_size
13801430 db .add (dcg_murfey [0 ])
13811431 db .commit ()
1432+ if _transport_object :
1433+ _transport_object .send (
1434+ _transport_object .feedback_queue ,
1435+ {
1436+ "register" : "atlas_update" ,
1437+ "atlas_id" : dcg_murfey .atlas_id ,
1438+ "atlas" : dcg_params .atlas ,
1439+ "sample" : dcg_params .sample ,
1440+ "atlas_pixel_size" : dcg_params .atlas_pixel_size ,
1441+ },
1442+ )
13821443 else :
13831444 dcg_parameters = {
13841445 "start_time" : str (datetime .datetime .now ()),
13851446 "experiment_type" : dcg_params .experiment_type ,
13861447 "experiment_type_id" : dcg_params .experiment_type_id ,
13871448 "tag" : dcg_params .tag ,
13881449 "session_id" : session_id ,
1450+ "atlas" : dcg_params .atlas ,
1451+ "sample" : dcg_params .sample ,
1452+ "atlas_pixel_size" : dcg_params .atlas_pixel_size ,
13891453 }
13901454
13911455 if _transport_object :
0 commit comments