Commit 47c27bf8 authored by Jan Kiene's avatar Jan Kiene
Browse files

cleanup and formatting

parent 48d82326
Loading
Loading
Loading
Loading
+29 −8
Original line number Diff line number Diff line
@@ -2,7 +2,9 @@

import argparse
from pathlib import Path
from ivas_processing_scripts import main as generate_test, config

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

HERE = Path(__file__).parent.absolute()
@@ -45,7 +47,9 @@ 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"experiments/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)
@@ -67,7 +71,9 @@ def create_experiment_setup(experiment, lab) -> list[Path]:
        suffix = cat + f"-lab_{lab}"
        input_path = base_path.joinpath("proc_input").joinpath(suffix)
        output_path = base_path.joinpath("proc_output").joinpath(suffix)
        bg_noise_path = base_path.joinpath("background_noise").joinpath(f"background_noise_{suffix}.wav")
        bg_noise_path = base_path.joinpath("background_noise").joinpath(
            f"background_noise_{suffix}.wav"
        )
        cfg_path = default_cfg_path.parent.joinpath(f"{experiment}{cat}-lab_{lab}.yml")
        cfgs.append(cfg_path)

@@ -77,7 +83,9 @@ def create_experiment_setup(experiment, lab) -> list[Path]:
        cfg.prerun_seed = seed
        cfg.input_path = str(input_path)
        cfg.output_path = str(output_path)
        if (bg_noise_pre_proc_2 := cfg.preprocessing_2.get("background_noise", None)) is not None:
        if (
            bg_noise_pre_proc_2 := cfg.preprocessing_2.get("background_noise", None)
        ) is not None:
            bg_noise_pre_proc_2["background_noise_path"] = str(bg_noise_path)

            # bg noise SNR only differs from default config for some experiments
@@ -105,7 +113,7 @@ def exp_lab_pair(arg):
    """
    Validation function for command line input
    """
    exp, lab = arg.split(',')
    exp, lab = arg.split(",")

    msg = "'{}' is not a valid {}. Possible values are: {}"
    if exp not in EXPERIMENTS_BS1534 + EXPERIMENTS_P800:
@@ -122,8 +130,21 @@ def exp_lab_pair(arg):

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")
    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, args.create_cfg_only)
+3 −1
Original line number Diff line number Diff line
@@ -135,7 +135,9 @@ class TestConfig:
        return cfg

    def to_file(self, outfile: Union[str, Path]):
        to_dump = self._dump_yaml({k:v for k, v in self.__dict__.items() if k in self._dump_keys})
        to_dump = self._dump_yaml(
            {k: v for k, v in self.__dict__.items() if k in self._dump_keys}
        )
        with open(outfile, "w") as f:
            yaml.dump(to_dump, f)

+5 −4
Original line number Diff line number Diff line
@@ -31,13 +31,12 @@
#

import shutil
import sys
from pathlib import Path

import pytest
import sys
from numpy.random import random, seed

from experiments import create_experiment_config, create_items_p800
from ivas_processing_scripts import main as generate_test
from ivas_processing_scripts.audiotools import audio
from ivas_processing_scripts.audiotools.audiofile import concat, write
@@ -51,7 +50,7 @@ from tests.constants import (

HERE = Path(__file__).parent.absolute()
sys.path.append(HERE.parent)
from generate_test import create_experiment_setup, Arguments
from generate_test import Arguments, create_experiment_setup


def setup_input_files_for_config(config):
@@ -99,7 +98,9 @@ def setup_input_files_for_config(config):
        write(bg_noise_path, noise)


@pytest.mark.parametrize("exp_lab_pair", zip(INPUT_EXPERIMENT_NAMES, LAB_IDS_FOR_EXPERIMENTS))
@pytest.mark.parametrize(
    "exp_lab_pair", zip(INPUT_EXPERIMENT_NAMES, LAB_IDS_FOR_EXPERIMENTS)
)
def test_generate_test_items(exp_lab_pair):
    exp_name, lab_id = exp_lab_pair
    cfgs = create_experiment_setup(exp_name, lab_id)