Esempio n. 1
0
 def test_load_namespace_with_reftype_attribute_check_autoclass_const(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)
     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. 2
0
    def setUp(self):
        self.foo_spec = GroupSpec(
            'A test group specification with data type Foo',
            data_type_def='Foo')
        self.bar_spec = GroupSpec(
            'A test group specification with a data type Bar',
            data_type_def='Bar',
            datasets=[DatasetSpec('an example dataset', 'int', name='data')],
            attributes=[
                AttributeSpec('attr1', 'an example string attribute', 'text'),
                AttributeSpec('attr2', 'an example integer attribute', 'int'),
                AttributeSpec('foo',
                              'a referenced foo',
                              RefSpec('Foo', 'object'),
                              required=False)
            ])

        self.spec_catalog = SpecCatalog()
        self.spec_catalog.register_spec(self.foo_spec, 'test.yaml')
        self.spec_catalog.register_spec(self.bar_spec, 'test.yaml')
        self.namespace = SpecNamespace('a test namespace',
                                       CORE_NAMESPACE, [{
                                           'source': 'test.yaml'
                                       }],
                                       version='0.1.0',
                                       catalog=self.spec_catalog)
        self.namespace_catalog = NamespaceCatalog()
        self.namespace_catalog.add_namespace(CORE_NAMESPACE, self.namespace)
        self.type_map = TypeMap(self.namespace_catalog)
        self.type_map.register_container_type(CORE_NAMESPACE, 'Foo', Foo)
        self.type_map.register_container_type(CORE_NAMESPACE, 'Bar', Bar)
        self.manager = BuildManager(self.type_map)
        self.foo_mapper = ObjectMapper(self.foo_spec)
        self.bar_mapper = ObjectMapper(self.bar_spec)
Esempio n. 3
0
 def setUpBarSpec(self):
     self.bar_spec = GroupSpec(
         doc='A test group specification with a data type Bar',
         data_type_def='Bar',
         attributes=[
             AttributeSpec('foo', 'a referenced foo',
                           RefSpec('Foo', 'object'))
         ])
Esempio n. 4
0
 def test_simplify_cpd_type_ref(self):
     compound_type = [
         DtypeSpec('test', 'test field', 'float'),
         DtypeSpec('test2', 'test field2',
                   RefSpec(target_type='MyType', reftype='object'))
     ]
     expected_result = ['float', 'object']
     result = DtypeHelper.simplify_cpd_type(compound_type)
     self.assertListEqual(result, expected_result)
Esempio n. 5
0
 def test_constructor_ref_spec(self):
     dtype = RefSpec('TimeSeries', 'object')
     spec = DatasetSpec(doc='my first dataset',
                        dtype=dtype,
                        name='dataset1',
                        dims=(None, None),
                        attributes=self.attributes,
                        linkable=False,
                        data_type_def='EphysData')
     self.assertDictEqual(spec['dtype'], dtype)
Esempio n. 6
0
 def setUpBazSpec(self):
     self.baz_spec = DatasetSpec(
         doc='a list of references to Foo objects',
         dtype=RefSpec('Foo', 'object'),
         name='MyBaz',
         shape=[None],
         data_type_def='Baz',
         attributes=[
             AttributeSpec('baz_attr', 'an example string attribute',
                           'text')
         ])
Esempio n. 7
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))
def main():
    ns_builder = NamespaceBuilder(
        doc="""HDMF extensions for storing hierarchical behavioral data""",
        name="""ndx-hierarchical-behavioral-data""",
        version="""0.1.1""",
        author=list(map(str.strip, """Ben Dichter""".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('TimeIntervals', namespace='core')
    ns_builder.include_type('DynamicTableRegion', namespace='core')
    ns_builder.include_type('VectorData', namespace='core')

    behav_table = NWBGroupSpec(
        neurodata_type_def='HierarchicalBehavioralTable',
        neurodata_type_inc='TimeIntervals',
        doc='DynamicTable that holds hierarchical behavioral information.')

    behav_table.add_dataset(name='label',
                            neurodata_type_inc='VectorData',
                            doc='The label associated with each item',
                            dtype='text')

    next_tier = behav_table.add_dataset(
        name='next_tier',
        neurodata_type_inc='DynamicTableRegion',
        doc='reference to the next tier',
    )
    next_tier.add_attribute(name='table',
                            dtype=RefSpec(target_type='TimeIntervals',
                                          reftype='object'),
                            doc='reference to the next level')
    behav_table.add_dataset(
        name='next_tier_index',
        neurodata_type_inc='VectorIndex',
        doc='Index dataset for next tier.',
    )

    new_data_types = [behav_table]

    # 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. 9
0
 def test_build_spec_reftype(self):
     spec_dict = {
         'name': 'attribute1',
         'doc': 'my first attribute',
         'dtype': {
             'target_type': 'AnotherType',
             'reftype': 'object'
         }
     }
     expected = spec_dict.copy()
     expected['dtype'] = RefSpec(target_type='AnotherType',
                                 reftype='object')
     ret = AttributeSpec.build_spec(spec_dict)
     self.assertTrue(isinstance(ret, AttributeSpec))
     self.assertDictEqual(ret, expected)
Esempio n. 10
0
 def setUpBazSpec(self):
     self.baz_spec = DatasetSpec(
         doc='a list of references to Foo objects',
         dtype=[
             DtypeSpec(name='id',
                       dtype='uint64',
                       doc='The unique identifier in this table.'),
             DtypeSpec(name='foo',
                       dtype=RefSpec('Foo', 'object'),
                       doc='The foo in this table.'),
         ],
         name='MyBaz',
         shape=[None],
         data_type_def='Baz',
         attributes=[
             AttributeSpec('baz_attr', 'an example string attribute',
                           'text')
         ])
Esempio n. 11
0
 def test_check_dtype_ref(self):
     refspec = RefSpec(target_type='target', reftype='object')
     self.assertIs(refspec, DtypeHelper.check_dtype(refspec))
Esempio n. 12
0
                             neurodata_type_inc='NWBDataInterface',
                             name='manipulations',
                             doc='stores maipulations',
                             quantity='?',
                             groups=[manipulation])

surgery = NWBGroupSpec(
    neurodata_type_def='Surgery',
    doc='information about a specific surgery',
    quantity='+',
    neurodata_type_inc='NWBDataInterface',
    datasets=[
        NWBDatasetSpec(name='devices',
                       quantity='?',
                       doc='links to implanted/explanted devices',
                       dtype=RefSpec('Device', 'object'))
    ],
    groups=[virus_injections, manipulations],
    attributes=[
        NWBAttributeSpec(name='start_datetime',
                         doc='datetime in ISO 8601',
                         dtype='text',
                         required=False),
        NWBAttributeSpec(name='end_datetime',
                         doc='datetime in ISO 8601',
                         dtype='text',
                         required=False),
        NWBAttributeSpec(
            name='weight',
            required=False,
            dtype='text',
Esempio n. 13
0
 def test_refspec_dtype(self):
     # just making sure this does not cause an error
     DtypeSpec('column1', 'an example column',
               RefSpec('TimeSeries', 'object'))
Esempio n. 14
0
def main():
    # these arguments were auto-generated from your cookie-cutter inputs
    ns_builder = NamespaceBuilder(
        doc=
        """Objects for rigorously defining spatial coordinates, object shapes, and transformations""",
        name="""ndx-spatial-coordinates""",
        version="""0.1.0""",
        author=list(map(str.strip, """Ben Dichter""".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('Container', namespace='hdmf-common')

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

    Space = GroupSpec(data_type_def='Space',
                      data_type_inc='Container',
                      doc='space',
                      attributes=[
                          AttributeSpec(name='R',
                                        doc='dimensionality of space',
                                        dtype='int')
                      ])

    Spaces = GroupSpec(data_type_def='Spaces',
                       data_type_inc='Container',
                       doc='contains spaces',
                       groups=[
                           GroupSpec(data_type_inc=Space,
                                     quantity='*',
                                     doc='spaces are stored here')
                       ])

    CoordinateSystem = GroupSpec(
        data_type_def='CoordinateSystem',
        data_type_inc='Container',
        doc='coordinate system',
        links=[
            LinkSpec(doc='link to space', target_type='Space', name='space')
        ],
        attributes=[
            AttributeSpec(name='R',
                          doc='dimensionality of coordinate system',
                          dtype='int')
        ])

    CoordinateSystems = GroupSpec(
        data_type_def='CoordinateSystems',
        data_type_inc='Container',
        doc='coordinate systems',
        groups=[
            GroupSpec(data_type_inc=CoordinateSystem,
                      quantity='*',
                      doc='coordinate systems are stored here')
        ],
    )

    RegistrationProtocol = GroupSpec(data_type_def='RegistrationProtocol',
                                     data_type_inc='Container',
                                     doc='registration protocol')

    RegistrationProtocols = GroupSpec(
        data_type_def='RegistrationProtocols',
        data_type_inc='Container',
        doc='registration protocols',
        groups=[
            GroupSpec(data_type_inc=RegistrationProtocol,
                      quantity='*',
                      doc='registration protocols are stored here')
        ],
    )

    CoordinateRegistrationProcess = GroupSpec(
        data_type_def='CoordinateRegistrationProcess',
        data_type_inc='Container',
        doc='coordinate registration process',
        links=[
            LinkSpec(doc='registration protocol',
                     target_type='RegistrationProtocol',
                     name='registration_protocol')
        ])

    CoordinateRegistrationProcesses = GroupSpec(
        data_type_def='CoordinateRegistrationProcesses',
        data_type_inc='Container',
        doc='registration process',
        groups=[
            GroupSpec(data_type_inc=CoordinateRegistrationProcess,
                      quantity='*',
                      doc='registration processes are stored here')
        ],
    )

    Transform = GroupSpec(
        data_type_def='Transform',
        data_type_inc='Container',
        doc='transform',
        links=[
            LinkSpec(doc='domain coordinate system',
                     target_type='CoordinateSystem',
                     name='domain_coordinate_system'),
            LinkSpec(doc='range coordinate system',
                     target_type='CoordinateSystem',
                     name='range_coordinate_system')
        ],
    )

    AffineTransform = GroupSpec(data_type_def='AffineTransform',
                                data_type_inc=Transform,
                                doc='affine transform',
                                datasets=[
                                    DatasetSpec(doc='affine transform matrix',
                                                dtype='float',
                                                shape=(None, None),
                                                name='M')
                                ])

    DeformableTransform = GroupSpec(
        data_type_def='DeformableTransform',
        data_type_inc=Transform,
        doc='deformable transform',
        datasets=[DatasetSpec(doc='vector image', dtype='float', name='I')])

    Transforms = GroupSpec(
        data_type_def='Transforms',
        data_type_inc='Container',
        doc='transforms',
        groups=[
            GroupSpec(data_type_inc=Transform,
                      quantity='*',
                      doc='transforms are stored here')
        ],
    )

    PhysicalObjectType = GroupSpec(data_type_def='PhysicalObjectType',
                                   data_type_inc='Container',
                                   doc='physical object type',
                                   groups=[
                                       GroupSpec(name='geometry',
                                                 doc='geometry',
                                                 datasets=[
                                                     DatasetSpec(name='nodes',
                                                                 doc='nodes',
                                                                 dtype='float',
                                                                 shape=(None,
                                                                        3)),
                                                     DatasetSpec(name='edges',
                                                                 doc='edges',
                                                                 dtype='uint',
                                                                 shape=(None,
                                                                        3))
                                                 ])
                                   ],
                                   links=[
                                       LinkSpec(name='coordinate_system',
                                                doc='coordinate system',
                                                target_type='CoordinateSystem')
                                   ])

    ElectrodeType = GroupSpec(data_type_def='ElectrodeType',
                              data_type_inc=PhysicalObjectType,
                              doc='electrode type',
                              attributes=[
                                  AttributeSpec(name='electrode_type',
                                                doc='electrode type',
                                                dtype='text')
                              ])

    ElectrodeTypes = GroupSpec(
        data_type_def='ElectrodeTypes',
        data_type_inc='Container',
        doc='electrode types',
        groups=[
            GroupSpec(data_type_inc=ElectrodeType,
                      quantity='*',
                      doc='electrode types are stored here')
        ],
    )

    PhysicalObjectWithSubObjectsType = GroupSpec(
        data_type_def='PhysicalObjectWithSubObjectsType',
        data_type_inc=PhysicalObjectType,
        doc='physical object with sub objects',
        groups=[
            GroupSpec(
                name='sites',
                doc='sites',
                datasets=[
                    DatasetSpec(
                        name='sites',
                        doc='sites',
                        dtype=[
                            DtypeSpec(
                                name='position',
                                doc='position',
                                dtype='float',
                                #shape=(3,)
                            ),
                            DtypeSpec(
                                name='normal',
                                doc='normal',
                                dtype='float',
                                #shape=(3,)
                            ),
                            DtypeSpec(name='object_type',
                                      doc='object type',
                                      dtype=RefSpec(
                                          target_type='PhysicalObjectType',
                                          reftype='object')),
                        ])
                ])
        ])

    ProbeType = GroupSpec(
        data_type_def='ProbeType',
        data_type_inc=PhysicalObjectWithSubObjectsType,
        doc='probe type',
    )

    ProbeTypes = GroupSpec(
        data_type_def='ProbeTypes',
        data_type_inc='Container',
        doc='probe types',
        groups=[
            GroupSpec(data_type_inc=ProbeType,
                      quantity='*',
                      doc='probe types are stored here')
        ],
    )

    SubjectBrain = GroupSpec(data_type_def='SubjectBrain',
                             data_type_inc=PhysicalObjectWithSubObjectsType,
                             doc='subject brain')

    SpaceInfo = GroupSpec(
        data_type_def='SpaceInfo',
        data_type_inc='Container',
        doc='all space info goes in here',
        groups=[
            GroupSpec(data_type_inc=Spaces, doc='spaces'),
            GroupSpec(data_type_inc=CoordinateSystems,
                      doc='coordinate systems'),
            GroupSpec(data_type_inc=RegistrationProtocols,
                      doc='registration protocols'),
            GroupSpec(data_type_inc=CoordinateRegistrationProcesses,
                      doc='registration processes'),
            GroupSpec(data_type_inc=Transforms, doc='transforms'),
            GroupSpec(data_type_inc=ElectrodeTypes, doc='electrode types'),
            GroupSpec(data_type_inc=ProbeTypes, doc='probe types'),
            GroupSpec(data_type_inc=SubjectBrain, doc='subject brain')
        ])

    new_data_types = [
        Space, Spaces, CoordinateSystem, CoordinateSystems,
        RegistrationProtocol, RegistrationProtocols,
        CoordinateRegistrationProcess, CoordinateRegistrationProcesses,
        Transform, AffineTransform, DeformableTransform, Transforms,
        PhysicalObjectType, ElectrodeType, ElectrodeTypes,
        PhysicalObjectWithSubObjectsType, ProbeType, ProbeTypes, SubjectBrain,
        SpaceInfo
    ]

    # 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 test_constructor(self):
     spec = RefSpec('TimeSeries', 'object')
     self.assertEqual(spec.target_type, 'TimeSeries')
     self.assertEqual(spec.reftype, 'object')
     json.dumps(spec)  # to ensure there are no circular links
Esempio n. 16
0
 def test_isregion(self):
     spec = RefSpec('TimeSeries', 'object')
     self.assertFalse(spec.is_region())
     spec = RefSpec('Data', 'region')
     self.assertTrue(spec.is_region())
Esempio n. 17
0
 def test_wrong_reference_type(self):
     with self.assertRaises(ValueError):
         RefSpec('TimeSeries', 'unknownreftype')
Esempio n. 18
0
 def test_is_ref(self):
     spec = DtypeSpec('column1', 'an example column',
                      RefSpec('TimeSeries', 'object'))
     self.assertTrue(DtypeSpec.is_ref(spec))
     spec = DtypeSpec('column1', 'an example column', 'int')
     self.assertFalse(DtypeSpec.is_ref(spec))
Esempio n. 19
0
    def test_value_none(self):
        spec = DatasetSpec('an example dataset', 'int', name='data')
        self.assertTupleEqual(ObjectMapper.convert_dtype(spec, None), (None, 'int'))

        spec = DatasetSpec('an example dataset', RefSpec(reftype='object', target_type='int'), name='data')
        self.assertTupleEqual(ObjectMapper.convert_dtype(spec, None), (None, 'object'))