hdmf-dev / hdmf

The Hierarchical Data Modeling Framework
http://hdmf.readthedocs.io
Other
48 stars 26 forks source link

Cannot write external links #87

Closed rly closed 5 years ago

rly commented 5 years ago

With the most recent 1.0.4 version of hdmf, parent-child relationships are enforced such that a child can have only one parent, which cannot be reassigned. This breaks linking of external files.

from pynwb import get_manager

manager = get_manager()

io = NWBHDF5IO(filename, 'r', manager=manager)
nwbfile1 = io.read()
ts = nwbfile1.get_acquisition('ts')

nwbfile2 = NWBFile(session_description='',
                   identifier='id',
                   session_start_time=start_time)
nwbfile2.add_acquisition(ts)

ts already has a parent nwbfile1. Therefore, nwbfile2 cannot add ts as a child.

Options:

  1. Allow Container.parent to be reset. This could lead to strange behavior and bugs down the road (or bugs that return).
  2. Linking is currently handled automagically during NWBHDF5IO.write. Instead of determining on write whether a link exists, ask the user to make all links explicit, e.g. nwbfile3.add_acquisition(NWBLink(ts)). This is more akin to a filesystem -- you can't have the same file in two different folders, but you can make a link/shortcut to the file and move that link around.
bendichter commented 5 years ago

I prefer 2. I don't really understand why links were "automagic" in the first place and that has been creating a lot of issues. In matnwb you need to define all links explicitly. We would need types for internal and external links and ideally you would be able to specify absolute or relative path for external links

rly commented 5 years ago

I also prefer 2. While we decide on this, I'm issuing a hotfix for 1.0.4 -> 1.0.5.