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¶
- description = 'A type allowing any value that is expresible in some type.'¶
- 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.
- classmethod get_temptype(typedef, return_none=False)[source]¶
Extract temporary type from type definition.
- Parameters:
- Returns:
Temporary type definition or None if not present.
- Return type:
- metadata_properties = ['type', 'temptype']¶
- name = 'any'¶
- properties = ['type', 'title', 'temptype']¶
- python_types = (<class 'object'>,)¶
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'>)¶
- 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'>)¶
yggdrasil.metaschema.datatypes.ClassMetaschemaType module¶
- class yggdrasil.metaschema.datatypes.ClassMetaschemaType.ClassMetaschemaType(**typedef)[source]¶
Bases:
MetaschemaType
Type for evaluating classes.
- cross_language_support = False¶
- description = 'Type for Python classes.'¶
- encoded_type = 'string'¶
- name = 'class'¶
- classmethod normalize(obj, working_dir=None)[source]¶
Normalize an object, if possible, to conform to this type.
- python_types = (<class 'type'>,)¶
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:
- Returns:
Coerced object.
- Return type:
- Raises:
RuntimeError – If obj is a dictionary, but key_order is not provided.
- description = 'A container of other types.'¶
- classmethod encode_data_readable(obj, typedef, **kwargs)[source]¶
Encode an object’s data in a readable format.
- classmethod extract_typedef(metadata)[source]¶
Extract the minimum typedef required for this type from the provided metadata.
- name = 'container'¶
- python_types = []¶
- 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:
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:
- 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:
- classmethod extract_typedef(metadata)[source]¶
Extract the minimum typedef required for this type from the provided metadata.
- fixed_properties = {}¶
- is_fixed = True¶
- classmethod typedef_base2fixed(typedef)[source]¶
Transform a type definition from the unfixed base type to the fixed type alias by removing fixed properties.
- 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.
- 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:
- classmethod updated_fixed_properties(obj)[source]¶
Get a version of the fixed properties schema that includes information from the object.
- 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.InstanceMetaschemaType module¶
- class yggdrasil.metaschema.datatypes.InstanceMetaschemaType.InstanceMetaschemaType(**typedef)[source]¶
Bases:
MetaschemaType
Type for evaluating instances of Python classes.
- cross_language_support = False¶
- definition_properties = ['type', 'class']¶
- description = 'Type for Python class instances.'¶
- extract_properties = ['type', 'title', 'class', 'args', 'kwargs']¶
- metadata_properties = ['type', 'class', 'args', 'kwargs']¶
- name = 'instance'¶
- properties = ['type', 'title', 'class', 'args', 'kwargs']¶
- python_types = (<class 'object'>,)¶
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:
- Raises:
RuntimeError – If obj is a dictionary, but key_order is not provided.
- description = 'A container of ordered values.'¶
- extract_properties = ['type', 'title', 'items']¶
- metadata_properties = ['type', 'items']¶
- name = 'array'¶
- properties = ['type', 'title', 'items']¶
- python_types = (<class 'list'>, <class 'tuple'>, <class 'numpy.ndarray'>, <class 'pandas.core.frame.DataFrame'>)¶
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'¶
- 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'¶
- python_types = (<class 'int'>,)¶
- class yggdrasil.metaschema.datatypes.JSONMetaschemaType.JSONMetaschemaTypeBase(**typedef)[source]¶
Bases:
MetaschemaType
Base type for default JSON types.
- description = 'A json base type.'¶
- 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'¶
- 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'¶
- 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:
- 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']¶
- 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:
- 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:
- classmethod coerce_type(obj, typedef=None, **kwargs)[source]¶
Coerce objects of specific types to match the data type.
- 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:
- Raises:
ValueError – If the metadata does not match the type definition.
ValueError – If the decoded object does not match type definition.
- definition_properties = ['type']¶
- 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:
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:
- 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:
- 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_readable(obj, typedef)[source]¶
Encode an object’s data in a readable format.
- classmethod encode_type(obj, typedef=None, is_validated=False, **kwargs)[source]¶
Encode an object’s type definition.
- Parameters:
- Raises:
MetaschemaTypeError – If the object is not the correct type.
- Returns:
Encoded type definition.
- Return type:
- extract_properties = ['type', 'title']¶
- classmethod extract_typedef(metadata, reqkeys=None)[source]¶
Extract the minimum typedef required for this type from the provided metadata.
- classmethod get_extract_properties(metadata)[source]¶
Get the list of properties that should be kept when extracting a typedef from message metadata.
- inherit_properties = True¶
- is_fixed = False¶
- classmethod jsonschema_type_checker(checker, instance)[source]¶
Type checker for use with jsonschema >= 3.0.0.
- loaded_schema_file = None¶
- metadata_properties = ['type']¶
- name = 'base'¶
- 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:
- specificity = 0¶
- 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:
- 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.
- 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.
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.
- classmethod encode_type(obj, typedef=None, **kwargs)[source]¶
Encode an object’s type definition.
- Parameters:
- Returns:
Encoded type definition.
- Return type:
- classmethod get_type_class(typedef=None, obj=None)[source]¶
Get the type class from the provided typedef.
- inherit_properties = False¶
- 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:
- Raises:
MetaschemaTypeError – If the current type does not match the type being updated to.
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:
- 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.
- to_geom_args(conversion=1.0, name=None)[source]¶
Get arguments for creating a PlantGL geometry.
- Parameters:
- Returns:
Class, arguments and keyword arguments for PlantGL geometry.
- Return type:
- 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.
- 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:
- classmethod encode_data_readable(obj, typedef)[source]¶
Encode an object’s data in a readable format.
- 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¶
- 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.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:
- classmethod from_array_dict(in_dict)[source]¶
Get a version of the object from a dictionary of arrays.
- 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.
- to_geom_args(conversion=1.0, name=None, _as_obj=False)[source]¶
Get arguments for creating a PlantGL geometry.
- Parameters:
- Returns:
Class, arguments and keyword arguments for PlantGL geometry.
- Return type:
- 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.
- 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:
- classmethod encode_data_readable(obj, typedef)[source]¶
Encode an object’s data in a readable format.
- 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¶
- 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.
- yggdrasil.metaschema.datatypes.PlyMetaschemaType.get_schema()[source]¶
Return the Ply schema, initializing it if necessary.
- Returns:
Ply schema.
- Return type:
- 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:
- 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.
- yggdrasil.metaschema.datatypes.PlyMetaschemaType.translate_ply2fmt(type_ply)[source]¶
Get the corresponding type string for a Ply type string.
- 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:
- Raises:
ValueError – If the type string does not have a match.
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.
- definition_properties = ['type', 'subtype']¶
- description = 'A scalar value with or without units.'¶
- 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.
- 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:
- classmethod get_extract_properties(metadata)[source]¶
Get the list of properties that should be kept when extracting a typedef from message metadata.
- metadata_properties = ['type', 'subtype', 'precision', 'units']¶
- name = 'scalar'¶
- 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
- 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.
- definition_properties = ['type']¶
- description = 'A schema type for evaluating subschema.'¶
- example_data = {'type': 'boolean'}¶
- inherit_properties = ['extract_properties']¶
- metadata_properties = ['type']¶
- name = 'schema'¶
- properties = ['type']¶
- specificity = 1¶
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.
- yggdrasil.metaschema.datatypes.conversions.obj2ply(obj)[source]¶
Convert an Obj object to a Ply object.
- yggdrasil.metaschema.datatypes.conversions.ply2obj(ply)[source]¶
Convert a Ply object to an Obj object.
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.
- yggdrasil.metaschema.datatypes.complete_typedef(typedef)[source]¶
Complete the type definition by converting it into the standard format.
- yggdrasil.metaschema.datatypes.decode_data(obj, typedef)[source]¶
Decode a JSON serializable object to get the corresponding Python variable.
- yggdrasil.metaschema.datatypes.encode_data(obj, typedef=None)[source]¶
Encode an object into a JSON serializable 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.
- 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:
- yggdrasil.metaschema.datatypes.generate_data(typedef, **kwargs)[source]¶
Generate mock data for the specified type.
- yggdrasil.metaschema.datatypes.get_registered_types()[source]¶
Return a dictionary of registered types.
- Returns:
Registered type/class pairs.
- Return type:
- yggdrasil.metaschema.datatypes.get_type_class(type_name)[source]¶
Return a type class given it’s name.
- 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:
- yggdrasil.metaschema.datatypes.guess_type_from_msg(msg)[source]¶
Guess the type class from a message.
- Parameters:
- Raises:
ValueError – If a type class cannot be determined.
- Returns:
Instance of the appropriate type class.
- Return type:
- 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:
- 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.
- 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.