Skip to content

Commit 66784ae

Browse files
committed
[doc/tutorial] Add Property.values updates
1 parent 3b8d475 commit 66784ae

File tree

1 file changed

+63
-66
lines changed

1 file changed

+63
-66
lines changed

doc/tutorial.rst

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ The Document
237237
If you loaded the example odML file, let's have a first look at the Document::
238238

239239
>>> print odmlEX
240-
<Doc 42 by Douglas Adams (2 sections)>
240+
<Doc 42 by D. N. Adams (2 sections)>
241241

242242
As you can see, the printout gives you a short summary of the Document of the
243243
loaded example odML file.
@@ -293,7 +293,7 @@ Let's check out all attributes with the following commands::
293293
>>> print(odmlEX.parent)
294294
None
295295
>>> print(odmlEX.repository)
296-
http://portal.g-node.org/odml/terminologies/v1.0/terminologies.xml
296+
http://portal.g-node.org/odml/terminologies/v1.1/terminologies.xml
297297
>>> print(odmlEX.version)
298298
42
299299

@@ -307,7 +307,7 @@ Sections were attached to the Document of our example odML file using the
307307
following command::
308308

309309
>>> print(odmlEX.sections)
310-
[<Section TheCrew[crew] (4)>, <Section TheStarship[starship] (1)>]
310+
[Section[4/2] {name = TheCrew, type = crew, id = ...}, Section[1/7] {name = TheStarship, type = starship, id = ...}]
311311

312312
As expected from the Document printout our example contains two Sections. The
313313
printout and attributes of a Section are explained in the next chapter.
@@ -324,31 +324,32 @@ look at the first Section in the sections list attached to the Document in our
324324
example odML file::
325325

326326
>>> print(odmlEX.sections['TheCrew'])
327-
<Section TheCrew[crew] (4)>
327+
Section[4/2] {name = TheCrew, type = crew, id = ...}
328328
>>> print(odmlEX.sections[0])
329-
<Section TheCrew[crew] (4)>
329+
Section[4/2] {name = TheCrew, type = crew, id = ...}
330330
>>> print(odmlEX['TheCrew'])
331-
<Section TheCrew[crew] (4)>
331+
Section[4/2] {name = TheCrew, type = crew, id = ...}
332332
>>> print(odmlEX[0])
333-
<Section TheCrew[crew] (4)>
333+
Section[4/2] {name = TheCrew, type = crew, id = ...}
334334

335335
In the following we will call Sections explicitly by their name using the
336336
short cut notation.
337337

338338
The printout of a Section is similar to the Document printout and gives you
339339
already the following information:
340340

341-
- ``<...>`` indicates that you are looking at an object
342341
- ``Section`` tells you that you are looking at an odML Section
343-
- ``TheCrew`` is the name of this Section
344-
- ``[...]`` highlights the type of the Section (here ``crew``)
345-
- ``(4)`` states that this Section has four Sections directly attached to it
342+
- ``[4/2]`` states that this Section has four Sections and two Properties directly attached to it
343+
- ``{...}`` provides ``name``, ``type`` and ``id`` of the Section
344+
- ``name`` is the name of this Section, 'TheCrew' in the example case
345+
- ``type`` provides the type of the Section, 'crew' in the example case
346+
- ``id`` provides the uuid of the Section, the actual value has been omitted in the example to improve readability.
347+
346348

347-
Note that the Section printout tells you nothing about the number of attached
348-
Properties or again about the depth of a possible sub-Section tree below the
349-
directly attached ones. It also only list the type of the Section as one of the
350-
Section attributes. In total, a Section can be defined by the following 5
351-
attributes:
349+
Note that the Section printout tells you nothing about the depth of a possible
350+
sub-Section tree below the directly attached ones. It also only list the type
351+
of the Section as one of the Section attributes. In total, a Section can be
352+
defined by the following 5 attributes:
352353

353354
name
354355
- Returns the name of this Section. Should indicate what kind of
@@ -413,27 +414,27 @@ To see which Sections are directly attached to the Section 'TheCrew' again use
413414
the following command::
414415

415416
>>> print(odmlEX['TheCrew'].sections)
416-
[<Section Arthur Philip Dent[crew/person] (0)>,
417-
<Section Zaphod Beeblebrox[crew/person] (0)>,
418-
<Section Tricia Marie McMillan[crew/person] (0)>,
419-
<Section Ford Prefect[crew/person] (0)>]
417+
[Section[0/5] {name = Arthur Philip Dent, type = crew/person, id = ...},
418+
Section[0/5] {name = Zaphod Beeblebrox, type = crew/person, id = ...},
419+
Section[0/5] {name = Tricia Marie McMillan, type = crew/person, id = ...},
420+
Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}]
420421

421422
Or, for accessing these sub-Sections::
422423

423424
>>> print(odmlEX['TheCrew'].sections['Ford Prefect'])
424-
<Section Ford Prefect[crew/person] (0)>
425+
Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
425426
>>> print(odmlEX['TheCrew'].sections[3])
426-
<Section Ford Prefect[crew/person] (0)>
427+
Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
427428
>>> print(odmlEX['TheCrew']['Ford Prefect'])
428-
<Section Ford Prefect[crew/person] (0)>
429+
Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
429430
>>> print(odmlEX['TheCrew'][3])
430-
<Section Ford Prefect[crew/person] (0)>
431+
Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
431432

432433
As you learned, besides sub-Sections, a Section can also have Properties
433434
attached. Let's see which Properties are attached to the Section 'TheCrew'::
434435

435436
>>> print(odmlEX['TheCrew'].properties)
436-
[<Property NameCrewMembers>, <Property NoCrewMembers>]
437+
[Property: {name = NameCrewMembers}, Property: {name = NoCrewMembers}]
437438

438439
The printout and attributes of a Property are explained in the next chapter.
439440

@@ -445,17 +446,17 @@ Properties need to be called explicitly via the properties function of a
445446
Section. You can then either call a Property by name or by index::
446447

447448
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'])
448-
<Property NoCrewMembers>
449+
Property: {name = NoCrewMembers}
449450
>>> print(odmlEX['TheCrew'].properties[1])
450-
<Property NoCrewMembers>
451+
Property: {name = NoCrewMembers}
451452

452453
In the following we will only call Properties explicitly by their name.
453454

454455
The Property printout is reduced and only gives you information about the
455456
following:
456457

457-
- ``<...>`` indicates that you are looking at an object
458458
- ``Property`` tells you that you are looking at an odML Property
459+
- ``{...}`` provides the ``name`` of the Property
459460
- ``NoCrewMembers`` is the name of this Property
460461

461462
Note that the Property printout tells you nothing about the number of Values,
@@ -478,7 +479,7 @@ document
478479
parent
479480
- Returns the parent Section to which this Property was attached to.
480481

481-
value
482+
values
482483
- Returns the metadata of this Property. Can be either a single metadata or
483484
multiple, but homogeneous metadata (all with same dtype and unit). For
484485
this reason, the output is always provided as a list.
@@ -518,7 +519,7 @@ Let's check which attributes were defined for the Property 'NoCrewMembers'::
518519
Number of crew members
519520
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].document)
520521
<Doc 42 by D. N. Adams (2 sections)>
521-
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].value)
522+
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].values)
522523
[4]
523524
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].dtype)
524525
int
@@ -533,22 +534,22 @@ Let's check which attributes were defined for the Property 'NoCrewMembers'::
533534
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].dependency_value)
534535
None
535536

536-
As mentioned the value attribute of a Property can only contain multiple
537+
As mentioned the values attribute of a Property can only contain multiple
537538
metadata when they have the same ``dtype`` and ``unit``, as it is the case for
538539
the Property 'NameCrewMembers'::
539540

540-
>>> print(odmlEX['TheCrew'].properties['NameCrewMembers'].value)
541-
[u'Arthur Philip Dent',
542-
u'Zaphod Beeblebrox',
543-
u'Tricia Marie McMillan',
544-
u'Ford Prefect']
541+
>>> print(odmlEX['TheCrew'].properties['NameCrewMembers'].values)
542+
['Arthur Philip Dent',
543+
'Zaphod Beeblebrox',
544+
'Tricia Marie McMillan',
545+
'Ford Prefect']
545546
>>> print(odmlEX['TheCrew'].properties['NameCrewMembers'].dtype)
546547
person
547548
>>> print(odmlEX['TheCrew'].properties['NameCrewMembers'].unit)
548549
None
549550

550-
NOTE: 'property.value' will always return a copy! Any direct changes to the
551-
returned list will have no affect on the actual property value. If you want to
551+
NOTE: 'property.values' will always return a copy! Any direct changes to the
552+
returned list will have no affect on the actual property values. If you want to
552553
make changes to a property value, either use the 'append', 'extend' and 'remove'
553554
methods or assign a new value list to the property.
554555

@@ -664,7 +665,7 @@ updated::
664665
>>> print(MYodML)
665666
<Doc 42 by Douglas Adams (1 sections)>
666667
>>> print(MYodML.sections)
667-
[<Section TheCrew[crew] (0)>]
668+
[Section[0/0] {name = TheCrew, type = crew, id = ...}]
668669

669670
>>> print(sec1.document)
670671
<Doc 42 by D. N. Adams (1 sections)>
@@ -680,12 +681,12 @@ Let's try this with the next Section we create::
680681
parent=sec1)
681682

682683
>>> print(sec2)
683-
<Section Arthur Philip Dent[crew/person] (0)>
684+
Section[0/0] {name = Arthur Philip Dent, type = crew/person, id = ...}
684685

685686
>>> print(sec2.document)
686687
<Doc 42 by D. N. Adams (1 sections)>
687688
>>> print(sec2.parent)
688-
<Section TheCrew[crew] (1)>
689+
[Section[1/0] {name = TheCrew, type = crew, id = ...}
689690

690691
Note that all of our created Sections do not contain any Properties yet. Let's
691692
see if we can change this...
@@ -698,7 +699,7 @@ Let's create our first Property::
698699

699700
>>> prop1 = odml.Property(name="Gender",
700701
definition="Sex of the subject",
701-
value="male")
702+
values="male")
702703

703704
Note that again, only the name attribute is obligatory for creating a Property.
704705
The remaining attributes can be defined later on, or are automatically
@@ -752,16 +753,16 @@ automatically update its parent attribute::
752753
>>> print(prop1.document)
753754
<Doc 42 by D. N. Adams (1 sections)>
754755
>>> print(prop1.parent)
755-
<Section Arthur Philip Dent[crew/person] (0)>
756+
Section[0/1] {name = Arthur Philip Dent, type = crew/person, id = ...}
756757

757758
Next, let us create a Property with multiple metadata entries::
758759

759760
>>> prop2 = odml.Property(name="NameCrewMembers",
760761
definition="List of crew members names",
761-
value=["Arthur Philip Dent",
762-
"Zaphod Beeblebrox",
763-
"Tricia Marie McMillan",
764-
"Ford Prefect"],
762+
values=["Arthur Philip Dent",
763+
"Zaphod Beeblebrox",
764+
"Tricia Marie McMillan",
765+
"Ford Prefect"],
765766
dtype=odml.DType.person)
766767

767768
As you learned before, in such a case, the metadata entries must be
@@ -776,12 +777,12 @@ previously created Section 'TheCrew'::
776777
Note that it is also possible to add a metadata entry later on::
777778

778779
>>> prop2.append("Blind Passenger")
779-
>>> print(MYodML['TheCrew'].properties['NameCrewMembers'].value)
780-
[u'Arthur Philip Dent',
781-
u'Zaphod Beeblebrox',
782-
u'Tricia Marie McMillan',
783-
u'Ford Prefect',
784-
u'Blind Passenger']
780+
>>> print(MYodML['TheCrew'].properties['NameCrewMembers'].values)
781+
['Arthur Philip Dent',
782+
'Zaphod Beeblebrox',
783+
'Tricia Marie McMillan',
784+
'Ford Prefect',
785+
'Blind Passenger']
785786

786787

787788
The tuple datatype you might have noticed in the dtype table above has to be
@@ -794,17 +795,17 @@ by brackets and separated by a semicolon.
794795

795796
>>> pixel_prop = odml.Property(name="pixel map")
796797
>>> pixel_prop.dtype = "2-tuple"
797-
>>> pixel_prop.value = ["(1; 2)", "(3; 4)"]
798+
>>> pixel_prop.values = ["(1; 2)", "(3; 4)"]
798799

799800
>>> voxel_prop = odml.Property(name="voxel map")
800801
>>> voxel_prop.dtype = "3-tuple"
801-
>>> voxel_prop.value = "(1; 2; 3)"
802+
>>> voxel_prop.values = "(1; 2; 3)"
802803

803804
Please note, that inconsistent tuple values will raise an error:
804805

805806
>>> tprop = odml.Property(name="tuple fail")
806807
>>> tprop.dtype = "3-tuple"
807-
>>> tprop.value = ["(1; 2)"]
808+
>>> tprop.values = ["(1; 2)"]
808809

809810

810811
Printing XML-representation of an odML file:
@@ -883,13 +884,13 @@ After creating a Property with metadata the data type can be changed and the
883884
format of the corresponding entry will converted to the new data type, if the
884885
new format is valid for the given metadata::
885886

886-
>>> test_dtype_conv = odml.Property('p', value=1.0)
887-
>>> print(test_dtype_conv.value)
887+
>>> test_dtype_conv = odml.Property('p', values=1.0)
888+
>>> print(test_dtype_conv.values)
888889
[1.0]
889890
>>> print(test_dtype_conv.dtype)
890891
float
891892
>>> test_dtype_conv.dtype = odml.DType.int
892-
>>> print(test_dtype_conv.value)
893+
>>> print(test_dtype_conv.values)
893894
[1]
894895
>>> print(test_dtype_conv.dtype)
895896
int
@@ -899,22 +900,18 @@ If the conversion is invalid a ValueError is raised.
899900
Also note, that during such a process metadata loss may occur if a float is
900901
converted to an integer and then back to a float::
901902

902-
>>> test_dtype_conv = odml.Property('p', value=42.42)
903-
>>> print(test_dtype_conv.value)
903+
>>> test_dtype_conv = odml.Property('p', values=42.42)
904+
>>> print(test_dtype_conv.values)
904905
[42.42]
905906
>>> test_dtype_conv.dtype = odml.DType.int
906907
>>> test_dtype_conv.dtype = odml.DType.float
907-
>>> print(test_dtype_conv.value)
908+
>>> print(test_dtype_conv.values)
908909
[42.0]
909910

910911

911912
Advanced knowledge on Properties
912913
--------------------------------
913914

914-
Dependencies & dependency values
915-
********************************
916-
(coming soon)
917-
918915
Advanced knowledge on Sections
919916
------------------------------
920917

0 commit comments

Comments
 (0)