|
| 1 | +--- |
| 2 | +title: "HDMF" |
| 3 | +description: "Hierarchical Data Modeling Framework for working with hierarchical data" |
| 4 | +category: "core-development" |
| 5 | +image: "/images/hdmf_logo_framed.png" |
| 6 | +source_url: "https://github.com/hdmf-dev/hdmf" |
| 7 | +docs_url: "https://hdmf.readthedocs.io/en/stable/" |
| 8 | +weight: 130 |
| 9 | +--- |
| 10 | + |
| 11 | +## Description |
| 12 | + |
| 13 | +The Hierarchical Data Modeling Framework (HDMF) is a Python package for working with hierarchical data. It provides APIs for specifying data models, reading and writing data to different storage backends, and representing data with Python objects. |
| 14 | + |
| 15 | +HDMF builds the foundation for the PyNWB Python API for NWB. It offers a flexible, extensible approach to data modeling that allows for the creation of self-describing, structured data formats like NWB. |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +```bash |
| 20 | +pip install hdmf |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +HDMF provides low-level functionality for working with hierarchical data, typically used by developers creating APIs like PyNWB: |
| 26 | + |
| 27 | +```python |
| 28 | +from hdmf.spec import GroupSpec, DatasetSpec, NamespaceBuilder |
| 29 | +from hdmf.common import DynamicTable |
| 30 | + |
| 31 | +# Define a new data type specification |
| 32 | +spec = GroupSpec( |
| 33 | + doc='A custom data type', |
| 34 | + data_type_def='MyType', |
| 35 | + datasets=[ |
| 36 | + DatasetSpec( |
| 37 | + doc='An example dataset', |
| 38 | + name='data', |
| 39 | + dtype='float' |
| 40 | + ) |
| 41 | + ] |
| 42 | +) |
| 43 | + |
| 44 | +# Create a namespace for your specification |
| 45 | +namespace_builder = NamespaceBuilder( |
| 46 | + doc='My extension', |
| 47 | + name='my_extension', |
| 48 | + full_name='My Custom Extension', |
| 49 | + version='0.1.0' |
| 50 | +) |
| 51 | +namespace_builder.add_spec('my_extension.yaml', spec) |
| 52 | + |
| 53 | +# Working with DynamicTable |
| 54 | +table = DynamicTable( |
| 55 | + name='example_table', |
| 56 | + description='An example table' |
| 57 | +) |
| 58 | +table.add_column('column1', 'A string column', dtype='text') |
| 59 | +table.add_row(column1='example data') |
| 60 | +``` |
| 61 | + |
| 62 | +## Additional Information |
| 63 | + |
| 64 | +HDMF is primarily of interest to developers who need to: |
| 65 | + |
| 66 | +1. Create or extend data APIs like PyNWB |
| 67 | +2. Implement new storage backends |
| 68 | +3. Support new serialization formats |
| 69 | +4. Develop data conversion tools |
| 70 | +5. Create validation tools |
| 71 | + |
| 72 | +Understanding HDMF is helpful for advanced NWB users who want to contribute to the core NWB ecosystem or develop sophisticated extensions and tools. |
0 commit comments