@@ -237,7 +237,7 @@ The Document
237
237
If you loaded the example odML file, let's have a first look at the Document::
238
238
239
239
>>> print odmlEX
240
- <Doc 42 by Douglas Adams (2 sections)>
240
+ <Doc 42 by D. N. Adams (2 sections)>
241
241
242
242
As you can see, the printout gives you a short summary of the Document of the
243
243
loaded example odML file.
@@ -293,7 +293,7 @@ Let's check out all attributes with the following commands::
293
293
>>> print(odmlEX.parent)
294
294
None
295
295
>>> 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
297
297
>>> print(odmlEX.version)
298
298
42
299
299
@@ -307,7 +307,7 @@ Sections were attached to the Document of our example odML file using the
307
307
following command::
308
308
309
309
>>> 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 = ...} ]
311
311
312
312
As expected from the Document printout our example contains two Sections. The
313
313
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
324
324
example odML file::
325
325
326
326
>>> print(odmlEX.sections['TheCrew'])
327
- < Section TheCrew[ crew] (4)>
327
+ Section[4/2] {name = TheCrew, type = crew, id = ...}
328
328
>>> print(odmlEX.sections[0])
329
- < Section TheCrew[ crew] (4)>
329
+ Section[4/2] {name = TheCrew, type = crew, id = ...}
330
330
>>> print(odmlEX['TheCrew'])
331
- < Section TheCrew[ crew] (4)>
331
+ Section[4/2] {name = TheCrew, type = crew, id = ...}
332
332
>>> print(odmlEX[0])
333
- < Section TheCrew[ crew] (4)>
333
+ Section[4/2] {name = TheCrew, type = crew, id = ...}
334
334
335
335
In the following we will call Sections explicitly by their name using the
336
336
short cut notation.
337
337
338
338
The printout of a Section is similar to the Document printout and gives you
339
339
already the following information:
340
340
341
- - ``<...> `` indicates that you are looking at an object
342
341
- ``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
+
346
348
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:
352
353
353
354
name
354
355
- 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
413
414
the following command::
414
415
415
416
>>> 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 = ...} ]
420
421
421
422
Or, for accessing these sub-Sections::
422
423
423
424
>>> print(odmlEX['TheCrew'].sections['Ford Prefect'])
424
- < Section Ford Prefect[ crew/person] (0)>
425
+ Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
425
426
>>> print(odmlEX['TheCrew'].sections[3])
426
- < Section Ford Prefect[ crew/person] (0)>
427
+ Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
427
428
>>> print(odmlEX['TheCrew']['Ford Prefect'])
428
- < Section Ford Prefect[ crew/person] (0)>
429
+ Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
429
430
>>> print(odmlEX['TheCrew'][3])
430
- < Section Ford Prefect[ crew/person] (0)>
431
+ Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
431
432
432
433
As you learned, besides sub-Sections, a Section can also have Properties
433
434
attached. Let's see which Properties are attached to the Section 'TheCrew'::
434
435
435
436
>>> print(odmlEX['TheCrew'].properties)
436
- [< Property NameCrewMembers>, < Property NoCrewMembers> ]
437
+ [Property: {name = NameCrewMembers}, Property: {name = NoCrewMembers} ]
437
438
438
439
The printout and attributes of a Property are explained in the next chapter.
439
440
@@ -445,17 +446,17 @@ Properties need to be called explicitly via the properties function of a
445
446
Section. You can then either call a Property by name or by index::
446
447
447
448
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'])
448
- < Property NoCrewMembers>
449
+ Property: {name = NoCrewMembers}
449
450
>>> print(odmlEX['TheCrew'].properties[1])
450
- < Property NoCrewMembers>
451
+ Property: {name = NoCrewMembers}
451
452
452
453
In the following we will only call Properties explicitly by their name.
453
454
454
455
The Property printout is reduced and only gives you information about the
455
456
following:
456
457
457
- - ``<...> `` indicates that you are looking at an object
458
458
- ``Property `` tells you that you are looking at an odML Property
459
+ - ``{...} `` provides the ``name `` of the Property
459
460
- ``NoCrewMembers `` is the name of this Property
460
461
461
462
Note that the Property printout tells you nothing about the number of Values,
@@ -478,7 +479,7 @@ document
478
479
parent
479
480
- Returns the parent Section to which this Property was attached to.
480
481
481
- value
482
+ values
482
483
- Returns the metadata of this Property. Can be either a single metadata or
483
484
multiple, but homogeneous metadata (all with same dtype and unit). For
484
485
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'::
518
519
Number of crew members
519
520
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].document)
520
521
<Doc 42 by D. N. Adams (2 sections)>
521
- >>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].value )
522
+ >>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].values )
522
523
[4]
523
524
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].dtype)
524
525
int
@@ -533,22 +534,22 @@ Let's check which attributes were defined for the Property 'NoCrewMembers'::
533
534
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].dependency_value)
534
535
None
535
536
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
537
538
metadata when they have the same ``dtype `` and ``unit ``, as it is the case for
538
539
the Property 'NameCrewMembers'::
539
540
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']
545
546
>>> print(odmlEX['TheCrew'].properties['NameCrewMembers'].dtype)
546
547
person
547
548
>>> print(odmlEX['TheCrew'].properties['NameCrewMembers'].unit)
548
549
None
549
550
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
552
553
make changes to a property value, either use the 'append', 'extend' and 'remove'
553
554
methods or assign a new value list to the property.
554
555
@@ -664,7 +665,7 @@ updated::
664
665
>>> print(MYodML)
665
666
<Doc 42 by Douglas Adams (1 sections)>
666
667
>>> print(MYodML.sections)
667
- [< Section TheCrew[ crew] (0)> ]
668
+ [Section[0/0] {name = TheCrew, type = crew, id = ...} ]
668
669
669
670
>>> print(sec1.document)
670
671
<Doc 42 by D. N. Adams (1 sections)>
@@ -680,12 +681,12 @@ Let's try this with the next Section we create::
680
681
parent=sec1)
681
682
682
683
>>> print(sec2)
683
- < Section Arthur Philip Dent[ crew/person] (0)>
684
+ Section[0/0] {name = Arthur Philip Dent, type = crew/person, id = ...}
684
685
685
686
>>> print(sec2.document)
686
687
<Doc 42 by D. N. Adams (1 sections)>
687
688
>>> print(sec2.parent)
688
- < Section TheCrew[ crew] (1)>
689
+ [ Section[1/0] {name = TheCrew, type = crew, id = ...}
689
690
690
691
Note that all of our created Sections do not contain any Properties yet. Let's
691
692
see if we can change this...
@@ -698,7 +699,7 @@ Let's create our first Property::
698
699
699
700
>>> prop1 = odml.Property(name="Gender",
700
701
definition="Sex of the subject",
701
- value ="male")
702
+ values ="male")
702
703
703
704
Note that again, only the name attribute is obligatory for creating a Property.
704
705
The remaining attributes can be defined later on, or are automatically
@@ -752,16 +753,16 @@ automatically update its parent attribute::
752
753
>>> print(prop1.document)
753
754
<Doc 42 by D. N. Adams (1 sections)>
754
755
>>> print(prop1.parent)
755
- < Section Arthur Philip Dent[ crew/person] (0)>
756
+ Section[0/1] {name = Arthur Philip Dent, type = crew/person, id = ...}
756
757
757
758
Next, let us create a Property with multiple metadata entries::
758
759
759
760
>>> prop2 = odml.Property(name="NameCrewMembers",
760
761
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"],
765
766
dtype=odml.DType.person)
766
767
767
768
As you learned before, in such a case, the metadata entries must be
@@ -776,12 +777,12 @@ previously created Section 'TheCrew'::
776
777
Note that it is also possible to add a metadata entry later on::
777
778
778
779
>>> 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']
785
786
786
787
787
788
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.
794
795
795
796
>>> pixel_prop = odml.Property(name = " pixel map" )
796
797
>>> pixel_prop.dtype = " 2-tuple"
797
- >>> pixel_prop.value = [" (1; 2)" , " (3; 4)" ]
798
+ >>> pixel_prop.values = [" (1; 2)" , " (3; 4)" ]
798
799
799
800
>>> voxel_prop = odml.Property(name = " voxel map" )
800
801
>>> voxel_prop.dtype = " 3-tuple"
801
- >>> voxel_prop.value = " (1; 2; 3)"
802
+ >>> voxel_prop.values = " (1; 2; 3)"
802
803
803
804
Please note, that inconsistent tuple values will raise an error:
804
805
805
806
>>> tprop = odml.Property(name = " tuple fail" )
806
807
>>> tprop.dtype = " 3-tuple"
807
- >>> tprop.value = [" (1; 2)" ]
808
+ >>> tprop.values = [" (1; 2)" ]
808
809
809
810
810
811
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
883
884
format of the corresponding entry will converted to the new data type, if the
884
885
new format is valid for the given metadata::
885
886
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 )
888
889
[1.0]
889
890
>>> print(test_dtype_conv.dtype)
890
891
float
891
892
>>> test_dtype_conv.dtype = odml.DType.int
892
- >>> print(test_dtype_conv.value )
893
+ >>> print(test_dtype_conv.values )
893
894
[1]
894
895
>>> print(test_dtype_conv.dtype)
895
896
int
@@ -899,22 +900,18 @@ If the conversion is invalid a ValueError is raised.
899
900
Also note, that during such a process metadata loss may occur if a float is
900
901
converted to an integer and then back to a float::
901
902
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 )
904
905
[42.42]
905
906
>>> test_dtype_conv.dtype = odml.DType.int
906
907
>>> test_dtype_conv.dtype = odml.DType.float
907
- >>> print(test_dtype_conv.value )
908
+ >>> print(test_dtype_conv.values )
908
909
[42.0]
909
910
910
911
911
912
Advanced knowledge on Properties
912
913
--------------------------------
913
914
914
- Dependencies & dependency values
915
- ********************************
916
- (coming soon)
917
-
918
915
Advanced knowledge on Sections
919
916
------------------------------
920
917
0 commit comments