ndx-acquisition-module


Namendx-acquisition-module JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryExtension to add acquisition module
upload_time2023-02-01 00:27:26
maintainer
docs_urlNone
author
requires_python>=3.8
licenseBSD-3
keywords neurodatawithoutborders nwb nwb-extension ndx-extension
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ndx-acquisition-module

[![pipeline status](https://img.shields.io/gitlab/pipeline-status/fleischmann-lab/ndx/ndx-acquisition-module?branch=main&label=pipeline&style=for-the-badge)](https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-module/-/commits/main)
[![release](https://img.shields.io/gitlab/v/release/fleischmann-lab/ndx/ndx-acquisition-module?label=release&sort=date&style=for-the-badge)](https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-module/-/releases)
[![pypi package](https://img.shields.io/pypi/v/ndx-acquisition-module?label=pypi%20package&style=for-the-badge&color=blue)](https://pypi.org/pypi/ndx-acquisition-module)
[![license](https://img.shields.io/gitlab/license/fleischmann-lab/ndx/ndx-acquisition-module?color=yellow&label=license&style=for-the-badge)](LICENSE.txt)

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`](pyproject.toml) file.

Here are the minimum requirements:

- `python >=3.8`
- `pynwb>=1.5.0,<3`
- `hdmf>=3.4.7,<4`

## Installation

### Via `pip`

```bash
pip install ndx-acquisition-module
```

### Via `git`

```bash
pip install git+https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-module
```

## Usage

### Main usage

```python
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

```python
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.

```bash
pip install git+https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-module
```

And import, using `NWBHDF5IO(..., load_namespaces=True)` would not be enough.

```python
# 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

print(nwb.acquisition['raw_mod'])
```

which outputs:

```text
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:

```python
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:

```python
# new file completely
from pynwb import  NWBHDF5IO
nwb = NWBHDF5IO('test.nwb', mode='r', load_namespaces=True).read() # notice `load_namepsaces` is NEEDED

print(nwb.acquisition['raw_mod'])
```

which outputs:

```text
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:

```python
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
- [x] Publish on `pypi`
- [ ] Publish on `conda`

---

This extension was created using [ndx-template](https://github.com/nwb-extensions/ndx-template).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ndx-acquisition-module",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Tuan Pham <tuanhpham@brown.edu>",
    "keywords": "NeurodataWithoutBorders,NWB,nwb-extension,ndx-extension",
    "author": "",
    "author_email": "Tuan Pham <tuanhpham@brown.edu>",
    "download_url": "https://files.pythonhosted.org/packages/a1/ef/fa528d0f1c3a926c1a939beca8985d3b75858f40670e1f7f8f86a88267c0/ndx-acquisition-module-0.1.1.tar.gz",
    "platform": null,
    "description": "# ndx-acquisition-module\n\n[![pipeline status](https://img.shields.io/gitlab/pipeline-status/fleischmann-lab/ndx/ndx-acquisition-module?branch=main&label=pipeline&style=for-the-badge)](https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-module/-/commits/main)\n[![release](https://img.shields.io/gitlab/v/release/fleischmann-lab/ndx/ndx-acquisition-module?label=release&sort=date&style=for-the-badge)](https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-module/-/releases)\n[![pypi package](https://img.shields.io/pypi/v/ndx-acquisition-module?label=pypi%20package&style=for-the-badge&color=blue)](https://pypi.org/pypi/ndx-acquisition-module)\n[![license](https://img.shields.io/gitlab/license/fleischmann-lab/ndx/ndx-acquisition-module?color=yellow&label=license&style=for-the-badge)](LICENSE.txt)\n\nThis extension is used to allow adding modules in `nwbfile.acquisition`, similarly to how `nwbfile.processing` allows adding modules.\n\nMore specifically, this allows creating a module that has `TimeSeries` and `DynamicTable` objects, then users can add this module.\n\nThis is in alpha development stages. Please use with discretion.\n\n[TOC]\n\n## Requirement\n\nThe requirements and additional development requirements can be seen in [`pyproject.toml`](pyproject.toml) file.\n\nHere are the minimum requirements:\n\n- `python >=3.8`\n- `pynwb>=1.5.0,<3`\n- `hdmf>=3.4.7,<4`\n\n## Installation\n\n### Via `pip`\n\n```bash\npip install ndx-acquisition-module\n```\n\n### Via `git`\n\n```bash\npip install git+https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-module\n```\n\n## Usage\n\n### Main usage\n\n```python\nfrom ndx_acquisition_module import AcquisitionModule\n\nmod = AcquisitionModule(name=\"raw_mod\", description=\"raw acq module\")\n\n# Add data objects to created AcquisitionModule\nmod.add(time_series)  # add time series\nmod.add(dynamic_table)  # add dynamic table\n\n# Add AcquisitionModule to nwbfile.acquisition\nnwbfile.add_acquisition(mod)\n```\n\n### Full example\n\n```python\nfrom datetime import datetime\n\nimport numpy as np\nfrom dateutil import tz\nfrom hdmf.common import DynamicTable, VectorData\nfrom ndx_acquisition_module import AcquisitionModule\n\nfrom pynwb import NWBHDF5IO, NWBFile, TimeSeries\n\n# Create an example NWBFile\nnwbfile = NWBFile(\n  session_description=\"test session description\",\n  identifier=\"unique_identifier\",\n  session_start_time=datetime(2012, 2, 21, tzinfo=tz.gettz(\"US/Pacific\")),\n)\n\n# Create time series\nts = TimeSeries(\n  name=\"choice_series\",\n  description=\"raw choice series\",\n  data=np.random.randint(4, size=100),\n  timestamps=(np.arange(100).astype(\"float\") + 2) / 30,\n  unit=\"-\",\n)\n\n# Create dynamic table\ntbl = DynamicTable(\n  name=\"lookup_table\",\n  description=\"lookup table for `choice_series`\",\n  columns=[\n    VectorData(\n      name=\"lookup_id\", description=\"ID to look up\", data=[0, 1, 2, 3]\n    ),\n    VectorData(\n      name=\"lookup_name\",\n      description=\"name of ID\",\n      data=[\"water\", \"earth\", \"fire\", \"air\"],\n    ),\n  ],\n)\n\n# Create AcquisitionModule to store these objects\nmod = AcquisitionModule(name=\"raw_mod\", description=\"raw acq module\")\n\n# Add data objects to created AcquisitionModule\nmod.add(ts)  # add time series\nmod.add(tbl)  # add dynamic table\n\n# Add AcquisitionModule to nwbfile.acquisition\nnwbfile.add_acquisition(mod)\n\n# Write the file to disk\nfilename = \"test.nwb\"\nwith NWBHDF5IO(path=filename, mode=\"w\") as io:\n  io.write(nwbfile)\n\n```\n\n### API usage notes\n\n#### With package installed\n\nCurrently to use `mod.get(<object_name>)` or `mod[<object_name>]`, users would also need to install this package.\n\n```bash\npip install git+https://gitlab.com/fleischmann-lab/ndx/ndx-acquisition-module\n```\n\nAnd import, using `NWBHDF5IO(..., load_namespaces=True)` would not be enough.\n\n```python\n# new file completely\nfrom pynwb import  NWBHDF5IO\nfrom ndx_acquisition_module import AcquisitionModule\nnwb = NWBHDF5IO('test.nwb', mode='r').read() # notice `load_namepsaces` is not needed\n\nprint(nwb.acquisition['raw_mod'])\n```\n\nwhich outputs:\n\n```text\nraw_mod ndx_acquisition_module.AcquisitionModule at 0x139742592581104\nFields:\n  data_interfaces: {\n    choice_series <class 'pynwb.base.TimeSeries'>,\n    lookup_table <class 'hdmf.common.table.DynamicTable'>\n  }\n```\n\nTo access:\n\n```python\nnwb.acquisition['raw_mod']['lookup_table']\nnwb.acquisition['raw_mod']['choice_series']\n```\n\n#### Without package installed\n\nOtherwise, if `ndx-acquisition-module` is not installed, accessing the inside objects have to be done based on types:\n\n```python\n# new file completely\nfrom pynwb import  NWBHDF5IO\nnwb = NWBHDF5IO('test.nwb', mode='r', load_namespaces=True).read() # notice `load_namepsaces` is NEEDED\n\nprint(nwb.acquisition['raw_mod'])\n```\n\nwhich outputs:\n\n```text\nraw_mod abc.AcquisitionModule at 0x140252603705728\nFields:\n  description: raw acq module\n  dynamic_tables: {\n    lookup_table <class 'hdmf.common.table.DynamicTable'>\n  }\n  nwb_data_interfaces: {\n    choice_series <class 'pynwb.base.TimeSeries'>\n  }\n```\n\nTo access:\n\n```python\nnwb.acquisition['raw_mod'].dynamic_tables['lookup_table']\nnwb.acquisition['raw_mod'].nwb_data_interfaces['choice_series']\n```\n\n## TODOs\n\n- [ ] Figure out how to allow consistent access even if package is not installed, so that using `load_namespaces=True` is sufficient.\n- [ ] Edit `sphinx` deploy stage\n- [x] Publish on `pypi`\n- [ ] Publish on `conda`\n\n---\n\nThis extension was created using [ndx-template](https://github.com/nwb-extensions/ndx-template).\n",
    "bugtrack_url": null,
    "license": "BSD-3",
    "summary": "Extension to add acquisition module",
    "version": "0.1.1",
    "split_keywords": [
        "neurodatawithoutborders",
        "nwb",
        "nwb-extension",
        "ndx-extension"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fd73a7097d2025be31f0e811baf1c8ee89c302384942b215e57428ca04e3092d",
                "md5": "30da556d63ce58797c9a7f9afa83377e",
                "sha256": "93b97bc56b9a773faa57b40a43ab8ae5a5872a7214e1332945831c65a5a77381"
            },
            "downloads": -1,
            "filename": "ndx_acquisition_module-0.1.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "30da556d63ce58797c9a7f9afa83377e",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 6549,
            "upload_time": "2023-02-01T00:27:25",
            "upload_time_iso_8601": "2023-02-01T00:27:25.252552Z",
            "url": "https://files.pythonhosted.org/packages/fd/73/a7097d2025be31f0e811baf1c8ee89c302384942b215e57428ca04e3092d/ndx_acquisition_module-0.1.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a1effa528d0f1c3a926c1a939beca8985d3b75858f40670e1f7f8f86a88267c0",
                "md5": "a8962e6a04237bca811d136728ef21b2",
                "sha256": "25c13bd6d8c3437f7ef20c4a7caf26f574ee1160a704683e8e579f9bcdcb37be"
            },
            "downloads": -1,
            "filename": "ndx-acquisition-module-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a8962e6a04237bca811d136728ef21b2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 15780,
            "upload_time": "2023-02-01T00:27:26",
            "upload_time_iso_8601": "2023-02-01T00:27:26.911158Z",
            "url": "https://files.pythonhosted.org/packages/a1/ef/fa528d0f1c3a926c1a939beca8985d3b75858f40670e1f7f8f86a88267c0/ndx-acquisition-module-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-01 00:27:26",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "ndx-acquisition-module"
}
        
Elapsed time: 0.06432s