Skip to content

Commit ca32f0a

Browse files
committed
[docs] example update for create_data_array api change
1 parent 65f3b18 commit ca32f0a

17 files changed

+47
-79
lines changed

docs/source/annotations.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ in the `odml terminologies <https://github.com/G-Node/odml-terminologies>`_
1212
Most of the data entities can link to metadata sections.
1313

1414
.. literalinclude:: examples/annotations.py
15-
:lines: 5-22
15+
:lines: 5-21
1616
:caption: We can add arbitrary metadata in trees of *Sections* and *Properties* (:download:`example code <examples/annotations.py>`).
1717

1818
For a quick view of the metadata tree pretty-print it:
1919

2020
.. literalinclude:: examples/annotations.py
21-
:lines: 25
21+
:lines: 24
2222

2323
which leads to an output like this. The argument ``max_depth=-1`` notes that the full depth of the tree should be displayed. In the default case (``max_depth=1``) the display will be more compact and will not recursively traverse the whole tree.
2424

@@ -35,11 +35,11 @@ which leads to an output like this. The argument ``max_depth=-1`` notes that the
3535
The *Sections* add much like dictionaries. To access e.g. the "resting potential" of the cell we may call:
3636

3737
.. literalinclude:: examples/annotations.py
38-
:lines: 25
38+
:lines: 26
3939

4040
If we do not know the exact path of the *Section* we are looking for, we need to search it by passing a function (in this case a lambda function) to the ``find_section`` method. The following code shows two examples in which we look first for a section with a given name or second a section which contains a property with a certain name.
4141

4242
.. literalinclude:: examples/annotations.py
43-
:lines: 29 - 32
43+
:lines: 28 - 31
4444

4545
The result of the ``find_sections`` will always be list which may be empty if no match was found. Therefore, the call in the last line is to some extent risky and would lead to an OutOfBounds exception if the search failed.

docs/source/examples/annotations.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ def main():
44

55
nixfile = nixio.File.open("annotations.nix", mode=nixio.FileMode.Overwrite)
66
block = nixfile.create_block("recording 1", "nix.session")
7-
7+
88
session = nixfile.create_section('recording session', 'odml.recording')
99
session['experimenter'] = 'John Doe'
1010
session['recording date'] = '2014-01-01'
11-
11+
1212
subject = session.create_section('subject', 'odml.subject')
1313
subject['id'] = 'mouse xyz'
1414

1515
cell = subject.create_section('cell', 'odml.cell')
16-
v = -64.5
1716
p = cell.create_property('resting potential', -64.5)
1817
p.uncertainty = 2.25
1918
p.unit = 'mV'
@@ -27,11 +26,10 @@ def main():
2726
print(block.metadata["subject"]["cell"]["resting potential"])
2827

2928
print(session.find_sections(lambda s: s.name.lower() == "cell"))
30-
29+
3130
print(session.find_sections(lambda s: "resting potential" in s.props))
3231
print(session.find_sections(lambda s: "resting potential" in s.props)[0]["resting potential"])
3332
nixfile.close()
3433

3534
if __name__ == "__main__":
3635
main()
37-

docs/source/examples/categoryData.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ def create_data():
1313

1414
def store(nixfile, data, categories):
1515
b = nixfile.create_block("test", "nix.session")
16-
data_array = b.create_data_array("category data", "nix.categorical", data=data)
17-
data_array.label = "temperature"
18-
data_array.unit = "K"
19-
16+
data_array = b.create_data_array("category data", "nix.categorical", data=data, label="temperature", unit="K")
2017
data_array.append_set_dimension(categories)
2118

2219
return data_array

docs/source/examples/continuousRecording.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ def main():
4848

4949
nixfile = nixio.File.open("continuous_recording.nix", nixio.FileMode.Overwrite, compression=nixio.Compression.DeflateNormal)
5050
block = nixfile.create_block("Session 1", "nix.recording_session")
51-
data_array = block.create_data_array("multichannel_data", "nix.sampled.multichannel", dtype=nixio.DataType.Double, shape=(chunk_samples, number_of_channels))
52-
data_array.label = "voltage"
53-
data_array.unit = "mV"
51+
data_array = block.create_data_array("multichannel_data", "nix.sampled.multichannel", dtype=nixio.DataType.Double,
52+
shape=(chunk_samples, number_of_channels), label="voltage", unit="mV")
5453
data_array.append_sampled_dimension(0.001, label="time", unit="s")
5554
data_array.append_set_dimension(labels=["channel %i" % i for i in range(number_of_channels)])
5655

docs/source/examples/irregularlySampledData.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ def main():
5252
block = file.create_block("block name", "nix.session")
5353

5454
# create a 'DataArray' to take the data, add some information about the signal
55-
data = block.create_data_array("sinewave", "nix.irregular_sampled", data=values)
56-
data.unit = "mV"
57-
data.label = "voltage"
55+
data = block.create_data_array("sinewave", "nix.irregular_sampled", data=values,
56+
label="voltage", unit="mV")
5857
# add a descriptor for the xaxis
5958
data.append_range_dimension(ticks=times, label="time", unit="s")
6059

docs/source/examples/multipleTimeSeries.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,11 @@ def main():
6161
block = file.create_block("block name", "nix.session")
6262
# create a 'DataArray' to take the data, add some information about the signal
6363
y = np.vstack((sine, cosine))
64-
data = block.create_data_array("waveforms", "nix.regular_sampled.multiple_series", data=y)
65-
data.unit = "mV"
66-
data.label = "voltage"
64+
data = block.create_data_array("waveforms", "nix.regular_sampled.multiple_series", data=y, label="voltage", unit="mV")
6765
# descriptor for first dimension is a set
68-
set_dim = data.append_set_dimension()
69-
set_dim.labels = ['sin', 'cos']
66+
data.append_set_dimension(labels=['sin', 'cos'])
7067
# add a descriptor for the xaxis
71-
dim = data.append_sampled_dimension(stepsize)
72-
dim.unit = "s"
73-
dim.label = "time"
74-
dim.offset = 0.0 # optional
68+
data.append_sampled_dimension(stepsize, offset=0.0, label="time", unit="s")
7569

7670
# let's plot the data from the stored information
7771
plot_data(data)

docs/source/examples/multiple_points.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,10 @@ def main():
4646

4747
nixfile = nixio.File.open("multiple_points.nix", nixio.FileMode.Overwrite)
4848
block = nixfile.create_block("recording session", "nix.session")
49-
signal_array = block.create_data_array("signal", "nix.sampled", data=signal)
50-
signal_array.label = "voltage"
51-
signal_array.unit = "mV"
49+
signal_array = block.create_data_array("signal", "nix.sampled", data=signal, label="voltage", unit="mV")
5250
signal_array.append_sampled_dimension(sampling_interval, label="time", unit="s")
5351

54-
event_array = block.create_data_array("threshold crossings", "nix.events.threshold_crossings", data=events)
55-
event_array.label = "time"
56-
event_array.unit = "s"
52+
event_array = block.create_data_array("threshold crossings", "nix.events.threshold_crossings", data=events, label="time", unit="s")
5753
event_array.append_range_dimension_using_self()
5854

5955
mtag = block.create_multi_tag("event tag", "nix.tag.events", event_array)

docs/source/examples/rangeDimensionLink.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ def main():
1313
nixfile = nixio.File.open("range_link.nix", nixio.FileMode.Overwrite)
1414
b = nixfile.create_block("session", "nix.session")
1515

16-
data_array = b.create_data_array("event times", "nix.event.times", data=event_times)
17-
data_array.label = "time"
18-
data_array.unit = "s"
16+
data_array = b.create_data_array("event times", "nix.event.times", data=event_times, label="time", unit="s")
1917
data_array.append_range_dimension_using_self()
2018

2119
nixfile.close()

docs/source/examples/regularlySampledData.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ def main():
5454
block = file.create_block("block name", "nix.session")
5555

5656
# create a 'DataArray' to take the sinewave, add some information about the signal
57-
data = block.create_data_array("sinewave", "nix.regular_sampled", data=y)
58-
data.unit = "mV"
59-
data.label = "voltage"
57+
data = block.create_data_array("sinewave", "nix.regular_sampled", data=y,
58+
label="voltage", unit="mV")
6059
# add a descriptor for the xaxis
6160
data.append_sampled_dimension(stepsize, label="time", unit="s", offset=0.0)
6261

docs/source/examples/singleROI.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,9 @@ def main():
6969
# create a 'DataArray' to take the sinewave, add some information about the signal
7070
data = block.create_data_array("lenna", "nix.image.rgb", data=img_data)
7171
# add descriptors for width, height and channels
72-
height_dim = data.append_sampled_dimension(1)
73-
height_dim.label = "height"
74-
width_dim = data.append_sampled_dimension(1)
75-
width_dim.label = "width"
76-
color_dim = data.append_set_dimension()
77-
color_dim.labels = channels
72+
data.append_sampled_dimension(1, label="height")
73+
data.append_sampled_dimension(1, label="width")
74+
data.append_set_dimension(labels=channels)
7875

7976
# create a Tag, position and extent must be 3-D since the data is 3-D
8077
position = [250, 250, 0]

0 commit comments

Comments
 (0)