@@ -502,7 +502,8 @@ 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- # need to update ISPyB grid square here !!!!
505+ if _transport_object :
506+ _transport_object .do_update_grid_square (grid_square .id , grid_square_params )
506507 except Exception :
507508 if _transport_object :
508509 dcg = db .exec (
@@ -569,6 +570,7 @@ def register_foil_hole(
569570 foil_hole_params : FoilHoleParameters ,
570571 db = murfey_db ,
571572):
573+ # need to sort out foil hole update in ISPyB !!!
572574 try :
573575 gsid = (
574576 db .exec (
@@ -580,12 +582,6 @@ def register_foil_hole(
580582 .one ()
581583 .id
582584 )
583- if _transport_object :
584- fh_ispyb_response = _transport_object .do_insert_foil_hole (
585- gsid .id , foil_hole_params
586- )
587- else :
588- fh_ispyb_response = {"success" : False , "return_value" : None }
589585 except NoResultFound :
590586 log .debug (
591587 f"Foil hole { sanitise (str (foil_hole_params .name ))} could not be registered as grid square { sanitise (str (gs_name ))} was not found"
@@ -596,22 +592,51 @@ def register_foil_hole(
596592 jpeg_size = Image .open (secured_foil_hole_image_path ).size
597593 else :
598594 jpeg_size = (0 , 0 )
599- foil_hole = FoilHole (
600- id = fh_ispyb_response ["return_value" ] if fh_ispyb_response ["success" ] else None ,
601- name = foil_hole_params .name ,
602- session_id = session_id ,
603- grid_square_id = gsid ,
604- x_location = foil_hole_params .x_location ,
605- y_location = foil_hole_params .y_location ,
606- x_stage_position = foil_hole_params .x_stage_position ,
607- y_stage_position = foil_hole_params .y_stage_position ,
608- readout_area_x = foil_hole_params .readout_area_x ,
609- readout_area_y = foil_hole_params .readout_area_y ,
610- thumbnail_size_x = foil_hole_params .thumbnail_size_x or jpeg_size [0 ],
611- thumbnail_size_y = foil_hole_params .thumbnail_size_y or jpeg_size [1 ],
612- pixel_size = foil_hole_params .pixel_size ,
613- image = secured_foil_hole_image_path ,
614- )
595+ try :
596+ foil_hole = db .exec (
597+ select (FoilHole )
598+ .where (FoilHole .name == foil_hole_params .name )
599+ .where (FoilHole .grid_square_id == gsid )
600+ .where (FoilHole .session_id == session_id )
601+ ).one ()
602+ foil_hole .x_location = foil_hole_params .x_location
603+ foil_hole .y_location = foil_hole_params .y_location
604+ foil_hole .x_stage_position = foil_hole_params .x_stage_position
605+ foil_hole .y_stage_position = foil_hole_params .y_stage_position
606+ foil_hole .readout_area_x = foil_hole_params .readout_area_x
607+ foil_hole .readout_area_y = foil_hole_params .readout_area_y
608+ foil_hole .thumbnail_size_x = foil_hole_params .thumbnail_size_x or jpeg_size [0 ]
609+ foil_hole .thumbnail_size_y = foil_hole_params .thumbnail_size_y or jpeg_size [1 ]
610+ foil_hole .pixel_size = foil_hole_params .pixel_size
611+ if _transport_object :
612+ _transport_object .do_update_foil_hole (foil_hole .id , foil_hole_params )
613+ except Exception :
614+ if _transport_object :
615+ fh_ispyb_response = _transport_object .do_insert_foil_hole (
616+ gsid .id , foil_hole_params
617+ )
618+ else :
619+ fh_ispyb_response = {"success" : False , "return_value" : None }
620+ foil_hole = FoilHole (
621+ id = (
622+ fh_ispyb_response ["return_value" ]
623+ if fh_ispyb_response ["success" ]
624+ else None
625+ ),
626+ name = foil_hole_params .name ,
627+ session_id = session_id ,
628+ grid_square_id = gsid ,
629+ x_location = foil_hole_params .x_location ,
630+ y_location = foil_hole_params .y_location ,
631+ x_stage_position = foil_hole_params .x_stage_position ,
632+ y_stage_position = foil_hole_params .y_stage_position ,
633+ readout_area_x = foil_hole_params .readout_area_x ,
634+ readout_area_y = foil_hole_params .readout_area_y ,
635+ thumbnail_size_x = foil_hole_params .thumbnail_size_x or jpeg_size [0 ],
636+ thumbnail_size_y = foil_hole_params .thumbnail_size_y or jpeg_size [1 ],
637+ pixel_size = foil_hole_params .pixel_size ,
638+ image = secured_foil_hole_image_path ,
639+ )
615640 db .add (foil_hole )
616641 db .commit ()
617642 db .close ()
0 commit comments