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

Merge branch 'main' into fix_concatenation_order_in_experiments

parents 3564eb74 dabab8c0
Loading
Loading
Loading
Loading
Loading

generate_test.py

100644 → 100755
+3 −10
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ IN_FMT_FOR_MASA_EXPS = {
}


def generate_tests(exp_lab_pairs, run_parallel=True, create_cfg_only=False):
def generate_tests(exp_lab_pairs, create_cfg_only=False):
    """
    Create configs and run them for all given experiment/lab pairs
    """
@@ -64,15 +64,13 @@ def generate_tests(exp_lab_pairs, run_parallel=True, create_cfg_only=False):
        return

    args = [Arguments(str(cfg)) for cfg in cfgs]
    apply_func_parallel(generate_test, zip(args), type="mp" if run_parallel else None)
    apply_func_parallel(generate_test, zip(args), None)


class Arguments:
    def __init__(self, config):
        self.config = config
        self.debug = False
        # used to overwrite the multiprocessing key in the configs to rather parallelize on category level
        self.multiprocessing = False


def create_experiment_setup(experiment, lab) -> list[Path]:
@@ -178,15 +176,10 @@ if __name__ == "__main__":
        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)
    generate_tests(args.exp_lab_pairs, args.create_cfg_only)
+40 −19
Original line number Diff line number Diff line
@@ -31,7 +31,10 @@
#

import logging
from itertools import repeat
import sys
from itertools import product
from multiprocessing import Pool
from time import sleep

from ivas_processing_scripts.audiotools.metadata import check_ISM_metadata
from ivas_processing_scripts.constants import (
@@ -47,7 +50,11 @@ from ivas_processing_scripts.processing.processing import (
    process_item,
    reorder_items_list,
)
from ivas_processing_scripts.utils import DirManager, apply_func_parallel
from ivas_processing_scripts.utils import (
    DirManager,
    apply_func_parallel,
    progressbar_update,
)


def logging_init(args, cfg):
@@ -117,7 +124,7 @@ def main(args):
                metadata_str = []
                for o in range(len(metadata[i])):
                    metadata_str.append(str(metadata[i][o]))
                logger.info(
                logger.debug(
                    f"  ISM metadata files item {cfg.items_list[i]}: {', '.join(metadata_str)}"
                )

@@ -147,27 +154,41 @@ def main(args):
            # preprocess 2
            preprocess_2(cfg, logger)

        # run conditions
        for condition, out_dir, tmp_dir in zip(
            cfg.proc_chains, cfg.out_dirs, cfg.tmp_dirs
        # assemble a list of all item and condition combinations
        item_args = list()
        for (chain, tmp_dir, out_dir), (item, metadata) in product(
            zip(cfg.proc_chains, cfg.tmp_dirs, cfg.out_dirs),
            zip(cfg.items_list, cfg.metadata_path),
        ):
            chain = condition["processes"]
            item_args.append(
                (item, tmp_dir, out_dir, chain["processes"], logger, metadata)
            )

            logger.info(f"  Generating condition: {condition['name']}")
        if cfg.multiprocessing:
            # set up values for progress display and chunksize
            count = len(item_args)
            width = 80

            apply_func_parallel(
            # submit tasks to the pool
            p = Pool()
            results = p.starmap_async(
                process_item,
                zip(
                    cfg.items_list,
                    repeat(tmp_dir),
                    repeat(out_dir),
                    repeat(chain),
                    repeat(logger),
                    cfg.metadata_path,
                ),
                None,
                "mp" if cfg.multiprocessing else None,
                item_args,
            )

            # poll progress
            progressbar_update(0, count, width)
            while not results.ready():
                progressbar_update(count - int(results._number_left), count, width)
                sleep(0.1)
            progressbar_update(count, count, width)
            print("\n", flush=True, file=sys.stdout)

            p.close()
            p.join()

        else:
            apply_func_parallel(process_item, item_args, None, None, True)

    # copy configuration to output directory
    cfg.to_file(cfg.output_path.joinpath(f"{cfg.name}.yml"))
+2 −2
Original line number Diff line number Diff line
@@ -542,7 +542,7 @@ def binaural_fftconv_framewise(
            repeat(indices_HRIR),
        ),
        None,
        "mp",
        None,
        False,
    )

@@ -607,7 +607,7 @@ def render_ear(
            repeat(N_HRIR_taps),
        ),
        None,
        "mt",
        None,
        False,
    )

+1 −1
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ def render_oba_to_binaural(
                repeat(SourcePosition),
            ),
            None,
            "mt",
            None,
            False,
        )

+3 −0
Original line number Diff line number Diff line
@@ -89,6 +89,9 @@ def reverb(
            tmp_input.audio = resample_itu(tmp_input, IR.fs)
            tmp_input.fs = IR.fs

        # add trailing zeros
        tmp_input.audio = np.concatenate([tmp_input.audio, np.zeros((IR.audio.shape[0]-1, 1))])

        # write input audio signal to temporary file in .pcm format
        tmp_input_file = tmp_dir.joinpath("tmp_reverbIn.pcm")
        write(tmp_input_file, tmp_input.audio, tmp_input.fs)
Loading