Loading experiments/__init__.py 0 → 100644 +0 −0 Empty file added. experiments/create_experiment_config.py 0 → 100644 +71 −0 Original line number Diff line number Diff line #! /usr/bin/env python3 import argparse from pathlib import Path import re 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() def _get_seed(exp, lab): return 101 + EXPERIMENTS.index(exp) * 4 + LABS.index(lab) def _patch_value(line: str, value) -> str: line_split = line.split(':') line_split[-1] = f" {value}" return ':'.join(line_split) def create_experiment_setup(experiment, lab): default_cfg_path = HERE.joinpath(f"selection/{experiment}/config/{experiment}.yml") with open(default_cfg_path) as f: cfg_lines = f.readlines() 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 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") cat_cfg = [] for line in cfg_lines: new_line = line 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: new_line = _patch_value(line, seed) elif "input_path" in line: new_line = _patch_value(line, f'"{str(input_path)}"') elif "output_path" in line: new_line = _patch_value(line, f'"{str(output_path)}"') elif "snr" in line and patch_snr: new_line = _patch_value(line, 15) elif "background_noise_path" in line: 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)) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("experiment", type=str, choices=EXPERIMENTS_BS1534+EXPERIMENTS_P800) parser.add_argument("lab", type=str, choices=LABS) args = parser.parse_args() create_experiment_setup(args.experiment, args.lab) No newline at end of file Loading
experiments/create_experiment_config.py 0 → 100644 +71 −0 Original line number Diff line number Diff line #! /usr/bin/env python3 import argparse from pathlib import Path import re 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() def _get_seed(exp, lab): return 101 + EXPERIMENTS.index(exp) * 4 + LABS.index(lab) def _patch_value(line: str, value) -> str: line_split = line.split(':') line_split[-1] = f" {value}" return ':'.join(line_split) def create_experiment_setup(experiment, lab): default_cfg_path = HERE.joinpath(f"selection/{experiment}/config/{experiment}.yml") with open(default_cfg_path) as f: cfg_lines = f.readlines() 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 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") cat_cfg = [] for line in cfg_lines: new_line = line 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: new_line = _patch_value(line, seed) elif "input_path" in line: new_line = _patch_value(line, f'"{str(input_path)}"') elif "output_path" in line: new_line = _patch_value(line, f'"{str(output_path)}"') elif "snr" in line and patch_snr: new_line = _patch_value(line, 15) elif "background_noise_path" in line: 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)) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("experiment", type=str, choices=EXPERIMENTS_BS1534+EXPERIMENTS_P800) parser.add_argument("lab", type=str, choices=LABS) args = parser.parse_args() create_experiment_setup(args.experiment, args.lab) No newline at end of file