2323logger = getLogger ("murfey.workflows.tomo.feedback" )
2424
2525
26- def _ids_tomo_classification (app_id : int , recipe : str , _db ) -> Tuple [int , int ]:
26+ def _ids_tomo_classification (
27+ app_id : int , recipe : str , murfey_db : Session
28+ ) -> Tuple [int , int ]:
2729 dcg_id = (
28- _db .exec (
30+ murfey_db .exec (
2931 select (AutoProcProgram , ProcessingJob , DataCollection )
3032 .where (AutoProcProgram .id == app_id )
3133 .where (AutoProcProgram .pj_id == ProcessingJob .id )
@@ -35,7 +37,7 @@ def _ids_tomo_classification(app_id: int, recipe: str, _db) -> Tuple[int, int]:
3537 .dcg_id
3638 )
3739 pj_id = (
38- _db .exec (
40+ murfey_db .exec (
3941 select (ProcessingJob , DataCollection )
4042 .where (DataCollection .dcg_id == dcg_id )
4143 .where (ProcessingJob .dc_id == DataCollection .id )
@@ -47,11 +49,11 @@ def _ids_tomo_classification(app_id: int, recipe: str, _db) -> Tuple[int, int]:
4749 return dcg_id , pj_id
4850
4951
50- def _register_picked_tomogram_use_diameter (message : dict , _db : Session ):
52+ def _register_picked_tomogram_use_diameter (message : dict , murfey_db : Session ):
5153 """Received picked particles from the tomogram autopick service"""
5254 # Add this message to the table of seen messages
5355 dcg_id , pj_id = _ids_tomo_classification (
54- message ["program_id" ], "em-tomo-class2d" , _db
56+ message ["program_id" ], "em-tomo-class2d" , murfey_db
5557 )
5658
5759 pick_params = TomogramPicks (
@@ -61,16 +63,16 @@ def _register_picked_tomogram_use_diameter(message: dict, _db: Session):
6163 particle_count = message ["particle_count" ],
6264 tomogram_pixel_size = message ["pixel_size" ],
6365 )
64- _db .add (pick_params )
65- _db .commit ()
66+ murfey_db .add (pick_params )
67+ murfey_db .commit ()
6668
67- picking_db_len = _db .exec (
69+ picking_db_len = murfey_db .exec (
6870 select (func .count (ParticleSizes .id )).where (ParticleSizes .pj_id == pj_id )
6971 ).one ()
7072 if picking_db_len > default_tomo_parameters .batch_size_2d :
7173 # If there are enough particles to get a diameter
7274 instrument_name = (
73- _db .exec (
75+ murfey_db .exec (
7476 select (MurfeySession ).where (MurfeySession .id == message ["session_id" ])
7577 )
7678 .one ()
@@ -79,15 +81,15 @@ def _register_picked_tomogram_use_diameter(message: dict, _db: Session):
7981 machine_config = get_machine_config (instrument_name = instrument_name )[
8082 instrument_name
8183 ]
82- tomo_params = _db .exec (
84+ tomo_params = murfey_db .exec (
8385 select (TomographyProcessingParameters ).where (
8486 TomographyProcessingParameters .dcg_id == dcg_id
8587 )
8688 ).one ()
8789
8890 particle_diameter = tomo_params .particle_diameter
8991
90- feedback_params = _db .exec (
92+ feedback_params = murfey_db .exec (
9193 select (ClassificationFeedbackParameters ).where (
9294 ClassificationFeedbackParameters .pj_id == pj_id
9395 )
@@ -97,15 +99,15 @@ def _register_picked_tomogram_use_diameter(message: dict, _db: Session):
9799
98100 if not particle_diameter :
99101 # If the diameter has not been calculated then find it
100- picking_db = _db .exec (
102+ picking_db = murfey_db .exec (
101103 select (ParticleSizes .particle_size ).where (ParticleSizes .pj_id == pj_id )
102104 ).all ()
103105 particle_diameter = np .quantile (list (picking_db ), 0.75 )
104106 tomo_params .particle_diameter = particle_diameter
105- _db .add (tomo_params )
106- _db .commit ()
107+ murfey_db .add (tomo_params )
108+ murfey_db .commit ()
107109
108- tomo_pick_db = _db .exec (
110+ tomo_pick_db = murfey_db .exec (
109111 select (TomogramPicks ).where (TomogramPicks .pj_id == pj_id )
110112 ).all ()
111113 for saved_message in tomo_pick_db :
@@ -114,13 +116,13 @@ def _register_picked_tomogram_use_diameter(message: dict, _db: Session):
114116 str (i + 1 ): m
115117 for i , m in enumerate (
116118 _murfey_id (
117- _app_id (pj_id , _db ),
118- _db ,
119+ _app_id (pj_id , murfey_db ),
120+ murfey_db ,
119121 number = default_tomo_parameters .nr_classes_2d ,
120122 )
121123 )
122124 }
123- class2d_grp_uuid = _murfey_id (_app_id (pj_id , _db ), _db )[0 ]
125+ class2d_grp_uuid = _murfey_id (_app_id (pj_id , murfey_db ), murfey_db )[0 ]
124126 zocalo_message : dict = {
125127 "parameters" : {
126128 "tomogram" : saved_message .tomogram ,
@@ -130,7 +132,7 @@ def _register_picked_tomogram_use_diameter(message: dict, _db: Session):
130132 "kv" : tomo_params .voltage ,
131133 "node_creator_queue" : machine_config .node_creator_queue ,
132134 "session_id" : message ["session_id" ],
133- "autoproc_program_id" : _app_id (pj_id , _db ),
135+ "autoproc_program_id" : _app_id (pj_id , murfey_db ),
134136 "batch_size" : default_tomo_parameters .batch_size_2d ,
135137 "nr_classes" : default_tomo_parameters .nr_classes_2d ,
136138 "picker_id" : None ,
@@ -148,21 +150,21 @@ def _register_picked_tomogram_use_diameter(message: dict, _db: Session):
148150 "processing_recipe" , zocalo_message , new_connection = True
149151 )
150152 feedback_params .next_job += 2
151- _db .delete (saved_message )
153+ murfey_db .delete (saved_message )
152154 else :
153155 # If the diameter is known then just send the new message
154156 particle_diameter = tomo_params .particle_diameter
155157 class_uuids = {
156158 str (i + 1 ): m
157159 for i , m in enumerate (
158160 _murfey_id (
159- _app_id (pj_id , _db ),
160- _db ,
161+ _app_id (pj_id , murfey_db ),
162+ murfey_db ,
161163 number = default_tomo_parameters .nr_classes_2d ,
162164 )
163165 )
164166 }
165- class2d_grp_uuid = _murfey_id (_app_id (pj_id , _db ), _db )[0 ]
167+ class2d_grp_uuid = _murfey_id (_app_id (pj_id , murfey_db ), murfey_db )[0 ]
166168 zocalo_message = {
167169 "parameters" : {
168170 "tomogram" : message ["tomogram" ],
@@ -172,7 +174,7 @@ def _register_picked_tomogram_use_diameter(message: dict, _db: Session):
172174 "kv" : tomo_params .voltage ,
173175 "node_creator_queue" : machine_config .node_creator_queue ,
174176 "session_id" : message ["session_id" ],
175- "autoproc_program_id" : _app_id (pj_id , _db ),
177+ "autoproc_program_id" : _app_id (pj_id , murfey_db ),
176178 "batch_size" : default_tomo_parameters .batch_size_2d ,
177179 "nr_classes" : default_tomo_parameters .nr_classes_2d ,
178180 "picker_id" : None ,
@@ -190,17 +192,17 @@ def _register_picked_tomogram_use_diameter(message: dict, _db: Session):
190192 "processing_recipe" , zocalo_message , new_connection = True
191193 )
192194 feedback_params .next_job += 2
193- _db .add (feedback_params )
194- _db .commit ()
195+ murfey_db .add (feedback_params )
196+ murfey_db .commit ()
195197 else :
196198 # If not enough particles then save the new sizes
197199 particle_list = message .get ("particle_diameters" )
198200 assert isinstance (particle_list , list )
199201 for particle in particle_list :
200202 new_particle = ParticleSizes (pj_id = pj_id , particle_size = particle )
201- _db .add (new_particle )
202- _db .commit ()
203- _db .close ()
203+ murfey_db .add (new_particle )
204+ murfey_db .commit ()
205+ murfey_db .close ()
204206
205207
206208def picked_tomogram (message : dict , murfey_db : Session ) -> bool :
0 commit comments