cis_interface.metaschema.datatypes package

Submodules

cis_interface.metaschema.datatypes.ArrayMetaschemaType module

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

Bases: cis_interface.metaschema.datatypes.ScalarMetaschemaType.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 'unyt.array.unyt_array'>, <class 'numpy.ndarray'>)
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 cis_interface.metaschema.datatypes.ArrayMetaschemaType.OneDArrayMetaschemaType(**typedef)[source]

Bases: cis_interface.metaschema.datatypes.ScalarMetaschemaType.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 'unyt.array.unyt_array'>, <class 'numpy.ndarray'>)
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

cis_interface.metaschema.datatypes.ContainerMetaschemaType module

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

Bases: cis_interface.metaschema.datatypes.MetaschemaType.MetaschemaType

Type associated with a container of subtypes.

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)[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 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 = []
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

cis_interface.metaschema.datatypes.FixedMetaschemaType module

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

Bases: cis_interface.metaschema.datatypes.MetaschemaType.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

cis_interface.metaschema.datatypes.FixedMetaschemaType.create_fixed_type_class(name, description, base, fixed_properties, target_globals=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.
  • **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

cis_interface.metaschema.datatypes.FunctionMetaschemaType module

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

Bases: cis_interface.metaschema.datatypes.MetaschemaType.MetaschemaType

Type for evaluating functions.

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 = 'Type for callable Python functions.'
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 = 'function'
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 'builtin_function_or_method'>, <class 'function'>, <class 'builtin_function_or_method'>, <class 'method'>)

cis_interface.metaschema.datatypes.JSONArrayMetaschemaType module

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

Bases: cis_interface.metaschema.datatypes.ContainerMetaschemaType.ContainerMetaschemaType

Type associated with a set of subtypes.

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 that keys from a dictionary should be used to compose an array. 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.

definition_properties = ['type']
description = 'A container of ordered values.'
extract_properties = ['type', 'title', 'items']
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

cis_interface.metaschema.datatypes.JSONMetaschemaType module

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

Bases: cis_interface.metaschema.datatypes.JSONMetaschemaType.JSONMetaschemaType

JSON base boolean type.

description = 'JSON boolean type.'
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 cis_interface.metaschema.datatypes.JSONMetaschemaType.JSONIntegerMetaschemaType(**typedef)[source]

Bases: cis_interface.metaschema.datatypes.JSONMetaschemaType.JSONMetaschemaType

JSON base integer type.

description = 'JSON integer type.'
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 cis_interface.metaschema.datatypes.JSONMetaschemaType.JSONMetaschemaType(**typedef)[source]

Bases: cis_interface.metaschema.datatypes.MetaschemaType.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 cis_interface.metaschema.datatypes.JSONMetaschemaType.JSONNullMetaschemaType(**typedef)[source]

Bases: cis_interface.metaschema.datatypes.JSONMetaschemaType.JSONMetaschemaType

JSON base null type.

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

Bases: cis_interface.metaschema.datatypes.JSONMetaschemaType.JSONMetaschemaType

JSON base number type.

description = 'JSON number type.'
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 cis_interface.metaschema.datatypes.JSONMetaschemaType.JSONStringMetaschemaType(**typedef)[source]

Bases: cis_interface.metaschema.datatypes.JSONMetaschemaType.JSONMetaschemaType

JSON base string type.

description = 'JSON string type.'
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'>,)

cis_interface.metaschema.datatypes.JSONObjectMetaschemaType module

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

Bases: cis_interface.metaschema.datatypes.ContainerMetaschemaType.ContainerMetaschemaType

Type associated with a map.

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.

definition_properties = ['type']
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'>,)

cis_interface.metaschema.datatypes.MetaschemaType module

class cis_interface.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.
name

Name of the type for use in YAML files & form options.

Type:str
description

A short description of the type.

Type:str
properties

List of JSON schema properties that this type uses.

Type:list
definition_properties

Type properties that are required for YAML or form entries specifying the type. These will also be used to validate type definitions.

Type:list
metadata_properties

Type properties that are required for deserializing instances of the type that have been serialized.

Type:list
python_types

List of python types that this type encompasses.

Type:list
specificity

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.

Type:int
is_fixed

True if the type is a fixed version of another type. See FixedMetaschemaType for details.

Type:bool
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)[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.
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

classmethod decode(metadata, data, typedef=None, typedef_validated=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.
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)[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.
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, **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.
  • **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, **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 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
is_fixed = False
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 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

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 = []
serialize(obj, no_metadata=False, dont_encode=False, **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.
  • **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)[source]

Validates a type definition.

Parameters:obj (object) – Type definition to validate.
classmethod validate_instance(obj, typedef)[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.
classmethod validate_metadata(obj)[source]

Validates an encoded object.

Parameters:obj (string) – Encoded object to validate.
classmethod validator()[source]

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

cis_interface.metaschema.datatypes.ObjMetaschemaType module

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

Bases: cis_interface.metaschema.datatypes.PlyMetaschemaType.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

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.
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

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

Bases: cis_interface.metaschema.datatypes.FixedMetaschemaType.FixedMetaschemaType, cis_interface.metaschema.datatypes.JSONObjectMetaschemaType.JSONObjectMetaschemaType

Obj 3D structure map.

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

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'}
metadata_properties = ['type']
name = 'obj'
properties = ['type']
python_types = (<class 'dict'>, <class 'cis_interface.metaschema.datatypes.ObjMetaschemaType.ObjDict'>)
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
cis_interface.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.
cis_interface.metaschema.datatypes.ObjMetaschemaType.get_schema()[source]

Return the Obj schema, initializing it if necessary.

Returns:Obj schema.
Return type:dict

cis_interface.metaschema.datatypes.PlyMetaschemaType module

class cis_interface.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_dict()[source]

Get a version of the object as a pure dictionary.

bounds

Mins/maxs of vertices in each dimension.

Type:tuple
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_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.
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

mesh

Vertices for each face in the structure.

Type:list
nface

Number of faces.

Type:int
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 cis_interface.metaschema.datatypes.PlyMetaschemaType.PlyMetaschemaType(*args, **kwargs)[source]

Bases: cis_interface.metaschema.datatypes.FixedMetaschemaType.FixedMetaschemaType, cis_interface.metaschema.datatypes.JSONObjectMetaschemaType.JSONObjectMetaschemaType

Ply 3D structure map.

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

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'}
metadata_properties = ['type']
name = 'ply'
properties = ['type']
python_types = (<class 'dict'>, <class 'cis_interface.metaschema.datatypes.PlyMetaschemaType.PlyDict'>)
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
cis_interface.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.
cis_interface.metaschema.datatypes.PlyMetaschemaType.get_schema()[source]

Return the Ply schema, initializing it if necessary.

Returns:Ply schema.
Return type:dict
cis_interface.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.
cis_interface.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
cis_interface.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
cis_interface.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.
cis_interface.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

cis_interface.metaschema.datatypes.ScalarMetaschemaType module

class cis_interface.metaschema.datatypes.ScalarMetaschemaType.ScalarMetaschemaType(**typedef)[source]

Bases: cis_interface.metaschema.datatypes.MetaschemaType.MetaschemaType

Type associated with a scalar.

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)[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.
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
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.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'numpy.signedinteger'>, <class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numpy.uint64'>, <class 'numpy.int64'>, <class 'bytes'>, <class 'str'>, <class 'numpy.str_'>, <class 'float'>, <class 'numpy.unsignedinteger'>, <class 'int'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'unyt.array.unyt_quantity'>, <class 'numpy.complex64'>, <class 'numpy.float32'>, <class 'complex'>, <class 'numpy.uint16'>, <class 'numpy.int16'>)
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

cis_interface.metaschema.datatypes.SchemaMetaschemaType module

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

Bases: cis_interface.metaschema.datatypes.JSONObjectMetaschemaType.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

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

cis_interface.metaschema.datatypes.conversions module

cis_interface.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

cis_interface.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
cis_interface.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
cis_interface.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

exception cis_interface.metaschema.datatypes.MetaschemaTypeError[source]

Bases: TypeError

Error that should be raised when a class encounters a type it cannot handle.

cis_interface.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.
cis_interface.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.

cis_interface.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.
cis_interface.metaschema.datatypes.decode(msg)[source]

Decode an object from a message.

Parameters:msg (bytes) – Bytes encoded message.
Returns:Decoded Python object.
Return type:object
cis_interface.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
cis_interface.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

cis_interface.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

cis_interface.metaschema.datatypes.encode_type(obj, typedef=None)[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.
Returns:

Encoded JSON schema describing the object.

Return type:

dict

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

Return a dictionary of registered types.

Returns:Registered type/class pairs.
Return type:dict
cis_interface.metaschema.datatypes.get_type_class(type_name)[source]

Return a type class given it’s name.

Parameters:type_name (str) – Name of type class.
Returns:Type class.
Return type:class
cis_interface.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

cis_interface.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
cis_interface.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.
cis_interface.metaschema.datatypes.import_all_types()[source]

Import all types to ensure they are registered.

cis_interface.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.
cis_interface.metaschema.datatypes.register_type_from_file(path_to_schema)[source]

Decorator for registering a type by loading the schema describing it from a file. The original base class is discarded and replaced by one determined from the ‘type’ key in the schema. All attributes/methods for the class are preserved.

Parameters:path_to_schema (str) – Full path to the location of a schema file that can be loaded.
Returns:
Decorator that will modify a class according to the information
provided in the schema.
Return type:function