|
@@ -1,129 +0,0 @@
|
|
-import nixio as nix
|
|
|
|
-import matplotlib.pyplot as plt
|
|
|
|
-import numpy as np
|
|
|
|
-import os
|
|
|
|
-from IPython import embed
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-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
|
|
|
|
- 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)
|
|
|
|
- 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
|
|
|
|
- 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(max_depth=max_depth)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def find_mtags_for_tag(block, tag):
|
|
|
|
- """Finds the MultiTags (prepresentatives of the actual stimulus
|
|
|
|
- outputs) that ran during a RePro run. Relacs makes sure that stimulations
|
|
|
|
- with the same settings end up in the same MultiTag.
|
|
|
|
-
|
|
|
|
- Arguments:
|
|
|
|
- block --- nix.Block, the block in which to look for MultiTags
|
|
|
|
- tag --- nix.Tag, the Tag (aka, the RepPro run) defining the search interval
|
|
|
|
-
|
|
|
|
- Returns:
|
|
|
|
- a list of MultiTags
|
|
|
|
- a list of lists containing the position indices for the respective MultiTags
|
|
|
|
- """
|
|
|
|
- assert(isinstance(block, nix.pycore.block.Block))
|
|
|
|
- assert(isinstance(tag, nix.pycore.tag.Tag))
|
|
|
|
- mtags = []
|
|
|
|
- positions = []
|
|
|
|
- tag_start = np.atleast_1d(tag.position)
|
|
|
|
- tag_end = tag_start + np.atleast_1d(tag.extent)
|
|
|
|
- for mt in block.multi_tags:
|
|
|
|
- mt_starts = np.atleast_1d(mt.positions[:])
|
|
|
|
- mt_ends = mt_starts + np.atleast_1d(mt.extents[:])
|
|
|
|
- pos = np.argwhere(mt_starts[(mt_starts > tag_start) &
|
|
|
|
- (mt_starts < tag_end) &
|
|
|
|
- (mt_ends <= tag_end)])[:, 0]
|
|
|
|
- if len(pos) > 0:
|
|
|
|
- mtags.append(mt)
|
|
|
|
- positions.append(pos)
|
|
|
|
- return mtags, positions
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-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)))
|
|
|
|
- print("\n")
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def stimulus_overview(nf):
|
|
|
|
- assert(nf and isinstance(nf, nix.pycore.file.File) and nf.is_open)
|
|
|
|
- b = nf.blocks[0]
|
|
|
|
-
|
|
|
|
- print("Stimulations, aka RePro runs:")
|
|
|
|
- repro_runs = [t for t in b.tags if "repro_run" in t.type]
|
|
|
|
- for rr in repro_runs:
|
|
|
|
- start = rr.position[0]
|
|
|
|
- end = start + rr.extent[0]
|
|
|
|
- print("\t RePro %s, time: %.4f --> %.4f%s" % (rr.name, start, end, rr.units[0]))
|
|
|
|
- mts, positions = find_mtags_for_tag(b, rr)
|
|
|
|
- for mt, pos in zip(mts, positions):
|
|
|
|
- print("\t\t with %i stimulus repetitions" % (len(pos)))
|
|
|
|
- print("\n")
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-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.FileMode.ReadOnly)
|
|
|
|
-
|
|
|
|
- metadata_overview(nix_file)
|
|
|
|
-
|
|
|
|
- data_overview(nix_file)
|
|
|
|
-
|
|
|
|
- stimulus_overview(nix_file)
|
|
|
|
-
|
|
|
|
- nix_file.close()
|
|
|