G-Node / nixpy

Python library for NIX
https://readthedocs.org/projects/nixpy
Other
19 stars 26 forks source link

Broken references for nested Source #498

Closed plodocus closed 3 years ago

plodocus commented 3 years ago

I want to represent data coming from different channels from one probe using nested Sources. For example, if I had two probes with 32 channels each, I would have two Sources at the block level. Each of the Sources would have unique channel numbers. Concretely, I want to

  1. Get the probe identity (block-level Source) from referring objects like DataArray.
  2. Get all referring objects from a probe, e.g. all channels belonging to "region0"

Somehow, this doesn't work:

f =  nixio.File.open("test.nix", "w")
b = f.create_block("block0", "session")
s0 = b.create_source("region0", "region")
s00 = s0.create_source("chan0", "chan")
s01 = s0.create_source("chan1", "chan")
da0 = b.create_data_array("da0", "foodata", data=np.zeros(10))
da0.sources.append(s00)
da1 = b.create_data_array("da1", "foodata", data=np.zeros(10))
da1.sources.append(s01)

# trying to find data arrays from "chan0"
print(s00.referring_objects)
# This works
s_from_da = da0.sources[0]
print(s_from_da.referring_objects)
# parent should be "region0", but it's the block
print(s_from_da._parent)
# "s_from_da" is not its parent...
print(s_from_da == s00)
# get all data_arrays from "region0"
print(s0.referring_objects)

Did I misunderstand the concept of Source?

Edit: I guess that is related to the note at https://github.com/G-Node/nixpy/blob/fa561104305c73b233d9903d601440c390e2c042/nixio/source_link_container.py#L15 Doesn't sound like a solution is around the corner... So quickfix would be to have all those channel Sources at the top level and put them in a Group according to the probe?

Edit 2: Hmm, apparently Group is not considered a referring_object... Resorting to defining the probe/region in the Source's definition. Oh dear 😅

jgrewe commented 3 years ago

@DanBenHa sorry for the inconvenience. We will have a closer look at it. Your understanding of the source is correct and I think this can be considered a bug. When searching for the referring objects we do not check whether the parent is a Block, or a parent Source. In your case of nested sources we need to traverse to the root of the tree.

jgrewe commented 3 years ago

fixed with #499 closing this issue