def create_ephyspc_params(force=False, silent=False): if Path(params.getfile("ephyspc_params")).exists() and not force: print(f"{params.getfile('ephyspc_params')} exists already, exiting...") print(Path(params.getfile("ephyspc_params")).exists()) return if silent: data_folder_path = r"D:\iblrig_data\Subjects" remote_data_folder_path = r"\\iblserver.champalimaud.pt\ibldata\Subjects" probe_types = {"PROBE_TYPE_00": "3A", "PROBE_TYPE_01": "3B"} else: data_folder_path = cli_ask_default( r"Where's your LOCAL 'Subjects' data folder?", r"D:\iblrig_data\Subjects") remote_data_folder_path = cli_ask_default( r"Where's your REMOTE 'Subjects' data folder?", r"\\iblserver.champalimaud.pt\ibldata\Subjects", ) n_probes = int(cli_ask_default("How many probes are you using?", '2')) assert 100 > n_probes > 0, 'Please enter number between 1, 99 inclusive' probe_types = {} for i in range(n_probes): probe_types[f'PROBE_TYPE_{i:02}'] = cli_ask_options( f"What's the type of PROBE {i:02}?", ["3A", "3B"]) param_dict = { "DATA_FOLDER_PATH": data_folder_path, "REMOTE_DATA_FOLDER_PATH": remote_data_folder_path, **probe_types } params.write("ephyspc_params", param_dict) print(f"Created {params.getfile('ephyspc_params')}") print(param_dict) return param_dict
def test_param_get_file(self): home_dir = Path(params.getfile("toto")).parent # straight case the file is .{str} in the home directory assert home_dir.joinpath(".toto") == Path(params.getfile("toto")) # straight case the file is .{str} in the home directory assert home_dir.joinpath(".toto") == Path(params.getfile(".toto")) # subfolder case assert home_dir.joinpath(".toto", ".titi") == Path(params.getfile("toto/titi"))
def load_params_dict(params_fname: str) -> dict: params_fpath = Path(params.getfile(params_fname)) if not params_fpath.exists(): return None with open(params_fpath, "r") as f: out = json.load(f) return out
def create_videopc_params(force=False, silent=False): if Path(params.getfile("videopc_params")).exists() and not force: print(f"{params.getfile('videopc_params')} exists already, exiting...") print(Path(params.getfile("videopc_params")).exists()) return if silent: data_folder_path = r"D:\iblrig_data\Subjects" remote_data_folder_path = r"\\iblserver.champalimaud.pt\ibldata\Subjects" body_cam_idx = 0 left_cam_idx = 1 right_cam_idx = 2 else: data_folder_path = cli_ask_default( r"Where's your LOCAL 'Subjects' data folder?", r"D:\iblrig_data\Subjects") remote_data_folder_path = cli_ask_default( r"Where's your REMOTE 'Subjects' data folder?", r"\\iblserver.champalimaud.pt\ibldata\Subjects", ) body_cam_idx = cli_ask_default( "Please select the index of the BODY camera", "0") left_cam_idx = cli_ask_default( "Please select the index of the LEFT camera", "1") right_cam_idx = cli_ask_default( "Please select the index of the RIGHT camera", "2") param_dict = { "DATA_FOLDER_PATH": data_folder_path, "REMOTE_DATA_FOLDER_PATH": remote_data_folder_path, "BODY_CAM_IDX": body_cam_idx, "LEFT_CAM_IDX": left_cam_idx, "RIGHT_CAM_IDX": right_cam_idx, } params.write("videopc_params", param_dict) print(f"Created {params.getfile('videopc_params')}") print(param_dict) return param_dict
def test_new_default_param(self): # in this case an updated version of the codes brings in a new parameter default = { 'A': 'tata2', 'O': 'toto2', 'I': 'titi2', 'E': 'tete2', 'num': 15, 'liste': [1, 'turlu'] } expected_result = { 'A': 'tata', 'O': 'toto', 'I': 'titi', 'num': 15, 'liste': [1, 'turlu'], 'apath': str(Path('/gna/gna/gna')), 'E': 'tete2', } par2 = params.read('toto', default=default) self.assertCountEqual(par2.as_dict(), expected_result) # on the next path the parameter has been added to the param file par2 = params.read('toto', default=default) self.assertCountEqual(par2.as_dict(), expected_result) # check that it doesn't break if a named tuple is given instead of a dict par3 = params.read('toto', default=par2) self.assertEqual(par2, par3) # check that a non-existing parfile raises error pstring = str(uuid.uuid4()) with self.assertRaises(FileNotFoundError): params.read(pstring) # check that a non-existing parfile with default returns default par = params.read(pstring, default=default) self.assertCountEqual(par, params.from_dict(default)) # even if this default is a Params named tuple par = params.read(pstring, default=par) self.assertEqual(par, params.from_dict(default)) # check default empty dict pstring = 'foobar' filename = Path(params.getfile(pstring)) self.assertFalse(filename.exists()) par = params.read(pstring, default={}) self.assertIsNone(par) self.assertTrue(filename.exists())
def tearDown(self): # at last delete the param file Path(params.getfile('toto')).unlink(missing_ok=True) Path(params.getfile('foobar')).unlink(missing_ok=True)