Commit eddac253 authored by Jan Kiene's avatar Jan Kiene
Browse files

add argument for only creating the config files + small fixes

parent 02406cb2
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -2,34 +2,34 @@

import argparse
from pathlib import Path

HERE = Path(__file__).parent.absolute()

from ivas_processing_scripts import main as generate_test, config
from ivas_processing_scripts.utils import apply_func_parallel

HERE = Path(__file__).parent.absolute()
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"]]
LAB_IDS = ["a", "b", "c", "d"]

# TODO: this is a placeholder for later, currently everything is FOA
IN_FMT_FOR_MASA_EXPS = {
    "P800-8": dict(zip([f"cat{i}" for i in range(1, 7)], ["FOA"] * 6)),
    "P800-9": dict(zip([f"cat{i}" for i in range(1, 7)], ["FOA"] * 6)),
    "BS1534-7a": dict(zip([f"cat{i}" for i in range(1, 3)], ["FOA"] * 2)),
    "BS1534-7b": dict(zip([f"cat{i}" for i in range(1, 3)], ["FOA"] * 2)),
    "BS1534-7a": {"cat1": "FOA", "cat2": "HOA2"},
    "BS1534-7b": {"cat1": "FOA", "cat2": "HOA2"},
}


def generate_tests(exp_lab_pairs, run_parallel=True):
def generate_tests(exp_lab_pairs, run_parallel=True, create_cfg_only=False):
    """
    Create configs and run them for all given experiment/lab pairs
    """
    # get config paths for all given experiment/lab combis and flatten into single list
    # get config paths for all given experiment/lab combis
    cfgs = [create_experiment_setup(exp, lab) for exp, lab in exp_lab_pairs]
    cfgs = [c for cl in cfgs for c in cl]

    args = [Arguments(str, cfg) for cfg in cfgs]
    if create_cfg_only:
        return

    # flatten into single list
    cfgs = [c for cl in cfgs for c in cl]
    args = [Arguments(str(cfg)) for cfg in cfgs]
    apply_func_parallel(generate_test, zip(args), type="mp" if run_parallel else None)


@@ -45,7 +45,7 @@ def create_experiment_setup(experiment, lab) -> list[Path]:
    """
    Create the config files for all categories for the given experiment and lab id.
    """
    default_cfg_path = HERE.joinpath(f"selection/{experiment}/config/{experiment}.yml")
    default_cfg_path = HERE.joinpath(f"experiments/selection/{experiment}/config/{experiment}.yml")

    num_categories = 1
    # for P800 we nee 6 categories (for each background/scene)
@@ -58,9 +58,9 @@ def create_experiment_setup(experiment, lab) -> list[Path]:

    # calculate the seed value according to processing plan
    experiments = EXPERIMENTS_P800 + EXPERIMENTS_BS1534
    seed = 101 + experiments.index(exp) * 4 + LAB_IDS.index(lab)
    seed = 101 + experiments.index(experiment) * 4 + LAB_IDS.index(lab)

    base_path = Path(HERE.name).joinpath(f"selection/{experiment}")
    base_path = Path(HERE.name).joinpath(f"experiments/selection/{experiment}")

    cfgs = list()
    for cat in categories:
@@ -124,5 +124,6 @@ if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("exp_lab_pairs", type=exp_lab_pair, nargs="+", help="The combinations of experiment/lab-id that you want to generate, separated by whitespace. Experiment and lab id need to be separated by a comma.")
    parser.add_argument("--no_parallel", action="store_true", help="If given, configs will not be run in parallel")
    parser.add_argument("--create_cfg_only", action="store_true", help="If given, only create the configs and folder structure without processing items")
    args = parser.parse_args()
    generate_tests(args.exp_lab_pairs, not args.no_parallel)
    generate_tests(args.exp_lab_pairs, not args.no_parallel, args.create_cfg_only)