NeurodataWithoutBorders / pynwb

A Python API for working with Neurodata stored in the NWB Format
https://pynwb.readthedocs.io
Other
174 stars 85 forks source link

Enable write of compound data types with FORM #79

Closed ajtritt closed 6 years ago

ajtritt commented 6 years ago

Users would like to specify, read, and write compound data types.

The following subtasks will be needed to accomplish this.

nicain commented 6 years ago

First cut at this in: https://github.com/nicain/pynwb/tree/feature/table_writer

Try with this sample code:

import numpy as np
from pynwb import get_class, load_namespaces
from datetime import datetime
from pynwb import NWBFile
import pandas as pd
from form.backends.hdf5 import HDF5IO
from pynwb import get_build_manager

ns_path = "alleninstitute.namespace.yaml"
ext_source = "alleninstitute.extensions.yaml"

help_attr = NWBAttributeSpec(name='help',
                             dtype='str',
                             doc='no help for you',
                             value='YUP')

nwb_ds = NWBDatasetSpec(doc='dataset_doc',
                        dtype=[{'dtype': 'int', 'label': 'foo'},
                               {'dtype': 'float', 'label': 'bar'}],
                        name='table')

ns_builder = NWBNamespaceBuilder('Allen Institute extensions', "alleninstitute")
ext = NWBGroupSpec('An example table spec',
                   datasets=[nwb_ds],
                   neurodata_type_inc='NWBContainer',
                   neurodata_type_def='Table',
                   attributes=[help_attr])

ns_builder.add_spec(ext_source, ext)
ns_builder.export(ns_path)

ns_path = "alleninstitute.namespace.yaml"
load_namespaces(ns_path)

Table = get_class('Table', 'alleninstitute')
fs = Table(table={'foo':[0, 1, 2], 'bar':[3, 4, 5]},
           name='my_population',
           source='acquisition',
           unit='second',
           help='None')

f = NWBFile(file_name='tmp.nwb',
            source='me',
            session_description='my first synthetic recording',
            identifier='EXAMPLE_ID',
            session_start_time=datetime.now(),
            experimenter='Dr. Bilbo Baggins',
            lab='Bag End Labatory',
            institution='University of Middle Earth at the Shire',
            experiment_description='empty',
            session_id='LONELYMTN')

f.add_stimulus(fs)

manager = get_build_manager()
io = HDF5IO('tmp.nwb', manager, mode='w')
io.write(f)
io.close()
oruebel commented 6 years ago

A couple of quick questions and comments for discussion:

ajtritt commented 6 years ago

Thanks for the feedback Oliver. Here are my thoughts to the issues you have raised (in the same order)

ajtritt commented 6 years ago

Example use of table/compound data type from @nicain https://github.com/nicain/example_nwb

oruebel commented 6 years ago

@ajtritt I assume this issue can be closed as well?

jcfr commented 6 years ago

Based on most recent comment. Closing.

Please, re-open if this is a mistake.