44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
import nixio as nix
|
|
from IPython import embed
|
|
from collections import defaultdict
|
|
import numpy as np
|
|
|
|
|
|
def open_nixio_new(nix_file):
|
|
|
|
f = nix.File.open(nix_file, nix.FileMode.ReadOnly)
|
|
b = f.blocks[0] # first block
|
|
mt = b.multi_tags['moving object-1']
|
|
comb_pos = mt.positions[:]
|
|
comb_ext = np.array(mt.extents[:])
|
|
spikes = b.data_arrays["Spikes-1"][:]
|
|
|
|
feature_dict = {}
|
|
for feat in mt.features:
|
|
feature_dict.update({feat.data.name[16:]: mt.features[feat.data.name].data[:]})
|
|
|
|
tags = b.tags
|
|
intervals_dict = defaultdict(list)
|
|
|
|
for tag in tags:
|
|
if tag.name.startswith('Baseline'):
|
|
continue
|
|
curr_comb = tag.metadata["RePro-Info"]["settings"]["object"]
|
|
travel_dist = tag.metadata["RePro-Info"]["settings"]["traveldist"]
|
|
repro_pos, = tag.position
|
|
repro_ext, = tag.extent
|
|
idx_qry = np.logical_and(repro_pos < comb_pos, comb_pos < (repro_pos + repro_ext))
|
|
tag_idx = np.flatnonzero(idx_qry)
|
|
tag_pos = comb_pos[idx_qry]
|
|
|
|
for idx, position in zip(tag_idx, tag_pos):
|
|
if idx == (len(comb_pos)-1):
|
|
break
|
|
curr_speed = feature_dict['speed'][idx]
|
|
travel_time = travel_dist/curr_speed
|
|
curr_pos = comb_pos[idx]
|
|
curr_dir = feature_dict['direction'][idx]
|
|
curr_spikes = spikes[(spikes < comb_pos[idx + 1]) & (spikes > comb_pos[idx])]
|
|
intervals_dict[(tag.name, travel_time, curr_speed, curr_dir, curr_comb)].append(curr_spikes)
|
|
|
|
return intervals_dict |