Extension to add acquisition module
Project description
ndx-acquisition-module
This extension is used to allow adding modules in nwbfile.acquisition
, similarly to how nwbfile.processing
allows adding modules.
More specifically, this allows creating a module that has TimeSeries
and DynamicTable
objects, then users can add this module.
This is in alpha development stages. Please use with discretion.
[TOC]
Requirement
The requirements and additional development requirements can be seen in pyproject.toml
file.
Here are the minimum requirements:
python >=3.8
pynwb>=1.5.0,<3
hdmf>=3.4.7,<4
Installation
pip install git+https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-module
Usage
Main usage
from ndx_acquisition_module import AcquisitionModule
mod = AcquisitionModule(name="raw_mod", description="raw acq module")
# Add data objects to created AcquisitionModule
mod.add(time_series) # add time series
mod.add(dynamic_table) # add dynamic table
# Add AcquisitionModule to nwbfile.acquisition
nwbfile.add_acquisition(mod)
Full example
from datetime import datetime
import numpy as np
from dateutil import tz
from hdmf.common import DynamicTable, VectorData
from ndx_acquisition_module import AcquisitionModule
from pynwb import NWBHDF5IO, NWBFile, TimeSeries
# Create an example NWBFile
nwbfile = NWBFile(
session_description="test session description",
identifier="unique_identifier",
session_start_time=datetime(2012, 2, 21, tzinfo=tz.gettz("US/Pacific")),
)
# Create time series
ts = TimeSeries(
name="choice_series",
description="raw choice series",
data=np.random.randint(4, size=100),
timestamps=(np.arange(100).astype("float") + 2) / 30,
unit="-",
)
# Create dynamic table
tbl = DynamicTable(
name="lookup_table",
description="lookup table for `choice_series`",
columns=[
VectorData(
name="lookup_id", description="ID to look up", data=[0, 1, 2, 3]
),
VectorData(
name="lookup_name",
description="name of ID",
data=["water", "earth", "fire", "air"],
),
],
)
# Create AcquisitionModule to store these objects
mod = AcquisitionModule(name="raw_mod", description="raw acq module")
# Add data objects to created AcquisitionModule
mod.add(ts) # add time series
mod.add(tbl) # add dynamic table
# Add AcquisitionModule to nwbfile.acquisition
nwbfile.add_acquisition(mod)
# Write the file to disk
filename = "test.nwb"
with NWBHDF5IO(path=filename, mode="w") as io:
io.write(nwbfile)
API usage notes
With package installed
Currently to use mod.get(<object_name>)
or mod[<object_name>]
, users would also need to install this package.
pip install git+https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-module
And import, using NWBHDF5IO(..., load_namespaces=True)
would not be enough.
# new file completely
from pynwb import NWBHDF5IO
from ndx_acquisition_module import AcquisitionModule
nwb = NWBHDF5IO('test.nwb', mode='r').read() # notice `load_namepsaces` is not needed
nwb.acquisition['raw_mod']
---------------------------------------------------
raw_mod ndx_acquisition_module.AcquisitionModule at 0x139742592581104
Fields:
data_interfaces: {
choice_series <class 'pynwb.base.TimeSeries'>,
lookup_table <class 'hdmf.common.table.DynamicTable'>
}
To access:
nwb.acquisition['raw_mod']['lookup_table']
nwb.acquisition['raw_mod']['choice_series']
Without package installed
Otherwise, if ndx-acquisition-module
is not installed, accessing the inside objects have to be done based on types:
# new file completely
from pynwb import NWBHDF5IO
nwb = NWBHDF5IO('test.nwb', mode='r', load_namespaces=True).read() # notice `load_namepsaces` is NEEDED
nwb.acquisition['raw_mod']
---------------------------------------------------
raw_mod abc.AcquisitionModule at 0x140252603705728
Fields:
description: raw acq module
dynamic_tables: {
lookup_table <class 'hdmf.common.table.DynamicTable'>
}
nwb_data_interfaces: {
choice_series <class 'pynwb.base.TimeSeries'>
}
To access:
nwb.acquisition['raw_mod'].dynamic_tables['lookup_table']
nwb.acquisition['raw_mod'].nwb_data_interfaces['choice_series']
TODOs
- Figure out how to allow consistent access even if package is not installed, so that using
load_namespaces=True
is sufficient. - Edit
sphinx
deploy stage - Publish on
pypi
/conda
This extension was created using ndx-template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ndx-acquisition-module-0.1.0.tar.gz
.
File metadata
- Download URL: ndx-acquisition-module-0.1.0.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bf5c4b9c93ad8e0706bd8314e2b9447926de4bc424b37f34d9e4d48f6629f58 |
|
MD5 | 2ce0f8ca50af83842b7978d8ed76dd9b |
|
BLAKE2b-256 | e39e3ccbb4ad2572fec76d09df105298c54c3b25771d22a6417d74f5a6befc3c |
Provenance
File details
Details for the file ndx_acquisition_module-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: ndx_acquisition_module-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 663eb81e4f103c25c927797c5b363b1f22d29de1bfbf9d2747084ebfa2d65333 |
|
MD5 | dfea6266e25c9ed5214b3b76b1a8ca02 |
|
BLAKE2b-256 | e236c7e82dfc2ba836807671391b0733561de36bd29bebce28d3cb81e3e567f3 |