5151from murfey .server .gain import Camera , prepare_eer_gain , prepare_gain
5252from murfey .server .murfey_db import murfey_db
5353from murfey .util import secure_path
54- from murfey .util .config import MachineConfig , from_file , settings
54+ from murfey .util .config import MachineConfig , machine_config_from_file , settings
5555from murfey .util .db import (
5656 AutoProcProgram ,
5757 ClientEnvironment ,
@@ -146,19 +146,19 @@ def connections_check():
146146def machine_info () -> Optional [MachineConfig ]:
147147 instrument_name = os .getenv ("BEAMLINE" )
148148 if settings .murfey_machine_configuration and instrument_name :
149- return from_file ( Path ( settings . murfey_machine_configuration ), instrument_name )[
150- instrument_name
151- ]
149+ return machine_config_from_file (
150+ Path ( settings . murfey_machine_configuration ), instrument_name
151+ )[ instrument_name ]
152152 return None
153153
154154
155155@lru_cache (maxsize = 5 )
156156@router .get ("/instruments/{instrument_name}/machine" )
157157def machine_info_by_name (instrument_name : str ) -> Optional [MachineConfig ]:
158158 if settings .murfey_machine_configuration :
159- return from_file ( Path ( settings . murfey_machine_configuration ), instrument_name )[
160- instrument_name
161- ]
159+ return machine_config_from_file (
160+ Path ( settings . murfey_machine_configuration ), instrument_name
161+ )[ instrument_name ]
162162 return None
163163
164164
@@ -1218,6 +1218,10 @@ async def request_tomography_preprocessing(
12181218 murfey_ids = _murfey_id (appid , db , number = 1 , close = False )
12191219 if not mrc_out .parent .exists ():
12201220 mrc_out .parent .mkdir (parents = True , exist_ok = True )
1221+ # Handle case when gain reference file is None
1222+ if not proc_file .gain_ref :
1223+ log .error ("No gain reference file was provided in the ProcessFile object" )
1224+ return proc_file
12211225 zocalo_message : dict = {
12221226 "recipes" : ["em-tomo-preprocess" ],
12231227 "parameters" : {
@@ -1236,7 +1240,9 @@ async def request_tomography_preprocessing(
12361240 "fm_dose" : proc_file .dose_per_frame ,
12371241 "gain_ref" : (
12381242 str (machine_config .rsync_basepath / proc_file .gain_ref )
1239- if proc_file .gain_ref and machine_config .data_transfer_enabled
1243+ if proc_file .gain_ref
1244+ and machine_config .data_transfer_enabled
1245+ and machine_config .rsync_basepath
12401246 else proc_file .gain_ref
12411247 ),
12421248 "fm_int_file" : proc_file .eer_fractionation_file ,
@@ -1249,7 +1255,7 @@ async def request_tomography_preprocessing(
12491255 _transport_object .send ("processing_recipe" , zocalo_message )
12501256 else :
12511257 log .error (
1252- f"Pe-processing was requested for { sanitise (ppath .name )} but no Zocalo transport object was found"
1258+ f"Preprocessing was requested for { sanitise (ppath .name )} but no Zocalo transport object was found"
12531259 )
12541260 return proc_file
12551261 else :
@@ -1285,6 +1291,8 @@ def suggest_path(
12851291 raise ValueError (
12861292 "No machine configuration set when suggesting destination path"
12871293 )
1294+ if not machine_config .rsync_basepath :
1295+ raise ValueError ("No rsync basepath set" )
12881296 check_path = machine_config .rsync_basepath / base_path
12891297 check_path_name = check_path .name
12901298 while check_path .exists ():
@@ -1366,6 +1374,8 @@ def start_dc(
13661374 machine_config = get_machine_config (instrument_name = instrument_name )[
13671375 instrument_name
13681376 ]
1377+ if not machine_config .rsync_basepath :
1378+ raise ValueError ("No rsync basepath set" )
13691379 log .info (
13701380 f"Starting data collection on microscope { get_microscope (machine_config = machine_config )} "
13711381 f"with basepath { sanitise (str (machine_config .rsync_basepath ))} and directory { sanitise (dc_params .image_directory )} "
@@ -1453,8 +1463,10 @@ async def process_gain(
14531463 executables = machine_config .external_executables
14541464 env = machine_config .external_environment
14551465 safe_path_name = secure_filename (gain_reference_params .gain_ref .name )
1466+ if not machine_config .rsync_basepath :
1467+ raise ValueError ("No rsync basepath set" )
14561468 filepath = (
1457- Path ( machine_config .rsync_basepath )
1469+ machine_config .rsync_basepath
14581470 / (machine_config .rsync_module or "data" )
14591471 / str (datetime .datetime .now ().year )
14601472 / secure_filename (visit_name )
@@ -1521,8 +1533,10 @@ async def write_eer_fractionation_file(
15211533 )
15221534 ) / secure_filename (fractionation_params .fractionation_file_name )
15231535 else :
1536+ if not machine_config .rsync_basepath :
1537+ raise ValueError ("rsync basepath not set" )
15241538 file_path = (
1525- Path ( machine_config .rsync_basepath )
1539+ machine_config .rsync_basepath
15261540 / (machine_config .rsync_module or "data" )
15271541 / str (datetime .datetime .now ().year )
15281542 / secure_filename (visit_name )
@@ -1566,8 +1580,10 @@ async def make_gif(
15661580 machine_config = get_machine_config (instrument_name = instrument_name )[
15671581 instrument_name
15681582 ]
1583+ if not machine_config .rsync_basepath :
1584+ raise ValueError ("rsync basepath not set" )
15691585 output_dir = (
1570- Path ( machine_config .rsync_basepath )
1586+ machine_config .rsync_basepath
15711587 / (machine_config .rsync_module or "data" )
15721588 / secure_filename (year )
15731589 / secure_filename (visit_name )
0 commit comments