Skip to content

Commit

Permalink
NWBHDF5IO ER and ER_Manager (#1684)
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 authored Jul 11, 2023
1 parent aae7d78 commit 4545d71
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## PyNWB 2.4.0 (Upcoming)

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

## PyNWB 2.3.3 (June 26, 2023)
Expand Down
4 changes: 2 additions & 2 deletions requirements-min.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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
numpy==1.16
hdmf==3.7.0
numpy==1.18
pandas==1.1.5
python-dateutil==2.7.3
setuptools
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.7.0
numpy==1.24.2
pandas==2.0.0
python-dateutil==2.8.2
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.7.0',
'numpy>=1.16',
'pandas>=1.1.5',
'python-dateutil>=2.7.3',
Expand Down
16 changes: 10 additions & 6 deletions src/pynwb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ 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_path', '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_path =\
popargs('path', 'mode', 'manager', 'extensions', 'load_namespaces',
'file', 'comm', 'driver', 'external_resources_path', kwargs)
# Define the BuildManager to use
if load_namespaces:
if manager is not None:
Expand Down Expand Up @@ -247,7 +250,8 @@ def __init__(self, **kwargs):
elif manager is None:
manager = get_manager()
# Open the file
super().__init__(path, manager=manager, mode=mode, file=file_obj, comm=comm, driver=driver)
super().__init__(path, manager=manager, mode=mode, file=file_obj, comm=comm,
driver=driver, external_resources_path=external_resources_path)

@property
def nwb_version(self):
Expand Down Expand Up @@ -297,7 +301,8 @@ 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)
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 +354,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)
11 changes: 11 additions & 0 deletions tests/unit/test_resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pynwb.resources import ExternalResources
from pynwb.testing import TestCase


class TestNWBContainer(TestCase):
def test_constructor(self):
"""
Test constructor
"""
er = ExternalResources()
self.assertIsInstance(er, ExternalResources)

0 comments on commit 4545d71

Please sign in to comment.