|
@@ -1,22 +1,52 @@
|
|
|
import os
|
|
|
import sys
|
|
|
+import numpy as np
|
|
|
import nixio as nix
|
|
|
import mne
|
|
|
|
|
|
|
|
|
+typemap = {
|
|
|
+ "str": str,
|
|
|
+ "int": int,
|
|
|
+ "float": float,
|
|
|
+ "bool": bool,
|
|
|
+ "tuple": tuple,
|
|
|
+ "list": list,
|
|
|
+ "numpy.float64": np.float64,
|
|
|
+ "numpy.ndarray": np.array,
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+def convert_prop_type(prop):
|
|
|
+ pt = prop.type[8:-2]
|
|
|
+ pv = prop.values
|
|
|
+ if len(pv) == 1:
|
|
|
+ pv = pv[0]
|
|
|
+
|
|
|
+ return typemap[pt](pv)
|
|
|
+
|
|
|
+
|
|
|
def md_to_dict(section):
|
|
|
sdict = dict()
|
|
|
for prop in section.props:
|
|
|
- values = list(prop.values)
|
|
|
- if len(values) == 1:
|
|
|
- values = values[0]
|
|
|
- sdict[prop.name] = values
|
|
|
+ sdict[prop.name] = convert_prop_type(prop)
|
|
|
+
|
|
|
+ if section.type[8:-2] == "mne.transforms.Transform":
|
|
|
+ to = sdict["to"]
|
|
|
+ fro = sdict["from"]
|
|
|
+ trans = sdict["trans"]
|
|
|
+ trans = section.referring_data_arrays()[0][:]
|
|
|
+ return mne.Transform(to, fro, trans)
|
|
|
|
|
|
for sec in section.sections:
|
|
|
if sec.name == "chs":
|
|
|
- print(str(sec) + "\n\n")
|
|
|
- print("\n".join(str(s) for s in sec.sections))
|
|
|
- sdict[sec.name] = md_to_dict(sec)
|
|
|
+ # make a list of dictionaries for the channels
|
|
|
+ chlist = list()
|
|
|
+ for chsec in sec.sections:
|
|
|
+ chlist.append(md_to_dict(chsec))
|
|
|
+ sdict[sec.name] = chlist
|
|
|
+ else:
|
|
|
+ sdict[sec.name] = md_to_dict(sec)
|
|
|
|
|
|
return sdict
|
|
|
|
|
@@ -40,7 +70,8 @@ def main():
|
|
|
info = mne.create_info(nchan, sfreq)
|
|
|
print(info)
|
|
|
|
|
|
- info.update(md_to_dict(infosec))
|
|
|
+ nixinfodict = md_to_dict(infosec)
|
|
|
+ info.update(nixinfodict)
|
|
|
|
|
|
print(info)
|
|
|
print(bvfile.info)
|