General AFNI NIML I/O support

Created on Feb 16, 2012

@author: Nikolaas. N. Oosterhof (

This function reads a NIML file and returns a dict that contains all NIML information in a tree-like structure (dicts for which some values are dicts themselves). Branches are stored in a ‘nodes’ field.

For specific types of data, consider afni_niml_dset or afni_niml_annot files which provide easier access to the data.


TODO: some nice refactoring of the code. Currently it’s a bit of
a mess.


find_attribute_node(niml_dict, key, value[, ...]) Finds a NIML node that matches a particular key and value
getnewidcode() Provides a new (random) id code for a NIML dataset
rawniml2string(p[, form]) Converts a raw NIML element to string representation
read(fn[, itemifsingletonlist, postfunction]) Reads a NIML dataset
safe_write(fnout, s[, mode]) Helper to write to a file and check result file size to match
setnewidcode(s) Sets a new (random) id code in a NIML dataset
string2rawniml(s[, i]) Parses a NIML string to a raw NIML tree-like structure
support_lists(f) Decorater to allow a function to support list input (and output)
write(fnout, niml[, form, prefunction])


BytesIO Create a buffered I/O implementation using an in-memory bytes buffer, ready for reading and writing.