29 lines
933 B
Python
29 lines
933 B
Python
import nixio
|
|
|
|
|
|
def create_metadata_from_dict(d: dict, section: nixio.Section) -> None:
|
|
for key, value in d.items():
|
|
if isinstance(value, dict):
|
|
new_sec = section.create_section(key, f"{type(key)}")
|
|
create_metadata_from_dict(value, new_sec)
|
|
else:
|
|
try:
|
|
section.create_property(key, values_or_dtype=value)
|
|
except TypeError:
|
|
if isinstance(value, list):
|
|
value = [str(i) for i in value]
|
|
else:
|
|
value = str(value)
|
|
section.create_property(key, values_or_dtype=value)
|
|
|
|
|
|
def create_dict_from_section(section: nixio.Section) -> dict:
|
|
d = {}
|
|
for key, value in section.items():
|
|
if isinstance(value, nixio.Section):
|
|
subdict = create_dict_from_section(value)
|
|
d[key] = subdict
|
|
else:
|
|
d[key] = value.values
|
|
return d
|