-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af72ee2
commit 5fbecee
Showing
3 changed files
with
133 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pynwb | ||
from contextlib import contextmanager | ||
|
||
|
||
@contextmanager | ||
def open_nwbfile_local(file_path: str): | ||
""" | ||
Context manager to open and close a local NWB file. | ||
Parameters | ||
---------- | ||
file_path : str | ||
Path to NWB file. | ||
Yields | ||
------ | ||
pynwb.NWBFile | ||
The opened NWB file. | ||
""" | ||
io = pynwb.NWBHDF5IO(file_path, 'r') | ||
try: | ||
nwbfile = io.read() | ||
yield nwbfile | ||
finally: | ||
io.close() | ||
|
||
|
||
def get_nwbfile_volume( | ||
nwbfile: pynwb.NWBFile, | ||
acquisition_name: str, | ||
volume_index: int, | ||
) -> pynwb.NWBFile: | ||
""" | ||
Get 3D volume from NWB file. | ||
Parameters | ||
---------- | ||
nwbfile : pynwb.NWBFile | ||
NWB file. | ||
acquisition_name : str | ||
Acquisition name. | ||
volume_index : int | ||
Volume index. | ||
Returns | ||
------- | ||
pynwb.NWBFile | ||
NWB file. | ||
""" | ||
return nwbfile.acquisition[acquisition_name].data[volume_index] |