Loading experiments/create_experiment_config.py +18 −12 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ EXPERIMENTS_P800 = [f"P800-{i}" for i in range(1, 10)] EXPERIMENTS_BS1534 = [f"BS1534-{i}{x}" for i in range(1, 8) for x in ["a", "b"]] EXPERIMENTS = EXPERIMENTS_P800 + EXPERIMENTS_BS1534 LABS = ["a", "b", "c", "d"] HERE = Path(__file__).absolute().resolve() HERE = Path(__file__).parent.absolute().resolve() def _get_seed(exp, lab): Loading @@ -17,7 +17,7 @@ def _get_seed(exp, lab): def _patch_value(line: str, value) -> str: line_split = line.split(':') line_split[-1] = f" {value}" line_split[-1] = f" {value}\n" return ':'.join(line_split) Loading @@ -29,12 +29,12 @@ def create_experiment_setup(experiment, lab): categories = [f"cat{i}" for i in range(1, 7)] if experiment in EXPERIMENTS_P800 else [""] seed = _get_seed(experiment, lab) base_path = default_cfg_path.parent.parent base_path = Path(HERE.name).joinpath(f"selection/{experiment}") for cat in categories: input_path = base_path.joinpath("proc_input").joinpath(cat) output_path = base_path.joinpath("proc_output").joinpath(cat) bg_noise_path = base_path.joinpath("background_noise").joinpath(f"background_noise_{cat}.wav") cfg_path = base_path.joinpath("config").joinpath(f"{experiment}{cat}.yml") cfg_path = default_cfg_path.parent.joinpath(f"{experiment}{cat}-lab_{lab}.yml") cat_cfg = [] for line in cfg_lines: Loading @@ -42,23 +42,29 @@ def create_experiment_setup(experiment, lab): cat_num = int(cat[-1]) patch_snr = experiment in ["P800-5", "P800-9"] and cat_num >= 3 if "name" in line: new_line = _patch_value(line, f"{experiment}{cat}-lab{lab}") elif "prerun_seed" in line: line_stripped = line.strip() if line_stripped.startswith("name:"): new_line = _patch_value(line, f"{experiment}{cat}-lab_{lab}") elif line_stripped.startswith("prerun_seed"): new_line = _patch_value(line, seed) elif "input_path" in line: elif line_stripped.startswith("input_path"): new_line = _patch_value(line, f'"{str(input_path)}"') elif "output_path" in line: elif line_stripped.startswith("output_path"): new_line = _patch_value(line, f'"{str(output_path)}"') elif "snr" in line and patch_snr: elif line_stripped.startswith("snr") and patch_snr: new_line = _patch_value(line, 15) elif "background_noise_path" in line: elif line_stripped.startswith("background_noise_path"): new_line = _patch_value(line, f'"{str(bg_noise_path)}"') cat_cfg.append(new_line) with open(cfg_path, "w") as f: f.write('\n'.join(cat_cfg)) f.writelines(cat_cfg) # ensure that necessary directories are there input_path.mkdir(parents=True, exist_ok=True) output_path.mkdir(parents=True, exist_ok=True) bg_noise_path.parent.mkdir(parents=True, exist_ok=True) if __name__ == "__main__": Loading Loading
experiments/create_experiment_config.py +18 −12 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ EXPERIMENTS_P800 = [f"P800-{i}" for i in range(1, 10)] EXPERIMENTS_BS1534 = [f"BS1534-{i}{x}" for i in range(1, 8) for x in ["a", "b"]] EXPERIMENTS = EXPERIMENTS_P800 + EXPERIMENTS_BS1534 LABS = ["a", "b", "c", "d"] HERE = Path(__file__).absolute().resolve() HERE = Path(__file__).parent.absolute().resolve() def _get_seed(exp, lab): Loading @@ -17,7 +17,7 @@ def _get_seed(exp, lab): def _patch_value(line: str, value) -> str: line_split = line.split(':') line_split[-1] = f" {value}" line_split[-1] = f" {value}\n" return ':'.join(line_split) Loading @@ -29,12 +29,12 @@ def create_experiment_setup(experiment, lab): categories = [f"cat{i}" for i in range(1, 7)] if experiment in EXPERIMENTS_P800 else [""] seed = _get_seed(experiment, lab) base_path = default_cfg_path.parent.parent base_path = Path(HERE.name).joinpath(f"selection/{experiment}") for cat in categories: input_path = base_path.joinpath("proc_input").joinpath(cat) output_path = base_path.joinpath("proc_output").joinpath(cat) bg_noise_path = base_path.joinpath("background_noise").joinpath(f"background_noise_{cat}.wav") cfg_path = base_path.joinpath("config").joinpath(f"{experiment}{cat}.yml") cfg_path = default_cfg_path.parent.joinpath(f"{experiment}{cat}-lab_{lab}.yml") cat_cfg = [] for line in cfg_lines: Loading @@ -42,23 +42,29 @@ def create_experiment_setup(experiment, lab): cat_num = int(cat[-1]) patch_snr = experiment in ["P800-5", "P800-9"] and cat_num >= 3 if "name" in line: new_line = _patch_value(line, f"{experiment}{cat}-lab{lab}") elif "prerun_seed" in line: line_stripped = line.strip() if line_stripped.startswith("name:"): new_line = _patch_value(line, f"{experiment}{cat}-lab_{lab}") elif line_stripped.startswith("prerun_seed"): new_line = _patch_value(line, seed) elif "input_path" in line: elif line_stripped.startswith("input_path"): new_line = _patch_value(line, f'"{str(input_path)}"') elif "output_path" in line: elif line_stripped.startswith("output_path"): new_line = _patch_value(line, f'"{str(output_path)}"') elif "snr" in line and patch_snr: elif line_stripped.startswith("snr") and patch_snr: new_line = _patch_value(line, 15) elif "background_noise_path" in line: elif line_stripped.startswith("background_noise_path"): new_line = _patch_value(line, f'"{str(bg_noise_path)}"') cat_cfg.append(new_line) with open(cfg_path, "w") as f: f.write('\n'.join(cat_cfg)) f.writelines(cat_cfg) # ensure that necessary directories are there input_path.mkdir(parents=True, exist_ok=True) output_path.mkdir(parents=True, exist_ok=True) bg_noise_path.parent.mkdir(parents=True, exist_ok=True) if __name__ == "__main__": Loading