flatten_metadata#
- petpal.utils.image_io.flatten_metadata(metadata: dict) dict#
Given a metadata dictionary, return an identical dictionary with any list-like or dict-like data replaced with individual values. Useful when converting several JSON files into a TSV file.
- Parameters:
metadata (dict) – The metadata file that may contain lists of data.
- Returns:
metadata_for_tsv (dict) –
- The same metadata with list-like data replaced with individual
values.
Note
List-like data is replaced by renaming the key it appears in with ordinal values. E.g. if metadata contains a key named
FitParswith value [4,6] then the function would create two new keys, FitPars_1 and Fit_Pars2 with values 4 and 6 respectively. Likewise, nested dictionaries are replaced by combining the two keys identifying the data with underscores. Function is not robust for doubly nested lists and dictionaries.