Closed pauladkisson closed 6 months ago
@rly do you have any suggestions how to fix this?
Hi, this is due to a combination of two issues. One is that HDMF 3.7.0 introduced a check to verify that the referenced table of a DynamicTableRegion has a shared ancestor with the object that the DTR is being added to, to prevent the user from creating invalid files where the referenced table is not in the file. That check assumed that the referenced table is set. But that is not always the case, as we see in this error. I'll create an issue in HDMF to not assume this.
In the meantime, the root trickiness that causes this error is that the FibersTable
contains DynamicTableRegion
columns that reference other tables, but the FibersTable
is not initialized with those other tables. So when you call FibersTable.add_row
, you have to use this hacky code https://github.com/catalystneuro/ndx-photometry/blob/main/src/pynwb/ndx_photometry/fibers_table.py#L46-L53 to check for the existence of the other tables in the parent NWB file, find the tables, and set them accordingly in order to add a row with a reference to the other tables. This makes strong assumptions that 1) the referenced tables have been added to the NWB file, and 2) that they live in nwbfile.lab_meta_data['fiber_photometry']
.
An alternative approach is to initialize the FibersTable
using the following:
fibers_table = FibersTable(
description="fibers table",
target_tables={
'excitation_source': excitationsources_table,
'photodetector': photodetectors_table,
'fluorophores': fluorophores_table,
},
)
Then you can run
fibers_table.add_fiber(
excitation_source=0, #integers indicated rows of excitation sources table
photodetector=0,
fluorophores=[0], #potentially multiple fluorophores, so list of indices
location='my location',
notes='notes'
)
before creating a FiberPhotometry
object and putting it in the NWBFile
. I think this is more flexible and elegant, at the cost of this special setup.
So while we sort out this issue in HDMF, I recommend:
FibersTable
as above and remove the note "# Important: we add the fibers to the fibers table after adding the metadata. This ensures that we can find this data in their tables of origin"FibersTable.__init__
that checks that the target tables are set on initialization, since these DTRs are required columnsadd_fiber
function (or keep it just in case)Since I have thought about this, I'm happy to submit a PR with this. Let me know what you think.
@rly Thank you that would be awesome!
When running my conversion w/ the latest HDMF versions (>=3.7.0), I get the following error during the construction of the
FiberPhotometry
object: