-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_extension_spec.py
More file actions
166 lines (158 loc) · 6 KB
/
create_extension_spec.py
File metadata and controls
166 lines (158 loc) · 6 KB
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
# -*- coding: utf-8 -*-
import os.path
from pynwb.spec import NWBNamespaceBuilder, export_spec, NWBGroupSpec, NWBAttributeSpec, NWBDatasetSpec
def main():
# these arguments were auto-generated from your cookiecutter inputs
ns_builder = NWBNamespaceBuilder(
doc="""Extension for defining neural probes in the probeinterface format""",
name="""ndx-probeinterface""",
version="""0.1.0""",
author=["Alessio Buccino", "Kyu Hyun Lee", "Geeling Chau"],
contact=["alessiop.buccino@gmail.com", "kyuhyun9056@gmail.com", "gchau@caltech.edu"],
)
# 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.
# all types included or used by the types specified here will also be
# included.
ns_builder.include_type(data_type="Device", namespace="core")
ns_builder.include_namespace("hdmf-common")
# TODO: define your new data types
# see https://pynwb.readthedocs.io/en/latest/extensions.html#extending-nwb
# for more information
contact_table = NWBGroupSpec(
doc="Neural probe contacts according to probeinterface specification",
datasets=[
NWBDatasetSpec(
name="contact_position",
doc="position of the contact",
dtype="float",
dims=[["num_contacts", "x, y"], ["num_contacts", "x, y, z"]],
shape=[[None, 2], [None, 3]],
neurodata_type_inc="VectorData",
),
NWBDatasetSpec(
name="contact_shape",
doc="shape of the contact; e.g. 'circle'",
dtype="text",
neurodata_type_inc="VectorData",
),
NWBDatasetSpec(
name="contact_id",
doc="unique ID of the contact",
dtype="text",
neurodata_type_inc="VectorData",
quantity="?",
),
NWBDatasetSpec(
name="shank_id",
doc="shank ID of the contact",
dtype="text",
neurodata_type_inc="VectorData",
quantity="?",
),
NWBDatasetSpec(
name="contact_plane_axes",
doc="the axes defining the contact plane",
dtype="float",
dims=[["num_contacts", "v1, v2", "x,y"], ["num_contacts", "v1,v2", "x, y, z"]],
shape=[[None, 2, 2], [None, 2, 3]],
neurodata_type_inc="VectorData",
quantity="?",
),
NWBDatasetSpec(
name="radius",
doc="radius of a circular contact",
dtype="float",
neurodata_type_inc="VectorData",
quantity="?",
),
NWBDatasetSpec(
name="width",
doc="width of a rectangular or square contact",
dtype="float",
neurodata_type_inc="VectorData",
quantity="?",
),
NWBDatasetSpec(
name="height",
doc="height of a rectangular contact",
dtype="float",
neurodata_type_inc="VectorData",
quantity="?",
),
NWBDatasetSpec(
name="device_channel_index_pi",
doc="index of the channel connected to the contact",
dtype="int",
neurodata_type_inc="VectorData",
quantity="?",
),
],
neurodata_type_inc="DynamicTable",
neurodata_type_def="ContactTable",
)
probe = NWBGroupSpec(
doc="Neural probe object according to probeinterface specification",
attributes=[
NWBAttributeSpec(
name="ndim",
doc="dimension of the probe",
dtype="int",
required=True,
default_value=2
),
NWBAttributeSpec(
name="model_name",
doc="model of the probe; e.g. 'Neuropixels 1.0'",
dtype="text",
required=False,
),
NWBAttributeSpec(
name="serial_number",
doc="serial number of the probe",
dtype="text",
required=False,
),
NWBAttributeSpec(
name="unit",
doc="SI unit used to define the probe; e.g. 'meter'.",
dtype="text",
required=True,
default_value="micrometer",
),
NWBAttributeSpec(
name="annotations",
doc="annotations attached to the probe",
dtype="text",
required=False
),
],
neurodata_type_inc="Device",
neurodata_type_def="Probe",
groups=[
NWBGroupSpec(
doc="Neural probe contacts according to probeinterface specification",
neurodata_type_inc="ContactTable",
quantity=1,
)
],
datasets=[
NWBDatasetSpec(
name="planar_contour",
doc="The planar polygon that outlines the probe contour.",
dtype="float",
dims=[["num_points", "x"], ["num_points", "x, y"], ["num_points", "x, y, z"]],
shape=[[None, 1], [None, 2], [None, 3]],
)
],
)
new_data_types = [probe, contact_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)
print("Spec files generated. Please make sure to rerun `pip install .` to load the changes.")
if __name__ == "__main__":
# usage: python create_extension_spec.py
main()