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 14 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# PyNWB Changelog

## PyNWB 2.3.4 (Upcoming)

### Enhancements and minor changes
- Add support for `ExternalResources`. @mavaylon1 [#1684](https://github.com/NeurodataWithoutBorders/pynwb/pull/1684)

## PyNWB 2.3.3 (June 26, 2023)

### Enhancements and minor changes
Expand Down
2 changes: 1 addition & 1 deletion requirements-min.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# minimum versions of package dependencies for installing PyNWB
h5py==2.10 # support for selection of datasets with list of indices added in 2.10
hdmf==3.5.4
hdmf==3.6.0
numpy==1.16
pandas==1.1.5
python-dateutil==2.7.3
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pinned dependencies to reproduce an entire development environment to use PyNWB
h5py==3.8.0
hdmf==3.5.4
hdmf==3.6.0
numpy==1.24.2; python_version >= "3.8"
numpy==1.21.5; python_version < "3.8" # note that numpy 1.22 dropped python 3.7 support
pandas==2.0.0; python_version >= "3.8"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

reqs = [
'h5py>=2.10',
'hdmf>=3.5.4',
'hdmf>=3.6.0',
'numpy>=1.16',
'pandas>=1.1.5',
'python-dateutil>=2.7.3',
Expand Down
19 changes: 14 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,15 @@ 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 +303,11 @@ 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
mavaylon1 marked this conversation as resolved.
Show resolved Hide resolved
return file

@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 @@ -349,7 +359,6 @@ def export(self, **kwargs):
from .core import NWBContainer, NWBData # noqa: F401,E402
from .base import TimeSeries, ProcessingModule # noqa: F401,E402
from .file import NWBFile # noqa: F401,E402

from . import behavior # noqa: F401,E402
from . import device # noqa: F401,E402
from . import ecephys # noqa: F401,E402
Expand Down
3 changes: 2 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 @@ -149,7 +150,7 @@ def __init__(self, **kwargs):


@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 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)