Skip to content

Commit c79068b

Browse files
Fixes for the processing parameters on instrument server (#524)
1 parent d9ad8b6 commit c79068b

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

src/murfey/client/analyser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ def post_transfer(self, transferred_file: Path):
218218
transferred_file, environment=self._environment
219219
)
220220
except Exception as e:
221-
logger.error(f"An exception was encountered post transfer: {e}")
221+
logger.error(
222+
f"An exception was encountered post transfer: {e}", exc_info=True
223+
)
222224

223225
def _analyse(self):
224226
logger.info("Analyser thread started")

src/murfey/instrument_server/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def run():
4141
)
4242

4343
handler = CustomHandler(ws.send)
44-
logging.getLogger().addHandler(handler)
44+
logging.getLogger("murfey").addHandler(handler)
45+
logging.getLogger("fastapi").addHandler(handler)
46+
logging.getLogger("uvicorn").addHandler(handler)
4547

4648
logger.info(
4749
f"Starting Murfey server version {murfey.__version__}, listening on {args.host}:{args.port}"

src/murfey/server/api/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,8 +1262,7 @@ async def request_tomography_preprocessing(
12621262

12631263
processing_job_parameters = db.exec(
12641264
select(TomographyProcessingParameters).where(
1265-
TomographyProcessingParameters.processing_job_id
1266-
== data_collection[2].id
1265+
TomographyProcessingParameters.pj_id == data_collection[2].id
12671266
)
12681267
).all()
12691268
if processing_job_parameters:
@@ -1547,7 +1546,7 @@ def register_proc(
15471546
proc_params: ProcessingJobParameters,
15481547
db=murfey_db,
15491548
):
1550-
proc_parameters = {
1549+
proc_parameters: dict = {
15511550
"session_id": session_id,
15521551
"experiment_type": proc_params.experiment_type,
15531552
"recipe": proc_params.recipe,
@@ -1565,7 +1564,8 @@ def register_proc(
15651564
).all()
15661565

15671566
if session_processing_parameters:
1568-
proc_params["job_parameters"].update(
1567+
job_parameters: dict = proc_parameters["job_parameters"]
1568+
job_parameters.update(
15691569
{
15701570
"gain_ref": session_processing_parameters[0].gain_ref,
15711571
"dose_per_frame": session_processing_parameters[0].dose_per_frame,
@@ -1575,6 +1575,7 @@ def register_proc(
15751575
"symmetry": session_processing_parameters[0].symmetry,
15761576
}
15771577
)
1578+
proc_parameters["job_parameters"] = job_parameters
15781579

15791580
if _transport_object:
15801581
_transport_object.send(

src/murfey/server/api/instrument.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ async def activate_instrument_server_for_session(
6060
machine_config = get_machine_config(instrument_name=instrument_name)[
6161
instrument_name
6262
]
63-
async with aiohttp.ClientSession() as session:
64-
async with session.post(
63+
async with aiohttp.ClientSession() as clientsession:
64+
async with clientsession.post(
6565
f"{machine_config.instrument_server_url}/sessions/{int(sanitise(str(session_id)))}/token",
6666
json={"access_token": token, "token_type": "bearer"},
6767
) as response:
@@ -80,11 +80,11 @@ async def check_if_session_is_active(instrument_name: str, session_id: int):
8080
if instrument_server_tokens.get(session_id) is None:
8181
return {"active": False}
8282
async with lock:
83-
async with aiohttp.ClientSession() as session:
83+
async with aiohttp.ClientSession() as clientsession:
8484
machine_config = get_machine_config(instrument_name=instrument_name)[
8585
instrument_name
8686
]
87-
async with session.get(
87+
async with clientsession.get(
8888
f"{machine_config.instrument_server_url}/sessions/{int(sanitise(str(session_id)))}/check_token",
8989
headers={
9090
"Authorization": f"Bearer {instrument_server_tokens[session_id]['access_token']}"
@@ -116,8 +116,8 @@ async def start_multigrid_watcher(
116116
"visit": visit,
117117
"default_model": str(machine_config.default_model),
118118
}
119-
async with aiohttp.ClientSession() as session:
120-
async with session.post(
119+
async with aiohttp.ClientSession() as clientsession:
120+
async with clientsession.post(
121121
f"{machine_config.instrument_server_url}/sessions/{session_id}/multigrid_watcher",
122122
json={
123123
"source": str(secure_path(watcher_spec.source / visit)),
@@ -154,6 +154,7 @@ async def pass_proc_params_to_instrument_server(
154154
session = db.exec(select(Session).where(Session.id == session_id)).one()
155155

156156
session_processing_parameters = SessionProcessingParameters(
157+
session_id=session_id,
157158
dose_per_frame=proc_params.dose_per_frame,
158159
gain_ref=session.current_gain_ref,
159160
symmetry=proc_params.symmetry,
@@ -170,8 +171,8 @@ async def pass_proc_params_to_instrument_server(
170171
]
171172
if machine_config.instrument_server_url:
172173
label = db.exec(select(Session).where(Session.id == session_id)).one().name
173-
async with aiohttp.ClientSession() as session:
174-
async with session.post(
174+
async with aiohttp.ClientSession() as clientsession:
175+
async with clientsession.post(
175176
f"{machine_config.instrument_server_url}/sessions/{session_id}/processing_parameters",
176177
json={
177178
"label": label,
@@ -199,8 +200,8 @@ async def check_instrument_server(instrument_name: str):
199200
instrument_name
200201
]
201202
if machine_config.instrument_server_url:
202-
async with aiohttp.ClientSession() as session:
203-
async with session.get(
203+
async with aiohttp.ClientSession() as clientsession:
204+
async with clientsession.get(
204205
f"{machine_config.instrument_server_url}/health",
205206
) as resp:
206207
data = await resp.json()
@@ -220,8 +221,8 @@ async def get_possible_gain_references(
220221
if machine_config.instrument_server_url:
221222
async with lock:
222223
token = instrument_server_tokens[session_id]["access_token"]
223-
async with aiohttp.ClientSession() as session:
224-
async with session.get(
224+
async with aiohttp.ClientSession() as clientsession:
225+
async with clientsession.get(
225226
f"{machine_config.instrument_server_url}/instruments/{sanitise(instrument_name)}/sessions/{sanitise(str(session_id))}/possible_gain_references",
226227
headers={"Authorization": f"Bearer {token}"},
227228
) as resp:
@@ -249,8 +250,8 @@ async def request_gain_reference_upload(
249250
visit_path = f"{datetime.datetime.now().year}/{visit}"
250251
data = {}
251252
if machine_config.instrument_server_url:
252-
async with aiohttp.ClientSession() as session:
253-
async with session.post(
253+
async with aiohttp.ClientSession() as clientsession:
254+
async with clientsession.post(
254255
f"{machine_config.instrument_server_url}/instruments/{instrument_name}/sessions/{session_id}/upload_gain_reference",
255256
json={
256257
"gain_path": str(gain_reference_request.gain_path),
@@ -282,8 +283,8 @@ async def request_upstream_tiff_data_download(
282283
/ secure_filename(visit_name)
283284
)
284285
if machine_config.instrument_server_url:
285-
async with aiohttp.ClientSession() as session:
286-
async with session.post(
286+
async with aiohttp.ClientSession() as clientsession:
287+
async with clientsession.post(
287288
f"{machine_config.instrument_server_url}/visits/{secure_filename(visit_name)}/sessions/{sanitise(str(session_id))}/upstream_tiff_data_request",
288289
json={"download_dir": download_dir},
289290
headers={
@@ -310,8 +311,8 @@ async def stop_rsyncer(
310311
instrument_name
311312
]
312313
if machine_config.instrument_server_url:
313-
async with aiohttp.ClientSession() as session:
314-
async with session.post(
314+
async with aiohttp.ClientSession() as clientsession:
315+
async with clientsession.post(
315316
f"{machine_config.instrument_server_url}/sessions/{session_id}/stop_rsyncer",
316317
json={
317318
"label": session_id,
@@ -337,8 +338,8 @@ async def finalise_rsyncer(
337338
instrument_name
338339
]
339340
if machine_config.instrument_server_url:
340-
async with aiohttp.ClientSession() as session:
341-
async with session.post(
341+
async with aiohttp.ClientSession() as clientsession:
342+
async with clientsession.post(
342343
f"{machine_config.instrument_server_url}/sessions/{session_id}/finalise_rsyncer",
343344
json={
344345
"label": session_id,
@@ -365,8 +366,8 @@ async def remove_rsyncer(
365366
]
366367
if isinstance(session_id, int):
367368
if machine_config.instrument_server_url:
368-
async with aiohttp.ClientSession() as session:
369-
async with session.post(
369+
async with aiohttp.ClientSession() as clientsession:
370+
async with clientsession.post(
370371
f"{machine_config.instrument_server_url}/sessions/{session_id}/remove_rsyncer",
371372
json={
372373
"label": session_id,
@@ -393,8 +394,8 @@ async def restart_rsyncer(
393394
]
394395
if isinstance(session_id, int):
395396
if machine_config.instrument_server_url:
396-
async with aiohttp.ClientSession() as session:
397-
async with session.post(
397+
async with aiohttp.ClientSession() as clientsession:
398+
async with clientsession.post(
398399
f"{machine_config.instrument_server_url}/sessions/{session_id}/restart_rsyncer",
399400
json={
400401
"label": session_id,

src/murfey/server/gain.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ class Camera(Enum):
1818
FALCON = 3
1919

2020

21-
def _sanitise(gain_path: Path) -> Path:
22-
dest = gain_path.parent / "gain" / gain_path.name.replace(" ", "_")
21+
def _sanitise(gain_path: Path, tag: str) -> Path:
22+
if tag:
23+
dest = gain_path.parent / f"gain_{tag}" / gain_path.name.replace(" ", "_")
24+
else:
25+
dest = gain_path.parent / "gain" / gain_path.name.replace(" ", "_")
2326
dest.write_bytes(gain_path.read_bytes())
2427
return dest
2528

@@ -57,7 +60,7 @@ async def prepare_gain(
5760
secure_path(gain_path.parent / f"gain_{tag}").mkdir(exist_ok=True)
5861
else:
5962
secure_path(gain_path.parent / "gain").mkdir(exist_ok=True)
60-
gain_path = _sanitise(gain_path)
63+
gain_path = _sanitise(gain_path, tag)
6164
flip = "flipx" if camera == Camera.K3_FLIPX else "flipy"
6265
gain_path_mrc = gain_path.with_suffix(".mrc")
6366
gain_path_superres = gain_path.parent / (gain_path.name + "_superres.mrc")

0 commit comments

Comments
 (0)