Example #1
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)
def main():
    ns_builder = NWBNamespaceBuilder(doc='{{ cookiecutter.description }}',
                                     name='{{ cookiecutter.namespace }}',
                                     version='{{ cookiecutter.version }}',
                                     author='{{ cookiecutter.author }}',
                                     contact='{{ cookiecutter.email }}')

    # CHANGEME
    # define the new data types
    # compartment_series = NWBGroupSpec(
    #     neurodata_type_def='CompartmentSeries',
    #     neurodata_type_inc='TimeSeries',
    #     doc='Stores continuous data from cell compartments',
    #     links=[
    #         NWBLinkSpec(name='compartments',
    #                     target_type='Compartments',
    #                     doc='metadata about compartments in this CompartmentSeries',
    #                     quantity='?')
    #     ]
    # )

    # CHANGEME
    # add the new data types to this list
    # new_data_types = [compartment_series]
    new_data_types = []

    # CHANGEME
    # Must include types that are used and their namespaces (where to find them)
    # ns_builder.include_type('TimeSeries', namespace='core')

    export_spec(ns_builder, new_data_types)
Example #3
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)
Example #4
0
def main():

    ns_builder = NWBNamespaceBuilder(
        doc="Detected events from optical physiology ROI fluorescence traces",
        name=f"""{NAMESPACE}""",
        version="""0.1.0""",
        author="""Allen Institute for Brain Science""",
        contact="""*****@*****.**"""
    )

    ns_builder.include_type('RoiResponseSeries', namespace='core')
    ns_builder.include_type('DynamicTableRegion', namespace='core')
    ns_builder.include_type('TimeSeries', namespace='core')
    ns_builder.include_type('NWBDataInterface', namespace='core')

    ophys_events_spec = NWBGroupSpec(
        neurodata_type_def='OphysEventDetection',
        neurodata_type_inc='RoiResponseSeries',
        name='event_detection',
        doc='Stores event detection output',
        datasets=[
            NWBDatasetSpec(
                name='lambdas',
                dtype='float',
                doc='calculated regularization weights',
                shape=(None,)
            ),
            NWBDatasetSpec(
                name='noise_stds',
                dtype='float',
                doc='calculated noise std deviations',
                shape=(None,)
            )
        ]
    )

    new_data_types = [ophys_events_spec]

    # export the spec to yaml files in the spec folder
    output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__)))
    export_spec(ns_builder, new_data_types, output_dir)
Example #5
0
def main():
    # the values for ns_builder are auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(doc='An NWB:N extension',
                                     name='ndx-task',
                                     version='0.1.0',
                                     author='Ben Dichter',
                                     contact='*****@*****.**')

    # see https://pynwb.readthedocs.io/en/latest/extensions.html#extending-nwb for more information

    task = NWBGroupSpec(neurodata_type_def='Task', neurodata_type_inc='NWBDataInterface', doc='task information')
    task.add_attribute(name='description', doc='describe the task', dtype='text', required=True)
    task.add_attribute(name='category', doc='free category field', dtype='text', required=False)
    task.add_attribute(name='help', doc='help', dtype='text', value='stores data about a specific task')

    task.add_attribute(name='auditory', doc='experiment involves auditory stimuli', dtype='bool', required=False)
    task.add_attribute(name='visual', doc='experiment involves visual stimuli', dtype='bool', required=False)
    task.add_attribute(name='decision', doc='experiment involves decision making', dtype='bool', required=False)
    task.add_attribute(name='navigation', doc='experiment involves a navigation task', dtype='bool', required=False)
    task.add_attribute(name='rest', doc='experiment involves no task or stimuli', dtype='bool', required=False)
    task.add_attribute(name='motor', doc='experiment involves a fine motor task', dtype='bool', required=False)
    task.add_attribute(name='olfactory', doc='experiment involves olfactory stimuli', dtype='bool', required=False)
    task.add_attribute(name='speech production', doc='experiment involves speaking', dtype='bool', required=False)
    task.add_attribute(name='speech perception', doc='experiment involves ', dtype='bool', required=False)

    tasks = NWBGroupSpec(neurodata_type_def='Tasks', neurodata_type_inc='LabMetaData', doc='holds task objects')
    tasks.add_group(neurodata_type_inc='Tasks', quantity='*', doc='task information')
    tasks.add_attribute(name='help', doc='help', dtype='text', value='stores Task objects')

    new_data_types = [task, tasks]

    ns_builder.include_type('NWBDataInterface', namespace='core')
    ns_builder.include_type('LabMetaData', namespace='core')

    export_spec(ns_builder, new_data_types)
Example #6
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.))
Example #7
0
def create_LabMetaData_extension_from_schemas(schema_list, prefix):

    # Initializations:
    outdir = os.path.abspath(os.path.dirname(__file__))
    ext_source = '%s_extension.yaml' % prefix
    ns_path = '%s_namespace.yaml' % prefix
    neurodata_type_list_as_str = str(
        [schema.neurodata_type for schema in schema_list])
    extension_doc = 'LabMetaData extensions: {neurodata_type_list_as_str} ({prefix})'.format(
        neurodata_type_list_as_str=neurodata_type_list_as_str, prefix=prefix)
    ns_builder = NWBNamespaceBuilder(extension_doc, prefix)

    for schema in schema_list:
        docval_list, attributes, nwbfields_list = extract_from_schema(schema)
        neurodata_type = schema.neurodata_type

        # Build the spec:
        ext_group_spec = NWBGroupSpec(neurodata_type_def=neurodata_type,
                                      neurodata_type_inc='LabMetaData',
                                      doc=extension_doc,
                                      attributes=attributes)

        # Add spec to builder:

        ns_builder.add_spec(ext_source, ext_group_spec)

    # Export spec
    ns_builder.export(ns_path, outdir=outdir)
Example #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)
Example #9
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.))
Example #10
0
def create_pynwb_extension_from_schemas(schema_list, prefix: str):

    # Initializations:
    outdir = os.path.abspath(os.path.dirname(__file__))
    ext_source = f'{prefix}.extension.yaml'
    ns_path = f'{prefix}.namespace.yaml'

    extension_doc = ("Allen Institute behavior and optical "
                     "physiology extensions")

    ns_builder = NWBNamespaceBuilder(
        doc=extension_doc,
        name=prefix,
        version="0.2.0",
        author="Allen Institute for Brain Science",
        contact="*****@*****.**")

    # Loops through and create NWB custom group specs for schemas found in:
    # allensdk.brain_observatory.behavior.schemas
    for schema in schema_list:
        docval_list, attributes, nwbfields_list = extract_from_schema(schema)

        # Build the spec:
        ext_group_spec = NWBGroupSpec(
            neurodata_type_def=schema.neurodata_type,
            neurodata_type_inc=schema.neurodata_type_inc,
            doc=schema.neurodata_doc,
            attributes=attributes)

        # Add spec to builder:
        ns_builder.add_spec(ext_source, ext_group_spec)

    # Export spec
    ns_builder.export(ns_path, outdir=outdir)
Example #11
0
def main():
    # the values for ns_builder are auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(doc='An NWB:N extension',
                                     name='ndx-experimenters',
                                     version='0.1.0',
                                     author='Ben Dichter',
                                     contact='*****@*****.**')

    # see https://pynwb.readthedocs.io/en/latest/extensions.html#extending-nwb for more information

    nwbfile = NWBGroupSpec(neurodata_type_def='NWBFile_experimenters',
                           neurodata_type_inc='NWBFile',
                           doc='Top level of NWB file.')
    general = nwbfile.add_group(
        name='general',
        doc=
        "Experimental metadata, including protocol, notes and description of hardware"
        "device(s).  COMMENT: The metadata stored in this section should be used to"
        "describe the experiment. Metadata necessary for interpreting the data is stored"
        "with the data. MORE_INFO: General experimental metadata, including animal"
        "strain, experimental protocols, experimenter, devices, etc, are stored under"
        "'general'. Core metadata (e.g., that required to interpret data fields) is"
        "stored with the data itself, and implicitly defined by the file specification"
        "is to use free-form text fields, such as would appear in sentences or paragraphs"
        "from a Methods section. Metadata fields are text to enable them to be more"
        "general, for example to represent ranges instead of numerical values. Machine-readable"
        "metadata is stored as attributes to these free-form datasets. All entries"
        "in the below table are to be included when data is present. Unused groups"
        "(e.g., intracellular_ephys in an optophysiology experiment) should not be"
        "created unless there is data to store within them.")
    general.add_dataset(name='experimenters',
                        shape=(None, ),
                        dtype='text',
                        doc='holds multiple experimenters')

    new_data_types = [nwbfile]

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

    export_spec(ns_builder, new_data_types)
Example #12
0
def main():
    ns_builder = NWBNamespaceBuilder(doc='transcriptions and other speech-related data',
                                     name='speech',
                                     version='0.1.1',
                                     author='Ben Dichter',
                                     contact='*****@*****.**')

    Transcription = NWBGroupSpec(neurodata_type_def='Transcription', neurodata_type_inc='NWBDataInterface',
                             name='transcription',
                             doc='holds tiers for different levels of transcription (e.g. sentence, word, phoneme)')
    Transcription.add_attribute(name='help', dtype='text', value='holds tiers for different levels of transcription',
                                doc='doc')
    Transcription.add_attribute(name='settings', dtype='text', required=False,
                                doc='text field for entering any algorithms and settings used for automatic transcription')
    
    for feature_type in ('phoneme_features', 'phonemes', 'syllables', 'words', 'sentences'):
        intervals = Transcription.add_group(name=feature_type, neurodata_type_inc='TimeIntervals', quantity='?',
                                            doc='label, start, and stop times for ' + feature_type)
        intervals.add_attribute(name='help', dtype='text', value='holds ' + feature_type + ' tier times',
                                doc='doc')

    new_data_types = [Transcription]

    ns_builder.include_type('NWBDataInterface', namespace='core')
    ns_builder.include_type('TimeIntervals', namespace='core')

    export_spec(ns_builder, new_data_types)
Example #13
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)
Example #14
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)
Example #15
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)
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
def main():
    # these arguments were auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(
        doc='An NWB:N extension for storing bipolar schema',
        name='ndx-bipolar-scheme',
        version='0.1.0',
        author=list(map(str.strip, 'Ben Dichter'.split(','))),
        contact=list(map(str.strip, '*****@*****.**'.split(','))))

    for type_name in ('LabMetaData', 'DynamicTableRegion', 'DynamicTable',
                      'VectorIndex'):
        ns_builder.include_type(type_name, namespace='core')

    ecephys_ext = NWBGroupSpec(
        name='extracellular_ephys_extensions',
        neurodata_type_def='EcephysExt',
        neurodata_type_inc='LabMetaData',
        doc=
        'Group that holds proposed extracellular electrophysiology extensions.'
    )
    bipolar_scheme = ecephys_ext.add_group(
        name='bipolar_scheme',
        neurodata_type_inc='DynamicTable',
        doc='Table that holds information about the bipolar scheme used')
    bipolar_scheme.add_dataset(name='anodes',
                               neurodata_type_inc='DynamicTableRegion',
                               doc='references the electrodes table')
    bipolar_scheme.add_dataset(name='cathode',
                               neurodata_type_inc='DynamicTableRegion',
                               doc='references the electrodes table')

    new_data_types = [ecephys_ext]

    # 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)
Example #18
0
def main():
    # these arguments were auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(
        doc="""DANDI project extension""",
        name="""ndx-dandi""",
        version="""0.1.0""",
        author=list(map(str.strip, """Yaroslav O Halchenko""".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
    #ns_builder.include_type('Subject', namespace='core')
    ns_builder.include_namespace('core')

    # TODO: define your new data types
    # see https://pynwb.readthedocs.io/en/latest/extensions.html#extending-nwb
    # for more information
    dandi_subject = NWBGroupSpec(
        neurodata_type_def='Subject',
        neurodata_type_inc='Subject',
        doc="TODO: somehow inherit",
        datasets=[
            NWBDatasetSpec(
                name='subject_id',
                quantity=1,  # 'zero_or_one',
                doc="TODO: somehow inherit")
        ])

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

    # 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)
Example #19
0
def main():
    ns_builder = NWBNamespaceBuilder(doc='data type for holding power or phase spectra for a signal',
                                     name='ndx-spectrum',
                                     version='0.2.2',
                                     author='Ben Dichter',
                                     contact='*****@*****.**')

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

    Spectrum = NWBGroupSpec(
        neurodata_type_def='Spectrum',
        neurodata_type_inc='NWBDataInterface',
        doc='type for storing power or phase of spectrum')

    for data_name in ('power', 'phase'):
        Spectrum.add_dataset(
            name=data_name,
            doc='spectrum values',
            dims=(('frequency',), ('frequency', 'channel')),
            shape=((None,), (None, None)),
            dtype='float',
            quantity='?')

    Spectrum.add_dataset(name='frequencies',
                         doc='frequencies of spectrum',
                         dims=('frequency',),
                         shape=(None,),
                         dtype='float')

    Spectrum.add_link(target_type='TimeSeries',
                      doc='timeseries that this spectrum describes',
                      quantity='?',
                      name='source_timeseries')

    Spectrum.add_dataset(name='electrodes',
                         doc='the electrodes that this series was generated from',
                         neurodata_type_inc='DynamicTableRegion',
                         quantity='?')

    new_data_types = [Spectrum]

    # 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)
Example #20
0
def main():
    ns_builder = NWBNamespaceBuilder(
        doc='holds metadata relevant for miniscope acquisition',
        name='ndx-miniscope',
        version='0.2.2',
        author='Ben Dichter',
        contact='*****@*****.**')

    Miniscope = NWBGroupSpec(
        neurodata_type_def='Miniscope',
        neurodata_type_inc='Device',
        doc='extension of Device to hold metadata specific to Miniscopes')
    Miniscope.add_attribute(name='excitation',
                            doc='magnitude of excitation',
                            dtype='int',
                            required=False)
    Miniscope.add_attribute(name='msCamExposure',
                            doc='exposure of camera (max=255)',
                            dtype='int',
                            required=False)

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

    export_spec(ns_builder, [Miniscope])
Example #21
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))
Example #22
0
def main():

    ns_builder = NWBNamespaceBuilder(
        doc="Stimulus images",
        name=f"""{NAMESPACE}""",
        version="""0.1.0""",
        author="""Allen Institute for Brain Science""",
        contact="""*****@*****.**"""
    )

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

    stimulus_template_spec = NWBGroupSpec(
        neurodata_type_def='StimulusTemplate',
        neurodata_type_inc='ImageSeries',
        doc='Note: image names in control_description are referenced by '
            'stimulus/presentation table as well as intervals '
            '\n'
            'Each image shown to the animals is warped to account for '
            'distance and eye position relative to the monitor. This  '
            'extension stores the warped images that were shown to the animal '
            'as well as an unwarped version of each image in which a mask has '
            'been applied such that only the pixels visible after warping are '
            'included',
        datasets=[
            NWBDatasetSpec(
                name='unwarped',
                dtype='float',
                doc='Original image with mask applied such that only the '
                    'pixels visible after warping are included',
                shape=(None, None, None)
            )
        ]
    )

    new_data_types = [stimulus_template_spec]

    # export the spec to yaml files in the spec folder
    output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__)))
    export_spec(ns_builder, new_data_types, output_dir)
Example #23
0
def main():
    ns_builder = NWBNamespaceBuilder(
        doc='type for storing time-varying 3D point clouds',
        name='ndx-pointcloudseries',
        version='0.0.1',
        author='Luiz Tauffer and Ben Dichter',
        contact='*****@*****.**')

    PointCloudSeries = NWBGroupSpec(
        doc='type for storing time-varying 3D point clouds',
        neurodata_type_def='PointCloudSeries',
        neurodata_type_inc='TimeSeries',
    )

    PointCloudSeries.add_dataset(name='point_cloud',
                                 neurodata_type_inc='VectorData',
                                 doc='datapoints locations over time',
                                 dims=('time', '[x, y, z]'),
                                 shape=(None, 3),
                                 dtype='float',
                                 quantity='?')

    PointCloudSeries.add_dataset(name='point_cloud_index',
                                 neurodata_type_inc='VectorIndex',
                                 doc='datapoints indices',
                                 dims=('index', ),
                                 shape=(None),
                                 quantity='?')

    PointCloudSeries.add_dataset(name='color',
                                 neurodata_type_inc='VectorData',
                                 doc='datapoints color',
                                 dims=('time', '[r, g, b]'),
                                 shape=(None, 3),
                                 dtype='float',
                                 quantity='?')

    PointCloudSeries.add_dataset(name='color_index',
                                 neurodata_type_inc='VectorIndex',
                                 doc='datapoints colors indices',
                                 dims=('index', ),
                                 shape=(None),
                                 quantity='?')

    new_data_types = [PointCloudSeries]

    ns_builder.include_type('TimeSeries', namespace='core')
    ns_builder.include_type('VectorData', namespace='core')
    ns_builder.include_type('VectorIndex', namespace='core')

    export_spec(ns_builder, new_data_types)
Example #24
0
 def test_catch_duplicate_spec(self):
     spec1 = NWBGroupSpec("This is my new group 1",
                          "Group1",
                          neurodata_type_inc="NWBDataInterface",
                          neurodata_type_def="Group1")
     spec2 = NWBGroupSpec("This is my new group 2",
                          "Group2",
                          groups=[spec1],
                          neurodata_type_inc="NWBDataInterface",
                          neurodata_type_def="Group2")
     ns_builder = NWBNamespaceBuilder("Example namespace", "pynwb_test_ext")
     ns_builder.add_spec(self.ext_source, spec1)
     with self.assertRaises(ValueError):
         ns_builder.add_spec(self.ext_source, spec2)
Example #25
0
import numpy as np
from datetime import datetime
import h5py

from pynwb.spec import (NWBGroupSpec, NWBDatasetSpec, NWBNamespaceBuilder)
from pynwb import get_class, load_namespaces, NWBHDF5IO, NWBFile

project_name = 'simulation_output'
ns_path = project_name + '.namespace.yaml'
ext_source = project_name + '.extensions.yaml'
ns_builder = NWBNamespaceBuilder(project_name, project_name)


def build_ext():
    datasets = [
        NWBDatasetSpec(doc='list of cell ids',
                       dtype='uint32',
                       shape=(None, 1),
                       name='gid',
                       quantity='?'),
        NWBDatasetSpec(doc='index pointer',
                       dtype='uint64',
                       shape=(None, 1),
                       name='index_pointer'),
        NWBDatasetSpec(
            doc=
            'cell compartment ids corresponding to a given column in the data',
            dtype='uint32',
            shape=(None, 1),
            name='element_id'),
        NWBDatasetSpec(
Example #26
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))
Example #27
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)
Example #28
0
def main():

    # these arguments were auto-generated from your cookiecutter inputs
    ns_builder = NWBNamespaceBuilder(
        doc='An NWB:N extension for storing bipolar schema',
        name='ndx-bipolar-scheme',
        version='0.3.0',
        author=list(
            map(str.strip, 'Ben Dichter,Armin Najarpour,Ryan Ly'.split(','))),
        contact=list(map(str.strip,
                         '*****@*****.**'.split(','))))

    for type_name in ('LabMetaData', 'DynamicTableRegion', 'DynamicTable',
                      'VectorIndex'):
        ns_builder.include_type(type_name, namespace='core')

    ecephys_ext = NWBGroupSpec(
        doc=
        'Group that holds proposed extracellular electrophysiology extensions.',
        neurodata_type_def='EcephysExt',
        neurodata_type_inc='LabMetaData',
        default_name='ecephys_ext',
        groups=[
            NWBGroupSpec(name='bipolar_scheme_table',
                         neurodata_type_inc='BipolarSchemeTable',
                         doc='Bipolar referencing scheme used',
                         quantity='?')
        ])

    bipolar_scheme = NWBGroupSpec(
        doc='Table that holds information about the bipolar scheme used',
        neurodata_type_def='BipolarSchemeTable',
        neurodata_type_inc='DynamicTable',
        default_name='bipolar_scheme')

    bipolar_scheme.add_dataset(name='anodes',
                               neurodata_type_inc='DynamicTableRegion',
                               doc='references the electrodes table',
                               dims=('num_electrodes', ),
                               shape=(None, ),
                               dtype='int')

    bipolar_scheme.add_dataset(name='cathodes',
                               neurodata_type_inc='DynamicTableRegion',
                               doc='references the electrodes table',
                               dims=('num_electrodes', ),
                               shape=(None, ),
                               dtype='int')

    bipolar_scheme.add_dataset(name='anodes_index',
                               neurodata_type_inc='VectorIndex',
                               doc='Indices for the anode table',
                               dims=('num_electrode_grp', ),
                               shape=(None, ))

    bipolar_scheme.add_dataset(name='cathodes_index',
                               neurodata_type_inc='VectorIndex',
                               doc='Indices for the cathode table',
                               dims=('num_electrode_grp', ),
                               shape=(None, ))

    new_data_types = [ecephys_ext, bipolar_scheme]

    # 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)
Example #29
0
 def test_constructor(self):
     self.ns_builder = NWBNamespaceBuilder(
         "Frank Laboratory NWB Extensions", "franklab", version='0.1')
Example #30
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))