forked from jgrewe/fishbook
[util] add method to find mtags that fit into a tagged region
This commit is contained in:
parent
8fb7d476e8
commit
3d0ffbc55c
20
util.py
20
util.py
@ -1,4 +1,5 @@
|
||||
from functools import reduce
|
||||
import numpy as np
|
||||
import nixio as nix
|
||||
import os
|
||||
import glob
|
||||
@ -102,6 +103,25 @@ def nix_metadata_to_yaml(section, cur_depth=0, val_count=1):
|
||||
return yaml
|
||||
|
||||
|
||||
def find_mtags_for_tag(block, tag):
|
||||
assert(isinstance(block, nix.pycore.block.Block))
|
||||
assert(isinstance(tag, nix.pycore.tag.Tag))
|
||||
mtags = []
|
||||
tag_start = np.atleast_1d(tag.position)
|
||||
tag_end = tag_start + np.atleast_1d(tag.extent)
|
||||
for mt in block.multi_tags:
|
||||
mt_start = np.atleast_1d(mt.positions[0, :])
|
||||
mt_end = np.atleast_1d(mt.positions[-1, :] + mt.extents[-1, :])
|
||||
in_tag = True
|
||||
for i in range(len(tag_start)):
|
||||
if mt_start[i] < tag_start[i] or mt_end[i] > tag_end[i]:
|
||||
in_tag = False
|
||||
break
|
||||
if in_tag:
|
||||
mtags.append(mt)
|
||||
return mtags
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
nix_file = "../../science/high_freq_chirps/data/2018-11-09-aa-invivo-1/2018-11-09-aa-invivo-1.nix"
|
||||
f = nix.File.open(nix_file, nix.FileMode.ReadOnly)
|
||||
|
Loading…
Reference in New Issue
Block a user