yggdrasil.metaschema.datatypes package

Submodules

yggdrasil.metaschema.datatypes.AnyMetaschemaType module

class yggdrasil.metaschema.datatypes.AnyMetaschemaType.AnyMetaschemaType(**typedef)[source]

Bases: MetaschemaType

Type associated with a scalar.

cross_language_support = False
classmethod decode_data(obj, typedef)[source]

Decode an object.

Parameters:
  • obj (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

Returns:

Decoded object.

Return type:

object

description = 'A type allowing any value that is expresible in some type.'
classmethod encode_data(obj, typedef)[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

classmethod encode_data_readable(obj, typedef)[source]

Encode an object’s data in a readable format that may not be decoded in exactly the same way.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

classmethod get_temptype(typedef, return_none=False)[source]

Extract temporary type from type definition.

Parameters:
  • typedef (dict) – Type definition containing temporary type under the temptype key.

  • return_none (bool, optional) – If True, None will be returned if there is not a temptype in the provided typedef. Defaults to False.

Returns:

Temporary type definition or None if not present.

Return type:

dict

classmethod issubtype(t)[source]

Determine if this type is a subclass of the provided type.

Parameters:

t (str) – Type name to check against.

Returns:

True if this type is a subtype of the specified type t.

Return type:

bool

metadata_properties = ['type', 'temptype']
name = 'any'
properties = ['type', 'title', 'temptype']
python_types = (<class 'object'>,)
classmethod transform_type(obj, typedef=None)[source]

Transform an object based on type info.

Parameters:
  • obj (object) – Object to transform.

  • typedef (dict, optional) – Type definition that should be used to transform the object. Defaults to None.

Returns:

Transformed object.

Return type:

object

classmethod validate(*args, **kwargs)[source]

Validate an object to check if it could be of this type. For this type, the returned boolean will always be True.

yggdrasil.metaschema.datatypes.ArrayMetaschemaType module

class yggdrasil.metaschema.datatypes.ArrayMetaschemaType.NDArrayMetaschemaType(**typedef)[source]

Bases: ScalarMetaschemaType

Type associated with a scalar.

description = 'An ND array with or without units.'
metadata_properties = ['type', 'subtype', 'precision', 'units', 'shape']
name = 'ndarray'
properties = ['type', 'title', 'subtype', 'precision', 'units', 'shape']
python_types = (<class 'numpy.ndarray'>, <class 'unyt.array.unyt_array'>)
classmethod validate(obj, raise_errors=False)[source]

Validate an object to check if it could be of this type.

Parameters:
  • obj (object) – Object to validate.

  • raise_errors (bool, optional) – If True, errors will be raised when the object fails to be validated. Defaults to False.

Returns:

True if the object could be of this type, False otherwise.

Return type:

bool

class yggdrasil.metaschema.datatypes.ArrayMetaschemaType.OneDArrayMetaschemaType(**typedef)[source]

Bases: ScalarMetaschemaType

Type associated with a scalar.

description = 'A 1D array with or without units.'
metadata_properties = ['type', 'subtype', 'precision', 'units', 'length']
name = '1darray'
properties = ['type', 'title', 'subtype', 'precision', 'units', 'length']
python_types = (<class 'numpy.ndarray'>, <class 'unyt.array.unyt_array'>)
classmethod validate(obj, raise_errors=False)[source]

Validate an object to check if it could be of this type.

Parameters:
  • obj (object) – Object to validate.

  • raise_errors (bool, optional) – If True, errors will be raised when the object fails to be validated. Defaults to False.

Returns:

True if the object could be of this type, False otherwise.

Return type:

bool

yggdrasil.metaschema.datatypes.ClassMetaschemaType module

class yggdrasil.metaschema.datatypes.ClassMetaschemaType.ClassMetaschemaType(**typedef)[source]

Bases: MetaschemaType

Type for evaluating classes.

cross_language_support = False
classmethod decode_data(obj, typedef, working_dir=None)[source]

Decode an object.

Parameters:
  • obj (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

  • working_dir (str, optional) – Working directory that should be used to make relative paths absolute. Defaults to None.

Returns:

Decoded object.

Return type:

object

description = 'Type for Python classes.'
classmethod encode_data(obj, typedef)[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

encoded_type = 'string'
name = 'class'
classmethod normalize(obj, working_dir=None)[source]

Normalize an object, if possible, to conform to this type.

Parameters:
  • obj (object) – Object to normalize.

  • working_dir (str, optional) – Working directory that should be used to make relative paths absolute. Defaults to None.

Returns:

Normalized object.

Return type:

object

python_types = (<class 'type'>,)
class yggdrasil.metaschema.datatypes.ClassMetaschemaType.ExampleClass(*args, **kwargs)[source]

Bases: object

yggdrasil.metaschema.datatypes.ContainerMetaschemaType module

class yggdrasil.metaschema.datatypes.ContainerMetaschemaType.ContainerMetaschemaType(*args, **kwargs)[source]

Bases: MetaschemaType

Type associated with a container of subtypes.

classmethod coerce_type(obj, typedef=None, **kwargs)[source]

Coerce objects of specific types to match the data type.

Parameters:
  • obj (object) – Object to be coerced.

  • typedef (dict, optional) – Type defintion that object should be coerced to. Defaults to None.

  • **kwargs – Additional keyword arguments are metadata entries that may aid in coercing the type.

Returns:

Coerced object.

Return type:

object

Raises:

RuntimeError – If obj is a dictionary, but key_order is not provided.

classmethod decode_data(obj, typedef)[source]

Decode an object.

Parameters:
  • obj (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

Returns:

Decoded object.

Return type:

object

description = 'A container of other types.'
classmethod encode_data(obj, typedef, **kwargs)[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

  • **kwargs – Additional keyword arguments are passed to the class method _encode_data_alias.

Returns:

Encoded object.

Return type:

string

classmethod encode_data_readable(obj, typedef, **kwargs)[source]

Encode an object’s data in a readable format.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

  • **kwargs – Additional keyword arguments are passed to the class method _encode_data_alias.

Returns:

Encoded object.

Return type:

string

classmethod extract_typedef(metadata)[source]

Extract the minimum typedef required for this type from the provided metadata.

Parameters:

metadata (dict) – Message metadata.

Returns:

Encoded type definition with unncessary properties removed.

Return type:

dict

name = 'container'
python_types = []
classmethod transform_type(obj, typedef=None)[source]

Transform an object based on type info.

Parameters:
  • obj (object) – Object to transform.

  • typedef (dict) – Type definition that should be used to transform the object.

Returns:

Transformed object.

Return type:

object

update_typedef(**kwargs)[source]

Update the current typedef with new values.

Parameters:

**kwargs – All keyword arguments are considered to be new type definitions. If they are a valid definition property, they will be copied to the typedef associated with the instance.

Returns:

A dictionary of keyword arguments that were not added to the

type definition.

Return type:

dict

yggdrasil.metaschema.datatypes.FixedMetaschemaType module

class yggdrasil.metaschema.datatypes.FixedMetaschemaType.FixedMetaschemaType(**typedef)[source]

Bases: MetaschemaType

Class that should be used to alias another type, but with certain properties fixed.

Parameters:

**kwargs – All keyword arguments are assumed to be type definition properties which will be used to validate serialized/deserialized messages.

fixed_properties

Type properties of the parent class that are fixed and the values they are fixed to.

Type:

dict

classmethod base()[source]

Get the type that this type is a fixed version of.

classmethod check_encoded(metadata, typedef=None, raise_errors=False, **kwargs)[source]

Checks if the metadata for an encoded object matches the type definition.

Parameters:
  • metadata (dict) – Meta data to be tested.

  • typedef (dict, optional) – Type properties that object should be tested against. Defaults to None and object may have any values for the type properties (so long as they match the schema.

  • raise_errors (bool, optional) – If True, any errors determining that encoded object is not of this type will be raised. Defaults to False.

  • **kwargs – Additional keyword arguments are passed to the parent class.

Returns:

True if the metadata matches the type definition, False

otherwise.

Return type:

bool

classmethod extract_typedef(metadata)[source]

Extract the minimum typedef required for this type from the provided metadata.

Parameters:

metadata (dict) – Message metadata.

Returns:

Encoded type definition with unncessary properties removed.

Return type:

dict

fixed_properties = {}
is_fixed = True
classmethod issubtype(t)[source]

Determine if this type is a subclass of the provided type.

Parameters:

t (str) – Type name to check against.

Returns:

True if this type is a subtype of the specified type t.

Return type:

bool

classmethod typedef_base2fixed(typedef)[source]

Transform a type definition from the unfixed base type to the fixed type alias by removing fixed properties.

Parameters:

typedef (dict) – Type definition for the unfixed base type that might include properties that are fixed in the base.

Returns:

Copy of type definition with fixed properties removed.

Return type:

dict

classmethod typedef_fixed2base(typedef)[source]

Transform a type definition from the fixed alias to the unfixed base by setting the fixed properties if they are not already present.

Parameters:

typedef (dict) – Type definition for the fixed alias type.

Returns:

Copy of type definition with fixed properties added.

Return type:

dict

update_typedef(**kwargs)[source]

Update the current typedef with new values.

Parameters:

**kwargs – All keyword arguments are considered to be new type definitions. If they are a valid definition property, they will be copied to the typedef associated with the instance.

Returns:

A dictionary of keyword arguments that were not added to the

type definition.

Return type:

dict

classmethod updated_fixed_properties(obj)[source]

Get a version of the fixed properties schema that includes information from the object.

Parameters:

obj (object) – Object to use to put constraints on the fixed properties schema.

Returns:

Fixed properties schema with object dependent constraints.

Return type:

dict

classmethod validate(obj, raise_errors=False)[source]

Validate an object to check if it could be of this type.

Parameters:
  • obj (object) – Object to validate.

  • raise_errors (bool, optional) – If True, errors will be raised when the object fails to be validated. Defaults to False.

Returns:

True if the object could be of this type, False otherwise.

Return type:

bool

yggdrasil.metaschema.datatypes.FixedMetaschemaType.create_fixed_type_class(name, description, base, fixed_properties, target_globals=None, class_name=None, **kwargs)[source]

Create a fixed class.

Parameters:
  • name (str) –

  • description (str) – Description of the fixed type.

  • base (MetaschemaType) – Base class that should be used.

  • fixed_properties (dict) – Mapping between properties that are fixed and the value they are fixed to.

  • target_globals (dict, optional) – Globals dictionary for module where the fixed class should be added. If None, the new class is returned. Defaults to None.

  • class_name (str, optional) – Name that should be given to the class. If not provided, defaults to ‘<name.title()>MetaschemaType’.

  • **kwargs – Additional keyword arguments are treated as attributes that should be set on the fixed class.

Returns:

The name of the class created if target_globals is provided,

the created class if target_globals is None.

Return type:

str, class

yggdrasil.metaschema.datatypes.FunctionMetaschemaType module

class yggdrasil.metaschema.datatypes.FunctionMetaschemaType.FunctionMetaschemaType(**typedef)[source]

Bases: ClassMetaschemaType

Type for evaluating functions.

description = 'Type for callable Python functions.'
name = 'function'
python_types = (<class 'builtin_function_or_method'>, <class 'function'>, <class 'builtin_function_or_method'>, <class 'method'>)
yggdrasil.metaschema.datatypes.FunctionMetaschemaType.example_func(x)[source]

yggdrasil.metaschema.datatypes.InstanceMetaschemaType module

class yggdrasil.metaschema.datatypes.InstanceMetaschemaType.InstanceMetaschemaType(**typedef)[source]

Bases: MetaschemaType

Type for evaluating instances of Python classes.

cross_language_support = False
classmethod decode_data(obj, typedef)[source]

Decode an object.

Parameters:
  • obj (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

Returns:

Decoded object.

Return type:

object

definition_properties = ['type', 'class']
description = 'Type for Python class instances.'
classmethod encode_data(obj, typedef)[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

extract_properties = ['type', 'title', 'class', 'args', 'kwargs']
classmethod get_test_data(typedef=None)[source]

object: Test data.

metadata_properties = ['type', 'class', 'args', 'kwargs']
name = 'instance'
properties = ['type', 'title', 'class', 'args', 'kwargs']
python_types = (<class 'object'>,)
classmethod validate(obj, raise_errors=False)[source]

Validate an object to check if it could be of this type.

Parameters:
  • obj (object) – Object to validate.

  • raise_errors (bool, optional) – If True, errors will be raised when the object fails to be validated. Defaults to False.

Returns:

True if the object could be of this type, False otherwise.

Return type:

bool

yggdrasil.metaschema.datatypes.JSONArrayMetaschemaType module

class yggdrasil.metaschema.datatypes.JSONArrayMetaschemaType.JSONArrayMetaschemaType(*args, **kwargs)[source]

Bases: ContainerMetaschemaType

Type associated with a set of subtypes.

Developer Notes:

Support for dynamic arrays in C/C++ is still under development.

classmethod coerce_type(obj, typedef=None, key_order=None, dont_wrap_single=False, **kwargs)[source]

Coerce objects of specific types to match the data type.

Parameters:
  • obj (object) – Object to be coerced.

  • typedef (dict, optional) – Type defintion that object should be coerced to. Defaults to None.

  • key_order (list, optional) – Order that keys from a dictionary should be used to compose an array. Defaults to None.

  • dont_wrap_single (bool, optional) – If True, single element data types will not attempt to wrap input object in additional list. Defaults to False.

  • **kwargs – Additional keyword arguments are metadata entries that may aid in coercing the type.

Returns:

Coerced object.

Return type:

object

Raises:

RuntimeError – If obj is a dictionary, but key_order is not provided.

description = 'A container of ordered values.'
classmethod encode_type(obj, **kwargs)[source]

Encode an object’s type definition.

Parameters:
  • obj (object) – Object to encode.

  • **kwargs – Additional keyword arguments are passed to the parent class’s method.

Returns:

Encoded type definition.

Return type:

dict

extract_properties = ['type', 'title', 'items']
classmethod get_test_data(typedef=None)[source]

object: Test data.

metadata_properties = ['type', 'items']
name = 'array'
classmethod normalize(obj)[source]

Normalize an object, if possible, to conform to this type.

Parameters:

obj (object) – Object to normalize.

Returns:

Normalized object.

Return type:

object

properties = ['type', 'title', 'items']
python_types = (<class 'list'>, <class 'tuple'>, <class 'numpy.ndarray'>, <class 'pandas.core.frame.DataFrame'>)
classmethod validate(obj, raise_errors=False)[source]

Validate an object to check if it could be of this type.

Parameters:
  • obj (object) – Object to validate.

  • raise_errors (bool, optional) – If True, errors will be raised when the object fails to be validated. Defaults to False.

Returns:

True if the object could be of this type, False otherwise.

Return type:

bool

yggdrasil.metaschema.datatypes.JSONMetaschemaType module

class yggdrasil.metaschema.datatypes.JSONMetaschemaType.JSONBooleanMetaschemaType(**typedef)[source]

Bases: JSONMetaschemaTypeBase

JSON base boolean type.

description = 'JSON boolean type.'
example_data = True
name = 'boolean'
classmethod normalize(obj)[source]

Normalize an object, if possible, to conform to this type.

Parameters:

obj (object) – Object to normalize.

Returns:

Normalized object.

Return type:

object

python_types = (<class 'bool'>,)
class yggdrasil.metaschema.datatypes.JSONMetaschemaType.JSONIntegerMetaschemaType(**typedef)[source]

Bases: JSONMetaschemaTypeBase

JSON base integer type.

cross_language_support = False
description = 'JSON integer type.'
example_data = 1
name = 'integer'
classmethod normalize(obj)[source]

Normalize an object, if possible, to conform to this type.

Parameters:

obj (object) – Object to normalize.

Returns:

Normalized object.

Return type:

object

python_types = (<class 'int'>,)
class yggdrasil.metaschema.datatypes.JSONMetaschemaType.JSONMetaschemaTypeBase(**typedef)[source]

Bases: MetaschemaType

Base type for default JSON types.

classmethod decode_data(obj, typedef)[source]

Decode an object.

Parameters:
  • obj (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

Returns:

Decoded object.

Return type:

object

description = 'A json base type.'
classmethod encode_data(obj, typedef)[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

name = 'json'
specificity = -1
class yggdrasil.metaschema.datatypes.JSONMetaschemaType.JSONNullMetaschemaType(**typedef)[source]

Bases: JSONMetaschemaTypeBase

JSON base null type.

description = 'JSON null type.'
example_data = None
name = 'null'
python_types = (<class 'NoneType'>,)
class yggdrasil.metaschema.datatypes.JSONMetaschemaType.JSONNumberMetaschemaType(**typedef)[source]

Bases: JSONMetaschemaTypeBase

JSON base number type.

Developer Notes:

This covers the JSON default for floating point or integer values.

description = 'JSON number type.'
example_data = 1.0
name = 'number'
classmethod normalize(obj)[source]

Normalize an object, if possible, to conform to this type.

Parameters:

obj (object) – Object to normalize.

Returns:

Normalized object.

Return type:

object

python_types = (<class 'numbers.Number'>,)
class yggdrasil.metaschema.datatypes.JSONMetaschemaType.JSONStringMetaschemaType(**typedef)[source]

Bases: JSONMetaschemaTypeBase

JSON base string type.

Developer Notes:

Encoding dependent on JSON library.

description = 'JSON string type.'
example_data = 'hello'
name = 'string'
classmethod normalize(obj)[source]

Normalize an object, if possible, to conform to this type.

Parameters:

obj (object) – Object to normalize.

Returns:

Normalized object.

Return type:

object

python_types = (<class 'str'>,)

yggdrasil.metaschema.datatypes.JSONObjectMetaschemaType module

class yggdrasil.metaschema.datatypes.JSONObjectMetaschemaType.JSONObjectMetaschemaType(*args, **kwargs)[source]

Bases: ContainerMetaschemaType

Type associated with a map.

Developer Notes:

Support for dynamic objects in C/C++ is still under development.

classmethod coerce_type(obj, typedef=None, key_order=None, **kwargs)[source]

Coerce objects of specific types to match the data type.

Parameters:
  • obj (object) – Object to be coerced.

  • typedef (dict, optional) – Type defintion that object should be coerced to. Defaults to None.

  • key_order (list, optional) – Order or keys correpsonding to elements in a provided list or tuple. Defaults to None.

  • **kwargs – Additional keyword arguments are metadata entries that may aid in coercing the type.

Returns:

Coerced object.

Return type:

object

Raises:

RuntimeError – If obj is a list or tuple, but key_order is not provided.

description = 'A container mapping between keys and values.'
extract_properties = ['type', 'title', 'properties']
classmethod get_test_data(typedef=None)[source]

object: Test data.

metadata_properties = ['type', 'properties']
name = 'object'
properties = ['type', 'title', 'properties']
python_types = (<class 'dict'>,)

yggdrasil.metaschema.datatypes.MetaschemaType module

class yggdrasil.metaschema.datatypes.MetaschemaType.MetaschemaType(**typedef)[source]

Bases: object

Base type that should be subclassed by user defined types. Attributes should be overwritten to match the type.

Parameters:

**kwargs – All keyword arguments are assumed to be type definition properties which will be used to validate serialized/deserialized messages.

Class Attributes:
name (str): Name of the type for use in YAML files & form options.

[REQUIRED]

description (str): A short description of the type. [REQUIRED] properties (list): List of JSON schema properties that this type uses.

These properties will be added to those form the paretn type class unless inherit_properties is False. Defaults to [‘type’, ‘title’].

definition_properties (list): Type properties that are required for YAML

or form entries specifying the type. These will also be used to validate type definitions. These properties will be added to those from the parent type class unless inherit_properties is False. Defaults to [‘type’].

metadata_properties (list): Type properties that are required for

deserializing instances of the type that have been serialized. These properties will be added to those from the parent class unless inherit_properties is False. Defaults to [‘type’].

extract_properties (list): Properties that will be extracted from the

metadata of a message to construct the type definition. These properties will be added to those from the parent class unless inherit_properties is False. Defaults to [‘type’, ‘title’].

python_types (list): List of python types that this type encompasses.

[REQUIRED].

specificity (int): Specificity of the type. Types with larger values are

more specific while types with smaller values are more general. Base types have a specificity of 0. More specific types are checked first before more general ones.

is_fixed (bool): True if the type is a fixed version of another type. See

FixedMetaschemaType for details.

inherit_properties (bool, list): If True, a type class’s properties will

be a combination of the parent class’s properties and those explicitly defined in the child class. If False, a type class’s properties will only be those explicitly defined in the child class. If a list of property attributes, only properties specified by those attributes will be inherited from the parent class.

schema_file (str, None): If set, the class’s schema is loaded from the

specified file at registration and moved to the loaded_schema_file class attribute. Defaults to None.

loaded_schema_file (str, None): The path to the file the schema for the

type was loaded from if it was loaded.

cross_language_support (bool): If True, this indicates the types should

be serializable across most (if not all) of the supported languages. If False, this type is not required to be serializable except to/from Python. Defaults to True.

classmethod check_decoded(obj, typedef=None, raise_errors=False, typedef_validated=False)[source]

Checks if an object is of the this type.

Parameters:
  • obj (object) – Object to be tested.

  • typedef (dict, optional) – Type properties that object should be tested against. Defaults to None and is not used.

  • raise_errors (bool, optional) – If True, any errors determining that decoded object is not of this type will be raised. Defaults to False.

  • typedef_validated (bool, optional) – If True, the type definition is taken as already having been validated and will not be validated again during the encoding process. Defaults to False.

Returns:

Truth of if the input object is of this type.

Return type:

bool

classmethod check_encoded(metadata, typedef=None, raise_errors=False, typedef_validated=False, metadata_validated=False)[source]

Checks if the metadata for an encoded object matches the type definition.

Parameters:
  • metadata (dict) – Meta data to be tested.

  • typedef (dict, optional) – Type properties that object should be tested against. Defaults to None and object may have any values for the type properties (so long as they match the schema.

  • raise_errors (bool, optional) – If True, any errors determining that encoded object is not of this type will be raised. Defaults to False.

  • typedef_validated (bool, optional) – If True, the type definition is taken as already having been validated and will not be validated again during the encoding process. Defaults to False.

  • metadata_validated (bool, optional) – If True, the metadata definition is taken as already having been valdiated and will not be validated again. Defaults to False.

Returns:

True if the metadata matches the type definition, False

otherwise.

Return type:

bool

classmethod coerce_type(obj, typedef=None, **kwargs)[source]

Coerce objects of specific types to match the data type.

Parameters:
  • obj (object) – Object to be coerced.

  • typedef (dict, optional) – Type defintion that object should be coerced to. Defaults to None.

  • **kwargs – Additional keyword arguments are metadata entries that may aid in coercing the type.

Returns:

Coerced object.

Return type:

object

cross_language_support = True
classmethod decode(metadata, data, typedef=None, typedef_validated=False, dont_check=False)[source]

Decode an object.

Parameters:
  • metadata (dict) – Meta data describing the data.

  • data (bytes) – Encoded data.

  • typedef (dict, optional) – Type properties that decoded object should be tested against. Defaults to None and object may have any values for the type properties (so long as they match the schema).

  • typedef_validated (bool, optional) – If True, the type definition is taken as already having been validated and will not be validated again during the encoding process. Defaults to False.

  • dont_check (bool, optional) – If True, the metadata will not be checked against the type definition. Defaults to False.

Returns:

Decoded object.

Return type:

object

Raises:
  • ValueError – If the metadata does not match the type definition.

  • ValueError – If the decoded object does not match type definition.

classmethod decode_data(obj, typedef)[source]

Decode an object.

Parameters:
  • obj (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

Returns:

Decoded object.

Return type:

object

definition_properties = ['type']
classmethod definition_schema()[source]

JSON schema for validating a type definition schema.

description = 'A generic base type for users to build on.'
deserialize(msg, no_data=False, metadata=None, dont_decode=False, dont_check=False)[source]

Deserialize a message.

Parameters:
  • msg (str, bytes) – Message to be deserialized.

  • no_data (bool, optional) – If True, only the metadata is returned. Defaults to False.

  • metadata (dict, optional) – Metadata that should be used to deserialize the message instead of the current header content. Defaults to None and is not used.

  • dont_decode (bool, optional) – If True, type specific and JSON decoding will not be used to decode the message. Defaults to False.

  • dont_check (bool, optional) – If True, the metadata will not be checked against the type definition. Defaults to False.

Returns:

Deserialized message and header information.

Return type:

tuple(obj, dict)

Raises:
  • TypeError – If msg is not bytes type (str on Python 2).

  • ValueError – If msg does not contain the header separator.

classmethod encode(obj, typedef=None, typedef_validated=False, dont_check=False, **kwargs)[source]

Encode an object.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict, optional) – Type properties that object should be tested against. Defaults to None and object may have any values for the type properties (so long as they match the schema.

  • typedef_validated (bool, optional) – If True, the type definition is taken as already having been validated and will not be validated again during the encoding process. Defaults to False.

  • dont_check (bool, optional) – If True, the object will not be checked against the type definition. Defaults to False.

  • **kwargs – Additional keyword arguments are added to the metadata.

Returns:

Encoded object with type definition and data

serialized to bytes.

Return type:

tuple(dict, bytes)

Raises:
  • ValueError – If the object does not match the type definition.

  • ValueError – If the encoded metadata does not match the type definition.

  • TypeError – If the encoded data is not of bytes type.

classmethod encode_data(obj, typedef)[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

classmethod encode_data_readable(obj, typedef)[source]

Encode an object’s data in a readable format.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

classmethod encode_type(obj, typedef=None, is_validated=False, **kwargs)[source]

Encode an object’s type definition.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict, optional) – Type properties that should be used to initialize the encoded type definition in certain cases. Defaults to None and is ignored.

  • **kwargs – Additional keyword arguments are treated as additional schema properties.

Raises:

MetaschemaTypeError – If the object is not the correct type.

Returns:

Encoded type definition.

Return type:

dict

extract_properties = ['type', 'title']
classmethod extract_typedef(metadata, reqkeys=None)[source]

Extract the minimum typedef required for this type from the provided metadata.

Parameters:
  • metadata (dict) – Message metadata.

  • reqkeys (list, optional) – Set of keys to keep in the definition. Defaults to the required definition keys.

Returns:

Encoded type definition with unncessary properties removed.

Return type:

dict

classmethod generate_data(typedef, **kwargs)[source]

Generate mock data for the specified type.

Parameters:

typedef (dict) – Type definition.

Returns:

Python object of the specified type.

Return type:

object

classmethod get_extract_properties(metadata)[source]

Get the list of properties that should be kept when extracting a typedef from message metadata.

Parameters:

metadata (dict) – Metadata that typedef is being extracted from.

Returns:

Keywords that should be kept in the typedef.

Return type:

list

classmethod get_test_data(typedef=None)[source]

object: Test data.

inherit_properties = True
is_fixed = False
classmethod issubtype(t)[source]

Determine if this type is a subclass of the provided type.

Parameters:

t (str, list) – Type name or list of type names to check against.

Returns:

True if this type is a subtype of the specified type t.

Return type:

bool

classmethod jsonschema_type_checker(checker, instance)[source]

Type checker for use with jsonschema >= 3.0.0.

Parameters:
  • checker (jsonschema.TypeChecker) – Type checker class.

  • instance (object) – Object being checked.

Returns:

True if instance could be of this type, False otherwise.

Return type:

bool

loaded_schema_file = None
metadata_properties = ['type']
classmethod metadata_schema()[source]

JSON schema for validating a JSON serialization of the type.

classmethod metaschema()[source]

JSON meta schema for validating schemas for this type.

name = 'base'
classmethod normalize(obj)[source]

Normalize an object, if possible, to conform to this type.

Parameters:

obj (object) – Object to normalize.

Returns:

Normalized object.

Return type:

object

classmethod normalize_definition(obj)[source]

Normalizes a type definition.

Parameters:

obj (object) – Type definition to normalize.

Returns:

Normalized type definition.

Return type:

object

properties = ['type', 'title']
python_types = []
schema_file = None
serialize(obj, no_metadata=False, dont_encode=False, dont_check=False, max_header_size=0, **kwargs)[source]

Serialize a message.

Parameters:
  • obj (object) – Python object to be formatted.

  • no_metadata (bool, optional) – If True, no metadata will be added to the serialized message. Defaults to False.

  • dont_encode (bool, optional) – If True, the input message will not be encoded using type specific or JSON encoding. Defaults to False.

  • dont_check (bool, optional) – If True, the object being serialized will not be checked against the type definition. Defaults to False.

  • max_header_size (int, optional) – Maximum size that header should occupy in order to be sent in a single message. A value of 0 indicates that any size header is valid. Defaults to 0.

  • **kwargs – Additional keyword arguments are added to the metadata.

Returns:

Serialized message.

Return type:

bytes, str

specificity = 0
classmethod transform_type(obj, typedef=None)[source]

Transform an object based on type info.

Parameters:
  • obj (object) – Object to transform.

  • typedef (dict) – Type definition that should be used to transform the object.

Returns:

Transformed object.

Return type:

object

update_typedef(**kwargs)[source]

Update the current typedef with new values.

Parameters:

**kwargs – All keyword arguments are considered to be new type definitions. If they are a valid definition property, they will be copied to the typedef associated with the instance.

Returns:

A dictionary of keyword arguments that were not added to the

type definition.

Return type:

dict

Raises:

MetaschemaTypeError – If the current type does not match the type being updated to.

classmethod validate(obj, raise_errors=False)[source]

Validate an object to check if it could be of this type.

Parameters:
  • obj (object) – Object to validate.

  • raise_errors (bool, optional) – If True, errors will be raised when the object fails to be validated. Defaults to False.

Returns:

True if the object could be of this type, False otherwise.

Return type:

bool

classmethod validate_definition(obj, **kwargs)[source]

Validates a type definition.

Parameters:
  • obj (object) – Type definition to validate.

  • **kwargs – Additional keyword arguments are passed to the validator.

classmethod validate_instance(obj, typedef, **kwargs)[source]

Validates an object against a type definition.

Parameters:
  • obj (object) – Object to validate against a type definition.

  • typedef (dict) – Type definition to validate against.

  • **kwargs – Additional keyword arguments are passed to the validator.

classmethod validate_metadata(obj, **kwargs)[source]

Validates an encoded object.

Parameters:
  • obj (string) – Encoded object to validate.

  • **kwargs – Additional keyword arguments are passed to the validator.

classmethod validator()[source]

JSON schema validator for the meta schema that includes added types.

yggdrasil.metaschema.datatypes.MultiMetaschemaType module

class yggdrasil.metaschema.datatypes.MultiMetaschemaType.MultiMetaschemaType(**typedef)[source]

Bases: MetaschemaType

Type class for handling behavior when more than one type is valid.

classmethod coerce_type(obj, typedef=None, **kwargs)[source]

Coerce objects of specific types to match the data type.

Parameters:
  • obj (object) – Object to be coerced.

  • typedef (dict, optional) – Type defintion that object should be coerced to. Defaults to None.

  • **kwargs – Additional keyword arguments are metadata entries that may aid in coercing the type.

Returns:

Coerced object.

Return type:

object

classmethod decode_data(obj, typedef)[source]

Decode an object.

Parameters:
  • obj (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

Returns:

Decoded object.

Return type:

object

classmethod definition_schema()[source]

JSON schema for validating a type definition schema.

classmethod encode_data(obj, typedef)[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

classmethod encode_type(obj, typedef=None, **kwargs)[source]

Encode an object’s type definition.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict, optional) – Type properties that should be used to initialize the encoded type definition in certain cases. Defaults to None and is ignored.

  • **kwargs – Additional keyword arguments are treated as additional schema properties.

Returns:

Encoded type definition.

Return type:

dict

classmethod get_type_class(typedef=None, obj=None)[source]

Get the type class from the provided typedef.

inherit_properties = False
classmethod issubtype(t)[source]

Determine if this type is a subclass of the provided type.

Parameters:

t (str, list) – Type name or list of type names to check against.

Returns:

True if this type is a subtype of the specified type t.

Return type:

bool

classmethod metadata_schema()[source]

JSON schema for validating a JSON serialization of the type.

classmethod normalize(obj)[source]

Normalize an object, if possible, to conform to this type.

Parameters:

obj (object) – Object to normalize.

Returns:

Normalized object.

Return type:

object

classmethod transform_type(obj, typedef=None)[source]

Transform an object based on type info.

Parameters:
  • obj (object) – Object to transform.

  • typedef (dict) – Type definition that should be used to transform the object.

Returns:

Transformed object.

Return type:

object

type_classes = {}
update_typedef(**kwargs)[source]

Update the current typedef with new values.

Parameters:

**kwargs – All keyword arguments are considered to be new type definitions. If they are a valid definition property, they will be copied to the typedef associated with the instance.

Returns:

A dictionary of keyword arguments that were not added to the

type definition.

Return type:

dict

Raises:

MetaschemaTypeError – If the current type does not match the type being updated to.

classmethod validate(obj, raise_errors=False)[source]

Validate an object to check if it could be of this type.

Parameters:
  • obj (object) – Object to validate.

  • raise_errors (bool, optional) – If True, errors will be raised when the object fails to be validated. Defaults to False.

Returns:

True if the object could be of this type, False otherwise.

Return type:

bool

yggdrasil.metaschema.datatypes.MultiMetaschemaType.create_multitype_class(types)[source]

Create a MultiMetaschemaType class that wraps multiple classes.

Parameters:

types (list) – List of names of types.

Returns:

Subclass of MultiMetaschemaType that add classes.

Return type:

class

yggdrasil.metaschema.datatypes.ObjMetaschemaType module

class yggdrasil.metaschema.datatypes.ObjMetaschemaType.ObjDict(*args, **kwargs)[source]

Bases: PlyDict

Enhanced dictionary class for storing Obj information.

append(solf)[source]

Append new ply information to this dictionary.

Parameters:

solf (ObjDict) – Another ply to append to this one.

apply_scalar_map(*args, **kwargs)[source]

Set the color of faces in a 3D object based on a scalar map. This creates a copy unless no_copy is True.

Parameters:
  • scalar_arr (arr) – Scalar values that should be mapped to colors for each face.

  • color_map (str, optional) – The name of the color map that should be used. Defaults to ‘plasma’.

  • vmin (float, optional) – Value that should map to the minimum of the colormap. Defaults to min(scalar_arr).

  • vmax (float, optional) – Value that should map to the maximum of the colormap. Defaults to max(scalar_arr).

  • scaling (str, optional) – Scaling that should be used to map the scalar array onto the colormap. Defaults to ‘linear’.

  • scale_by_area (bool, optional) – If True, the elements of the scalar array will be multiplied by the area of the corresponding face. If True, vmin and vmax should be in terms of the scaled array. Defaults to False.

  • no_copy (bool, optional) – If True, the returned object will not be a copy. Defaults to False.

Returns:

Obj with updated vertex colors.

Return type:

dict

as_array_dict()[source]

Get a version of the object as a dictionary of arrays.

as_trimesh(**kwargs)[source]

Get a version of the object as a trimesh class.

classmethod from_array_dict(in_dict)[source]

Get a version of the object from a dictionary of arrays.

classmethod from_shape(shape, d, conversion=1.0)[source]

Create a ply dictionary from a PlantGL shape and descritizer.

Parameters:
  • scene (openalea.plantgl.scene) – Scene that should be descritized.

  • d (openalea.plantgl.descritizer) – Descritizer.

  • conversion (float, optional) – Conversion factor that should be applied to the vertex positions. Defaults to 1.0.

classmethod from_trimesh(in_mesh)[source]

Get a version of the object from a trimesh class.

property mesh

Vertices for each face in the structure.

Type:

list

to_geom_args(conversion=1.0, name=None)[source]

Get arguments for creating a PlantGL geometry.

Parameters:
  • conversion (float, optional) – Conversion factor that should be applied to the vertices. Defaults to 1.0.

  • name (str, optional) – Name that should be given to the created PlantGL symbol. Defaults to None and is ignored.

Returns:

Class, arguments and keyword arguments for PlantGL geometry.

Return type:

tuple

property vertex_normals
class yggdrasil.metaschema.datatypes.ObjMetaschemaType.ObjMetaschemaType(*args, **kwargs)[source]

Bases: FixedMetaschemaType, JSONObjectMetaschemaType

Obj 3D structure map.

classmethod coerce_type(obj, typedef=None, **kwargs)[source]

Coerce objects of specific types to match the data type.

Parameters:
  • obj (object) – Object to be coerced.

  • typedef (dict, optional) – Type defintion that object should be coerced to. Defaults to None.

  • **kwargs – Additional keyword arguments are metadata entries that may aid in coercing the type.

Returns:

Coerced object.

Return type:

object

classmethod decode_data(msg, typedef)[source]

Decode an object.

Parameters:
  • msg (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

Returns:

Decoded object.

Return type:

object

definition_properties = ['type']
description = 'A mapping container for Obj 3D data.'
classmethod encode_data(obj, typedef, comments=[], newline='\n')[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

  • comments (list, optional) – List of comments that should be included in the file header. Defaults to lines describing the automated origin of the file.

  • newline (str, optional) – String that should be used to delineated end of lines. Defaults to ‘n’.

Returns:

Serialized message.

Return type:

bytes, str

classmethod encode_data_readable(obj, typedef)[source]

Encode an object’s data in a readable format.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

fixed_properties = {'definitions': {'curve': {'additionalProperties': False, 'description': 'Properties of describing a curve.', 'properties': {'ending_param': {'type': 'float'}, 'starting_param': {'type': 'float'}, 'vertex_indices': {'items': {'type': ['int', 'uint']}, 'minItems': 2, 'type': 'array'}}, 'required': ['starting_param', 'ending_param', 'vertex_indices'], 'type': 'object'}, 'curve2D': {'description': 'Array of parameter indices describine a 2D curve on a surface.', 'items': {'type': ['int', 'uint']}, 'minItems': 2, 'type': 'array'}, 'face': {'description': 'Array of vertex, texture, and normal indices describing a face.', 'items': {'additionalProperties': False, 'properties': {'normal_index': {'type': ['int', 'uint']}, 'texcoord_index': {'type': ['int', 'uint']}, 'vertex_index': {'type': ['int', 'uint']}}, 'required': ['vertex_index'], 'type': 'object'}, 'minItems': 3, 'type': 'array'}, 'line': {'description': 'Array of vertex indices and texture indices describing a line.', 'items': {'additionalProperties': False, 'properties': {'texcoord_index': {'type': ['int', 'uint']}, 'vertex_index': {'type': ['int', 'uint']}}, 'required': ['vertex_index'], 'type': 'object'}, 'minItems': 2, 'type': 'array'}, 'normal': {'additionalProperties': False, 'description': 'Map describing a single normal.', 'properties': {'i': {'type': 'float'}, 'j': {'type': 'float'}, 'k': {'type': 'float'}}, 'required': ['i', 'j', 'k'], 'type': 'object'}, 'param': {'additionalProperties': False, 'description': 'Map describing a single parameter space point.', 'properties': {'u': {'type': 'float'}, 'v': {'type': 'float'}, 'w': {'default': 1.0, 'type': 'float'}}, 'required': ['u', 'v'], 'type': 'object'}, 'point': {'description': 'Array of vertex indices describing a set of points.', 'items': {'type': ['int', 'uint']}, 'minItems': 1, 'type': 'array'}, 'surface': {'additionalProperties': False, 'description': 'Properties describing a surface.', 'properties': {'ending_param_u': {'type': 'float'}, 'ending_param_v': {'type': 'float'}, 'starting_param_u': {'type': 'float'}, 'starting_param_v': {'type': 'float'}, 'vertex_indices': {'items': {'additionalProperties': False, 'properties': {'normal_index': {'type': ['int', 'uint']}, 'texcoord_index': {'type': ['int', 'uint']}, 'vertex_index': {'type': ['int', 'uint']}}, 'required': ['vertex_index'], 'type': 'object'}, 'minItems': 2, 'type': 'array'}}, 'required': ['starting_param_u', 'ending_param_u', 'starting_param_v', 'ending_param_v', 'vertex_indices'], 'type': 'object'}, 'texcoord': {'additionalProperties': False, 'description': 'Map describing a single texture vertex.', 'properties': {'u': {'type': 'float'}, 'v': {'default': 0.0, 'type': 'float'}, 'w': {'default': 0.0, 'type': 'float'}}, 'required': ['u'], 'type': 'object'}, 'vertex': {'additionalProperties': False, 'description': 'Map describing a single vertex.', 'properties': {'blue': {'type': ['int', 'uint']}, 'green': {'type': ['int', 'uint']}, 'red': {'type': ['int', 'uint']}, 'w': {'default': 1.0, 'type': 'float'}, 'x': {'type': 'float'}, 'y': {'type': 'float'}, 'z': {'type': 'float'}}, 'required': ['x', 'y', 'z'], 'type': 'object'}}, 'dependencies': {'curve2Ds': ['params'], 'curves': ['vertices'], 'faces': ['vertices'], 'lines': ['vertices'], 'surfaces': ['vertices']}, 'description': 'A mapping container for Obj 3D data.', 'properties': {'curve2Ds': {'description': 'Array of curve2Ds.', 'items': {'$ref': '#/definitions/curve2D'}, 'type': 'array'}, 'curves': {'description': 'Array of curves.', 'items': {'$ref': '#/definitions/curve'}, 'type': 'array'}, 'faces': {'description': 'Array of faces.', 'items': {'$ref': '#/definitions/face'}, 'type': 'array'}, 'lines': {'description': 'Array of lines.', 'items': {'$ref': '#/definitions/line'}, 'type': 'array'}, 'material': {'description': 'Name of the material to use.', 'type': ['unicode', 'string']}, 'normals': {'description': 'Array of normals.', 'items': {'$ref': '#/definitions/normal'}, 'type': 'array'}, 'params': {'description': 'Array of parameter coordinates.', 'items': {'$ref': '#/definitions/param'}, 'type': 'array'}, 'points': {'description': 'Array of points.', 'items': {'$ref': '#/definitions/point'}, 'type': 'array'}, 'surfaces': {'description': 'Array of surfaces.', 'items': {'$ref': '#/definitions/surface'}, 'type': 'array'}, 'texcoords': {'description': 'Array of texture vertices.', 'items': {'$ref': '#/definitions/texcoord'}, 'type': 'array'}, 'vertices': {'description': 'Array of vertices.', 'items': {'$ref': '#/definitions/vertex'}, 'type': 'array'}}, 'required': ['vertices', 'faces'], 'title': 'obj', 'type': 'object'}
loaded_schema_file = '/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/yggdrasil/metaschema/datatypes/schemas/obj.json'
metadata_properties = ['type']
name = 'obj'
properties = ['type']
python_types = (<class 'dict'>, <class 'yggdrasil.metaschema.datatypes.ObjMetaschemaType.ObjDict'>, <class 'trimesh.base.Trimesh'>)
specificity = 1
classmethod updated_fixed_properties(obj)[source]

Get a version of the fixed properties schema that includes information from the object.

Parameters:

obj (object) – Object to use to put constraints on the fixed properties schema.

Returns:

Fixed properties schema with object dependent constraints.

Return type:

dict

yggdrasil.metaschema.datatypes.ObjMetaschemaType.create_schema(overwrite=False)[source]

Creates a file containing the Obj schema.

Parameters:

overwrite (bool, optional) – If True and a file already exists, the existing file will be replaced. If False, an error will be raised if the file already exists.

yggdrasil.metaschema.datatypes.ObjMetaschemaType.get_schema()[source]

Return the Obj schema, initializing it if necessary.

Returns:

Obj schema.

Return type:

dict

yggdrasil.metaschema.datatypes.PlyMetaschemaType module

class yggdrasil.metaschema.datatypes.PlyMetaschemaType.PlyDict(*args, **kwargs)[source]

Bases: dict

Enhanced dictionary class for storing Ply information.

append(solf)[source]

Append new ply information to this dictionary.

Parameters:

solf (PlyDict) – Another ply to append to this one.

apply_scalar_map(scalar_arr, color_map=None, vmin=None, vmax=None, scaling='linear', scale_by_area=False, no_copy=False, _as_obj=False)[source]

Set the color of faces in a 3D object based on a scalar map. This creates a copy unless no_copy is True.

Parameters:
  • scalar_arr (arr) – Scalar values that should be mapped to colors for each face.

  • color_map (str, optional) – The name of the color map that should be used. Defaults to ‘plasma’.

  • vmin (float, optional) – Value that should map to the minimum of the colormap. Defaults to min(scalar_arr).

  • vmax (float, optional) – Value that should map to the maximum of the colormap. Defaults to max(scalar_arr).

  • scaling (str, optional) – Scaling that should be used to map the scalar array onto the colormap. Defaults to ‘linear’.

  • scale_by_area (bool, optional) – If True, the elements of the scalar array will be multiplied by the area of the corresponding face. If True, vmin and vmax should be in terms of the scaled array. Defaults to False.

  • no_copy (bool, optional) – If True, the returned object will not be a copy. Defaults to False.

Returns:

Ply with updated vertex colors.

Return type:

dict

as_array_dict()[source]

Get a version of the object as a dictionary of arrays.

as_dict()[source]

Get a version of the object as a pure dictionary.

as_trimesh(**kwargs)[source]

Get a version of the object as a trimesh class.

property bounds

Mins/maxs of vertices in each dimension.

Type:

tuple

convert_arrays()[source]

Check fields and convert arrays to nested structures.

count_elements(element_name)[source]

Get the count of a certain element in the dictionary.

Parameters:

element_name (str) – Name of the element to count.

Returns:

Number of the provided element.

Return type:

int

classmethod from_array_dict(in_dict)[source]

Get a version of the object from a dictionary of arrays.

classmethod from_dict(in_dict)[source]

Get a version of the object from a dictionary.

classmethod from_scene(scene, d=None, conversion=1.0)[source]

Create a ply dictionary from a PlantGL scene and descritizer.

Parameters:
  • scene (openalea.plantgl.scene) – Scene that should be descritized.

  • d (openalea.plantgl.descritizer, optional) – Descritizer. Defaults to openalea.plantgl.all.Tesselator.

  • conversion (float, optional) – Conversion factor that should be applied to the vertex positions. Defaults to 1.0.

classmethod from_shape(shape, d, conversion=1.0, _as_obj=False)[source]

Create a ply dictionary from a PlantGL shape and descritizer.

Parameters:
  • scene (openalea.plantgl.scene) – Scene that should be descritized.

  • d (openalea.plantgl.descritizer) – Descritizer.

  • conversion (float, optional) – Conversion factor that should be applied to the vertex positions. Defaults to 1.0.

classmethod from_trimesh(in_mesh)[source]

Get a version of the object from a trimesh class.

merge(ply_list, no_copy=False)[source]

Merge a list of ply dictionaries.

Parameters:
  • ply_list (list) – Ply dictionaries.

  • no_copy (bool, optional) – If True, the current dictionary will be updated, otherwise a copy will be returned with the update. Defaults to False.

Returns:

Merged ply dictionary.

Return type:

dict

property mesh

Vertices for each face in the structure.

Type:

list

property nface

Number of faces.

Type:

int

property nvert

Number of vertices.

Type:

int

to_geom_args(conversion=1.0, name=None, _as_obj=False)[source]

Get arguments for creating a PlantGL geometry.

Parameters:
  • conversion (float, optional) – Conversion factor that should be applied to the vertices. Defaults to 1.0.

  • name (str, optional) – Name that should be given to the created PlantGL symbol. Defaults to None and is ignored.

Returns:

Class, arguments and keyword arguments for PlantGL geometry.

Return type:

tuple

to_scene(conversion=1.0, name=None)[source]

Create a PlantGL scene from a Ply dictionary.

Parameters:
  • conversion (float, optional) – Conversion factor that should be applied to the vertices. Defaults to 1.0.

  • name (str, optional) – Name that should be given to the created PlantGL symbol. Defaults to None and is ignored.

Returns:

class yggdrasil.metaschema.datatypes.PlyMetaschemaType.PlyMetaschemaType(*args, **kwargs)[source]

Bases: FixedMetaschemaType, JSONObjectMetaschemaType

Ply 3D structure map.

classmethod coerce_type(obj, typedef=None, **kwargs)[source]

Coerce objects of specific types to match the data type.

Parameters:
  • obj (object) – Object to be coerced.

  • typedef (dict, optional) – Type defintion that object should be coerced to. Defaults to None.

  • **kwargs – Additional keyword arguments are metadata entries that may aid in coercing the type.

Returns:

Coerced object.

Return type:

object

classmethod decode_data(msg, typedef)[source]

Decode an object.

Parameters:
  • msg (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

Returns:

Decoded object.

Return type:

object

definition_properties = ['type']
description = 'A mapping container for Ply 3D data.'
classmethod encode_data(obj, typedef, element_order=None, property_order=None, default_rgb=[0, 0, 0], comments=[], newline='\n', plyformat='ascii 1.0')[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

  • element_order (list, optional) – Order that elements should be written to the file. If not provided, the order is determined based on typical ply files with remaining elements output in sorted order.

  • property_order (dict, optional) – Dictionary of property order for each element determining the order that they properties should be written to the file. If not provided, the orders are determined based on typical ply files with remaining elements output in sorted order.

  • default_rgb (list, optional) – Default color in RGB that should be used for missing colors. Defaults to [0, 0, 0].

  • comments (list, optional) – List of comments that should be included in the file header. Defaults to lines describing the automated origin of the file.

  • newline (str, optional) – String that should be used to delineated end of lines. Defaults to ‘n’.

  • plyformat (str, optional) – String describing the ply format and version. Defaults to ‘ascii 1.0’.

Returns:

Serialized message.

Return type:

bytes, str

classmethod encode_data_readable(obj, typedef)[source]

Encode an object’s data in a readable format.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

fixed_properties = {'definitions': {'color': {'type': ['int', 'uint']}, 'coord': {'type': 'float'}, 'edge': {'additionalProperties': False, 'description': 'Vertex indices describing an edge.', 'properties': {'blue': {'type': ['int', 'uint']}, 'green': {'type': ['int', 'uint']}, 'red': {'type': ['int', 'uint']}, 'vertex1': {'type': ['int', 'uint']}, 'vertex2': {'type': ['int', 'uint']}}, 'required': ['vertex1', 'vertex2'], 'type': 'object'}, 'face': {'additionalProperties': False, 'description': 'Map describing a single face.', 'properties': {'vertex_index': {'items': {'type': ['int', 'uint']}, 'minItems': 3, 'type': 'array'}}, 'required': ['vertex_index'], 'type': 'object'}, 'index': {'type': ['int', 'uint']}, 'vertex': {'additionalProperties': False, 'description': 'Map describing a single vertex.', 'properties': {'blue': {'type': ['int', 'uint']}, 'green': {'type': ['int', 'uint']}, 'red': {'type': ['int', 'uint']}, 'x': {'type': 'float'}, 'y': {'type': 'float'}, 'z': {'type': 'float'}}, 'required': ['x', 'y', 'z'], 'type': 'object'}}, 'dependencies': {'edges': ['vertices'], 'faces': ['vertices']}, 'description': 'A mapping container for Ply 3D data.', 'properties': {'edges': {'description': 'Array of edges.', 'items': {'$ref': '#/definitions/edge'}, 'type': 'array'}, 'faces': {'description': 'Array of faces.', 'items': {'$ref': '#/definitions/face'}, 'type': 'array'}, 'material': {'description': 'Name of the material to use.', 'type': ['unicode', 'string']}, 'vertices': {'description': 'Array of vertices.', 'items': {'$ref': '#/definitions/vertex'}, 'type': 'array'}}, 'required': ['vertices', 'faces'], 'title': 'ply', 'type': 'object'}
loaded_schema_file = '/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/yggdrasil/metaschema/datatypes/schemas/ply.json'
metadata_properties = ['type']
name = 'ply'
properties = ['type']
python_types = (<class 'dict'>, <class 'yggdrasil.metaschema.datatypes.PlyMetaschemaType.PlyDict'>, <class 'trimesh.base.Trimesh'>)
specificity = 1
classmethod updated_fixed_properties(obj)[source]

Get a version of the fixed properties schema that includes information from the object.

Parameters:

obj (object) – Object to use to put constraints on the fixed properties schema.

Returns:

Fixed properties schema with object dependent constraints.

Return type:

dict

yggdrasil.metaschema.datatypes.PlyMetaschemaType.create_schema(overwrite=False)[source]

Creates a file containing the Ply schema.

Parameters:

overwrite (bool, optional) – If True and a file already exists, the existing file will be replaced. If False, an error will be raised if the file already exists.

yggdrasil.metaschema.datatypes.PlyMetaschemaType.get_key_order(all_keys, default_order)[source]

Determine the order of keys based on the keys and default order. Keys are added first in the default order and then alphabetically.

Parameters:
  • all_keys (list) – List of all keys that should be present in the returned list.

  • default_order (list) – Default order for keys that may or may not be in all_keys.

Returns:

Key order.

Return type:

list

yggdrasil.metaschema.datatypes.PlyMetaschemaType.get_schema()[source]

Return the Ply schema, initializing it if necessary.

Returns:

Ply schema.

Return type:

dict

yggdrasil.metaschema.datatypes.PlyMetaschemaType.plural2singular(e_plur)[source]

Get the singular version of a plural element name. If the plural version ends with the suffix ‘ices’, it is replaced with the singular suffix ‘ex’. If the plural version ends with an ‘s’, it is removed.

Parameters:

e_plur (str) – Plural version of an element name.

Returns:

Singular version of the plural element name e_plur.

Return type:

str

Raises:

ValueError – If a singular version cannot be determined.

yggdrasil.metaschema.datatypes.PlyMetaschemaType.singular2plural(e_sing)[source]

Get the plural version of a singular element name. If the singular version ends with the suffix ‘ex’ it is replaced with the plural suffix ‘ices’. Otherwise, an ‘s’ is appended to the singular name to make it plural.

Parameters:

e_sing (str) – Singular version of an element name.

Returns:

Plural version of the singular element name e_sing.

Return type:

str

yggdrasil.metaschema.datatypes.PlyMetaschemaType.translate_ply2fmt(type_ply)[source]

Get the corresponding type string for a Ply type string.

Parameters:

type_ply (str) – Ply type string.

Returns:

C-style format string.

Return type:

str

yggdrasil.metaschema.datatypes.PlyMetaschemaType.translate_ply2py(type_ply)[source]

Get the corresponding Python type for the Ply type string.

Parameters:

type_ply (str) – Ply type string.

Returns:

Python type.

Return type:

type

Raises:

ValueError – If the type string does not have a match.

yggdrasil.metaschema.datatypes.PlyMetaschemaType.translate_py2ply(py_obj)[source]

Get the correpsonding Ply type string for the provided Python object.

Parameters:

py_obj (object) – Python object.

Returns:

Ply type string.

Return type:

str

yggdrasil.metaschema.datatypes.ScalarMetaschemaType module

class yggdrasil.metaschema.datatypes.ScalarMetaschemaType.BytesMetaschemaType(**typedef)

Bases: FixedMetaschemaType, ScalarMetaschemaType

A bytes value with or without units.

Developer Notes:

Precision X is preserved.

definition_properties = ['type']
description = 'A bytes value with or without units.'
fixed_properties = {'subtype': 'bytes'}
metadata_properties = ['type', 'precision', 'units']
name = 'bytes'
properties = ['type', 'title', 'precision', 'units']
python_types = (<class 'bytes'>, <class 'numpy.bytes_'>, <class 'unyt.array.unyt_quantity'>)
specificity = 1
class yggdrasil.metaschema.datatypes.ScalarMetaschemaType.ComplexMetaschemaType(**typedef)

Bases: FixedMetaschemaType, ScalarMetaschemaType

A complex value with or without units.

Developer Notes:

Precision X is preserved.

definition_properties = ['type']
description = 'A complex value with or without units.'
fixed_properties = {'subtype': 'complex'}
metadata_properties = ['type', 'precision', 'units']
name = 'complex'
properties = ['type', 'title', 'precision', 'units']
python_types = (<class 'complex'>, <class 'numpy.complex128'>, <class 'numpy.complex64'>, <class 'numpy.complex128'>, <class 'numpy.complex256'>, <class 'unyt.array.unyt_quantity'>)
specificity = 1
class yggdrasil.metaschema.datatypes.ScalarMetaschemaType.FloatMetaschemaType(**typedef)

Bases: FixedMetaschemaType, ScalarMetaschemaType

A float value with or without units.

Developer Notes:

Precision X is preserved.

definition_properties = ['type']
description = 'A float value with or without units.'
fixed_properties = {'subtype': 'float'}
metadata_properties = ['type', 'precision', 'units']
name = 'float'
properties = ['type', 'title', 'precision', 'units']
python_types = (<class 'float'>, <class 'numpy.float64'>, <class 'numpy.float16'>, <class 'numpy.float32'>, <class 'numpy.float64'>, <class 'numpy.float128'>, <class 'unyt.array.unyt_quantity'>)
specificity = 1
class yggdrasil.metaschema.datatypes.ScalarMetaschemaType.IntMetaschemaType(**typedef)

Bases: FixedMetaschemaType, ScalarMetaschemaType

A int value with or without units.

Developer Notes:

Precision X is preserved.

definition_properties = ['type']
description = 'A int value with or without units.'
fixed_properties = {'subtype': 'int'}
metadata_properties = ['type', 'precision', 'units']
name = 'int'
properties = ['type', 'title', 'precision', 'units']
python_types = (<class 'int'>, <class 'numpy.int64'>, <class 'numpy.int8'>, <class 'numpy.int16'>, <class 'numpy.int32'>, <class 'numpy.int64'>, <class 'numpy.signedinteger'>, <class 'unyt.array.unyt_quantity'>)
specificity = 1
class yggdrasil.metaschema.datatypes.ScalarMetaschemaType.ScalarMetaschemaType(**typedef)[source]

Bases: MetaschemaType

Type associated with a scalar.

Developer Notes:

yggdrasil defines scalars as an umbrella type encompassing int, uint, float, bytes, and unicode.

classmethod as_python_type(obj, typedef)[source]

Convert a possible numpy type into a native Python type if possible.

Parameters:
  • obj (object) – Object to convert.

  • typedef (dict) – Type definition for the object.

Returns:

Native Python version of input object if conversion possible.

Return type:

object

classmethod decode_data(obj, typedef)[source]

Decode an object.

Parameters:
  • obj (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

Returns:

Decoded object.

Return type:

object

definition_properties = ['type', 'subtype']
description = 'A scalar value with or without units.'
classmethod encode_data(obj, typedef)[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

classmethod encode_data_readable(obj, typedef)[source]

Encode an object’s data in a readable format that may not be decoded in exactly the same way.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

extract_properties = ['type', 'title', 'subtype', 'precision', 'units']
classmethod from_array(arr, unit_str=None, dtype=None, typedef=None)[source]

Get object representation of the data.

Parameters:
  • arr (np.ndarray) – Numpy array.

  • unit_str (str, optional) – Units that should be added to returned object.

  • dtype (np.dtype, optional) – Numpy data type that should be maintained as a base class when adding units. Defaults to None and is determined from the object or typedef (if provided).

  • typedef (dict, optional) – Type definition that should be used to decode the object. Defaults to None and is determined from the object or dtype (if provided).

Returns:

Object representation of the data in the input array.

Return type:

object

classmethod get_extract_properties(metadata)[source]

Get the list of properties that should be kept when extracting a typedef from message metadata.

Parameters:

metadata (dict) – Metadata that typedef is being extracted from.

Returns:

Keywords that should be kept in the typedef.

Return type:

list

classmethod get_test_data(typedef=None)[source]

object: Test data.

metadata_properties = ['type', 'subtype', 'precision', 'units']
name = 'scalar'
classmethod normalize(obj)[source]

Normalize an object, if possible, to conform to this type.

Parameters:

obj (object) – Object to normalize.

Returns:

Normalized object.

Return type:

object

properties = ['type', 'title', 'subtype', 'precision', 'units']
python_types = (<class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numpy.uint64'>, <class 'numpy.int64'>, <class 'numpy.str_'>, <class 'str'>, <class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.unsignedinteger'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'numpy.complex64'>, <class 'numpy.float32'>, <class 'numpy.uint16'>, <class 'numpy.signedinteger'>, <class 'numpy.int16'>, <class 'complex'>, <class 'bytes'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'float'>, <class 'int'>, <class 'unyt.array.unyt_quantity'>)
classmethod to_array(obj)[source]

Get np.array representation of the data.

Parameters:

obj (object) – Object to get array for.

Returns:

Array representation of object.

Return type:

np.ndarray

classmethod transform_type(obj, typedef=None)[source]

Transform an object based on type info.

Parameters:
  • obj (object) – Object to transform.

  • typedef (dict, optional) – Type definition that should be used to transform the object. Defaults to None.

Returns:

Transformed object.

Return type:

object

classmethod validate(obj, raise_errors=False)[source]

Validate an object to check if it could be of this type.

Parameters:
  • obj (object) – Object to validate.

  • raise_errors (bool, optional) – If True, errors will be raised when the object fails to be validated. Defaults to False.

Returns:

True if the object could be of this type, False otherwise.

Return type:

bool

class yggdrasil.metaschema.datatypes.ScalarMetaschemaType.UintMetaschemaType(**typedef)

Bases: FixedMetaschemaType, ScalarMetaschemaType

A uint value with or without units.

Developer Notes:

Precision X is preserved.

definition_properties = ['type']
description = 'A uint value with or without units.'
fixed_properties = {'subtype': 'uint'}
metadata_properties = ['type', 'precision', 'units']
name = 'uint'
properties = ['type', 'title', 'precision', 'units']
python_types = (<class 'numpy.uint64'>, <class 'numpy.uint8'>, <class 'numpy.uint16'>, <class 'numpy.uint32'>, <class 'numpy.uint64'>, <class 'numpy.unsignedinteger'>, <class 'unyt.array.unyt_quantity'>)
specificity = 1
class yggdrasil.metaschema.datatypes.ScalarMetaschemaType.UnicodeMetaschemaType(**typedef)

Bases: FixedMetaschemaType, ScalarMetaschemaType

A unicode value with or without units.

Developer Notes:

Precision X is preserved.

definition_properties = ['type']
description = 'A unicode value with or without units.'
fixed_properties = {'subtype': 'unicode'}
metadata_properties = ['type', 'precision', 'units']
name = 'unicode'
properties = ['type', 'title', 'precision', 'units']
python_types = (<class 'str'>, <class 'numpy.str_'>, <class 'unyt.array.unyt_quantity'>)
specificity = 1

yggdrasil.metaschema.datatypes.SchemaMetaschemaType module

class yggdrasil.metaschema.datatypes.SchemaMetaschemaType.SchemaMetaschemaType(*args, **kwargs)[source]

Bases: JSONObjectMetaschemaType

Schema type.

classmethod decode_data(obj, typedef)[source]

Decode an object.

Parameters:
  • obj (string) – Encoded object to decode.

  • typedef (dict) – Type definition that should be used to decode the object.

Returns:

Decoded object.

Return type:

object

definition_properties = ['type']
description = 'A schema type for evaluating subschema.'
classmethod encode_data(obj, typedef)[source]

Encode an object’s data.

Parameters:
  • obj (object) – Object to encode.

  • typedef (dict) – Type definition that should be used to encode the object.

Returns:

Encoded object.

Return type:

string

example_data = {'type': 'boolean'}
inherit_properties = ['extract_properties']
metadata_properties = ['type']
name = 'schema'
classmethod normalize(obj)[source]

Normalize an object, if possible, to conform to this type.

Parameters:

obj (object) – Object to normalize.

Returns:

Normalized object.

Return type:

object

properties = ['type']
specificity = 1
classmethod validate(obj, raise_errors=False)[source]

Validate an object to check if it could be of this type.

Parameters:
  • obj (object) – Object to validate.

  • raise_errors (bool, optional) – If True, errors will be raised when the object fails to be validated. Defaults to False.

Returns:

True if the object could be of this type, False otherwise.

Return type:

bool

yggdrasil.metaschema.datatypes.conversions module

yggdrasil.metaschema.datatypes.conversions.get_conversion(from_type, to_type)[source]

Get a conversion function for moving from one type to the other.

Parameters:
  • from_type (str) – Name of type being converted from.

  • to_type (str) – Name of type being converted to.

Returns:

Method for performing the conversion. If there is no known

conversion between the specified types, None will be returned.

Return type:

function

yggdrasil.metaschema.datatypes.conversions.obj2ply(obj)[source]

Convert an Obj object to a Ply object.

Parameters:

obj (dict) – Obj type object.

Returns:

Ply data container.

Return type:

dict

yggdrasil.metaschema.datatypes.conversions.ply2obj(ply)[source]

Convert a Ply object to an Obj object.

Parameters:

ply (dict) – Ply type object.

Returns:

Obj data container.

Return type:

dict

yggdrasil.metaschema.datatypes.conversions.register_conversion(from_type, to_type)[source]

Register a conversion function for going between types.

Parameters:
  • from_type (str) – Name of type being converted from.

  • to_type (str) – Name of type being converted to.

Returns:

Decorator that will register the conversion.

Return type:

function

Module contents

class yggdrasil.metaschema.datatypes.MetaschemaTypeMeta(name, bases, class_dict)[source]

Bases: type

Meta class for registering datatypes.

yggdrasil.metaschema.datatypes.add_type_from_schema(path_to_schema, **kwargs)[source]

Add a type from a schema in a file.

Parameters:
  • path_to_schema (string) – Full path to the location of a schema file that can be loaded.

  • target_globals (dict, optional) – Globals dictionary for module where the fixed class should be added. If None, the new class is returned. Defaults to local globals.

  • **kwargs – Additional keyword arguments are assumed to be attributes for the new class.

yggdrasil.metaschema.datatypes.compare_schema(schema1, schema2, root1=None, root2=None)[source]

Compare two schemas for compatibility.

Parameters:
  • schema1 (dict) – First schema.

  • schema2 (dict) – Second schema.

  • root1 (dict, optional) – Root for first schema. Defaults to None and is set to schema1.

  • root2 (dict, optional) – Root for second schema. Defaults to None and is set to schema2.

Yields:

str – Comparision failure messages.

yggdrasil.metaschema.datatypes.complete_typedef(typedef)[source]

Complete the type definition by converting it into the standard format.

Parameters:

typedef (str, dict, list) – A type name, type definition dictionary, dictionary of subtype definitions, or a list of subtype definitions.

Returns:

Type definition dictionary.

Return type:

dict

Raises:

TypeError – If typedef is not a valid type.

yggdrasil.metaschema.datatypes.decode(msg)[source]

Decode an object from a message.

Parameters:

msg (bytes) – Bytes encoded message.

Returns:

Decoded Python object.

Return type:

object

yggdrasil.metaschema.datatypes.decode_data(obj, typedef)[source]

Decode a JSON serializable object to get the corresponding Python variable.

Parameters:
  • obj (object) – JSON serializable object representing an encoded form of a message.

  • typedef (dict) – JSON schema describing the object.

Returns:

Deserialized version of the object.

Return type:

object

yggdrasil.metaschema.datatypes.encode(obj)[source]

Encode an object into a message.

Parameters:

obj (object) – Python object to be encoded.

Returns:

Encoded message.

Return type:

bytes

yggdrasil.metaschema.datatypes.encode_data(obj, typedef=None)[source]

Encode an object into a JSON serializable object.

Parameters:
  • obj (object) – Python object to be encoded.

  • typedef (dict, optional) – JSON schema describing the object. Defaults to None and class is determined from the object.

Returns:

JSON serializable version of the object.

Return type:

object

yggdrasil.metaschema.datatypes.encode_data_readable(obj, typedef=None)[source]

Encode an object into a JSON serializable object that is human readable but dosn’t guarantee identical deserialization.

Parameters:
  • obj (object) – Python object to be encoded.

  • typedef (dict, optional) – JSON schema describing the object. Defaults to None and class is determined from the object.

Returns:

JSON serializable version of the object.

Return type:

object

yggdrasil.metaschema.datatypes.encode_type(obj, typedef=None, **kwargs)[source]

Encode an object into a JSON schema that can be used to both describe the object and validate others.

Parameters:
  • obj (object) – Python object to be encoded.

  • typedef (dict, optional) – Type properties that should be used to initialize the encoded type definition in certain cases. Defaults to None and is ignored.

  • **kwargs – Additional keyword arguments are passed to the identified type class’s encode_type method.

Returns:

Encoded JSON schema describing the object.

Return type:

dict

yggdrasil.metaschema.datatypes.generate_data(typedef, **kwargs)[source]

Generate mock data for the specified type.

Parameters:
  • typedef (dict) – Type definition.

  • **kwargs – Additional keyword arguments are passed to the generating class’s generate_data method.

Returns:

Python object of the specified type.

Return type:

object

yggdrasil.metaschema.datatypes.get_registered_types()[source]

Return a dictionary of registered types.

Returns:

Registered type/class pairs.

Return type:

dict

yggdrasil.metaschema.datatypes.get_type_class(type_name)[source]

Return a type class given it’s name.

Parameters:

type_name (str, list) – Name of type class or list of names of type classes.

Returns:

Type class.

Return type:

class

yggdrasil.metaschema.datatypes.get_type_from_def(typedef, dont_complete=False)[source]

Return the type instance based on the provided type definition.

Parameters:
  • typedef (obj) – This can be the name of a type, a dictionary containing a type definition (the ‘typename’ keyword must be specified), or a complex type (a list or dictionary containing types).

  • dont_complete (bool, optional) – If True, the type definition will be used as-is. Otherwise it will be completed using normalization which can be time consuming. Defaults to False.

Returns:

Instance of the appropriate type class.

Return type:

MetaschemaType

yggdrasil.metaschema.datatypes.guess_type_from_msg(msg)[source]

Guess the type class from a message.

Parameters:

msg (str, bytes) – Message containing metadata.

Raises:

ValueError – If a type class cannot be determined.

Returns:

Instance of the appropriate type class.

Return type:

MetaschemaType

yggdrasil.metaschema.datatypes.guess_type_from_obj(obj)[source]

Guess the type class for a given Python object.

Parameters:

obj (object) – Python object.

Returns:

Instance of the appropriate type class.

Return type:

MetaschemaType

Raises:

ValueError – If a type class cannot be determined.

yggdrasil.metaschema.datatypes.import_schema_types()[source]

Import all types to ensure they are registered.

yggdrasil.metaschema.datatypes.is_default_typedef(typedef)[source]

Determine if a type definition is the default type definition.

Parameters:

typedef (dict) – Type definition to test.

Returns:

True if typedef is the default, False otherwise.

Return type:

bool

yggdrasil.metaschema.datatypes.register_type(type_class)[source]

Register a type class, recording methods for encoding/decoding.

Parameters:

type_class (class) – Class to be registered.

Raises:
  • ValueError – If the type is already registered.

  • ValueError – If the type is a default JSON type.

  • ValueError – If any of the type’s properties are not registered.

yggdrasil.metaschema.datatypes.resolve_schema_references(schema, resolver=None)[source]

Resolve references within a schema.

Parameters:
  • schema (dict) – Schema with references to resolve.

  • top_level (dict, optional) – Reference to the top level schema.

Returns:

Schema with references replaced with internal references.

Return type:

dict

yggdrasil.metaschema.datatypes.transform_type(obj, typedef=None)[source]

Transform an object based on type info.

Parameters:
  • obj (object) – Object to transform.

  • typedef (dict) – Type definition that should be used to transform the object.

Returns:

Transformed object.

Return type:

object