def write_metadata(path, meta='.meta.yaml', **params):
"""Writes metadata for a dataset.
Args:
path (str): path to **dataset** (not meta file) whose metadata
is to be written. If the meta file already exists, it will be
overwritten.
meta (str): suffix identifying the dataset's meta file
**params: all other keyword arguments are treated as dataset attributes,
and added to the meta file
"""
if 'n_channels' in params:
del params['n_channels']
if 'n_samples' in params:
del params['n_samples']
if os.path.isdir(path):
metafile = os.path.join(path, meta[1:])
else:
metafile = path + meta
for k, v in params.items():
if isinstance(v, (np.ndarray, np.generic)):
params[k] = v.tolist()
with codecs.open(metafile, 'w', encoding='utf-8') as yaml_file:
yaml_file.write(yaml.safe_dump(params, default_flow_style=False))
评论列表
文章目录