def synthesize(self):
    if os.path.exists(os.path.join(self.local_path, 'TUT_Rare_sound_events_mixture_synthesizer', '__init__.py')):
        open(os.path.join(self.local_path, 'TUT_Rare_sound_events_mixture_synthesizer', '__init__.py'), 'a').close()
    sys.path.append(os.path.join(self.local_path, 'TUT_Rare_sound_events_mixture_synthesizer'))
    from core import generate_mixture_recipes
    from core import do_mixing
    scene_label = 'synthetic'
    subset_map = {'train': 'devtrain', 'test': 'devtest'}
    data_path = os.path.join(os.path.abspath(self.local_path), 'data')
    set_progress = tqdm(['train', 'test'], desc='{0: <25s}'.format('Set'), file=sys.stdout, leave=False, disable=self.disable_progress_bar, ascii=self.use_ascii_progress_bar)
    for subset_label in set_progress:
        if self.log_system_progress:
            self.logger.info('  {title:<15s} [{subset_label:<30s}]'.format(title='Set ', subset_label=subset_label))
        subset_name_on_disk = subset_map[subset_label]
        mixing_params = {'event_presence_prob': self.synth_parameters[subset_label]['event_presence_prob'], 'mixtures_per_class': self.synth_parameters[subset_label]['mixtures_per_class'], 'ebrs': self.synth_parameters[subset_label]['ebr_list'], 'seed': self.synth_parameters[subset_label]['seed']}
        param_hash = self.synth_parameters[subset_label]['param_hash']
        mixture_parameters = os.path.join(self.local_path, 'data', 'mixture_data', subset_name_on_disk, param_hash, 'parameters.yaml')
        if (not os.path.isfile(mixture_parameters)):
            Path().makedirs(path=os.path.join(self.local_path, 'data', 'mixture_data', subset_name_on_disk, param_hash))
            ParameterContainer(mixing_params).save(filename=mixture_parameters)
        recipes_exists = True
        for event_label in self.event_labels():
            recipe_filename = (((('mixture_recipes_' + subset_name_on_disk) + '_') + event_label) + '.yaml')
            if (not os.path.isfile(os.path.join(self.local_path, 'data', 'mixture_data', subset_name_on_disk, param_hash, 'meta', recipe_filename))):
                recipes_exists = False
        if (not recipes_exists):
            generate_mixture_recipes(data_path=data_path, current_subsets=numpy.array([subset_name_on_disk]), mixing_params=mixing_params)
        mixture_audio_exists = True
        audio_files = Path().file_list(path=os.path.join(self.local_path, 'data', 'mixture_data', subset_name_on_disk, param_hash, 'audio'))
        for event_label in self.event_labels():
            event_audio = []
            for f in audio_files:
                if (event_label in f):
                    event_audio.append(f)
            if (len(event_audio) != self.synth_parameters[subset_label]['mixtures_per_class']):
                mixture_audio_exists = False
        if (not mixture_audio_exists):
            do_mixing(data_path=data_path, current_subsets=numpy.array([subset_name_on_disk]), magic_anticlipping_factor=0.2, param_hash=param_hash, dcase_compatibility_mode=True)
    if (not self.meta_container.exists()):
        meta_data = MetaDataContainer()
        for class_label in self.event_labels():
            for (subset_label, subset_name_on_disk) in iteritems(subset_map):
                subset_name_on_disk = subset_map[subset_label]
                param_hash = self.synth_parameters[subset_label]['param_hash']
                mixture_path = os.path.join('data', 'mixture_data', subset_name_on_disk, param_hash, 'audio')
                mixture_meta_path = os.path.join(self.local_path, 'data', 'mixture_data', subset_name_on_disk, param_hash, 'meta')
                event_list_filename = os.path.join(mixture_meta_path, (((('event_list_' + subset_name_on_disk) + '_') + class_label) + '.csv'))
                if os.path.isfile(event_list_filename):
                    current_meta = MetaDataContainer(filename=event_list_filename).load(fields=['filename', 'onset', 'offset', 'event_label'])
                    for item in current_meta:
                        item.filename = os.path.join(mixture_path, item.filename)
                        item.scene_label = scene_label
                    meta_data += current_meta
        meta_data.save(filename=self.meta_file)
        self.load()
    train_filename = self.evaluation_setup_filename(setup_part='train', fold=1, file_extension='txt')
    test_filename = self.evaluation_setup_filename(setup_part='test', fold=1, file_extension='txt')
    evaluate_filename = self.evaluation_setup_filename(setup_part='evaluate', fold=1, file_extension='txt')
    evaluation_setup_exists = True
    if ((not os.path.isfile(train_filename)) or (not os.path.isfile(test_filename)) or (not os.path.isfile(evaluate_filename))):
        evaluation_setup_exists = False
    if (not evaluation_setup_exists):
        param_hash_train = self.synth_parameters['train']['param_hash']
        mixture_meta_path_train = os.path.join(self.local_path, 'data', 'mixture_data', subset_map['train'], param_hash_train, 'meta')
        mixture_path_train = os.path.join('data', 'mixture_data', subset_map['train'], param_hash_train, 'audio')
        param_hash_test = self.synth_parameters['test']['param_hash']
        mixture_meta_path_test = os.path.join(self.local_path, 'data', 'mixture_data', subset_map['test'], param_hash_test, 'meta')
        mixture_path_test = os.path.join('data', 'mixture_data', subset_map['test'], param_hash_test, 'audio')
        train_meta = MetaDataContainer()
        for class_label in self.event_labels():
            event_list_filename = os.path.join(mixture_meta_path_train, (((('event_list_' + subset_map['train']) + '_') + class_label) + '.csv'))
            current_meta = MetaDataContainer(filename=event_list_filename).load(fields=['filename', 'onset', 'offset', 'event_label'])
            for item in current_meta:
                item.filename = os.path.join(mixture_path_train, item.filename)
                item.scene_label = scene_label
            train_meta += current_meta
        train_meta.save(filename=train_filename)
        test_meta = MetaDataContainer()
        for class_label in self.event_labels():
            event_list_filename = os.path.join(mixture_meta_path_test, (((('event_list_' + subset_map['test']) + '_') + class_label) + '.csv'))
            current_meta = MetaDataContainer(filename=event_list_filename).load(fields=['filename', 'onset', 'offset', 'event_label'])
            current_meta_ = MetaDataContainer()
            for item in current_meta:
                item.filename = os.path.join(mixture_path_test, item.filename)
                current_meta_.append(MetaDataItem({'filename': item.filename, 'scene_label': scene_label}))
            test_meta += current_meta_
        test_meta.save(filename=test_filename)
        eval_meta = MetaDataContainer()
        for class_label in self.event_labels():
            event_list_filename = os.path.join(mixture_meta_path_test, (((('event_list_' + subset_map['test']) + '_') + class_label) + '.csv'))
            current_meta = MetaDataContainer(filename=event_list_filename).load(fields=['filename', 'onset', 'offset', 'event_label'])
            for item in current_meta:
                item.filename = os.path.join(mixture_path_test, item.filename)
                item.scene_label = scene_label
            eval_meta += current_meta
        eval_meta.save(filename=evaluate_filename)
        self.load()
def synthesize(self):
    if os.path.exists(os.path.join(self.local_path, 'TUT_Rare_sound_events_mixture_synthesizer', '__init__.py')):
        open(os.path.join(self.local_path, 'TUT_Rare_sound_events_mixture_synthesizer', '__init__.py'), 'a').close()
    sys.path.append(os.path.join(self.local_path, 'TUT_Rare_sound_events_mixture_synthesizer'))
    from core import generate_mixture_recipes
    from core import do_mixing
    scene_label = 'synthetic'
    subset_map = {'train': 'devtrain', 'test': 'devtest'}
    data_path = os.path.join(os.path.abspath(self.local_path), 'data')
    set_progress = tqdm(['train', 'test'], desc='{0: <25s}'.format('Set'), file=sys.stdout, leave=False, disable=self.disable_progress_bar, ascii=self.use_ascii_progress_bar)
    for subset_label in set_progress:
        if self.log_system_progress:
            self.logger.info('  {title:<15s} [{subset_label:<30s}]'.format(title='Set ', subset_label=subset_label))
        subset_name_on_disk = subset_map[subset_label]
        mixing_params = {'event_presence_prob': self.synth_parameters[subset_label]['event_presence_prob'], 'mixtures_per_class': self.synth_parameters[subset_label]['mixtures_per_class'], 'ebrs': self.synth_parameters[subset_label]['ebr_list'], 'seed': self.synth_parameters[subset_label]['seed']}
        param_hash = self.synth_parameters[subset_label]['param_hash']
        mixture_parameters = os.path.join(self.local_path, 'data', 'mixture_data', subset_name_on_disk, param_hash, 'parameters.yaml')
        if (not os.path.isfile(mixture_parameters)):
            Path().makedirs(path=os.path.join(self.local_path, 'data', 'mixture_data', subset_name_on_disk, param_hash))
            ParameterContainer(mixing_params).save(filename=mixture_parameters)
        recipes_exists = True
        for event_label in self.event_labels():
            recipe_filename = (((('mixture_recipes_' + subset_name_on_disk) + '_') + event_label) + '.yaml')
            if (not os.path.isfile(os.path.join(self.local_path, 'data', 'mixture_data', subset_name_on_disk, param_hash, 'meta', recipe_filename))):
                recipes_exists = False
        if (not recipes_exists):
            generate_mixture_recipes(data_path=data_path, current_subsets=numpy.array([subset_name_on_disk]), mixing_params=mixing_params)
        mixture_audio_exists = True
        audio_files = Path().file_list(path=os.path.join(self.local_path, 'data', 'mixture_data', subset_name_on_disk, param_hash, 'audio'))
        for event_label in self.event_labels():
            event_audio = []
            for f in audio_files:
                if (event_label in f):
                    event_audio.append(f)
            if (len(event_audio) != self.synth_parameters[subset_label]['mixtures_per_class']):
                mixture_audio_exists = False
        if (not mixture_audio_exists):
            do_mixing(data_path=data_path, current_subsets=numpy.array([subset_name_on_disk]), magic_anticlipping_factor=0.2, param_hash=param_hash, dcase_compatibility_mode=True)
    if (not self.meta_container.exists()):
        meta_data = MetaDataContainer()
        for class_label in self.event_labels():
            for (subset_label, subset_name_on_disk) in iteritems(subset_map):
                subset_name_on_disk = subset_map[subset_label]
                param_hash = self.synth_parameters[subset_label]['param_hash']
                mixture_path = os.path.join('data', 'mixture_data', subset_name_on_disk, param_hash, 'audio')
                mixture_meta_path = os.path.join(self.local_path, 'data', 'mixture_data', subset_name_on_disk, param_hash, 'meta')
                event_list_filename = os.path.join(mixture_meta_path, (((('event_list_' + subset_name_on_disk) + '_') + class_label) + '.csv'))
                if os.path.isfile(event_list_filename):
                    current_meta = MetaDataContainer(filename=event_list_filename).load(fields=['filename', 'onset', 'offset', 'event_label'])
                    for item in current_meta:
                        item.filename = os.path.join(mixture_path, item.filename)
                        item.scene_label = scene_label
                    meta_data += current_meta
        meta_data.save(filename=self.meta_file)
        self.load()
    train_filename = self.evaluation_setup_filename(setup_part='train', fold=1, file_extension='txt')
    test_filename = self.evaluation_setup_filename(setup_part='test', fold=1, file_extension='txt')
    evaluate_filename = self.evaluation_setup_filename(setup_part='evaluate', fold=1, file_extension='txt')
    evaluation_setup_exists = True
    if ((not os.path.isfile(train_filename)) or (not os.path.isfile(test_filename)) or (not os.path.isfile(evaluate_filename))):
        evaluation_setup_exists = False
    if (not evaluation_setup_exists):
        param_hash_train = self.synth_parameters['train']['param_hash']
        mixture_meta_path_train = os.path.join(self.local_path, 'data', 'mixture_data', subset_map['train'], param_hash_train, 'meta')
        mixture_path_train = os.path.join('data', 'mixture_data', subset_map['train'], param_hash_train, 'audio')
        param_hash_test = self.synth_parameters['test']['param_hash']
        mixture_meta_path_test = os.path.join(self.local_path, 'data', 'mixture_data', subset_map['test'], param_hash_test, 'meta')
        mixture_path_test = os.path.join('data', 'mixture_data', subset_map['test'], param_hash_test, 'audio')
        train_meta = MetaDataContainer()
        for class_label in self.event_labels():
            event_list_filename = os.path.join(mixture_meta_path_train, (((('event_list_' + subset_map['train']) + '_') + class_label) + '.csv'))
            current_meta = MetaDataContainer(filename=event_list_filename).load(fields=['filename', 'onset', 'offset', 'event_label'])
            for item in current_meta:
                item.filename = os.path.join(mixture_path_train, item.filename)
                item.scene_label = scene_label
            train_meta += current_meta
        train_meta.save(filename=train_filename)
        test_meta = MetaDataContainer()
        for class_label in self.event_labels():
            event_list_filename = os.path.join(mixture_meta_path_test, (((('event_list_' + subset_map['test']) + '_') + class_label) + '.csv'))
            current_meta = MetaDataContainer(filename=event_list_filename).load(fields=['filename', 'onset', 'offset', 'event_label'])
            current_meta_ = MetaDataContainer()
            for item in current_meta:
                item.filename = os.path.join(mixture_path_test, item.filename)
                current_meta_.append(MetaDataItem({'filename': item.filename, 'scene_label': scene_label}))
            test_meta += current_meta_
        test_meta.save(filename=test_filename)
        eval_meta = MetaDataContainer()
        for class_label in self.event_labels():
            event_list_filename = os.path.join(mixture_meta_path_test, (((('event_list_' + subset_map['test']) + '_') + class_label) + '.csv'))
            current_meta = MetaDataContainer(filename=event_list_filename).load(fields=['filename', 'onset', 'offset', 'event_label'])
            for item in current_meta:
                item.filename = os.path.join(mixture_path_test, item.filename)
                item.scene_label = scene_label
            eval_meta += current_meta
        eval_meta.save(filename=evaluate_filename)
        self.load()