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

NWBHDF5IO ER and ER_Manager #1684

Merged
merged 28 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/pynwb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from hdmf.backends.hdf5 import HDF5IO as _HDF5IO
from hdmf.build import BuildManager, TypeMap
import hdmf.common
from hdmf.common.resources import ExternalResources

CORE_NAMESPACE = 'core'

Expand Down Expand Up @@ -215,10 +216,14 @@ class NWBHDF5IO(_HDF5IO):
{'name': 'file', 'type': [h5py.File, 'S3File'], 'doc': 'a pre-existing h5py.File object', 'default': None},
{'name': 'comm', 'type': "Intracomm", 'doc': 'the MPI communicator to use for parallel I/O',
'default': None},
{'name': 'driver', 'type': str, 'doc': 'driver for h5py to use when opening HDF5 file', 'default': None})
{'name': 'driver', 'type': str, 'doc': 'driver for h5py to use when opening HDF5 file', 'default': None},
{'name': 'external_resources', 'type': str,
'doc': 'The path to the ExternalResources',
'default': None},)
def __init__(self, **kwargs):
path, mode, manager, extensions, load_namespaces, file_obj, comm, driver =\
popargs('path', 'mode', 'manager', 'extensions', 'load_namespaces', 'file', 'comm', 'driver', kwargs)
path, mode, manager, extensions, load_namespaces, file_obj, comm, driver, external_resources =\
popargs('path', 'mode', 'manager', 'extensions', 'load_namespaces', 'file', 'comm', 'driver', 'external_resources', kwargs)
self.external_resources = external_resources
# Define the BuildManager to use
if load_namespaces:
if manager is not None:
Expand Down Expand Up @@ -297,7 +302,13 @@ def read(self, **kwargs):
raise TypeError("NWB version %s not supported. PyNWB supports NWB files version 2 and above." %
str(file_version_str))
# read the file
return super().read(**kwargs)
file = super().read(**kwargs)
if self.external_resources is not None:
er_read=ExternalResources.from_flat_tsv(path=self.external_resources)
file.link_resources(er_read)
mavaylon1 marked this conversation as resolved.
Show resolved Hide resolved
return file
else:
return super().read(**kwargs)

@docval({'name': 'src_io', 'type': HDMFIO,
'doc': 'the HDMFIO object (such as NWBHDF5IO) that was used to read the data to export'},
Expand Down Expand Up @@ -348,7 +359,8 @@ def export(self, **kwargs):
from . import io as __io # noqa: F401,E402
from .core import NWBContainer, NWBData # noqa: F401,E402
from .base import TimeSeries, ProcessingModule # noqa: F401,E402
from .file import NWBFile # noqa: F401,E402
from .file import NWBFile # noqa: F401,E402
from .resources import ExternalResources

from . import behavior # noqa: F401,E402
from . import device # noqa: F401,E402
Expand Down
6 changes: 5 additions & 1 deletion src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd

from hdmf.common import DynamicTableRegion, DynamicTable
from hdmf.container import ExternalResourcesManager
from hdmf.utils import docval, getargs, get_docval, popargs, popargs_to_dict, AllowPositional

from . import register_class, CORE_NAMESPACE
Expand Down Expand Up @@ -147,9 +148,12 @@ def __init__(self, **kwargs):
for key, val in args_to_set.items():
setattr(self, key, val)

# class NWBExternalResourcesManager(ExternalResourcesManager):
# def __init__(self):
# super().__init__()

@register_class('NWBFile', CORE_NAMESPACE)
class NWBFile(MultiContainerInterface):
class NWBFile(MultiContainerInterface, ExternalResourcesManager):
"""
A representation of an NWB file.
"""
Expand Down
10 changes: 10 additions & 0 deletions src/pynwb/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from hdmf.common import ExternalResources as hdmf_ExternalResources
from . import get_type_map as tm
from . import register_class, CORE_NAMESPACE
from hdmf.utils import docval, get_docval

class ExternalResources(hdmf_ExternalResources):
@docval(*get_docval(hdmf_ExternalResources.__init__))
def __init__(self, **kwargs):
kwargs['type_map'] = tm()
super().__init__(**kwargs)