Browse Source

[single cell ephys] improve section printing

Jan Grewe 5 years ago
parent
commit
1f3a7747d5
1 changed files with 38 additions and 13 deletions
  1. 38 13
      single_cell_intracellular_spikes/explore.py

+ 38 - 13
single_cell_intracellular_spikes/explore.py

@@ -2,20 +2,45 @@ import nixio as nix
 import matplotlib.pyplot as plt
 import numpy as np
 import os
+from IPython import embed
 
 
-def metadata_overview(nf):
-  
-  for s in nf.sections:
-    s.pprint(depth=-1)
-  
+def metadata_overview(nf, sec_type=None, sec_name=None):
+    """Display stored metadata using the section's pprint function.
+
+    If the desired section name or type are provided, the find_sections
+    method is used to filter the metadata, if neither is provided all sections
+    will be printed.
+
+    Arguments:
+    nf -- opened nix file
+
+    Keyword arguments:
+    sec_type --- string: the section type (default None)
+    sec_name --- string, the section name (default None)
+    """
+    if sec_type or sec_name:
+        sec_type = sec_type.lower() if sec_type else None
+        sec_name = sec_name.lower() if sec_name else None
+        sections = nf.find_sections(lambda s:
+                                    (sec_type and sec_type in s.type.lower() or not sec_type)
+                                    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()
+    else:
+        for s in nf.sections:
+            s.pprint(max_depth=-1)
+
 
 if __name__ == "__main__":
-  example_file = "2018-11-05-ab-invivo-1.nix"
-  if not os.path.exists(example_file):
-    print("Example file was not found")
-    exit()
-  nix_file = nix.File.open(example_file, nix.File.ReadOnly)
-  metadata_overview(nix_file)
-  nix_file.close()
-  
+    example_file = "2018-11-05-ab-invivo-1.nix"
+    if not os.path.exists(example_file):
+        print("Example file was not found")
+        exit()
+    nix_file = nix.File.open(example_file, nix.FileMode.ReadOnly)
+    metadata_overview(nix_file, sec_type="recording", sec_name="recording")
+
+    nix_file.close()
+
+