-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_extension_spec.py
399 lines (366 loc) · 10.9 KB
/
create_extension_spec.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# -*- coding: utf-8 -*-
import os.path
from hdmf.spec import NamespaceBuilder, GroupSpec, AttributeSpec, \
LinkSpec, DatasetSpec, DtypeSpec, RefSpec, export_spec
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, """ben.dichter@catalystneuro.com""".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',
shape=(
[None]*3,
[None]*4
)
)
]
)
Transforms = GroupSpec(
data_type_def='Transforms',
data_type_inc='Container',
doc='transforms',
groups=[
GroupSpec(
data_type_inc=Transform,
quantity='*',
doc='transforms are stored here'
)
],
)
Geometry = GroupSpec(
data_type_def='Geometry',
data_type_inc='Container',
doc='doc',
links=[
LinkSpec(
name='coordinate_system',
doc='coordinate system',
target_type='CoordinateSystem'
)
]
)
TriangularMeshGeometry = GroupSpec(
data_type_def='TriangularMeshGeometry',
data_type_inc='Geometry',
doc='trimesh geometry',
datasets=[
DatasetSpec(
name='nodes',
doc='nodes',
dtype='float',
shape=(
(None, 2),
(None, 3)
)
),
DatasetSpec(
name='edges',
doc='edges',
dtype='uint',
shape=(None, 3)
)
],
)
PhysicalObjectType = GroupSpec(
data_type_def='PhysicalObjectType',
data_type_inc='Container',
doc='physical object with sub objects',
datasets=[
DatasetSpec(
quantity='?',
name='children',
doc='children',
dtype=[
DtypeSpec(
name='position',
doc='position',
dtype='float',
#shape=(
# (2,),
# (3,)
#),
#dims=(
# ('x, y'),
# ('x, y, z')
#)
),
DtypeSpec(
name='normal',
doc='normal',
dtype='float',
#shape=(3,)
),
DtypeSpec(
name='object_type',
doc='object type',
dtype=RefSpec(
target_type='PhysicalObjectType',
reftype='object'
)
),
]
)
]
)
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'
)
],
)
ProbeType = GroupSpec(
data_type_def='ProbeType',
data_type_inc=PhysicalObjectType,
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=PhysicalObjectType,
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,
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)
if __name__ == "__main__":
# usage: python create_extension_spec.py
main()