Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiTag.tagged_data: OOB and non-intuitive slicing #502

Closed
refactoriel opened this issue May 21, 2021 · 1 comment
Closed

MultiTag.tagged_data: OOB and non-intuitive slicing #502

refactoriel opened this issue May 21, 2021 · 1 comment

Comments

@refactoriel
Copy link

Suppose I have a sparsely firing neuron and I want to count how many spikes I have per trial. I'd define a MultiTag as the trials with some positions and extents. With tagged_data I would get all and only those spikes present in a range defined by a position and its extent.
When I try this, I get out-of-bound errors or incorrect data. Wouldn't it be possible to just return an empty numpy array if there is no data within a range? This is probably a design choice but it seems a bit weird to me.

timestamps = np.array([2.8, 3.8])

f = nixio.File.open("test.nix", "w")
b = f.create_block("block0", "foo")

da_ts = b.create_data_array("spike_times", "foo", data=timestamps)
da_ts.unit = "s" 
da_ts.label = "time"
dim = da_ts.append_range_dimension()
dim.link_data_array(da_ts, [-1])

# only trial 2 (3.8 to 4.2) has a spike
pos = b.create_data_array("pos", "foo", data=[2.0, 3.0, 3.8, 6.4])
ext = b.create_data_array("ext", "foo", data=[0.4, 0.4, 0.4, 0.4])
mt = b.create_multi_tag("trials", "foo", positions=pos)
mt.extents = ext 
mt.references.append(da_ts)
# trial 0: no spikes: expect empty array, get OOB
print(mt.tagged_data(0, "spike_times")[:])
# trial 1: no spikes: expect empty array (or at least the closest spike), get next trial's spike
print(mt.tagged_data(1, "spike_times")[:])
# trial 2: 1 spike: expect 1 spike, get the correct spike
print(mt.tagged_data(2, "spike_times")[:])
# trial 3: no spikes: expect empty array, get OOB
print(mt.tagged_data(3, "spike_times")[:])
@jgrewe
Copy link
Member

jgrewe commented May 28, 2021

We had a short meeting in which we discussed about this point. The rationale was to keep the python implementation similar to the C++ implementation in which we so far had no invalid or empty DataView. We will change this and, much as you suggest, return empty arrays in cases the tagged range is invalid or does not contain data.
Thanks for the report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants