Utils

Utility functions and classes.

General functions

dcase_util.utils. *

get_audio_info(filename[, logger])

Get information about audio file without opening it.

get_media_duration(filename[, logger])

Get media file duration using ffprobe.

merge_media_files(source_a_filename, ...[, ...])

Merge media files using ffmpeg.

get_class_inheritors(klass)

Get all classes inherited from given class

get_byte_string(num_bytes[, show_bytes])

Output number of bytes according to locale and with IEC binary prefixes

check_pkg_resources(package_requirement[, ...])

is_int(value)

Check if given value is integer

is_float(value)

Check if given value is float

is_jupyter()

Check if code is run in Jupyter (Jupyter notebook, Jupyter console, or ipython qtconsole).

SuppressStdoutAndStderr

dcase_util.utils.SuppressStdoutAndStderr

SuppressStdoutAndStderr()

Context manager to suppress STDOUT and STDERR

VectorRecipeParser

dcase_util.utils.VectorRecipeParser

VectorRecipeParser([delimiters, default_stream])

Files

dcase_util.utils. *

argument_file_exists(filename)

Argument file checker

filelist_exists(filelist)

Check that all file in the list exists

posix_path(path)

Converts path to POSIX format

Path

dcase_util.utils.Path

Path([path])

Utility class for paths

Path.posix([path])

Converts path to POSIX format

Path.posix_to_nt([path])

Converts posix formatted path to nt

Path.file_list([path, recursive, ...])

Get file list

Path.exists([path])

Checks that path exists

Path.file_count([path])

File count under given path including sub directories.

Path.size_bytes([path])

Total byte count of all files under given path.

Path.size_string([path, show_bytes])

Total data size of all files under given path returned in human readable form.

Path.makedirs([path])

Create given path.

Path.create([paths])

Create given paths.

ApplicationPaths

dcase_util.utils.ApplicationPaths

ApplicationPaths([parameter_container])

Utility class for application paths, paths are automatically generated based on parameters through parameter hash.

ApplicationPaths.generate(path_base, structure)

Generate application paths and include parameter hashes to the paths

ApplicationPaths.directory_name(prefix, ...)

Generate directory name.

ApplicationPaths.save_parameters_to_path(...)

Save parameters to each application sub-directory.

ApplicationPaths.construct_path(path_parts)

Generate all combinations of based on path parts

FileFormat

dcase_util.utils.FileFormat

FileFormat()

FileFormat.detect(filename[, ...])

Detect file format.

FileFormat.detect_based_on_filename(filename)

Detect file format based on filename.

FileFormat.detect_based_on_content(filename)

Detect file format based on content by using python-magic.

FileFormat.validate_label(label)

Validate file format label against labels known by this class

Hash

get_parameter_hash(params)

Get unique hash string (md5) for given parameter dict

get_file_hash(filename)

Get unique hash string (md5) for given file

Logging

setup_logging

Decorator class to allow only one execution

DisableLogger

dcase_util.utils.DisableLogger

DisableLogger()

Math

dcase_util.utils.SimpleMathStringEvaluator

SimpleMathStringEvaluator

SimpleMathStringEvaluator()

Simple math string evaluator

SimpleMathStringEvaluator.eval(string)

Evaluate math in the string

Timer

dcase_util.utils.Timer

Timer()

Timer class

Timer.start()

Start timer

Timer.stop()

Stop timer

Timer.elapsed()

Return elapsed time in seconds since timer was started

Timer.get_string([elapsed])

Get elapsed time in a string format

Validators

FieldValidator

dcase_util.utils.FieldValidator

FieldValidator()

FieldValidator.process(field)

Test field

FieldValidator.is_empty(field)

Test for empty field

FieldValidator.is_number(field)

Test for number field

FieldValidator.is_audiofile(field)

Test for audio file field

FieldValidator.is_list(field)

Test for list field, valid delimiters [ : ; #]

FieldValidator.is_alpha(field[, length])

Test for alpha field with length 1

Examples

dcase_util.utils.Example

Some example data for easy testing and tutoring.

Example()

Example files for tutorials

Example.audio_filename()

Example.acoustic_scene_audio_filename()

Example.audio_filename_mp3()

Example.acoustic_scene_audio_filename_mp3()

Example.audio_container()

Example.event_metadata_container([filename])

Example.scene_metadata_container([filename])

Example.tag_metadata_container([filename])

Example.feature_container([filename])

Example.feature_repository([filename])