Parsing¶
Parsing module within the ketos library
This module provides utilities to parse various string structures.
-
ketos.data_handling.parsing.
load_audio_representation
(path, name=None)[source]¶ Load audio representation settings from JSON file.
- Args:
- path: str
Path to json file
- name: str
Heading of the relevant section of the json file
- Returns:
- d: dict
Dictionary with the settings
- Example:
>>> import json >>> from ketos.data_handling.parsing import load_audio_representation >>> # create json file with spectrogram settings >>> json_str = '{"spectrogram": {"type": "MagSpectrogram", "rate": "20 kHz", "window": "0.1 s", "step": "0.025 s", "window_func": "hamming", "freq_min": "30Hz", "freq_max": "3000Hz"}}' >>> path = 'ketos/tests/assets/tmp/config.py' >>> file = open(path, 'w') >>> _ = file.write(json_str) >>> file.close() >>> # load settings back from json file >>> settings = load_audio_representation(path=path, name='spectrogram') >>> print(settings) {'type': 'MagSpectrogram', 'rate': 20000.0, 'window': 0.1, 'step': 0.025, 'freq_min': 30, 'freq_max': 3000, 'window_func': 'hamming'} >>> # clean up >>> os.remove(path)
-
ketos.data_handling.parsing.
parse_audio_representation
(s)[source]¶ Parse audio representation settings for generating waveforms or spectrograms.
- Args:
- s: str
Json-format string with the settings
- Returns:
- d: dict
Dictionary with the settings
-
ketos.data_handling.parsing.
parse_value
(x, name, unit=None, typ='float')[source]¶ Parse data fields in dictionary.
- Args:
- x: dict
Dictionary containing the data
- name: str
Name of field to be parsed
- unit: str
Physical unit to be used for the parsed quantity, e.g., Hz
- typ: str
Variable type
- Returns:
- v: same type as typ
Parsed data