Skip to content

Commit 54fdf96

Browse files
committed
[docs] update news and annotations
1 parent 8cb8a9a commit 54fdf96

File tree

3 files changed

+77
-18
lines changed

3 files changed

+77
-18
lines changed

docs/source/annotations.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,35 @@ The *Sections* add much like dictionaries. To access e.g. the "resting potential
3737
.. literalinclude:: examples/annotations.py
3838
:lines: 26
3939

40+
Extending Properties
41+
--------------------
42+
43+
Properties can carry multiple values and additional information such as a definition.
44+
45+
.. literalinclude:: examples/annotations.py
46+
:lines: 33-35
47+
48+
Reading the values will return a tuple. This has the background that one cannot change a tuple. Changing the values stored in a *Property* can be done e.g. by the ``extend_values`` method
49+
50+
.. literalinclude:: examples/annotations.py
51+
:lines: 37-38
52+
53+
One can extend it by single values or by lists of values.
54+
55+
The data type of all values must, however, be the same. Adding a number to the list of strings will fail with a ``TypeError``:
56+
57+
.. literalinclude:: examples/annotations.py
58+
:lines: 40-43
59+
60+
.. code-block:: text
61+
62+
New data type '<class 'numpy.int64'>' is inconsistent with the Property's data type '<class 'numpy.str_'>'
63+
64+
**Note:** Once the property has been created, the data type can't be changed. One would need to create a replacement with the desired data type.
65+
66+
Finding annotations
67+
-------------------
68+
4069
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.
4170

4271
.. literalinclude:: examples/annotations.py

docs/source/examples/annotations.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ def main():
2929

3030
print(session.find_sections(lambda s: "resting potential" in s.props))
3131
print(session.find_sections(lambda s: "resting potential" in s.props)[0]["resting potential"])
32+
33+
observations = subject.create_property("observations", ["p10", "p12", "p14"])
34+
observations.definition = "Some behavioral observations I did on several days"
35+
print(observations.values)
36+
37+
observations.extend_values("p16")
38+
observations.extend_values(["p18", "p20"])
39+
40+
try:
41+
observations.extend_values(22)
42+
except TypeError as e:
43+
print(e)
44+
3245
nixfile.close()
3346

3447
if __name__ == "__main__":

docs/source/news.rst

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,57 @@
22
Changes in version 1.5
33
######################
44

5-
With version 1.5 we introduced several changes on the library as well as on the data model side (nix model version 1.2). Some are even breaking changes.
6-
1.5 libraries can open files that have been written with pre 1.5 libraries. Old files cannot be opened for ``ReadWrite`` access.
7-
You may want to convert such files using the ``nixio`` command line tool that comes with the library or via also implement upgrade into a script.
5+
With version 1.5 we introduced several changes on the library as well as on the data model side (nix model version 1.2). **Some of these changes are breaking changes.** That is, you may need to adapt your code. Or convert files (see below).
6+
7+
Files written with nixpy versions < 1.5 (model version 1.1) can be opened for reading **but not** for writing. Trying to do so will lead to an exception:
8+
9+
.. code-block:: python
10+
11+
import nixio
12+
print("Opening in ReadOnly mode is possible.")
13+
nixfile = nixio.File.open("old_format_file.nix", nixio.FileMode.ReadOnly)
14+
print("file format version:", f.version)
15+
16+
print("Opening in ReadWrite model will fail:")
17+
nixfile = nixio.File.open("old_format_file.nix", nixio.FileMode.ReadWrite)
18+
19+
.. code-block:: text
20+
21+
Opening in ReadOnly mode is possible.
22+
File format version: (1, 1, 0)
23+
Opening in ReadWrite model will fail:
24+
159 if mode == FileMode.ReadWrite:
25+
160 if not can_write(self):
26+
--> 161 raise RuntimeError("Cannot open file for writing. "
27+
162 "Incompatible version.")
28+
163 elif mode == FileMode.ReadOnly:
29+
30+
RuntimeError: Cannot open file for writing. Incompatible version.
31+
32+
33+
You may want to convert such files using the ``nixio`` command line tool that comes with the library.
834

935
.. code-block:: bash
1036
1137
nixio upgrade --help
1238
39+
40+
Or implement conversion into your code:
41+
1342
.. code-block:: python
1443
1544
import nixio
1645
filename = "test.nix"
1746
nixio.file_upgrade(filename, quiet=False)
1847
19-
Pass ``quiet=False`` in order to get some feedback on what the tool did. **Note** Files are replaced *in place*. Make sure to backup your files before upgrading.
48+
Pass ``quiet=False`` in order to get some feedback on what the tool did. **Note: Files are replaced *in place*. Make sure to backup your files before upgrading.**
2049

2150
Model changes
2251
#############
2352

24-
* the metadata model was simplified to reflects the changes introduced to the underlying **odml** data model. Accordingly the *Value* entity does no longer exist. New versions of the library can read but not write old data.
25-
* New *DataFrame* entity.
53+
* the metadata model was simplified to reflects the changes introduced to the underlying **odml** data model. Accordingly the *Value* entity does no longer exist. New versions of the library can read but not write old data. Experience showed that almost all use cases stored single Values in a *Property*. The overhead (code and also file size) of keeping each value in a separate Enitiy is not justified. The *Property* now keeps all information that was Value related, such as the uncertainty. If you want to store multiple values in a property this is still possible but they have to have the same data type. (see :ref:`Annotations with arbitrary metadata` for more information).
54+
* New *DataFrame* entity that stores tabular data. Each column has a name, unit, and data type. (see :ref:`The DataFrame` for more information).
2655
* *Tags* and *MultiTags* can link to DataFrames as features.
27-
* *RangeDimension* can link to DataFrames as source for the ticks.
28-
* *AliasRangeDimension* has been removed, the equivalent can be achieved with linking to a *DataArray*.
29-
30-
The *DataFrame*
31-
###############
32-
33-
The *DataFrame* is a new entity that stored tabular data. Each column has a name, unit, and data type. (see :ref:`The DataFrame` for more information)
34-
35-
*RangeDimension*
36-
################
37-
3856
* *RangeDimensions* ticks can now be stored within the dimension descriptor, or in linked DataArrays or DataFrames. Ticks must still be one-dimensional (see :ref:`RangeDimension` for more information).
3957
* Because of the above change, the former *AliasRangeDimension* is no longer needed. The same functionality is achieved by linking the *RangeDimension* to the *DataArray* itself.
4058

@@ -45,7 +63,6 @@ API changes
4563
* ``SampledDimension.axis`` can now be called with an optional argument ``start_position`` to get an axis that starts at the given position. Starting at a given index is still possible.
4664
* ``Block.create_data_array`` has additional keyword-arguments to directly provide label and unit.
4765

48-
4966
Misc
5067
####
5168

0 commit comments

Comments
 (0)