metadata API#
Manage rsml metadata attributes
The metadata element in rsml contains some mandatory content and optional ones. In the IO operation from openalea.rsml file to&from mtg, these metadata are looked for in the ‘metadata’ graph property of the mtg:
mtg.graph_properties()['metadata']
- Mandatory metadata:
version: set 1.0
unit: default is ‘pixel’
resolution: default is 1
software: default is ‘openalea’
user: default is ‘’
file-key: default is a random unique identifier (uuid4)
- Optional metadata:
property_definition: ….
function_definition: ….
time_sequence: …
set_metadata can be used to retrieve the metadata dictionary. This function also fill missing items, folowing the specified behavior describe in the function documentation.
- openalea.rsml.metadata.add_property_definition(g, label, type, unit=None, default=None)[source]#
add a rsml property definition to mtg g
- Inputs:
- label:
The label of the property
- type:
Either a string of the rsml type, or a python type object for which the suitable rsml type is selected using the rsml_type function.
- openalea.rsml.metadata.filter_literal(obj, default=None)[source]#
return given obj with only “literal” types
The output can be safely converted to string and evaluated using ast.literal_eval:
import ast safe_obj = filter_literal(obj) assert ast.literal_eval(repr(save_obj))==safe_obj
literal types are strings, number, tuples, lists, dicts, booleans and None
- For non-literal content:
object with an iteritems attribute are parsed and converted to dict
object with an __iter__ attribute are parsed and converted to list
the rest is replaced by given default
- openalea.rsml.metadata.rsml_type(python_type)[source]#
Automatically select rsml type for the given python_type
- openalea.rsml.metadata.set_metadata(g)[source]#
Set the rsml ‘metadata’ element from the graph-properties of mtg g
The rsml metadata is a dictionary equivalent to the metadata xml element of rsml. Its main purpose is to be used by rsml.io.Dumper.
This dictionary is constructed from the ‘metadata’ item of g.graph_properties(), if it exist. Then it adds missing items. In particular:
it set the ‘last-modified’ item to current time
if missing, it set the ‘file-key’ item to a random unique id (uuid4)
if the ‘image’ item is a string, convert it to a dict with item ‘name’
if ‘image.captured’ is missing, try to set it to the file ‘image.name’ creation time, if the file exists.
if ‘image.sha256’ is missing, try to set it to file ‘image.name’ hash
This function update given mtg g in-place and returns its updated ‘metadata’ graph properties.
Download the source file ../../src/openalea/rsml/metadata.py.