Esempio n. 1
0
 def test_catch_dup_name(self):
     ns_builder1 = NWBNamespaceBuilder('Extension for us in my Lab',
                                       "pynwb_test_extension1",
                                       version='0.1.0')
     ext1 = NWBGroupSpec('A custom ElectricalSeries for my lab',
                         attributes=[
                             NWBAttributeSpec(name='trode_id',
                                              doc='the tetrode id',
                                              dtype='int')
                         ],
                         neurodata_type_inc='ElectricalSeries',
                         neurodata_type_def='TetrodeSeries')
     ns_builder1.add_spec(self.ext_source1, ext1)
     ns_builder1.export(self.ns_path1, outdir=self.tempdir)
     ns_builder2 = NWBNamespaceBuilder('Extension for us in my Lab',
                                       "pynwb_test_extension1",
                                       version='0.1.0')
     ext2 = NWBGroupSpec('A custom ElectricalSeries for my lab',
                         attributes=[
                             NWBAttributeSpec(name='trode_id',
                                              doc='the tetrode id',
                                              dtype='int')
                         ],
                         neurodata_type_inc='ElectricalSeries',
                         neurodata_type_def='TetrodeSeries')
     ns_builder2.add_spec(self.ext_source2, ext2)
     ns_builder2.export(self.ns_path2, outdir=self.tempdir)
     type_map = get_type_map(
         extensions=os.path.join(self.tempdir, self.ns_path1))
     type_map.load_namespaces(os.path.join(self.tempdir, self.ns_path2))
Esempio n. 2
0
def extract_from_schema(schema):

    # Extract fields from Schema:
    docval_list = [{'name': 'name', 'type': str, 'doc': 'name'}]
    attributes = []
    nwbfields_list = []
    for name, val in schema().fields.items():
        if type(val) == fields.List:
            attributes.append(
                NWBAttributeSpec(name=name,
                                 dtype=STYPE_DICT[type(val)],
                                 doc=val.metadata['doc'],
                                 shape=val.metadata['shape']))
        else:
            attributes.append(
                NWBAttributeSpec(name=name,
                                 dtype=STYPE_DICT[type(val)],
                                 doc=val.metadata['doc']))
        docval_list.append({
            'name': name,
            'type': TYPE_DICT[type(val)],
            'doc': val.metadata['doc']
        })
        nwbfields_list.append(name)

    return docval_list, attributes, nwbfields_list
Esempio n. 3
0
 def test_catch_dup_name(self):
     ns_builder1 = NWBNamespaceBuilder('Extension for us in my Lab',
                                       "pynwb_test_extension1")
     ext1 = NWBGroupSpec('A custom ElectricalSeries for my lab',
                         attributes=[
                             NWBAttributeSpec(name='trode_id',
                                              doc='the tetrode id',
                                              dtype='int')
                         ],
                         neurodata_type_inc='ElectricalSeries',
                         neurodata_type_def='TetrodeSeries')
     ns_builder1.add_spec(self.ext_source1, ext1)
     ns_builder1.export(self.ns_path1, outdir=self.tempdir)
     ns_builder2 = NWBNamespaceBuilder('Extension for us in my Lab',
                                       "pynwb_test_extension1")
     ext2 = NWBGroupSpec('A custom ElectricalSeries for my lab',
                         attributes=[
                             NWBAttributeSpec(name='trode_id',
                                              doc='the tetrode id',
                                              dtype='int')
                         ],
                         neurodata_type_inc='ElectricalSeries',
                         neurodata_type_def='TetrodeSeries')
     ns_builder2.add_spec(self.ext_source2, ext2)
     ns_builder2.export(self.ns_path2, outdir=self.tempdir)
     type_map = get_type_map(
         extensions=os.path.join(self.tempdir, self.ns_path1))
     with self.assertWarnsRegex(
             UserWarning,
             r"ignoring namespace '\S+' because it already exists"):
         type_map.load_namespaces(os.path.join(self.tempdir, self.ns_path2))
def build_settings(dict):
    """ WIP builds metadata based on passed in dict Does not support dict(s) deeper than 1 ATM"""

    # Settings:
    neurodata_type = 'MetaData'
    prefix = 'NHP'
    outdir = './'
    extension_doc = 'lab metadata extension'

    metadata_ext_group_spec = NWBGroupSpec(neurodata_type_def=neurodata_type,
                                           neurodata_type_inc='LabMetaData',
                                           doc=extension_doc,
                                           attributes=[
                                               NWBAttributeSpec(
                                                   name='experiment_id',
                                                   dtype='int',
                                                   doc='HW'),
                                               NWBAttributeSpec(name='test',
                                                                dtype='text',
                                                                doc='HW')
                                           ])

    #Export spec:
    ext_source = '%s_extension.yaml' % prefix
    ns_path = '%s_namespace.yaml' % prefix
    ns_builder = NWBNamespaceBuilder(extension_doc, prefix, version=str(1))
    ns_builder.add_spec(ext_source, metadata_ext_group_spec)
    ns_builder.export(ns_path, outdir=outdir)

    #Read spec and load namespace:
    ns_abs_path = os.path.join(outdir, ns_path)
    load_namespaces(ns_abs_path)

    class MetaData(LabMetaData):
        __nwbfields__ = ('experiment_id', 'test')

        @docval({
            'name': 'name',
            'type': str,
            'doc': 'name'
        }, {
            'name': 'experiment_id',
            'type': int,
            'doc': 'HW'
        }, {
            'name': 'test',
            'type': str,
            'doc': 'HW'
        })
        def __init__(self, **kwargs):
            name, ophys_experiment_id, test = popargs('name', 'experiment_id',
                                                      'test', kwargs)
            super(OphysBehaviorMetaData, self).__init__(name=name)
            self.experiment_id = experiment_id
            self.test = test

    register_class('MetaData', prefix, MetaData)
    return MetaData
Esempio n. 5
0
    def test_lab_meta(self):
        ns_builder = NWBNamespaceBuilder('Extension for use in my Lab', self.prefix, version='0.1.0')
        test_meta_ext = NWBGroupSpec(
            neurodata_type_def='MyTestMetaData',
            neurodata_type_inc='LabMetaData',
            doc='my test meta data',
            attributes=[
                NWBAttributeSpec(name='test_attr', dtype='float', doc='test_dtype')])
        ns_builder.add_spec(self.ext_source, test_meta_ext)
        ns_builder.export(self.ns_path, outdir=self.tempdir)
        ns_abs_path = os.path.join(self.tempdir, self.ns_path)

        load_namespaces(ns_abs_path)

        @register_class('MyTestMetaData', self.prefix)
        class MyTestMetaData(LabMetaData):
            __nwbfields__ = ('test_attr',)

            @docval({'name': 'name', 'type': str, 'doc': 'name'},
                    {'name': 'test_attr', 'type': float, 'doc': 'test attribute'})
            def __init__(self, **kwargs):
                test_attr = popargs('test_attr', kwargs)
                super(MyTestMetaData, self).__init__(**kwargs)
                self.test_attr = test_attr

        nwbfile = NWBFile("a file with header data", "NB123A",  datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal()))

        nwbfile.add_lab_meta_data(MyTestMetaData(name='test_name', test_attr=5.))
Esempio n. 6
0
def main():
    ns_builder = NWBNamespaceBuilder(doc='{{ cookiecutter.description }}',
                                     name='{{ cookiecutter.namespace }}',
                                     version='{{ cookiecutter.version }}',
                                     author='{{ cookiecutter.author }}',
                                     contact='{{ cookiecutter.email }}')

    # TODO: define the new data types
    custom_electrical_series = NWBGroupSpec(
        neurodata_type_def='TetrodeSeries',
        neurodata_type_inc='ElectricalSeries',
        doc='A custom ElectricalSeries for my lab',
        attributes=[
            NWBAttributeSpec(name='trode_id',
                             doc='the tetrode id',
                             dtype='int')
        ],
    )

    # TODO: add the new data types to this list
    new_data_types = [custom_electrical_series]

    # TODO: include the types that are used and their namespaces (where to find them)
    ns_builder.include_type('ElectricalSeries', namespace='core')

    export_spec(ns_builder, new_data_types)
Esempio n. 7
0
    def test_lab_meta_auto(self):
        ns_builder = NWBNamespaceBuilder('Extension for use in my Lab',
                                         self.prefix,
                                         version='0.1.0')
        test_meta_ext = NWBGroupSpec(neurodata_type_def='MyTestMetaData',
                                     neurodata_type_inc='LabMetaData',
                                     doc='my test meta data',
                                     attributes=[
                                         NWBAttributeSpec(name='test_attr',
                                                          dtype='float',
                                                          doc='test_dtype')
                                     ])
        ns_builder.add_spec(self.ext_source, test_meta_ext)
        ns_builder.export(self.ns_path, outdir=self.tempdir)
        ns_abs_path = os.path.join(self.tempdir, self.ns_path)

        load_namespaces(ns_abs_path)

        MyTestMetaData = get_class('MyTestMetaData', self.prefix)

        nwbfile = NWBFile("a file with header data", "NB123A",
                          datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal()))

        nwbfile.add_lab_meta_data(
            MyTestMetaData(name='test_name', test_attr=5.))
Esempio n. 8
0
 def test_load_namespace_with_reftype_attribute_check_autoclass_const(self):
     ns_builder = NWBNamespaceBuilder('Extension for use in my Lab',
                                      self.prefix)
     test_ds_ext = NWBDatasetSpec(
         doc='test dataset to add an attr',
         name='test_data',
         shape=(None, ),
         attributes=[
             NWBAttributeSpec(name='target_ds',
                              doc='the target the dataset applies to',
                              dtype=RefSpec('TimeSeries', 'object'))
         ],
         neurodata_type_def='my_new_type')
     ns_builder.add_spec(self.ext_source, test_ds_ext)
     ns_builder.export(self.ns_path, outdir=self.tempdir)
     type_map = get_type_map(
         extensions=os.path.join(self.tempdir, self.ns_path))
     my_new_type = type_map.get_container_cls(self.prefix, 'my_new_type')
     docval = None
     for tmp in get_docval(my_new_type.__init__):
         if tmp['name'] == 'target_ds':
             docval = tmp
             break
     self.assertIsNotNone(docval)
     self.assertEqual(docval['type'], TimeSeries)
Esempio n. 9
0
 def test_export(self):
     ns_builder = NWBNamespaceBuilder('Extension for use in my Lab', self.prefix, version='0.1.0')
     ext1 = NWBGroupSpec('A custom ElectricalSeries for my lab',
                         attributes=[NWBAttributeSpec(name='trode_id', doc='the tetrode id', dtype='int')],
                         neurodata_type_inc='ElectricalSeries',
                         neurodata_type_def='TetrodeSeries')
     ns_builder.add_spec(self.ext_source, ext1)
     ns_builder.export(self.ns_path, outdir=self.tempdir)
Esempio n. 10
0
 def test_export(self):
     ns_builder = NWBNamespaceBuilder('Extension for us in my Lab', "pynwb_test_extension")
     ext1 = NWBGroupSpec('A custom ElectricalSeries for my lab',
                         attributes=[NWBAttributeSpec('trode_id', 'int', 'the tetrode id')],
                         neurodata_type_inc='ElectricalSeries',
                         neurodata_type_def='TetrodeSeries')
     ns_builder.add_spec(self.ext_source, ext1)
     ns_builder.export(self.ns_path, outdir=self.tempdir)
Esempio n. 11
0
 def test_catch_dup_name(self):
     ns_builder1 = NWBNamespaceBuilder('Extension for us in my Lab', "pynwb_test_extension1")
     ext1 = NWBGroupSpec('A custom ElectricalSeries for my lab',
                         attributes=[NWBAttributeSpec('trode_id', 'int', 'the tetrode id')],
                         neurodata_type_inc='ElectricalSeries',
                         neurodata_type_def='TetrodeSeries')
     ns_builder1.add_spec(self.ext_source1, ext1)
     ns_builder1.export(self.ns_path1, outdir=self.tempdir)
     ns_builder2 = NWBNamespaceBuilder('Extension for us in my Lab', "pynwb_test_extension1")
     ext2 = NWBGroupSpec('A custom ElectricalSeries for my lab',
                         attributes=[NWBAttributeSpec('trode_id', 'int', 'the tetrode id')],
                         neurodata_type_inc='ElectricalSeries',
                         neurodata_type_def='TetrodeSeries')
     ns_builder2.add_spec(self.ext_source2, ext2)
     ns_builder2.export(self.ns_path2, outdir=self.tempdir)
     load_namespaces(os.path.join(self.tempdir, self.ns_path1))
     with self.assertRaises(KeyError):
         load_namespaces(os.path.join(self.tempdir, self.ns_path2))
Esempio n. 12
0
def _extract_attributes(attributes, fields_to_skip=None):
    res = []
    for name, val in attributes.items():
        if fields_to_skip and name in fields_to_skip:
            continue

        if type(val) == fields.List:
            res.append(NWBAttributeSpec(name=name,
                                        dtype=STYPE_DICT[type(val)],
                                        doc=val.metadata['doc'],
                                        shape=val.metadata['shape']))
        elif type(val) == fields.Nested:
            continue
        else:
            res.append(NWBAttributeSpec(name=name,
                                        dtype=STYPE_DICT[type(val)],
                                        doc=val.metadata['doc']))
    return res
Esempio n. 13
0
 def test_load_namespace_with_reftype_attribute(self):
     ns_builder = NWBNamespaceBuilder('Extension for use in my Lab', self.prefix, version='0.1.0')
     test_ds_ext = NWBDatasetSpec(doc='test dataset to add an attr',
                                  name='test_data', shape=(None,),
                                  attributes=[NWBAttributeSpec(name='target_ds',
                                                               doc='the target the dataset applies to',
                                                               dtype=RefSpec('TimeSeries', 'object'))],
                                  neurodata_type_def='my_new_type')
     ns_builder.add_spec(self.ext_source, test_ds_ext)
     ns_builder.export(self.ns_path, outdir=self.tempdir)
     get_type_map(extensions=os.path.join(self.tempdir, self.ns_path))
Esempio n. 14
0
def main():
    # these arguments were auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(
        doc='NWB extension for survey/behavioral data',
        name='ndx-survey-data',
        version='0.2.0',
        author=list(map(str.strip, 'Ben Dichter, Armin Najarpour Foroushani'.split(','))),
        contact=list(map(str.strip, '*****@*****.**'.split(',')))
    )

    for type_name in ('DynamicTable', 'VectorData'):
        ns_builder.include_type(type_name, namespace='core')

    survey_data = NWBGroupSpec(
        doc='Table that holds information about the survey/behavior',
        neurodata_type_def='SurveyTable',
        neurodata_type_inc='DynamicTable',
        default_name='survey_data'
    )

    question_response = NWBDatasetSpec(
        doc='Column that holds information about a question',
        neurodata_type_def='QuestionResponse',
        neurodata_type_inc='VectorData',
        default_name='question_response',
        attributes=[NWBAttributeSpec(name='options',
                                     doc='Response Options',
                                     dtype='text',
                                     shape=(None,),
                                     dims=('num_options',))]
    )

    survey_data.add_dataset(
        neurodata_type_inc='VectorData',
        doc='UNIX time of survey response',
        name='unix_timestamp',
        dtype='int',
        shape=(None,),
        dims=('num_responses',)
    )

    new_data_types = [survey_data, question_response]

    # export the spec to yaml files in the spec folder
    output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'spec'))
    export_spec(ns_builder, new_data_types, output_dir)
Esempio n. 15
0
def main():
    # these arguments were auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(
        doc="""{{ cookiecutter.description }}""",
        name="""{{ cookiecutter.namespace }}""",
        version="""{{ cookiecutter.version }}""",
        author=list(map(str.strip,
                        """{{ cookiecutter.author }}""".split(','))),
        contact=list(map(str.strip,
                         """{{ cookiecutter.email }}""".split(','))))

    # TODO: specify the neurodata_types that are used by the extension as well
    # as in which namespace they are found
    # this is similar to specifying the Python modules that need to be imported
    # to use your new data types
    ns_builder.include_type('ElectricalSeries', namespace='core')

    # TODO: define your new data types
    # see https://pynwb.readthedocs.io/en/latest/extensions.html#extending-nwb
    # for more information
    tetrode_series = NWBGroupSpec(
        neurodata_type_def='TetrodeSeries',
        neurodata_type_inc='ElectricalSeries',
        doc=('An extension of ElectricalSeries to include the tetrode ID for '
             'each time series.'),
        attributes=[
            NWBAttributeSpec(name='trode_id',
                             doc='The tetrode ID.',
                             dtype='int32')
        ],
    )

    # TODO: add all of your new data types to this list
    new_data_types = [tetrode_series]

    # export the spec to yaml files in the spec folder
    output_dir = os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', '..', 'spec'))
    export_spec(ns_builder, new_data_types, output_dir)
Esempio n. 16
0
def main():
    # these arguments were auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(
        doc=
        """An NWB extension to describe the detailed genotype of an experimental subject""",
        name="""ndx-genotype""",
        version="""0.1.0""",
        author=list(
            map(str.strip,
                """Ryan Ly, Oliver Ruebel, Pam Baker, Lydia Ng""".split(','))),
        contact=list(map(str.strip, """*****@*****.**""".split(','))))

    ns_builder.include_type('Subject', namespace='core')
    ns_builder.include_type('NWBFile', namespace='core')
    ns_builder.include_type('NWBContainer', namespace='core')
    ns_builder.include_type('DynamicTable', namespace='core')
    ns_builder.include_type('VectorData', namespace='core')
    ns_builder.include_type('Data', namespace='core')
    ns_builder.include_type('Container', namespace='core')

    genotypes_table_spec = NWBGroupSpec(
        neurodata_type_def='GenotypesTable',
        neurodata_type_inc='DynamicTable',
        doc='A table to hold structured genotype information.',
        attributes=[
            NWBAttributeSpec(
                name='process',
                doc=
                'Description of the process or assay used to determine the genotype, e.g., PCR.',
                dtype='text',
                required=False,
            ),
            NWBAttributeSpec(
                name='process_url',
                doc=
                ('URL to online document that provides further details of the protocol used, e.g., '
                 'https://dx.doi.org/10.17504/protocols.io.yjifuke'),
                dtype='text',
                required=False,
            ),
            NWBAttributeSpec(
                name='assembly',
                doc=
                'Description of the assembly of the reference genome, e.g., GRCm38.p6.',
                dtype='text',
                required=False,
            ),
            NWBAttributeSpec(
                name='annotation',
                doc=('Description of the annotation of the reference genome, '
                     'e.g., NCBI Mus musculus Annotation Release 108.'),
                dtype='text',
                required=False,
            ),
        ],
        datasets=[
            NWBDatasetSpec(
                name='locus_symbol',
                neurodata_type_inc='VectorData',
                doc='Symbol/name of the locus, e.g., Rorb.',
                dtype='text',
            ),
            NWBDatasetSpec(
                name='locus_type',
                neurodata_type_inc='VectorData',
                doc=
                'Type of the locus, e.g., Gene, Transgene, Unclassified other.',
                dtype='text',
                quantity='?',
            ),
            NWBDatasetSpec(
                name='allele1_symbol',
                neurodata_type_inc='VectorData',
                doc=('Symbol/name of the first allele, e.g., Rorb-IRES2-Cre. '
                     '"wt" should be used to represent wild-type.'),
                dtype='text',
            ),
            NWBDatasetSpec(
                name='allele1_type',
                neurodata_type_inc='VectorData',
                doc=
                ('Type of the first allele, e.g., Targeted (Recombinase), '
                 'Transgenic (Null/knockout, Transactivator), Targeted (Conditional ready, Inducible, Reporter).'
                 '"Wild Type" should be used to represent wild-type. Allele types can be found at: '
                 'http://www.informatics.jax.org/userhelp/ALLELE_phenotypic_categories_help.shtml#method'
                 ),
                dtype='text',
                quantity='?',
            ),
            NWBDatasetSpec(
                name='allele2_symbol',
                neurodata_type_inc='VectorData',
                doc=('Smybol/name of the second allele, e.g., Rorb-IRES2-Cre. '
                     '"wt" should be used to represent wild-type.'),
                dtype='text',
            ),
            NWBDatasetSpec(
                name='allele2_type',
                neurodata_type_inc='VectorData',
                doc=
                ('Type of the second allele, e.g., Targeted (Recombinase), '
                 'Transgenic (Null/knockout, Transactivator), Targeted (Conditional ready, Inducible, Reporter).'
                 '"Wild Type" should be used to represent wild-type. Allele types can be found at: '
                 'http://www.informatics.jax.org/userhelp/ALLELE_phenotypic_categories_help.shtml#method'
                 ),
                dtype='text',
                quantity='?',
            ),
            NWBDatasetSpec(
                name='allele3_symbol',
                neurodata_type_inc='VectorData',
                doc=('Symbol/name of the third allele, e.g., Rorb-IRES2-Cre. '
                     '"wt" should be used to represent wild-type.'),
                dtype='text',
                quantity='?',
            ),
            NWBDatasetSpec(
                name='allele3_type',
                neurodata_type_inc='VectorData',
                doc=
                ('Type of the third allele, e.g., Targeted (Recombinase), '
                 'Transgenic (Null/knockout, Transactivator), Targeted (Conditional ready, Inducible, Reporter).'
                 '"Wild Type" should be used to represent wild-type. Allele types can be found at: '
                 'http://www.informatics.jax.org/userhelp/ALLELE_phenotypic_categories_help.shtml#method'
                 ),
                dtype='text',
                quantity='?',
            ),
        ],
    )

    genotype_subject_spec = NWBGroupSpec(
        neurodata_type_def='GenotypeSubject',
        neurodata_type_inc='Subject',
        doc=
        ('An enhanced Subject type that has an additional field for a genotype table. '
         'NOTE: If this proposal for extension '
         'to NWB gets merged with the core schema, then this type would be removed and the'
         'Subject specification updated instead.'),
        groups=[
            NWBGroupSpec(
                name='genotypes_table',
                neurodata_type_inc='GenotypeTable',
                doc='Structured genotype information for the subject.',
                quantity='?',
            ),
        ],
    )

    genotype_nwbfile_spec = NWBGroupSpec(
        neurodata_type_def='GenotypeNWBFile',
        neurodata_type_inc='NWBFile',
        doc=
        ('Extension of the NWBFile class to allow 1) placing the new GenotypeSubject type '
         'in /general/subject in the NWBFile and 2) placing the new ontologies group containing an '
         'ontology table and ontology map. NOTE: If this proposal for extension '
         'to NWB gets merged with the core schema, then this type would be removed and the '
         'NWBFile specification updated instead. The ontologies types will be incorporated from HDMF '
         'when they are finalized.'),
        groups=[
            NWBGroupSpec(
                name='general',  # override existing general group
                doc='Expanded definition of general from NWBFile.',
                groups=[
                    NWBGroupSpec(
                        name='subject',  # override existing subject type
                        neurodata_type_inc='GenotypeSubject',
                        doc=
                        'Subject information with structured genotype information.',
                        quantity='?',
                    ),
                ],
            ),
            NWBGroupSpec(
                name='.ontologies',
                doc='Information about ontological terms used in this file.',
                quantity='?',
                datasets=[
                    NWBDatasetSpec(
                        name='objects',
                        neurodata_type_inc='OntologyTable',
                        doc='The objects that conform to an ontology.',
                    ),
                    NWBDatasetSpec(
                        name='terms',
                        neurodata_type_inc='OntologyMap',
                        doc='The ontological terms that get used in this file.',
                    ),
                ],
            ),
        ],
    )

    ontology_table_spec = NWBDatasetSpec(
        neurodata_type_def='OntologyTable',
        doc=
        ('A table for identifying which objects in a file contain values that correspond to ontology terms or '
         'centrally registered IDs (CRIDs)'),
        dtype=[
            NWBDtypeSpec(name='id',
                         dtype='uint64',
                         doc='The unique identifier in this table.'),
            NWBDtypeSpec(
                name='object_id',
                dtype='text',
                doc='The UUID for the object that uses this ontology term.'),
            NWBDtypeSpec(
                name='field',
                dtype='text',
                doc=
                'The field from the object (specified by object_id) that uses this ontological term.'
            ),
            NWBDtypeSpec(
                name='item',
                dtype='uint64',
                doc='An index into the OntologyMap that contains the term.'),
        ],
        shape=[None],
    )

    ontology_map_spec = NWBDatasetSpec(
        neurodata_type_def='OntologyMap',
        doc=
        ('A table for mapping user terms (i.e., keys) to ontology terms / registry symbols / '
         'centrally registered IDs (CRIDs)'),
        dtype=[
            NWBDtypeSpec(name='id',
                         dtype='uint64',
                         doc='The unique identifier in this table.'),
            NWBDtypeSpec(
                name='key',
                dtype='text',
                doc=
                'The user key that maps to the ontology term / registry symbol.'
            ),
            NWBDtypeSpec(
                name='ontology',
                dtype='text',
                doc='The ontology/registry that the term/symbol comes from.'),
            NWBDtypeSpec(
                name='uri',
                dtype='text',
                doc=
                'The unique resource identifier for the ontology term / registry symbol.'
            ),
        ],
        shape=[None],
    )

    new_data_types = [
        genotypes_table_spec, genotype_subject_spec, genotype_nwbfile_spec,
        ontology_table_spec, ontology_map_spec
    ]

    # export the spec to yaml files in the spec folder
    output_dir = os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', '..', 'spec'))
    export_spec(ns_builder, new_data_types, output_dir)
                        NWBGroupSpec, NWBNamespaceBuilder)

# This is the script used to generate the AIBS ecephys NWB extension .yaml
# files. It can be run by installing pynwb and executing
# `nwb_extension_builder.py`. It will generate the .yaml extension files in
# the same directory which the script is run in. For more details see:
# https://pynwb.readthedocs.io/en/stable/extensions.html

ns_builder = NWBNamespaceBuilder(doc="Allen Institute Ecephys Extension",
                                 version="0.2.0",
                                 name="ndx-aibs-ecephys",
                                 author="Allen Institute for Brain Science",
                                 contact="*****@*****.**")

probe_id_attr = NWBAttributeSpec(name="probe_id",
                                 doc="Unique ID of the neuropixels probe",
                                 dtype="int")

# Ecephys probe device extension (inherits from NWB `Device`)
sampling_rate_attr = NWBAttributeSpec(name="sampling_rate",
                                      doc="The sampling rate for the device",
                                      dtype="float64")

ecephys_probe_attributes = [sampling_rate_attr, probe_id_attr]

ecephys_probe_ext = NWBGroupSpec(doc="A neuropixels probe device",
                                 attributes=ecephys_probe_attributes,
                                 neurodata_type_def="EcephysProbe",
                                 neurodata_type_inc="Device")

# Ecephys electrode group extension (inherits from NWB `ElectrodeGroup`)
Esempio n. 18
0
def main():
    # these arguments were auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(
        doc='NWB extension to store single or multi-animal pose tracking.',
        name='ndx-pose',
        version='0.2.0',
        author=['Ryan Ly', 'Ben Dichter', 'Alexander Mathis', 'Talmo Pereira'],
        contact=['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'],
    )

    ns_builder.include_type('SpatialSeries', namespace='core')
    ns_builder.include_type('TimeSeries', namespace='core')
    ns_builder.include_type('NWBDataInterface', namespace='core')
    ns_builder.include_type('NWBContainer', namespace='core')

    pose_estimation_series = NWBGroupSpec(
        neurodata_type_def='PoseEstimationSeries',
        neurodata_type_inc='SpatialSeries',
        doc='Estimated position (x, y) or (x, y, z) of a body part over time.',
        datasets=[
            NWBDatasetSpec(
                name='data',
                doc='Estimated position (x, y) or (x, y, z).',
                dtype='float32',
                dims=[['num_frames', 'x, y'], ['num_frames', 'x, y, z']],
                shape=[[None, 2], [None, 3]],
                attributes=[
                    NWBAttributeSpec(
                        name='unit',
                        dtype='text',
                        default_value='pixels',
                        doc=("Base unit of measurement for working with the data. The default value "
                             "is 'pixels'. Actual stored values are not necessarily stored in these units. "
                             "To access the data in these units, multiply 'data' by 'conversion'."),
                        required=True,
                    ),
                ],
            ),
            NWBDatasetSpec(
                name='confidence',
                doc='Confidence or likelihood of the estimated positions, scaled to be between 0 and 1.',
                dtype='float32',
                dims=['num_frames'],
                shape=[None],
                attributes=[
                    NWBAttributeSpec(
                        name='definition',
                        dtype='text',
                        doc=("Description of how the confidence was computed, e.g., "
                             "'Softmax output of the deep neural network'."),
                        required=False,
                    ),
                ],
            ),
        ],
    )

    pose_grouping_series = NWBGroupSpec(
        neurodata_type_def='PoseGroupingSeries',
        neurodata_type_inc='TimeSeries',
        doc='Instance-level part grouping timeseries for the individual animal. This contains metadata of the part grouping procedure for multi-animal pose trackers.',
        datasets=[
            NWBDatasetSpec(
                name='name',
                doc="Description of the type of localization, e.g., 'Centroid' or 'Bounding box'.",
                dtype='text'
            ),
            NWBDatasetSpec(
                name='data',
                doc='Score of the grouping approach that associated all of the keypoints to the same animal within the frame.',
                dtype='float32',
                dims=['num_frames'],
                shape=[None]
            ),
            NWBDatasetSpec(
                name='location',
                doc='Animal location for two-stage (top-down) multi-animal models, e.g., centroid or bounding box.',
                dtype='float32',
                dims=[['num_frames', 'x, y'], ['num_frames', 'x, y, z'], ['num_frames', 'x1, y1, x2, y2'], ['num_frames', 'x1, y1, z1, x2, y2, z2']],
                shape=[[None, 2], [None, 3], [None, 4], [None, 6]],
                quantity="?"
            ),
        ],
    )


    animal_identity_series = NWBGroupSpec(
        neurodata_type_def='AnimalIdentitySeries',
        neurodata_type_inc='TimeSeries',
        doc='Identity of the animal predicted by a tracking or re-ID algorithm in multi-animal experiments.',
        datasets=[
            NWBDatasetSpec(
                name='data',
                doc='Score of the identity assignment approach that associated all of the keypoints to the same animal over frames, e.g., MOT tracking score or ID classification probability.',
                dtype='float32',
                dims=['num_frames'],
                shape=[None],
            ),
            NWBDatasetSpec(
                name='name',
                doc='Unique animal identifier, track label, or class name used to identify this animal in the experiment.',
                dtype='text'
            ),
        ],
    )

    pose_estimation = NWBGroupSpec(
        neurodata_type_def='PoseEstimation',
        neurodata_type_inc='NWBDataInterface',
        doc=('Group that holds estimated position data for multiple body parts, computed from the same video with '
             'the same tool/algorithm. The timestamps of each child PoseEstimationSeries type should be the same.'),
        default_name='PoseEstimation',
        groups=[
            NWBGroupSpec(
                neurodata_type_inc='PoseEstimationSeries',
                doc='Estimated position data for each body part.',
                quantity='*',
            ),
            NWBGroupSpec(
                neurodata_type_inc='PoseGroupingSeries',
                doc='Part grouping metadata for the individual in multi-animal experiments.',
                quantity='?',
            ),
            NWBGroupSpec(
                neurodata_type_inc='AnimalIdentitySeries',
                doc='Predicted identity of the individual in multi-animal experiments.',
                quantity='?',
            ),
        ],
        datasets=[
            NWBDatasetSpec(
                name='description',
                doc='Description of the pose estimation procedure and output.',
                dtype='text',
                quantity='?',
            ),
            NWBDatasetSpec(
                name='original_videos',
                doc='Paths to the original video files. The number of files should equal the number of camera devices.',
                dtype='text',
                dims=['num_files'],
                shape=[None],
                quantity='?',
            ),
            NWBDatasetSpec(
                name='labeled_videos',
                doc='Paths to the labeled video files. The number of files should equal the number of camera devices.',
                dtype='text',
                dims=['num_files'],
                shape=[None],
                quantity='?',
            ),
            NWBDatasetSpec(
                name='dimensions',
                doc='Dimensions of each labeled video file.',
                dtype='uint8',
                dims=['num_files', 'width, height'],
                shape=[None, 2],
                quantity='?',
            ),
            NWBDatasetSpec(
                name='scorer',
                doc='Name of the scorer / algorithm used.',
                dtype='text',
                quantity='?',
            ),
            NWBDatasetSpec(
                name='source_software',
                doc='Name of the software tool used. Specifying the version attribute is strongly encouraged.',
                dtype='text',
                quantity='?',
                attributes=[
                    NWBAttributeSpec(
                        name='version',
                        doc='Version string of the software tool used.',
                        dtype='text',
                        required=False,
                    ),
                ],
            ),
            NWBDatasetSpec(
                name='nodes',
                doc=('Array of body part names corresponding to the names of the SpatialSeries objects within this '
                     'group.'),
                dtype='text',
                dims=['num_body_parts'],
                shape=[None],
                quantity='?',
            ),
            NWBDatasetSpec(
                name='edges',
                doc=("Array of pairs of indices corresponding to edges between nodes. Index values correspond to row "
                     "indices of the 'nodes' dataset. Index values use 0-indexing."),
                dtype='uint8',
                dims=['num_edges', 'nodes_index, nodes_index'],
                shape=[None, 2],
                quantity='?',
            ),
        ],
        # TODO: collections of multiple links is currently buggy in PyNWB/HDMF
        # links=[
        #     NWBLinkSpec(
        #         target_type='Device',
        #         doc='Camera(s) used to record the videos.',
        #         quantity='*',
        #     ),
        # ],
    )

    new_data_types = [pose_estimation_series, pose_estimation, pose_grouping_series, animal_identity_series]

    # export the spec to yaml files in the spec folder
    output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'spec'))
    export_spec(ns_builder, new_data_types, output_dir)
Esempio n. 19
0
def main():
    # these arguments were auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(
        doc='An extension to hold metadata about a multi-electrode probe.',
        name='ndx-probe',
        version='0.1.0',
        author=list(map(str.strip, 'Ryan Ly'.split(','))),
        contact=list(map(str.strip, '*****@*****.**'.split(',')))
    )

    ns_builder.include_type('ElectrodeGroup', namespace='core')

    stereotrode = NWBGroupSpec(
        neurodata_type_def='Stereotrode',
        neurodata_type_inc='ElectrodeGroup',
        doc=('A subtype of ElectrodeGroup to include metadata about a single stereotrode (group of 2 closely spaced '
             'electrodes) on a shank of a probe.'),
        attributes=[
            NWBAttributeSpec(
                name='location',
                doc=('Location of the stereotrode in the brain (optional). Specify the area, layer, comments on '
                     'estimation of area/layer, etc. Use standard atlas names for anatomical regions when '
                     'possible.'),
                dtype='text',
                required=False
            )
        ]
    )

    tetrode = NWBGroupSpec(
        neurodata_type_def='Tetrode',
        neurodata_type_inc='ElectrodeGroup',
        doc=('A subtype of ElectrodeGroup to include metadata about a single tetrode (group of 4 closely spaced '
             'electrodes) on a shank of a probe.'),
        attributes=[
            NWBAttributeSpec(
                name='location',
                doc=('Location of the tetrode in the brain (optional). Specify the area, layer, comments on '
                     'estimation of area/layer, etc. Use standard atlas names for anatomical regions when '
                     'possible.'),
                dtype='text',
                required=False
            )
        ]
    )

    shank = NWBGroupSpec(
        neurodata_type_def='Shank',
        neurodata_type_inc='ElectrodeGroup',
        doc=('A subtype of ElectrodeGroup to include metadata about a single shank of a probe.')
    )

    entry_point_ap_dtype = NWBDtypeSpec(name='ap',
                                        dtype='float',
                                        doc='Anterior-Posterior coordinate, in mm.')
    entry_point_lr_dtype = NWBDtypeSpec(name='lr',
                                        dtype='float',
                                        doc='Left-Right coordinate, in mm.')
    entry_point_dv_dtype = NWBDtypeSpec(name='dv',
                                        dtype='float',
                                        doc='Dorsal-Ventral coordinate, in mm.')

    entry_point = NWBDatasetSpec(
        name='entry_point',
        doc='The coordinates of the entry point.',
        dtype=[entry_point_ap_dtype, entry_point_lr_dtype, entry_point_dv_dtype],  # compound dtype
        attributes=[
            NWBAttributeSpec(
                name='reference',
                doc=('Description of the reference atlas used for the coordinates, e.g., Allen Institute Common '
                     'Coordinate Framework v3, or stereotaxic coordinates with zero point at ear-bar zero.'),
                dtype='text'
            ),
            NWBAttributeSpec(
                name='unit',
                doc='Unit of measurement for the coordinates.',
                dtype='text',
                value='millimeters'
            )
        ],
        quantity='?'
    )

    angle_coronal_dtype = NWBDtypeSpec(
       name='coronal',
       dtype='float',
       doc='Coronal angle, in degrees'
    )
    angle_sagittal_dtype = NWBDtypeSpec(
        name='sagittal',
        dtype='float',
        doc='Sagittal angle, in degrees'
    )
    angle_axial_dtype = NWBDtypeSpec(
        name='axial',
        dtype='float',
        doc='Axial angle, in degrees'
    )

    angle = NWBDatasetSpec(
        name='angle',
        doc='The angle of the probe.',
        dtype=[angle_coronal_dtype, angle_sagittal_dtype, angle_axial_dtype],  # compound dtype
        attributes=[
            NWBAttributeSpec(
                name='reference',
                doc='Description of the reference frame used for the angles, e.g., which direction is angle zero.',
                dtype='text'
            ),
            NWBAttributeSpec(
                name='unit',
                doc='Unit of measurement for the angles.',
                dtype='text',
                value='degrees'
            )
        ],
        quantity='?'
    )

    distance_advanced = NWBDatasetSpec(
        name='distance_advanced',
        doc='The distance that the probe was advanced from the surface of the brain, in mm.',
        dtype='float',
        attributes=[
            NWBAttributeSpec(
                name='unit',
                doc='Unit of measurement for the distance.',
                dtype='text',
                value='millimeters'
            )
        ],
        quantity='?'
    )

    probe = NWBGroupSpec(
        neurodata_type_def='Probe',
        neurodata_type_inc='Device',
        doc=('Metadata about a multi-electrode probe (or array), which contains one or many shanks. '
             'Each shank should be represented as an ElectrodeGroup. Sub-groupings within a shank '
             'should also be represented as ElectrodeGroups.'),
        attributes=[
            NWBAttributeSpec(
                name='description',
                doc='Description of the probe as free-form text.',
                dtype='text',
            ),
            NWBAttributeSpec(
                name='model',
                doc='Model name of the probe.',
                dtype='text',
            ),
            NWBAttributeSpec(
                name='manufacturer',
                doc='Manufacturer name of the probe.',
                dtype='text',
            ),
            NWBAttributeSpec(
                name='id',
                doc='Serial number or other unique identifier of the probe.',
                dtype='text',
                required=False
            ),
        ],
        datasets=[
            entry_point,
            angle,
            distance_advanced,
        ]
    )

    new_data_types = [stereotrode, tetrode, shank, probe]

    # export the spec to yaml files in the spec folder
    output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'spec'))
    export_spec(ns_builder, new_data_types, output_dir)
Esempio n. 20
0
def main():
    ns_builder = NWBNamespaceBuilder(
        doc='NWB extension for hierarchical behavioral data',
        name='ndx-hierarchical-behavioral-data',
        version='0.1.0',
        author=['Ben Dichter', 'Armin Najarpour Foroushani'],
        contact=['*****@*****.**'])

    # Add the type we want to include from core to this list
    include_core_types = ['DynamicTable', 'DynamicTableRegion', 'VectorIndex']
    # Include the types that are used by the extension and their namespaces (where to find them)
    for type_name in include_core_types:
        ns_builder.include_type(type_name, namespace='core')

    # Create our table to store phonemes
    phonemes_table_spec = NWBGroupSpec(
        name='phonemes',
        neurodata_type_def='PhonemesTable',
        neurodata_type_inc='DynamicTable',
        doc='A table to store different phonemes',
        attributes=[
            NWBAttributeSpec(
                name='description',
                dtype='text',
                doc='Description of what is in this dynamic table.',
                value='Table for storing phonemes related data')
        ],
        datasets=[
            NWBDatasetSpec(
                name='label',
                neurodata_type_inc='DynamicTableRegion',
                doc=
                'Column for storing phonemes. Each row in this DynamicTableRegion is a phoneme.',
                dims=('num_phonemes', ),
                shape=(None, ),
                dtype='text')
        ])

    # Create our table to store syllables
    syllables_table_spec = NWBGroupSpec(
        name='syllables',
        neurodata_type_def='SyllablesTable',
        neurodata_type_inc='DynamicTable',
        doc='A table to store different syllables',
        attributes=[
            NWBAttributeSpec(
                name='description',
                dtype='text',
                doc='Description of what is in this dynamic table.',
                value='Table for storing syllables related data')
        ],
        datasets=[
            NWBDatasetSpec(
                name='label',
                neurodata_type_inc='DynamicTableRegion',
                doc=
                'Column for storing syllables. Each row in this DynamicTableRegion is a syllable '
                'consisting of phonemes.',
                attributes=[
                    NWBAttributeSpec(
                        name='table',
                        dtype=NWBRefSpec(target_type='PhonemesTable',
                                         reftype='object'),
                        doc='Reference to the PhonemesTable table that '
                        'this table region applies to. This specializes the '
                        'attribute inherited from DynamicTableRegion to fix '
                        'the type of table that can be referenced here.')
                ],
                dims=('num_syllables', ),
                shape=(None, ),
                dtype='text'),
            NWBDatasetSpec(
                name='phonemes_index',
                neurodata_type_inc='VectorIndex',
                doc=
                'Column for storing a link to the constituting phonemes (rows)',
                dims=('num_syllables', ),
                shape=(None, ))
        ])

    # Create our table to store words
    words_table_spec = NWBGroupSpec(
        name='words',
        neurodata_type_def='WordsTable',
        neurodata_type_inc='DynamicTable',
        doc='A table to store different words',
        attributes=[
            NWBAttributeSpec(
                name='description',
                dtype='text',
                doc='Description of what is in this dynamic table.',
                value='Table for storing word related data')
        ],
        datasets=[
            NWBDatasetSpec(
                name='label',
                neurodata_type_inc='DynamicTableRegion',
                doc=
                'Column for storing words. Each row in this DynamicTableRegion is a word '
                'consisting of syllables.',
                attributes=[
                    NWBAttributeSpec(
                        name='table',
                        dtype=NWBRefSpec(target_type='SyllablesTable',
                                         reftype='object'),
                        doc='Reference to the SyllablesTable table that '
                        'this table region applies to. This specializes the '
                        'attribute inherited from DynamicTableRegion to fix '
                        'the type of table that can be referenced here.')
                ],
                dims=('num_words', ),
                shape=(None, ),
                dtype='text'),
            NWBDatasetSpec(
                name='syllables_index',
                neurodata_type_inc='VectorIndex',
                doc=
                'Column for storing a link to the constituting syllables (rows)',
                dims=('num_words', ),
                shape=(None, ))
        ])

    # Create our table to store sentences
    sentences_table_spec = NWBGroupSpec(
        name='sentences',
        neurodata_type_def='SentencesTable',
        neurodata_type_inc='DynamicTable',
        doc='A table to store different sentences',
        attributes=[
            NWBAttributeSpec(
                name='description',
                dtype='text',
                doc='Description of what is in this dynamic table.',
                value='Table for storing sentence related data')
        ],
        datasets=[
            NWBDatasetSpec(
                name='label',
                neurodata_type_inc='DynamicTableRegion',
                doc=
                'Column for storing sentences. Each row in this DynamicTableRegion is a sentence '
                'consisting of words.',
                attributes=[
                    NWBAttributeSpec(
                        name='table',
                        dtype=NWBRefSpec(target_type='WordsTable',
                                         reftype='object'),
                        doc='Reference to the WordsTable table that '
                        'this table region applies to. This specializes the '
                        'attribute inherited from DynamicTableRegion to fix '
                        'the type of table that can be referenced here.')
                ],
                dims=('num_sentences', ),
                shape=(None, ),
                dtype='text'),
            NWBDatasetSpec(
                name='words_index',
                neurodata_type_inc='VectorIndex',
                doc=
                'Column for storing a link to the constituting words (rows)',
                dims=('num_sentences', ),
                shape=(None, ))
        ])

    # Create a table to group together all the above groups
    transcription_table_spec = NWBGroupSpec(
        name='transcription',
        neurodata_type_def='TranscriptionTable',
        neurodata_type_inc='DynamicTable',
        doc=
        'This DynamicTable is intended to group together a collection of sub-tables. Each sub-table is a '
        'DynamicTable itself. This type effectively defines a 2-level table in which the main data is stored in '
        'the main table implemented by this type and additional columns of the table are grouped into categories, '
        'with each category being represented by a separate DynamicTable stored within the group.'
        'Here, sub-tables are: sentence table which stores different sentences; words table which stores '
        'constituting words; syllables table for storing syllables of each word; and phonemes table for storing '
        'consisting of phonemes.',
        attributes=[
            NWBAttributeSpec(
                name='categories',
                dtype='text',
                dims=['num_categories'],
                doc=
                'The names of the categories in this TranscriptionTable. Each '
                'category is represented by one DynamicTable stored in the parent group.'
                'This attribute should be used to specify an order of categories.',
                shape=[None])
        ],
        groups=[
            NWBGroupSpec(
                neurodata_type_inc='DynamicTable',
                doc=
                'A DynamicTable representing a particular category for columns in the '
                'TranscriptionTable parent container. The name of the category is given by '
                'the name of the DynamicTable and its description by the description attribute '
                'of the DynamicTable.',
                quantity='*')
        ])

    # Add all of our new data types to this list
    new_data_types = [
        sentences_table_spec, words_table_spec, syllables_table_spec,
        phonemes_table_spec, transcription_table_spec
    ]

    # export the spec to yaml files in the spec folder
    output_dir = os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', '..', 'spec'))
    export_spec(ns_builder, new_data_types, output_dir)
def main():
    # the values for ns_builder are auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(doc='Implement proposal for hierarchical metadata structure '
                                         'for intracellular electrophysiology data ',
                                     name='ndx-icephys-meta',
                                     version='0.2.0',
                                     author=['Oliver Ruebel',
                                             'Ryan Ly',
                                             'Benjamin Dichter',
                                             'Thomas Braun',
                                             'Andrew Tritt'],
                                     contact=['*****@*****.**',
                                              '*****@*****.**',
                                              '*****@*****.**',
                                              'None',
                                              '*****@*****.**'])

    # Create a vector-data column that references a range in a time series. I/e., a VectorData column
    # with a compound data type storing the start_index, count, and TimeSeries reference
    reference_timeseries_vectordata = NWBDatasetSpec(
        neurodata_type_inc='VectorData',
        neurodata_type_def='TimeSeriesReferenceVectorData',
        doc='Column storing references to a TimeSeries (rows). For each TimeSeries this VectorData '
            'column stores the start_index and count to indicate the range in time to be selected '
            'as well as an object reference to the TimeSeries.',
        dtype=[
            NWBDtypeSpec(name='idx_start',
                         dtype='int32',
                         doc="Start index into the TimeSeries 'data' and 'timestamp' datasets of the "
                              "referenced TimeSeries. The first dimension of those arrays is always time."),
            NWBDtypeSpec(name='count',
                         dtype='int32',
                         doc="Number of data samples available in this time series, during this epoch"),
            NWBDtypeSpec(name='timeseries',
                         dtype=NWBRefSpec(target_type='TimeSeries',
                                          reftype='object'),
                         doc='The TimeSeries that this index applies to')
        ]
    )

    # Create a collection of aligned dynamic tables
    aligned_dynamic_tables_spec = NWBGroupSpec(
        neurodata_type_inc='DynamicTable',
        neurodata_type_def='AlignedDynamicTable',
        doc='DynamicTable container that subports storing a collection of subtables. Each sub-table is a '
            'DynamicTable itself that is aligned with the main table by row index. I.e., all '
            'DynamicTables stored in this group MUST have the same number of rows. This type effectively '
            'defines a 2-level table in which the main data is stored in the main table implemented by this type '
            'and additional columns of the table are grouped into categories, with each category being '
            'represented by a separate DynamicTable stored within the group.',
        attributes=[NWBAttributeSpec(name='categories',
                                     dtype='text',
                                     dims=['num_categories'],
                                     doc='The names of the categories in this AlignedDynamicTable. Each '
                                         'category is represented by one DynamicTable stored in the parent group. '
                                         'This attribute should be used to specify an order of categories.',
                                     shape=[None])
                    ],
        groups=[NWBGroupSpec(neurodata_type_inc='DynamicTable',
                             doc='A DynamicTable representing a particular category for columns in the '
                                 'AlignedDynamicTable parent container. The table MUST be aligned '
                                 'with (i.e., have the same number of rows) as all other DynamicTables '
                                 'stored in the AlignedDynamicTable parent container. The name of '
                                 'the category is given by the name of the DynamicTable and its description '
                                 'by the description attribute of the DynamicTable.',
                             quantity='*')
                ]
    )

    electrodes_table_spec = NWBGroupSpec(
        neurodata_type_inc='DynamicTable',
        neurodata_type_def='IntracellularElectrodesTable',
        doc='Table for storing intracellular electrode related metadata.',
        attributes=[NWBAttributeSpec(name='description',
                                     dtype='text',
                                     doc='Description of what is in this dynamic table.',
                                     value='Table for storing intracellular electrode related metadata.')],
        datasets=[NWBDatasetSpec(
            name='electrode',
            neurodata_type_inc='VectorData',
            doc='Column for storing the reference to the intracellular electrode.',
            dtype=NWBRefSpec(target_type='IntracellularElectrode',
                             reftype='object')
            ),
        ]
    )

    stimuli_table_spec = NWBGroupSpec(
        neurodata_type_inc='DynamicTable',
        neurodata_type_def='IntracellularStimuliTable',
        doc='Table for storing intracellular stimulus related metadata.',
        attributes=[NWBAttributeSpec(name='description',
                                     dtype='text',
                                     doc='Description of what is in this dynamic table.',
                                     value='Table for storing intracellular stimulus related metadata.')],
        datasets=[NWBDatasetSpec(
            name='stimulus',
            neurodata_type_inc='TimeSeriesReferenceVectorData',
            doc='Column storing the reference to the recorded stimulus for the recording (rows).'),
        ]
    )

    responses_table_spec = NWBGroupSpec(
        neurodata_type_inc='DynamicTable',
        neurodata_type_def='IntracellularResponsesTable',
        doc='Table for storing intracellular response related metadata.',
        attributes=[NWBAttributeSpec(name='description',
                                     dtype='text',
                                     doc='Description of what is in this dynamic table.',
                                     value='Table for storing intracellular response related metadata.')],
        datasets=[NWBDatasetSpec(
            name='response',
            neurodata_type_inc='TimeSeriesReferenceVectorData',
            doc='Column storing the reference to the recorded response for the recording (rows)'),
        ]
    )

    # Create our table to group stimulus and response for Intracellular Electrophysiology Recordings
    icephys_recordings_table_spec = NWBGroupSpec(
        name='intracellular_recordings',
        neurodata_type_def='IntracellularRecordingsTable',
        neurodata_type_inc='AlignedDynamicTable',
        doc='A table to group together a stimulus and response from a single electrode and a single simultaneous '
            'recording. Each row in the table represents a single recording consisting typically of a stimulus and a '
            'corresponding response. In some cases, however, only a stimulus or a response are recorded as '
            'as part of an experiment. In this case both, the stimulus and response will point to the same '
            'TimeSeries while the idx_start and count of the invalid column will be set to -1, thus, '
            'indicating that no values have been recorded for the stimulus or response, respectively. Note, '
            'a recording MUST contain at least a stimulus or a response. Typically the stimulus and response '
            'are PatchClampSeries. However, the use of AD/DA channels that are not associated to an electrode '
            'is also common in intracellular electrophysiology, in which case other TimeSeries may be used.',
        attributes=[NWBAttributeSpec(
                        name='description',
                        dtype='text',
                        doc='Description of the contents of this table. Inherited from AlignedDynamicTable '
                            'and overwritten here to fix the value of the attribute',
                        value='A table to group together a stimulus and response from a single electrode '
                              'and a single simultaneous recording and for storing metadata about the '
                              'intracellular recording.'),
                    ],
        groups=[
            NWBGroupSpec(
                name='electrodes',
                neurodata_type_inc='IntracellularElectrodesTable',
                doc='Table for storing intracellular electrode related metadata.',
            ),
            NWBGroupSpec(
                name='stimuli',
                neurodata_type_inc='IntracellularStimuliTable',
                doc='Table for storing intracellular stimulus related metadata.'
            ),
            NWBGroupSpec(
                name='responses',
                neurodata_type_inc='IntracellularResponsesTable',
                doc='Table for storing intracellular response related metadata.'
            ),
        ]
    )

    # Create a SimultaneousRecordingsTable (similar to trials) table to group
    # intracellular electrophysiology recording that were
    # recorded at the same time and belong together
    simultaneous_recordings_table_spec = NWBGroupSpec(
        name='simultaneous_recordings',
        neurodata_type_def='SimultaneousRecordingsTable',
        neurodata_type_inc='DynamicTable',
        doc='A table for grouping different intracellular recordings from the '
            'IntracellularRecordingsTable table together that were recorded simultaneously '
            'from different electrodes',
        datasets=[NWBDatasetSpec(name='recordings',
                                 neurodata_type_inc='DynamicTableRegion',
                                 doc='A reference to one or more rows in the IntracellularRecordingsTable table.',
                                 attributes=[
                                     NWBAttributeSpec(
                                        name='table',
                                        dtype=NWBRefSpec(target_type='IntracellularRecordingsTable',
                                                         reftype='object'),
                                        doc='Reference to the IntracellularRecordingsTable table that '
                                            'this table region applies to. This specializes the '
                                            'attribute inherited from DynamicTableRegion to fix '
                                            'the type of table that can be referenced here.'
                                     )]),
                  NWBDatasetSpec(name='recordings_index',
                                 neurodata_type_inc='VectorIndex',
                                 doc='Index dataset for the recordings column.')
                  ]
        )

    # Create the SequentialRecordingsTable table to group different SimultaneousRecordingsTable together
    sequentialrecordings_table_spec = NWBGroupSpec(
        name='sequential_recordings',
        neurodata_type_def='SequentialRecordingsTable',
        neurodata_type_inc='DynamicTable',
        doc='A table for grouping different sequential recordings from the '
            'SimultaneousRecordingsTable table together. This is typically '
            'used to group together sequential recordings where the a sequence '
            'of stimuli of the same type with varying parameters '
            'have been presented in a sequence.',
        datasets=[NWBDatasetSpec(name='simultaneous_recordings',
                                 neurodata_type_inc='DynamicTableRegion',
                                 doc='A reference to one or more rows in the SimultaneousRecordingsTable table.',
                                 attributes=[
                                     NWBAttributeSpec(
                                        name='table',
                                        dtype=NWBRefSpec(target_type='SimultaneousRecordingsTable',
                                                         reftype='object'),
                                        doc='Reference to the SimultaneousRecordingsTable table that this table region '
                                            'applies to. This specializes the attribute inherited '
                                            'from DynamicTableRegion to fix the type of table that '
                                            'can be referenced here.'
                                     )
                                 ]),
                  NWBDatasetSpec(name='simultaneous_recordings_index',
                                 neurodata_type_inc='VectorIndex',
                                 doc='Index dataset for the simultaneous_recordings column.'),
                  NWBDatasetSpec(name='stimulus_type',
                                 neurodata_type_inc='VectorData',
                                 doc='The type of stimulus used for the sequential recording.',
                                 dtype='text')
                  ]
        )

    # Create the RepetitionsTable table to group different SequentialRecordingsTable together
    repetitions_table_spec = NWBGroupSpec(
        name='repetitions',
        neurodata_type_def='RepetitionsTable',
        neurodata_type_inc='DynamicTable',
        doc='A table for grouping different sequential intracellular recordings together. '
            'With each SequentialRecording typically representing a particular type of stimulus, the '
            'RepetitionsTable table is typically used to group sets of stimuli applied in sequence.',
        datasets=[NWBDatasetSpec(name='sequential_recordings',
                                 neurodata_type_inc='DynamicTableRegion',
                                 doc='A reference to one or more rows in the SequentialRecordingsTable table.',
                                 attributes=[
                                     NWBAttributeSpec(
                                        name='table',
                                        dtype=NWBRefSpec(target_type='SequentialRecordingsTable',
                                                         reftype='object'),
                                        doc='Reference to the SequentialRecordingsTable table that this table region '
                                            'applies to. This specializes the attribute inherited '
                                            'from DynamicTableRegion to fix the type of table that '
                                            'can be referenced here.'
                                     )
                                 ]),
                  NWBDatasetSpec(name='sequential_recordings_index',
                                 neurodata_type_inc='VectorIndex',
                                 doc='Index dataset for the sequential_recordings column.')
                  ]
        )

    # Create ExperimentalConditionsTable tbale for grouping different RepetitionsTable together
    experimental_conditions_table_spec = NWBGroupSpec(
        name='experimental_conditions',
        neurodata_type_def='ExperimentalConditionsTable',
        neurodata_type_inc='DynamicTable',
        doc='A table for grouping different intracellular recording repetitions together that '
            'belong to the same experimental experimental_conditions.',
        datasets=[NWBDatasetSpec(name='repetitions',
                                 neurodata_type_inc='DynamicTableRegion',
                                 doc='A reference to one or more rows in the RepetitionsTable table.',
                                 attributes=[
                                     NWBAttributeSpec(
                                        name='table',
                                        dtype=NWBRefSpec(target_type='RepetitionsTable',
                                                         reftype='object'),
                                        doc='Reference to the RepetitionsTable table that this table region '
                                            'applies to. This specializes the attribute inherited '
                                            'from DynamicTableRegion to fix the type of table that '
                                            'can be referenced here.'
                                     )
                                 ]),
                  NWBDatasetSpec(name='repetitions_index',
                                 neurodata_type_inc='VectorIndex',
                                 doc='Index dataset for the repetitions column.')
                  ]
        )

    # Update NWBFile to modify /general/intracellular_ephys in NWB to support adding the new structure there
    # NOTE: If this proposal for extension to NWB gets merged with the core schema the new NWBFile type would
    #       need to be removed and the NWBFile schema updated instead
    icephys_file_spec = NWBGroupSpec(
        neurodata_type_inc='NWBFile',
        neurodata_type_def='ICEphysFile',
        doc='Extension of the NWBFile class to allow placing the new icephys '
            'metadata types in /general/intracellular_ephys in the NWBFile '
            'NOTE: If this proposal for extension to NWB gets merged with '
            'the core schema, then this type would be removed and the '
            'NWBFile specification updated instead.',
        groups=[NWBGroupSpec(
         name='general',
         doc='expand definition of general from NWBFile',
         groups=[NWBGroupSpec(name='intracellular_ephys',
                              doc='expand definition from NWBFile',
                              groups=[NWBGroupSpec(neurodata_type_inc='IntracellularRecordingsTable',
                                                   doc=icephys_recordings_table_spec.doc,
                                                   name='intracellular_recordings',
                                                   quantity='?'),
                                      NWBGroupSpec(neurodata_type_inc='SimultaneousRecordingsTable',
                                                   doc=simultaneous_recordings_table_spec.doc,
                                                   name='simultaneous_recordings',
                                                   quantity='?'),
                                      NWBGroupSpec(neurodata_type_inc='SequentialRecordingsTable',
                                                   doc=sequentialrecordings_table_spec.doc,
                                                   name='sequential_recordings',
                                                   quantity='?'),
                                      NWBGroupSpec(neurodata_type_inc='RepetitionsTable',
                                                   doc=repetitions_table_spec.doc,
                                                   name='repetitions',
                                                   quantity='?'),
                                      NWBGroupSpec(neurodata_type_inc='ExperimentalConditionsTable',
                                                   doc=experimental_conditions_table_spec.doc,
                                                   name='experimental_conditions',
                                                   quantity='?'),
                                      # Update doc on SweepTable to declare it as deprecated
                                      NWBGroupSpec(neurodata_type_inc='SweepTable',
                                                   doc='[DEPRACATED] Table used to group different PatchClampSeries.'
                                                       'SweepTable is being replaced by IntracellularRecordingsTable '
                                                       'and SimultaneousRecordingsTable tabels (and corresponding '
                                                       'SequentialRecordingsTable, RepetitionsTable and '
                                                       'ExperimentalConditions tables.',
                                                   name='sweep_table',
                                                   quantity='?')
                                      ],
                              datasets=[NWBDatasetSpec(name='filtering',
                                                       doc='[DEPRECATED] Use IntracellularElectrode.filtering instead. '
                                                            'Description of filtering used. Includes filtering type '
                                                            'and parameters, frequency fall-off, etc. If this changes '
                                                            'between TimeSeries, filter description should be stored '
                                                            'as a text attribute for each TimeSeries.',
                                                       dtype='text',
                                                       quantity='?')]
                              )
                 ]
            )
        ]
    )

    # Add the type we want to include from core to this list
    include_core_types = ['Container',
                          'DynamicTable',
                          'DynamicTableRegion',
                          'VectorData',
                          'VectorIndex',
                          'PatchClampSeries',
                          'IntracellularElectrode',
                          'NWBFile']
    # Include the types that are used by the extension and their namespaces (where to find them)
    for type_name in include_core_types:
        ns_builder.include_type(type_name, namespace='core')

    # Add our new data types to this list
    new_data_types = [aligned_dynamic_tables_spec,
                      reference_timeseries_vectordata,
                      icephys_recordings_table_spec,
                      simultaneous_recordings_table_spec,
                      sequentialrecordings_table_spec,
                      repetitions_table_spec,
                      experimental_conditions_table_spec,
                      icephys_file_spec,
                      electrodes_table_spec,
                      stimuli_table_spec,
                      responses_table_spec]

    # Export the spec
    project_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
    output_dir = os.path.join(project_dir, 'spec')
    export_spec(ns_builder=ns_builder,
                new_data_types=new_data_types,
                output_dir=output_dir)
    print("Exported specification to: %s" % output_dir)
Esempio n. 22
0
from datetime import datetime
from dateutil.parser import parse as parse_date

import re

namespace = 'buzsaki_meta'
ns_path = namespace + ".namespace.yaml"
ext_source = namespace + ".extensions.yaml"

manipulation = NWBGroupSpec(neurodata_type_def='Manipulation',
                            neurodata_type_inc='NWBDataInterface',
                            quantity='+',
                            doc='manipulation',
                            attributes=[
                                NWBAttributeSpec(name='brain_region_target',
                                                 dtype='text',
                                                 doc='Allan Institute Acronym')
                            ])

virus_injection = NWBGroupSpec(
    neurodata_type_inc='NWBDataInterface',
    neurodata_type_def='VirusInjection',
    quantity='+',
    doc='notes about surgery that includes virus injection',
    datasets=[
        NWBDatasetSpec(name='coordinates',
                       doc='(AP, ML, DV) of virus injection',
                       dtype='float',
                       shape=(3, ))
    ],
    attributes=[
Esempio n. 23
0
# (For more information on the available tools for creating extensions, see :ref:`extending-nwb`).
#
#
# The following block of code demonstrates how to create a new namespace, and then add a new `neurodata_type`
# to this namespace. Finally,
# it calls :py:meth:`~pynwb.form.spec.write.NamespaceBuilder.export` to save the extensions to disk for downstream use.

from pynwb.spec import NWBNamespaceBuilder, NWBGroupSpec, NWBAttributeSpec

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

ns_builder = NWBNamespaceBuilder('Extension for use in my Lab', "mylab")
ext = NWBGroupSpec(
    'A custom ElectricalSeries for my lab',
    attributes=[NWBAttributeSpec('trode_id', 'the tetrode id', 'int')],
    neurodata_type_inc='ElectricalSeries',
    neurodata_type_def='TetrodeSeries')

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

####################
# Running this block will produce two YAML files.
#
# The first file contains the specification of the namespace.
#
# .. code-block:: yaml
#
#     # mylab.namespace.yaml
#     namespaces:
Esempio n. 24
0
A cookie-cutter guide for creating your own extension.
"""
from pynwb.spec import NWBDatasetSpec, NWBNamespaceBuilder, NWBGroupSpec, NWBAttributeSpec, RefSpec

namespace = 'template [CHANGE TO NAME]'
ns_path = namespace + ".namespace.yaml"
ext_source = namespace + ".extensions.yaml"

spec = NWBGroupSpec(
    neurodata_type_def='',
    neurodata_type_inc='NWBDataInterface',
    quantity='?',
    doc='',
    groups=[],
    attributes=[
        NWBAttributeSpec(name='', doc='', dtype='', required=False),
        NWBAttributeSpec(name='help',
                         doc='help',
                         dtype='text',
                         value='ENTER HELP INFO HERE')
    ],
    datasets=[NWBDatasetSpec(name='', doc='', dtype='', shape=())])

ns_builder = NWBNamespaceBuilder(doc=namespace + ' extensions',
                                 name=namespace,
                                 version='1.0',
                                 author='Ben Dichter',
                                 contact='*****@*****.**')
specs = (spec, )
for spec in specs:
    ns_builder.add_spec(ext_source, spec)
Esempio n. 25
0
# sphinx_gallery_thumbnail_path = 'figures/gallery_thumbnails_extensions.png'
from pynwb.spec import NWBNamespaceBuilder, NWBGroupSpec, NWBAttributeSpec

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

ns_builder = NWBNamespaceBuilder('Extension for use in my Lab',
                                 "mylab",
                                 version='0.1.0')

ns_builder.include_type('ElectricalSeries', namespace='core')

ext = NWBGroupSpec(
    'A custom ElectricalSeries for my lab',
    attributes=[NWBAttributeSpec('trode_id', 'the tetrode id', 'int')],
    neurodata_type_inc='ElectricalSeries',
    neurodata_type_def='TetrodeSeries')

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

####################
# Running this block will produce two YAML files.
#
# The first file, mylab.namespace.yaml, contains the specification of the namespace.
#
# .. code-block:: yaml
#
#     namespaces:
#     - doc: Extension for use in my Lab
Esempio n. 26
0
def main():
    ns_builder = NWBNamespaceBuilder(doc='describe a maze of arbitrary shape',
                                     name='ndx-maze',
                                     version='0.1.0',
                                     author='Ben Dichter',
                                     contact='*****@*****.**')

    node = NWBGroupSpec(
        neurodata_type_def='Node',
        neurodata_type_inc='NWBDataInterface',
        doc=
        "Abstract representation for any kind of node in the topological graph We won't actually"
        " implement abstract nodes. Rather this is a parent group from which our more specific "
        "types of nodes will inherit. Note that NWB specifications have inheritance. The quantity "
        "'*' means that we can have any number (0 or more) nodes.",
        quantity='*',
        attributes=[
            NWBAttributeSpec('name', 'the name of this node', 'text'),
            NWBAttributeSpec(name='help',
                             doc='help doc',
                             dtype='text',
                             value='Apparatus Node')
        ])

    edge = NWBGroupSpec(
        neurodata_type_def='Edge',
        neurodata_type_inc='NWBDataInterface',
        doc=
        "Edges between any two nodes in the graph. An edge's only dataset is the name (string) of "
        "the two nodes that the edge connects Note that we don't actually include the nodes "
        "themselves, just their names, in an edge.",
        quantity='*',
        datasets=[
            NWBDatasetSpec(doc='names of the nodes this edge connects',
                           name='edge_nodes',
                           dtype='text',
                           dims=['first_node_name|second_node_name'],
                           shape=[2])
        ],
        attributes=[
            NWBAttributeSpec(name='help',
                             doc='help doc',
                             dtype='text',
                             value='Apparatus Edge')
        ])

    point_node = NWBGroupSpec(
        neurodata_type_def='PointNode',
        neurodata_type_inc='Node',
        doc=
        'A node that represents a single 2D point in space (e.g. reward well, novel object'
        ' location)',
        quantity='*',
        datasets=[
            NWBDatasetSpec(doc='x/y coordinate of this 2D point',
                           name='coords',
                           dtype='float',
                           dims=['num_coords', 'x_vals|y_vals'],
                           shape=[1, 2])
        ],
        attributes=[
            NWBAttributeSpec(name='help',
                             doc='help doc',
                             dtype='text',
                             value='Apparatus Point')
        ])

    segment_node = NWBGroupSpec(
        neurodata_type_def='SegmentNode',
        neurodata_type_inc='Node',
        doc=
        'A node that represents a linear segment in 2D space, defined by its start and end'
        ' points (e.g. a single arm of W-track maze)',
        quantity='*',
        datasets=[
            NWBDatasetSpec(
                doc=
                'x/y coordinates of the start and end points of this segment',
                name='coords',
                dtype='float',
                dims=['num_coords', 'x_vals|y_vals'],
                shape=[None, 2])
        ],
        attributes=[
            NWBAttributeSpec(name='help',
                             doc='help doc',
                             dtype='text',
                             value='Apparatus Segment')
        ])

    polygon_node = NWBGroupSpec(
        neurodata_type_def='PolygonNode',
        neurodata_type_inc='Node',
        doc=
        'A node that represents a polygon area (e.g. open field, sleep box). A polygon is'
        ' defined by its external vertices and, optionally, by any interior points of '
        'interest (e.g. interior wells, objects)',
        quantity='*',
        datasets=[
            NWBDatasetSpec(
                doc='x/y coordinates of the exterior points of this polygon',
                name='coords',
                dtype='float',
                dims=['num_coords', 'x_vals|y_vals'],
                shape=[None, 2]),
            NWBDatasetSpec(
                doc='x/y coordinates of interior points inside this polygon',
                name='interior_coords',
                dtype='float',
                quantity='?',
                dims=['num_coords', 'x_vals|y_vals'],
                shape=[None, 2])
        ],
        attributes=[
            NWBAttributeSpec(name='help',
                             doc='help doc',
                             dtype='text',
                             value='Apparatus Polygon')
        ])

    environment = NWBGroupSpec(neurodata_type_def='Environment',
                               neurodata_type_inc='NWBDataInterface',
                               default_name='Environment',
                               doc='a graph of nodes and edges',
                               quantity='*',
                               groups=[
                                   NWBGroupSpec(neurodata_type_inc='Node',
                                                doc='nodes in the graph',
                                                quantity='*'),
                                   NWBGroupSpec(neurodata_type_inc='Edge',
                                                doc='edges in the graph',
                                                quantity='*')
                               ],
                               attributes=[
                                   NWBAttributeSpec(name='help',
                                                    doc='help doc',
                                                    dtype='text',
                                                    value='Environment')
                               ])

    environments = NWBGroupSpec(neurodata_type_def='Environments',
                                neurodata_type_inc='LabMetaData',
                                default_name='environments',
                                doc='holds environments',
                                quantity='?',
                                groups=[
                                    NWBGroupSpec(
                                        neurodata_type_inc='Environment',
                                        doc='holds structure of environment',
                                        quantity='*')
                                ],
                                attributes=[
                                    NWBAttributeSpec(name='help',
                                                     doc='help doc',
                                                     dtype='text',
                                                     value='help')
                                ])

    new_data_types = [
        node, edge, point_node, segment_node, polygon_node, environment,
        environments
    ]

    # TODO: include the types that are used and their namespaces (where to find them)
    ns_builder.include_type('NWBDataInterface', namespace='core')
    ns_builder.include_type('LabMetaData', namespace='core')

    export_spec(ns_builder, new_data_types)
Esempio n. 27
0
# provide an example of how to create an extension for subsequent use.
# (For more information on the available tools for creating extensions, see :ref:`extending-nwb`).
#
#
# The following block of code demonstrates how to create a new namespace, and then add a new `neurodata_type`
# to this namespace. Finally,
# it calls :py:meth:`~pynwb.form.spec.write.NamespaceBuilder.export` to save the extensions to disk for downstream use.

from pynwb.spec import NWBNamespaceBuilder, NWBGroupSpec, NWBAttributeSpec

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

ns_builder = NWBNamespaceBuilder('Extension for use in my Lab', "mylab")
ext = NWBGroupSpec('A custom ElectricalSeries for my lab',
                   attributes=[NWBAttributeSpec('trode_id', 'int', 'the tetrode id')],
                   neurodata_type_inc='ElectricalSeries',
                   neurodata_type_def='TetrodeSeries')

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

####################
# Running this block will produce two YAML files.
#
# The first file contains the specification of the namespace.
#
# .. code-block:: yaml
#
#     # mylab.namespace.yaml
#     namespaces:
Esempio n. 28
0
def main():
    # these arguments were auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(
        doc="""labels for behavior or neural data""",
        name="""ndx-labels""",
        version="""0.1.0""",
        author=list(map(str.strip, """Akshay Jaggi, Kanishk Jain, Jim Robinson-Bohnslav""".split(','))),
        contact=list(map(str.strip, """*****@*****.**""".split(',')))
    )

    # TODO: specify the neurodata_types that are used by the extension as well
    # as in which namespace they are found
    # this is similar to specifying the Python modules that need to be imported
    # to use your new data types
    # as of HDMF 1.6.1, the full ancestry of the neurodata_types that are used by
    # the extension should be included, i.e., the neurodata_type and its parent
    # type and its parent type and so on. this will be addressed in a future
    # release of HDMF.
    ns_builder.include_type('ElectricalSeries', namespace='core')
    ns_builder.include_type('ImageSeries', namespace='core')
    ns_builder.include_type('TimeSeries', namespace='core')
    ns_builder.include_type('NWBDataInterface', namespace='core')
    ns_builder.include_type('NWBContainer', namespace='core')
    ns_builder.include_type('DynamicTableRegion', namespace='hdmf-common')
    ns_builder.include_type('VectorData', namespace='hdmf-common')
    ns_builder.include_type('Data', namespace='hdmf-common')

    # TODO: define your new data types
    # see https://pynwb.readthedocs.io/en/latest/extensions.html#extending-nwb
    # for more information

    representation_series = NWBGroupSpec(
        neurodata_type_def='RepresentationSeries',
        neurodata_type_inc='TimeSeries',
        doc=('Extends TimeSeries to include abstract representations of raw data (e.g. PCs, tSNE)'),
        attributes=[
            NWBAttributeSpec(
                name='method',
                doc='a description of the method used to derive the representation',
                dtype='text'
            ),
            NWBAttributeSpec(
                name='unit',
                doc='required unit for RepresentationSeries, default to "a.u."',
                default_value="a.u.",
                dtype='text',
                required=False
            ),
        ],
        links=[
            NWBLinkSpec(
                name="video",
                target_type="ImageSeries",
                doc="ref to video that's being labeled",
                quantity="?"
            )
        ],
        datasets=[
            NWBDatasetSpec(
                name='data',
                doc='float array of the value of m factors for n time steps',
                dtype='float64',
                dims=['num_frames', 'num_factors'],
                shape=(None, None),
            ),
        ]
    )

    label_series = NWBGroupSpec(
        neurodata_type_def='LabelSeries',
        neurodata_type_inc='TimeSeries',
        doc=('Extends TimeSeries to capture labels encoded'),
        attributes=[
            NWBAttributeSpec(
                name='exclusive',
                doc='whether the labels are exclusive or not',
                dtype='bool'
            ),
            NWBAttributeSpec(
                name='method',
                doc='a description of the method used to derive the labels (e.g. DeepEthogram v0.1.0)',
                dtype='text'
            ),
            NWBAttributeSpec(
                name='unit',
                doc='required unit for LabelSeries, default to "label"',
                default_value="label",
                dtype='text',
                required=False
            ),
        ],
        links=[
            NWBLinkSpec(
                name="representation",
                target_type="RepresentationSeries",
                doc="ref to representation series",
                quantity="?"
            ),
            NWBLinkSpec(
                name="video",
                target_type="ImageSeries",
                doc="ref to video that's being labeled",
                quantity="?"
            )
        ],
        datasets=[
            NWBDatasetSpec(
                name='data',
                doc='Binary array of k labels for all n time steps',
                dtype='int32',
                dims=['num_frames', 'num_labels'],
                shape=(None, None),
            ),
            NWBDatasetSpec(
                name='scores',
                doc='Float array of the probabilities of each of the k labels for all n time steps',
                dtype='float64',
                dims=['num_frames', 'num_labels'],
                shape=(None, None),
                quantity="?"
            ),
            NWBDatasetSpec(
                name="vocabulary",
                doc="list of k labels for the behaviors",
                dtype="text",
                dims=['num_labels'],
                shape=(None,),
                quantity="?"
            )
        ]
    )

    # TODO: add all of your new data types to this list
    new_data_types = [label_series, representation_series]

    # export the spec to yaml files in the spec folder
    output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'spec'))
    export_spec(ns_builder, new_data_types, output_dir)
Esempio n. 29
0
def main():
    ns_builder = NWBNamespaceBuilder(
        doc='nwb extention for voltage imaging technique called TEMPO',
        name=name,
        version='0.1.0',
        author=list(map(str.strip, 'Saksham Sharda'.split(','))),
        contact=list(map(str.strip, '*****@*****.**'.split(',')))
    )

    ns_builder.include_type('VectorData', namespace='hdmf-common')
    ns_builder.include_type('DynamicTable', namespace='hdmf-common')
    ns_builder.include_type('Subject', namespace='core')
    ns_builder.include_type('NWBDataInterface', namespace='core')
    ns_builder.include_type('NWBContainer', namespace='core')
    ns_builder.include_type('Device', namespace='core')

    measurement = NWBDatasetSpec('Flexible vectordataset with a custom unit/conversion/resolution'
                                 ' field similar to timeseries.data',
                                 attributes=[
                                     NWBAttributeSpec('unit',
                                                      'The base unit of measure used to store data. This should be in the SI unit.'
                                                      'COMMENT: This is the SI unit (when appropriate) of the stored data, such as '
                                                      'Volts. If the actual data is stored in millivolts, the field ''conversion'' '
                                                      'below describes how to convert the data to the specified SI unit.',
                                                      'text'),
                                     NWBAttributeSpec('conversion',
                                                      'Scalar to multiply each element in '
                                                      'data to convert it to the specified unit',
                                                      'float32', required=False, default_value=1.0),
                                     NWBAttributeSpec('resolution',
                                                      'Smallest meaningful difference between values in data, stored in the specified '
                                                      'by unit. COMMENT: E.g., the change in value of the least significant bit, or '
                                                      'a larger number if signal noise is known to be present. If unknown, use -1.0',
                                                      'float32', required=False, default_value=0.0)
                                 ],
                                 neurodata_type_def='Measurement',
                                 neurodata_type_inc='VectorData',
                                 )

    # Typedef for laserline
    laserline_device = NWBGroupSpec(neurodata_type_def='LaserLine',
                                    neurodata_type_inc='Device',
                                    doc='description of laserline device, part for a TEMPO device',
                                    attributes=[
                                        NWBAttributeSpec('reference',
                                                         'reference of the laserline module',
                                                         dtype='text',
                                                         required=False)
                                    ],
                                    quantity='*')

    laserline_device.add_dataset(
        name='analog_modulation_frequency',
        neurodata_type_inc=measurement,
        doc='analog_modulation_frequency of the laserline module',
        shape=(1,),
        dtype='text',
        quantity='?'
    )

    laserline_device.add_dataset(
        name='power',
        neurodata_type_inc=measurement,
        doc='power of the laserline module',
        shape=(1,),
        dtype='float',
        quantity='?'
    )

    laserline_devices = NWBGroupSpec(neurodata_type_def='LaserLineDevices',
                                     neurodata_type_inc='NWBDataInterface',
                                     name='laserline_devices',
                                     doc='A container for dynamic addition of LaserLine devices',
                                     quantity='?',
                                     groups=[laserline_device])

    # Typedef for PhotoDetector
    photodetector_device = NWBGroupSpec(neurodata_type_def='PhotoDetector',
                                        neurodata_type_inc='Device',
                                        doc='description of photodetector device, part for a TEMPO device',
                                        attributes=[
                                            NWBAttributeSpec('reference',
                                                             'reference of the photodetector module',
                                                             dtype='text',
                                                             required=False)
                                        ],
                                        quantity='*')

    photodetector_device.add_dataset(
        name='gain',
        neurodata_type_inc=measurement,
        doc='gain of the photodetector module',
        shape=(1,),
        dtype='float',
        quantity='?'
    )

    photodetector_device.add_dataset(
        name='bandwidth',
        neurodata_type_inc=measurement,
        doc='bandwidth metadata of the photodetector module',
        shape=(1,),
        dtype='float',
        quantity='?'
    )

    photodetector_devices = NWBGroupSpec(neurodata_type_def='PhotoDetectorDevices',
                                         neurodata_type_inc='NWBDataInterface',
                                         name='photodetector_devices',
                                         doc='A container for dynamic addition of PhotoDetector devices',
                                         quantity='?',
                                         groups=[photodetector_device])

    # Typedef for LockInAmplifier
    lockinamp_device = NWBGroupSpec(neurodata_type_def='LockInAmplifier',
                                    neurodata_type_inc='DynamicTable',
                                    doc='description of lock_in_amp device, part for a TEMPO device',
                                    attributes=[
                                        NWBAttributeSpec('demodulation_filter_order',
                                                         'demodulation_filter_order of the lockinamp_device module',
                                                         dtype='float',
                                                         required=False,
                                                         default_value=-1),
                                        NWBAttributeSpec('reference',
                                                         'reference of the lockinamp_device module',
                                                         dtype='text',
                                                         required=False)
                                    ],
                                    quantity='*')

    lockinamp_device.add_dataset(
        name='demod_bandwidth',
        neurodata_type_inc=measurement,
        doc='demod_bandwidth of lock_in_amp',
        shape=(1,),
        dtype='float',
        quantity='?'
    )

    lockinamp_device.add_dataset(
        name='channel_name',
        neurodata_type_inc='VectorData',
        doc='name of the channel of lock_in_amp',
        dims=('no_of_channels',),
        shape=(None,),
        dtype='text',
        quantity='?'
    )

    lockinamp_device.add_dataset(
        name='offset',
        neurodata_type_inc=measurement,
        doc='offset for channel of lock_in_amp',
        dims=('no_of_channels',),
        shape=(None,),
        dtype='float',
        quantity='?'
    )

    lockinamp_device.add_dataset(
        name='gain',
        neurodata_type_inc='VectorData',
        doc='gain for channel of lock_in_amp',
        dims=('no_of_channels',),
        shape=(None,),
        dtype='float',
        quantity='?'
    )

    lockinamp_devices = NWBGroupSpec(neurodata_type_def='LockInAmplifierDevices',
                                     neurodata_type_inc='NWBDataInterface',
                                     name='lockinamp_devices',
                                     doc='A container for dynamic addition of LockInAmplifier devices',
                                     quantity='?',
                                     groups=[lockinamp_device])

    tempo_device = NWBGroupSpec(neurodata_type_def='TEMPO',
                                neurodata_type_inc='Device',
                                doc='datatype for a TEMPO device',
                                attributes=[NWBAttributeSpec(
                                    name='no_of_modules',
                                    doc='the number of electronic modules with this acquisition system',
                                    dtype='int',
                                    required=False,
                                    default_value=3)],
                                groups=[laserline_devices,
                                        photodetector_devices,
                                        lockinamp_devices]
                                )

    # surgical meta-data specification:

    surgery = NWBGroupSpec(neurodata_type_def='Surgery',
                           neurodata_type_inc='Subject',
                           doc='Surgery related meta-data of subject',
                           name='surgery_data',
                           attributes=[NWBAttributeSpec(
                                   name='surgery_date',
                                   doc='date of surgery',
                                   dtype='text',
                                   required=False),
                               NWBAttributeSpec(
                                   name='surgery_notes',
                                   doc='surgery notes',
                                   dtype='text',
                                   required=False),
                               NWBAttributeSpec(
                                   name='surgery_pharmacology',
                                   doc='pharmacology data',
                                   dtype='text',
                                   required=False),
                               NWBAttributeSpec(
                                   name='surgery_arget_anatomy',
                                   doc='target anatomy of the surgery',
                                   dtype='text',
                                   required=False)],
                           groups=[
                                NWBGroupSpec(
                                   name='implantation',
                                   doc='implantation related data',
                                   links=[NWBLinkSpec(name='implantation_device',
                                                      doc='device implanted during surgery',
                                                      target_type='Device')],
                                   attributes=[NWBAttributeSpec(
                                                  name='ophys_implant_name',
                                                  doc='optical physiology implant name',
                                                  dtype='text',
                                                  required=False),
                                               NWBAttributeSpec(
                                                 name='ephys_implant_name',
                                                 doc='electrophysiology implant name',
                                                 dtype='text',
                                                 required=False)],
                                   quantity='?'),
                                NWBGroupSpec(
                                    name='virus_injection',
                                    doc='virus injection related data',
                                    attributes=[NWBAttributeSpec(
                                                   name='virus_injection_id',
                                                   doc='id of virus injected',
                                                   dtype='text',
                                                   required=False),
                                                NWBAttributeSpec(
                                                    name='virus_injection_opsin',
                                                    doc='opsin/protein used',
                                                    dtype='text',
                                                    required=False),
                                                NWBAttributeSpec(
                                                    name='virus_injection_opsin_l_r',
                                                    doc='opsin/protein left/right description'
                                                        'enter \'L\' or \'R\'',
                                                    dtype='text',
                                                    required=False,
                                                    default_value='L/R'),
                                                NWBAttributeSpec(
                                                    name='virus_injection_scheme',
                                                    doc='description of injection scheme eg.'
                                                    '\'single_bolus\'',
                                                    dtype='text',
                                                    required=False),
                                                NWBAttributeSpec(
                                                    name='virus_injection_tag',
                                                    doc='tag for the virus injected',
                                                    dtype='text',
                                                    required=False),
                                                NWBAttributeSpec(
                                                    name='virus_injection_coordinates_description',
                                                    doc='description of coordinates'
                                                        '\'AP\'/\'ML\'/\'DV\'',
                                                    dtype='text',
                                                    required=False),
                                                NWBAttributeSpec(
                                                    name='virus_injection_volume',
                                                    doc='volume of virus injected in ml',
                                                    dtype='float',
                                                    required=False,
                                                    default_value=-1.0)],
                                    datasets=[NWBDatasetSpec(
                                                    name='virus_injection_coordinates',
                                                    doc='coordinates of virus injection',
                                                    dtype='text',
                                                    quantity='?')],
                                    quantity='?'),
                                NWBGroupSpec(
                                    name='ophys_injection',
                                    doc='optical physiology fluorescence injection metadata',
                                    attributes=[NWBAttributeSpec(
                                                    name='ophys_injection_date',
                                                    doc='date of fluorscent protein injection',
                                                    dtype='text',
                                                    required=False),
                                                NWBAttributeSpec(
                                                    name='ophys_injection_volume',
                                                    doc='volume of fluorscent protein injected',
                                                    dtype='float',
                                                    required=False),
                                                NWBAttributeSpec(
                                                    name='ophys_injection_brain_area',
                                                    doc='brain area of fluorscent protein injection',
                                                    dtype='text',
                                                    required=False)
                                                ],
                                    datasets=[NWBDatasetSpec(
                                                    name='ophys_injection_flr_protein_data',
                                                    doc='fluorescence protein name and concentration table',
                                                    neurodata_type_inc='DynamicTable')
                                              ],
                                    quantity='?')
                                    ],
                           quantity='?')

    subject = NWBGroupSpec(
                        neurodata_type_def='SubjectComplete',
                        neurodata_type_inc='Surgery',
                        doc='Mouse metadata used with the TEMPO device',
                        attributes=[NWBAttributeSpec(
                                       name='sacrificial_date',
                                       doc='sacrificial date of the animal ',
                                       dtype='text',
                                       required=False),
                                    NWBAttributeSpec(
                                       name='strain',
                                       doc='strain of the animal',
                                       dtype='text',
                                       required=False)],
                           )

    new_data_types = [measurement, tempo_device, surgery, subject]
    export_spec(ns_builder, new_data_types)
Esempio n. 30
0
from pynwb import register_class, load_namespaces, NWBFile, NWBHDF5IO, get_class
from hdmf.utils import docval
from pynwb.file import Subject as original_Subject, NWBContainer, MultiContainerInterface

name = 'mworks'
ns_path = name + ".namespace.yaml"
ext_source = name + ".extensions.yaml"

main_screen_info = NWBGroupSpec(
    neurodata_type_def='mainScreenInfo',
    neurodata_type_inc='NWBDataInterface',
    quantity='?',
    doc='',
    attributes=[
        NWBAttributeSpec(name='always_display_mirror_window',
                         doc='doc',
                         dtype='bool',
                         required=False),
        NWBAttributeSpec(name='distance',
                         doc='doc',
                         dtype='float',
                         required=False),
        NWBAttributeSpec(name='width',
                         doc='doc',
                         dtype='float',
                         required=False),
        NWBAttributeSpec(name='mirror_window_base_height',
                         doc='doc',
                         dtype='float',
                         required=False),
        NWBAttributeSpec(name='gammaR',
                         doc='doc',