You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On write, Container.container_source is set for all built objects not read from a file. This field tracks where a Container object is located on disk (e.g., file path) so that links can be made across files. This also prevents a Container object from being written to multiple files.
Oddly, in some cases, Container.container_source is not set at all. Specifically, when Container A makes a reference to Container B, and Container A gets built first, then Container B does not get a container_source. However, if no container makes a reference to Container B before Container B is built, then Container B does get a container_source.
This occurs in PyNWB when writing an NWBFile with a Device, an ElectrodeGroup, and an ElectricalSeries that references those. The ElectricalSeries gets built first, which results in the Device and ElectrodeGroup being built without a container_source set.
If users are not careful, this can lead to unexpected/inconsistent behavior when interacting with a Container that is missing its container_source. For example, a Container without a container_source can be added to multiple files under different build managers. This creates a broken link in all files after the first. Admittedly, this is a bit of an edge case and is minor.
MWE:
frompynwbimportNWBFile, NWBHDF5IOfrompynwb.ecephysimportElectricalSeriesfromdatetimeimportdatetimeimportnumpyasnpnwbfile=NWBFile(session_description='ADDME',
identifier='ADDME',
session_start_time=datetime.now().astimezone())
dev1=nwbfile.create_device('dev1')
group=nwbfile.create_electrode_group('tetrode1', 'tetrode description', 'tetrode location', dev1)
nwbfile.add_electrode(id=1, x=1.0, y=2.0, z=3.0, imp=-1.0, location='CA1', filtering='none', group=group,
group_name='tetrode1')
region=nwbfile.create_electrode_table_region(
region=(0, ),
name='electrodes',
description='desc'
)
ts=ElectricalSeries(
name='test_data',
data=np.arange(10),
timestamps=np.arange(10),
electrodes=region
)
nwbfile.add_acquisition(ts)
withNWBHDF5IO('nwbfile.nwb', 'w') asio:
io.write(nwbfile)
# dev1 and group do not have container_source set. all other Containers do.print(dev1.container_source)
print(group.container_source)
# add dev1 and group to a new filenwbfile2=NWBFile(session_description='ADDME',
identifier='ADDME',
session_start_time=datetime.now().astimezone())
nwbfile2.add_device(dev1)
nwbfile2.add_electrode_group(group)
# using a new build manager, a new file can be written with dev1 and group,# but the file has broken links for themwithNWBHDF5IO('nwbfile2.nwb', 'w') asio:
io.write(nwbfile2)
The text was updated successfully, but these errors were encountered:
On write,
Container.container_source
is set for all built objects not read from a file. This field tracks where aContainer
object is located on disk (e.g., file path) so that links can be made across files. This also prevents aContainer
object from being written to multiple files.Oddly, in some cases,
Container.container_source
is not set at all. Specifically, when Container A makes a reference to Container B, and Container A gets built first, then Container B does not get acontainer_source
. However, if no container makes a reference to Container B before Container B is built, then Container B does get acontainer_source
.This occurs in PyNWB when writing an NWBFile with a Device, an ElectrodeGroup, and an ElectricalSeries that references those. The ElectricalSeries gets built first, which results in the Device and ElectrodeGroup being built without a
container_source
set.If users are not careful, this can lead to unexpected/inconsistent behavior when interacting with a
Container
that is missing itscontainer_source
. For example, aContainer
without acontainer_source
can be added to multiple files under different build managers. This creates a broken link in all files after the first. Admittedly, this is a bit of an edge case and is minor.MWE:
The text was updated successfully, but these errors were encountered: