|
@@ -5,7 +5,19 @@ import os
|
|
|
from IPython import embed
|
|
|
|
|
|
|
|
|
-def metadata_overview(nf, sec_type=None, sec_name=None):
|
|
|
+def metadata_overview(nf):
|
|
|
+ assert(nf and isinstance(nf, nix.pycore.file.File) and nf.is_open)
|
|
|
+
|
|
|
+ print("Print some of the stored metadata")
|
|
|
+ print_metadata(nix_file, sec_type="recording", sec_name="recording", max_depth=0)
|
|
|
+ print("\n")
|
|
|
+ print_metadata(nix_file, sec_name="subject")
|
|
|
+ print("\n")
|
|
|
+ print_metadata(nix_file, sec_name="cell")
|
|
|
+ print("\n")
|
|
|
+
|
|
|
+
|
|
|
+def print_metadata(nf, sec_type=None, sec_name=None, max_depth=-1):
|
|
|
"""Display stored metadata using the section's pprint function.
|
|
|
|
|
|
If the desired section name or type are provided, the find_sections
|
|
@@ -18,7 +30,10 @@ def metadata_overview(nf, sec_type=None, sec_name=None):
|
|
|
Keyword arguments:
|
|
|
sec_type --- string: the section type (default None)
|
|
|
sec_name --- string, the section name (default None)
|
|
|
+ max_depth --- int, the maximum depth of the metadata tree (default -1, i.e. unlimited)
|
|
|
"""
|
|
|
+ assert(not sec_name or isinstance(sec_name, str))
|
|
|
+ assert(not sec_type or isinstance(sec_type, str))
|
|
|
|
|
|
sec_type = sec_type.lower() if sec_type else None
|
|
|
sec_name = sec_name.lower() if sec_name else None
|
|
@@ -27,7 +42,28 @@ def metadata_overview(nf, sec_type=None, sec_name=None):
|
|
|
and (sec_name and sec_name in s.name.lower() or not sec_name)
|
|
|
or (not sec_name and not sec_type))
|
|
|
for s in sections:
|
|
|
- s.pprint()
|
|
|
+ s.pprint(max_depth=max_depth)
|
|
|
+
|
|
|
+
|
|
|
+def data_overview(nf):
|
|
|
+ assert(nf and isinstance(nf, nix.pycore.file.File) and nf.is_open)
|
|
|
+ b = nf.blocks[0]
|
|
|
+
|
|
|
+ print("Regularly sampled data:")
|
|
|
+ regular_sampled_data = [da for da in b.data_arrays if da.dimensions[0].dimension_type == nix.DimensionType.Sample]
|
|
|
+ for rsd in regular_sampled_data:
|
|
|
+ print("\t%s, size: %s" % (rsd.name, str(rsd.shape)))
|
|
|
+
|
|
|
+ print("Event data:")
|
|
|
+ event_data = [da for da in b.data_arrays if da.dimensions[0].dimension_type == nix.DimensionType.Range]
|
|
|
+ for ed in event_data:
|
|
|
+ print("\t%s, size: %s" % (ed.name, str(ed.shape)))
|
|
|
+
|
|
|
+ print("Sets:")
|
|
|
+ set_data = [da for da in b.data_arrays if da.dimensions[0].dimension_type == nix.DimensionType.Set]
|
|
|
+ for sd in set_data:
|
|
|
+ print("\t%s, size: %s" % (sd.name, str(sd.shape)))
|
|
|
+
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
@@ -36,9 +72,9 @@ if __name__ == "__main__":
|
|
|
print("Example file was not found")
|
|
|
exit()
|
|
|
nix_file = nix.File.open(example_file, nix.FileMode.ReadOnly)
|
|
|
- embed()
|
|
|
- metadata_overview(nix_file, sec_type="recording", sec_name="recording")
|
|
|
|
|
|
- nix_file.close()
|
|
|
+ metadata_overview(nix_file)
|
|
|
|
|
|
+ data_overview(nix_file)
|
|
|
|
|
|
+ nix_file.close()
|