Debian Codegraph @

docs/source/user_api.rst

raw
1 ========================
2 High Level API Reference
3 ========================
4
5
6 File
7 ====
8
9 A File represents a specific data source of a NIX back-end for example an NIX HDF5 file. All entities of the nix data
10 model must exist in the context of an open File object. Therefore NIX entities can't be
11 initialized via their constructors but only through the factory methods of their respective parent entity.
12
13 Working with files
14 ------------------
15
16 .. code-block:: python
17 :linenos:
18
19 file = File.open("test.h5", FileMode.ReadWrite)
20 # do some work
21 file.close()
22
23
24 File open modes
25 ---------------
26
27 .. autoclass:: nixio.FileMode
28 :members:
29 :undoc-members:
30 :exclude-members: names, values
31
32 File API
33 --------
34
35 .. autoclass:: nixio.File
36 :members:
37 :inherited-members:
38 :undoc-members:
39
40 Block
41 =====
42
43 The Block entity is a top-level, summarizing element that allows to
44 group the other data entities belonging for example to the same recording session.
45 All data entities such as Source, DataArray, DataFrame, Tag and
46 MultiTag have to be associated with one Block.
47
48 Create a new Block
49 ------------------
50
51 A block can only be created on an existing file object. Do not use the blocks constructors for this
52 purpose.
53
54 .. code-block:: python
55 :linenos:
56
57 block = file.create_block("session one", "recordingsession");
58
59 Working with blocks
60 -------------------
61
62 After a block was created it can be used to create further entities. See the documentation of
63 Source, DataArray, DataFrame, Tag and MultiTag for more information. The next example shows how some
64 properties of a block can be accessed.
65
66 .. code-block:: python
67 :linenos:
68
69 block = file.blocks[some_id]
70
71 # add metadata to a block
72 section = file.sections[sec_id]
73 block.metadata = section
74
75 # get associated metadata from a block
76 block.metadata
77
78 # remove associated metadata from a block
79 block.metadata = None
80
81 Deleting a block
82 ----------------
83
84 When a block is deleted from a file all contained data e.g. sources, data arrays
85 and tags will be removed too.
86
87 .. code-block:: python
88 :linenos:
89
90 del file.blocks[some_id]
91
92 Block API
93 ---------
94
95 .. autoclass:: nixio.Block
96 :members:
97 :inherited-members:
98 :undoc-members:
99
100 DataArray
101 =========
102
103 The DataArray is the core entity of the NIX data model, its purpose is to
104 store arbitrary n-dimensional data. In addition to the common fields id,
105 name, type, and definition the DataArray stores sufficient information to
106 understand the physical nature of the stored data.
107
108 A guiding principle of the data model is provides enough information to create a
109 plot of the stored data. In order to do so, the DataArray defines a property
110 dataType which provides the physical type of the stored data (for example
111 16 bit integer or double precision IEEE floatingpoint number).
112 The property unit specifies the SI unit of the values stored in the
113 DataArray whereas the label defines what is given in this units.
114 Together, both specify what corresponds to the the y-axis of a plot.
115
116 In some cases it is much more efficient or convenient to store data not as
117 floating point numbers but rather as (16 bit) integer values as, for example
118 read from a data acquisition board. In order to convert such data to the
119 correct values, we follow the approach taken by the comedi data-acquisition
120 library (http://www.comedi.org) and provide polynomCoefficients and an
121 expansionOrigin.
122
123 Create and delete a DataArray
124 -----------------------------
125
126 A DataArray can only be created at an existing block. Do not use the
127 DataArrays constructors for this purpose.
128
129 .. code-block:: python
130 :linenos:
131
132 data_array = block.crate_data_array("matrix", "data");
133 del block.data_arrays[data_array]
134
135
136 DataArray API
137 -------------
138
139 .. autoclass:: nixio.DataArray
140 :members:
141 :inherited-members:
142 :undoc-members:
143
144 DataSet
145 =======
146
147 The DataSet object is used for data input/output to the underlying storage.
148
149 .. autoclass:: nixio.data_array.DataSet
150 :members:
151 :inherited-members:
152 :undoc-members:
153
154 DataFrame
155 =========
156
157 The DataFrame presents data in a rows-and-columns format.
158
159 Create and delete a DataFrame
160 -----------------------------
161
162 .. code-block:: python
163 :linenos:
164
165 data_array = block.create_data_frame("table", "df", col_dict={}, data=[]);
166 del block.data_frames[data_frame]
167
168 DataFrame API
169 -------------
170
171 .. autoclass:: nixio.DataFrame
172 :members:
173 :inherited-members:
174 :undoc-members:
175
176 Tags
177 ====
178
179 Besides the DataArray the tag entities can be considered as the other
180 core entities of the data model.
181 They are meant to attach annotations directly to the data and to establish meaningful
182 links between different kinds of stored data.
183 Most importantly tags allow the definition of points or regions of interest in data
184 that is stored in other DataArray entities. The data array entities the
185 tag applies to are defined by its property references.
186
187 Further the referenced data is defined by an origin vector called position
188 and an optional extent vector that defines its size.
189 Therefore position and extent of a tag, together with the references field
190 defines a group of points or regions of interest collected from a subset of all
191 available DataArray entities.
192
193 Further tags have a field called features which makes it possible to associate
194 other data with the tag. Semantically a feature of a tag is some additional data that
195 contains additional information about the points of hyperslabs defined by the tag.
196 This could be for example data that represents a stimulus (e.g. an image or a
197 signal) that was applied in a certain interval during the recording.
198
199 Tag API
200 -------
201
202 .. autoclass:: nixio.Tag
203 :members:
204 :inherited-members:
205 :undoc-members:
206
207 MultiTag API
208 ------------
209
210 .. autoclass:: nixio.MultiTag
211 :members:
212 :inherited-members:
213 :undoc-members:
214
215 Source
216 ======
217
218 .. autoclass:: nixio.Source
219 :members:
220 :inherited-members:
221 :undoc-members:
222
223
224 Group
225 =====
226
227 Groups establish a simple way of grouping entities that in some way
228 belong together. The Group exists inside a Block and can contain
229 (link) DataArrays, Tags, and MultiTags. As any other nix-entity, the
230 Groups is named, has a type, and a definition property. Additionally,
231 it contains data_arrays, tags, and multi_tags lists. As indicated
232 before, the group does only link the entities. Thus, deleting elements
233 from the lists does not remove them from file, it merely removes the
234 link from the group.
235
236 .. code-block:: python
237 :linenos:
238
239 data_array = block.create_data_array("matrix", "data");
240 tag = block.create_tag("a tag", "event", [0.0, 1.0])
241 group = block.create_group("things that belong together", "group")
242 group.tags.append(tag)
243 group.data_arrays.append(data_array)
244
245 del group.data_arrays[data_array]
246 del group.tags[tag]
247
248
249 Group API
250 ---------
251
252 .. autoclass:: nixio.Group
253 :members:
254 :inherited-members:
255 :undoc-members:
256
257
258 Section
259 =======
260
261 Metadata stored in a NIX file can be accessed directly from an open file.
262
263 Create and delete sub sections
264 ------------------------------
265
266 .. code-block:: python
267 :linenos:
268
269 sub = section.create_section("a name", "type")
270 del section.sections[sub]
271
272 Add and remove properties
273 -------------------------
274
275 Properties can be created using the create_property method. Existing properties can be accessed and deleted
276 directly from the respective section.
277
278 .. code-block:: python
279 :linenos:
280
281 section.create_property("one", [1])
282 section.create_property("two", [2])
283
284 # iterate over properties
285 for p in section:
286 print(p)
287
288 # access by name
289 one = section["one"]
290
291 # convert properties into a dict
292 dct = dict(section.items())
293
294 # delete properties
295 del section["one"]
296 del section["two"]
297
298 Section API
299 -----------
300
301 .. autoclass:: nixio.Section
302 :members:
303 :inherited-members:
304 :undoc-members:
305
306 Property
307 ========
308
309 .. autoclass:: nixio.Property
310 :members:
311 :inherited-members:
312 :undoc-members:
313