yggdrasil.serialize package

Submodules

yggdrasil.serialize.AsciiMapSerialize module

class yggdrasil.serialize.AsciiMapSerialize.AsciiMapSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.SerializeBase.SerializeBase

Class for serializing/deserializing name/value mapping.

Parameters

delimiter (str, optional) – Delimiter that should be used to separate name/value pairs in the map. Defaults to t.

classmethod concatenate(objects, **kwargs)[source]

Concatenate objects to get object that would be recieved if the concatenated serialization were deserialized.

Parameters
  • objects (list) – Objects to be concatenated.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Set of objects that results from concatenating those provided.

Return type

list

concats_as_str = False
default_datatype = {'type': 'object'}
func_deserialize(msg)[source]

Deserialize a message.

Parameters

msg (bytes) – Message to be deserialized.

Returns

Deserialized Python dictionary.

Return type

dict

func_serialize(args)[source]

Serialize a message.

Parameters

args (dict) – Python dictionary to be serialized.

Returns

Serialized message.

Return type

bytes, str

classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns

Dictionary of variables to use for testing.

Return type

dict

yggdrasil.serialize.AsciiTableSerialize module

class yggdrasil.serialize.AsciiTableSerialize.AsciiTableSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.DefaultSerialize.DefaultSerialize

Class for serialize table output into bytes messages comprising a formatted ASCII table.

Parameters
  • format_str (str, optional) – If provided, this string will be used to format messages from a list of arguments and parse messages to get a list of arguments in C printf/scanf style. Defaults to None and messages are assumed to already be bytes.

  • field_names (list, optional) – The names of fields in the format string. If not provided, names are set based on the order of the fields in the format string.

  • field_units (list, optional) – The units of fields in the format string. If not provided, all fields are assumed to be dimensionless.

  • as_array (bool, optional) – If True, each of the arguments being serialized/deserialized will be arrays that are converted to/from bytes in column major (‘F’) order. Otherwise, each argument should be a scalar. Defaults to False.

  • delimiter (str, optional) – Character(s) that should be used to separate columns. Defaults to ‘t’.

  • use_astropy (bool, optional) – If True, the astropy package will be used to serialize/deserialize table. Defaults to False.

  • **kwargs – Additional keyword args are processed as part of the type definition.

format_str

Format string used to format/parse bytes messages from/to a list of arguments in C printf/scanf style.

Type

str

field_names

The names of fields in the format string.

Type

list

field_units

The units of fields in the format string.

Type

list

as_array

True or False depending if serialized/deserialized python objects will be arrays or scalars.

Type

bool

delimiter

Character(s) that should be used to separate columns.

Type

str

use_astropy

If True, the astropy package will be used to serialize/deserialize table.

Type

bool

default_datatype = {'type': 'array'}
default_read_meth = 'readline'
deserialize_file_header(fd)[source]

Deserialize the header information from the file and update the serializer.

Parameters

fd (file) – File containing header.

func_deserialize(msg)[source]

Deserialize a message.

Parameters

msg – Message to be deserialized.

Returns

Deserialized message.

Return type

obj

func_serialize(args)[source]

Serialize a message.

Parameters

args – List of arguments to be formatted or numpy array to be serialized.

Returns

Serialized message.

Return type

bytes, str

classmethod get_testing_options(**kwargs)[source]

Method to return a dictionary of testing options for this class.

Parameters

**kwargs – Keyword arguments are passed to the parent class’s method.

Returns

Dictionary of variables to use for testing.

Return type

dict

has_header = True
property read_meth

Method that should be used to read data for deserialization.

Type

str

serialize_file_header()[source]

Return the serialized header information that should be prepended to files serialized using this class.

Returns

Header string that should be written to the file.

Return type

bytes

update_field_names()[source]

list: Names for each field in the data type.

update_field_units()[source]

list: Units for each field in the data type.

update_format_str()[source]

Update the format string based on the type definition.

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

Update serializer with provided information.

Parameters
  • *args – All arguments are passed to the parent class’s method.

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

yggdrasil.serialize.DefaultSerialize module

class yggdrasil.serialize.DefaultSerialize.DefaultSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.SerializeBase.SerializeBase

Default class for serializing/deserializing a python object into/from a bytes message.

Parameters

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

classmethod concatenate(objects, as_array=False, **kwargs)[source]

Concatenate objects to get object that would be recieved if the concatenated serialization were deserialized.

Parameters
  • objects (list) – Objects to be concatenated.

  • as_array (bool, optional) – If True, the objects in the list are complete columns in a table and as_format is set to True. Defaults to False.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Set of objects that results from concatenating those provided.

Return type

list

func_deserialize = None
func_serialize = None
classmethod get_testing_options(**kwargs)[source]

Method to return a dictionary of testing options for this class.

classmethod object2array(obj, as_array=False, field_names=None, **kwargs)[source]

Convert a message object into an array.

Parameters
  • obj (object) – Object that would be serialized by this class and should be returned in an array form.

  • as_array (bool, optional) – If True, the objects in the list are complete columns in a table and as_format is set to True. Defaults to False.

  • field_names (list, optional) – The field names associated with a table-like data type. Defaults to None. This keyword must be provided if as_array is True.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Array version of the provided object.

Return type

np.array

classmethod object2dict(obj, as_array=False, field_names=None, **kwargs)[source]

Convert a message object into a dictionary.

Parameters
  • obj (object) – Object that would be serialized by this class and should be returned in a dictionary form.

  • as_array (bool, optional) – If True, the objects in the list are complete columns in a table and as_format is set to True. Defaults to False.

  • field_names (list, optional) – The field names associated with a table-like data type. Defaults to None. This keyword must be provided if as_array is True.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Dictionary version of the provided object.

Return type

dict

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

Update serializer with provided information.

Parameters
  • *args – All arguments are passed to the parent class’s method.

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

yggdrasil.serialize.DirectSerialize module

class yggdrasil.serialize.DirectSerialize.DirectSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.SerializeBase.SerializeBase

Class for directly serializing bytes.

classmethod concatenate(objects, **kwargs)[source]

Concatenate objects to get object that would be recieved if the concatenated serialization were deserialized.

Parameters
  • objects (list) – Objects to be concatenated.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Set of objects that results from concatenating those provided.

Return type

list

default_datatype = {'type': 'bytes'}
func_deserialize(msg)[source]

Deserialize a message.

Parameters

msg – Message to be deserialized.

Returns

Deserialized message.

Return type

obj

func_serialize(args)[source]

Serialize a message.

Parameters

args – List of arguments to be formatted or numpy array to be serialized.

Returns

Serialized message.

Return type

bytes, str

classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns

Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for comms tested with the

provided content.

empty (object): Object produced from deserializing an empty

message.

objects (list): List of objects to be serialized/deserialized. extra_kwargs (dict): Extra keyword arguments not used to

construct type definition.

typedef (dict): Type definition resulting from the supplied

kwargs.

dtype (np.dtype): Numpy data types that is consistent with the

determined type definition.

Return type

dict

yggdrasil.serialize.FunctionalSerialize module

class yggdrasil.serialize.FunctionalSerialize.FunctionalSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.SerializeBase.SerializeBase

Class for serializing/deserializing a Python object into/from a bytes message using defined functions.

Parameters
  • encoded_datatype (schema, optional) – JSON schema describing the type that serialized objects should conform to. Defaults to the class attribute default_encoded_datatype. If either func_serialize or func_deserialize are not provided, this needs to be specified in order to serialize non-bytes objects.

  • func_serialize (func, optional) – Callable object that takes Python objects as input and returns a representation that conforms to encoded_datatype. Defaults to None and the default serialization for encoded_datatype will be used.

  • func_deserialize (func, optional) – Callable object that takes objects of a type that conforms to encoded_datatype and returns a deserialized Python object. Defaults to None and the default deserialization for encoded_datatype will be used.

  • **kwargs – Additional keyword args are passed to the parent class’s constructor.

property empty_msg

Object indicating empty message.

Type

obj

func_deserialize = None
func_serialize = None
property serializer_info

Serializer info.

Type

dict

yggdrasil.serialize.JSONSerialize module

class yggdrasil.serialize.JSONSerialize.JSONSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.SerializeBase.SerializeBase

Class for serializing a python object into a bytes message using JSON.

Parameters
  • indent (str, int, optional) – String or number of spaces that should be used to indent each level within the seiralized structure. Defaults to ‘t’.

  • sort_keys (bool, optional) – If True, the serialization of dictionaries will be in key sorted order. Defaults to True.

classmethod concatenate(objects, **kwargs)[source]

Concatenate objects to get object that would be recieved if the concatenated serialization were deserialized.

Parameters
  • objects (list) – Objects to be concatenated.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Set of objects that results from concatenating those provided.

Return type

list

concats_as_str = False
default_datatype = {'type': 'object'}
func_deserialize(msg)[source]

Deserialize a message.

Parameters

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

Returns

Deserialized Python object.

Return type

obj

func_serialize(args)[source]

Serialize a message.

Parameters

args (obj) – Python object to be serialized.

Returns

Serialized message.

Return type

bytes, str

classmethod get_testing_options(**kwargs)[source]

Method to return a dictionary of testing options for this class.

Returns

Dictionary of variables to use for testing.

Return type

dict

yggdrasil.serialize.MatSerialize module

class yggdrasil.serialize.MatSerialize.MatSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.SerializeBase.SerializeBase

Class for serializing a python object into a bytes message using the Matlab .mat format.

classmethod concatenate(objects, **kwargs)[source]

Concatenate objects to get object that would be recieved if the concatenated serialization were deserialized.

Parameters
  • objects (list) – Objects to be concatenated.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Set of objects that results from concatenating those provided.

Return type

list

concats_as_str = False
default_datatype = {'type': 'object'}
func_deserialize(msg)[source]

Deserialize a message.

Parameters

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

Returns

Deserialized Python object.

Return type

obj

func_serialize(args)[source]

Serialize a message.

Parameters

args (obj) – Python object to be serialized.

Returns

Serialized message.

Return type

bytes, str

Raises

TypeError – If args is not a dictionary.

classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns

Dictionary of variables to use for testing.

Return type

dict

yggdrasil.serialize.ObjSerialize module

class yggdrasil.serialize.ObjSerialize.ObjSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.PlySerialize.PlySerialize

Class for serializing/deserializing .obj file formats. Reader adapted from https://www.pygame.org/wiki/OBJFileLoader.

default_datatype = {'type': 'obj'}
func_deserialize(msg)[source]

Deserialize a message.

Parameters

msg (bytes) – Message to be deserialized.

Returns

Deserialized message.

Return type

obj

func_serialize(args)[source]

Serialize a message.

Parameters

args – List of arguments to be formatted or numpy array to be serialized.

Returns

Serialized message.

Return type

bytes

classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns

Dictionary of variables to use for testing.

Return type

dict

yggdrasil.serialize.PandasSerialize module

class yggdrasil.serialize.PandasSerialize.PandasSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.AsciiTableSerialize.AsciiTableSerialize

Class for serializing/deserializing Pandas data frames.

Parameters
  • no_header (bool, optional) – If True, headers will not be read or serialized from/to tables. Defaults to False.

  • str_as_bytes (bool, optional) – If True, strings in columns are read as bytes. Defaults to False.

classmethod apply_field_names(frame, field_names=None)[source]

Apply field names as columns to a frame, first checking for a mapping. If there is a direct mapping, the columns are reordered to match the order of the field names. If there is not an overlap in the field names and columns, a one-to-one mapping is assumed, but a warning is issued. If there is a partial overlap, an error is raised.

Parameters
  • frame (pandas.DataFrame) – Frame to apply field names to as columns.

  • field_names (list, optional) – New field names that should be applied. If not provided, the original frame will be returned unaltered.

Returns

Frame with updated field names.

Return type

pandas.DataFrame

Raises

RuntimeError – If there is a partial overlap between the field names and columns.

as_array = True
cformat2nptype(*args, **kwargs)[source]

Method to convert c format string to numpy data type.

Parameters
  • *args – Arguments are passed to serialize.cformat2nptype.

  • **kwargs – Keyword arguments are passed to serialize.cformat2nptype.

Returns

Corresponding numpy data type.

Return type

np.dtype

classmethod concatenate(objects, **kwargs)[source]

Concatenate objects to get object that would be recieved if the concatenated serialization were deserialized.

Parameters
  • objects (list) – Objects to be concatenated.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Set of objects that results from concatenating those provided.

Return type

list

concats_as_str = False
consolidate_array(out)[source]

Consolidate message into a structure numpy array if possible.

Parameters

out (list, tuple, np.ndarray) – Object to consolidate into a structured numpy array.

Returns

Structured numpy array containing consolidated message.

Return type

np.ndarray

Raises

ValueError – If the array cannot be consolidated.

default_read_meth = 'read'
deserialize_file_header(fd)[source]

Deserialize the header information from the file and update the serializer.

Parameters

fd (file) – File containing header.

disable_file_header()[source]

Set serializer attributes to disable file headers from being included in the serializations.

property empty_msg

Object indicating empty message.

Type

obj

enable_file_header()[source]

Set serializer attributes to enable file headers to be included in the serializations.

func_deserialize(msg)[source]

Deserialize a message.

Parameters

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

Returns

Deserialized Python object.

Return type

obj

func_serialize(args)[source]

Serialize a message.

Parameters

args (obj) – Python object to be serialized.

Returns

Serialized message.

Return type

bytes, str

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

Get the field names for an array of fields.

Parameters
  • *args – Arguments are passed to the parent class’s method.

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

Returns

Names for each field in the data type.

Return type

list

classmethod get_testing_options(not_as_frames=False, no_names=False, no_header=False, **kwargs)[source]

Method to return a dictionary of testing options for this class.

Parameters
  • not_as_frames (bool, optional) – If True, the returned example includes data that is not in a pandas data frame. Defaults to False.

  • no_names (bool, optional) – If True, an example is returned where the names are not provided to the deserializer. Defaults to False.

  • no_header (bool, optional) – If True, an example is returned

  • False. (where a header is not included. Defaults to) –

Returns

Dictionary of variables to use for testing.

Return type

dict

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

Convert a message object into an array.

Parameters
  • obj (object) – Object that would be serialized by this class and should be returned in an array form.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Array version of the provided object.

Return type

np.array

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

Convert a message object into a dictionary.

Parameters
  • obj (object) – Object that would be serialized by this class and should be returned in a dictionary form.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Dictionary version of the provided object.

Return type

dict

property send_converter
serialize_file_header()[source]

Return the serialized header information that should be prepended to files serialized using this class.

Returns

Header string that should be written to the file.

Return type

bytes

yggdrasil.serialize.PickleSerialize module

class yggdrasil.serialize.PickleSerialize.PickleSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.DefaultSerialize.DefaultSerialize

Class for serializing a python object into a bytes message by pickling.

classmethod concatenate(objects, **kwargs)[source]

Concatenate objects to get object that would be recieved if the concatenated serialization were deserialized.

Parameters
  • objects (list) – Objects to be concatenated.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Set of objects that results from concatenating those provided.

Return type

list

func_deserialize(msg)[source]

Deserialize a message.

Parameters

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

Returns

Deserialized Python object.

Return type

obj

func_serialize(args)[source]

Serialize a message.

Parameters

args (obj) – Python object to be serialized.

Returns

Serialized message.

Return type

bytes, str

classmethod get_first_frame(msg)[source]

Extract one frame from the provided message that may contain one or more frames.

Parameters

msg (bytes) – Message containing one or more frames.

Returns

Portion of message containing the first frame. If no frames

are found, an empty string will be returned.

Return type

bytes

classmethod get_testing_options(**kwargs)[source]

Method to return a dictionary of testing options for this class.

Returns

Dictionary of variables to use for testing.

Return type

dict

is_framed = True

yggdrasil.serialize.PlySerialize module

class yggdrasil.serialize.PlySerialize.PlySerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.SerializeBase.SerializeBase

Class for serializing/deserializing .ply file formats.

Parameters
  • write_header (bool, optional) – If True, headers will be added to serialized output. Defaults to True.

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

write_header

If True, headers will be added to serialized output.

Type

bool

newline

String that should be used for new lines.

Type

str

default_rgb

Default color in RGB that should be used for missing colors.

Type

list

classmethod concatenate(objects, **kwargs)[source]

Concatenate objects to get object that would be recieved if the concatenated serialization were deserialized.

Parameters
  • objects (list) – Objects to be concatenated.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Set of objects that results from concatenating those provided.

Return type

list

concats_as_str = False
default_datatype = {'type': 'ply'}
func_deserialize(msg)[source]

Deserialize a message.

Parameters

msg (bytes) – Message to be deserialized.

Returns

Deserialized message.

Return type

obj

func_serialize(args)[source]

Serialize a message.

Parameters

args – List of arguments to be formatted or numpy array to be serialized.

Returns

Serialized message.

Return type

bytes

classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns

Dictionary of variables to use for testing.

Return type

dict

yggdrasil.serialize.SerializeBase module

class yggdrasil.serialize.SerializeBase.SerializeBase(*args, **kwargs)[source]

Bases: yggdrasil.tools.YggClass

Base class for serializing/deserializing a Python object into/from a bytes message.

Parameters
  • newline (str, optional) – One or more characters indicating a newline. Defaults to ‘n’.

  • comment (str, optional) – One or more characters indicating a comment. Defaults to ‘# ‘.

  • datatype (schema, optional) – JSON schema defining the type of object that the serializer will be used to serialize/deserialize. Defaults to default_datatype.

  • **kwargs – Additional keyword args are processed as part of the type definition.

initialized

True if the serializer has been initialized either by input arguments specifying the type or by infering the type from a processed message.

Type

bool

Class Attributes:
has_header (bool): True if the serialization has a header when written

to a file.

default_read_meth (str): Default method that data should be read from

a file for deserialization.

is_framed (bool): True if the serialization has a frame allowing

multiple serialized objects to be recovered from a single message.

concats_as_str (bool): True if serialized objects can be concatenated

directly as strings.

encoded_datatype (schema): JSON schema defining the type of object

produced by the class’s func_serialize method. For most classes this will be {‘type’: ‘bytes’}, indicating that the method will produce bytes suitable for serialization.

static before_registration(cls)[source]

Operations that should be performed to modify class attributes prior to registration.

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

Method to convert c format string to numpy data type.

Parameters
  • *args – Arguments are passed to serialize.cformat2nptype.

  • **kwargs – Keyword arguments are passed to serialize.cformat2nptype.

Returns

Corresponding numpy data type.

Return type

np.dtype

classmethod concatenate(objects, **kwargs)[source]

Concatenate objects to get object that would be recieved if the concatenated serialization were deserialized.

Parameters
  • objects (list) – Objects to be concatenated.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Set of objects that results from concatenating those provided.

Return type

list

concats_as_str = True
consolidate_array(out)[source]

Consolidate message into a structure numpy array if possible.

Parameters

out (list, tuple, np.ndarray) – Object to consolidate into a structured numpy array.

Returns

Structured numpy array containing consolidated message.

Return type

np.ndarray

Raises

ValueError – If the array cannot be consolidated.

default_datatype = {'type': 'bytes'}
default_encoded_datatype = {'type': 'bytes'}
default_read_meth = 'read'
deserialize(msg, **kwargs)[source]

Deserialize a message.

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

  • **kwargs – Additional keyword arguments are passed to the deserialize method of the datatype class.

Returns

Deserialized message and header information.

Return type

tuple(obj, dict)

Raises

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

deserialize_file_header(fd)[source]

Deserialize the header information from the file and update the serializer.

Parameters

fd (file) – File containing header.

disable_file_header()[source]

Set serializer attributes to disable file headers from being included in the serializations.

property empty_msg

Object indicating empty message.

Type

obj

enable_file_header()[source]

Set serializer attributes to enable file headers to be included in the serializations.

property encoded_typedef

Type definition for encoded data objects.

Type

dict

func_deserialize(msg)[source]

Deserialize a message.

Parameters

msg – Message to be deserialized.

Returns

Deserialized message.

Return type

obj

func_serialize(args)[source]

Serialize a message.

Parameters

args – List of arguments to be formatted or numpy array to be serialized.

Returns

Serialized message.

Return type

bytes, str

get_field_names(as_bytes=False)[source]

Get the field names for an array of fields.

Parameters

as_bytes (bool, optional) – If True, the field names will be returned as bytes. If False the field names will be returned as unicode. Defaults to False.

Returns

Names for each field in the data type.

Return type

list

get_field_units(as_bytes=False)[source]

Get the field units for an array of fields.

Parameters

as_bytes (bool, optional) – If True, the field units will be returned as bytes. If False the field units will be returned as unicode. Defaults to False.

Returns

Units for each field in the data type.

Return type

list

get_status_message(nindent=0, extra_lines_before=None, extra_lines_after=None)[source]

Return lines composing a status message.

Parameters
  • nindent (int, optional) – Number of tabs that should be used to indent each line. Defaults to 0.

  • extra_lines_before (list, optional) – Additional lines that should be added to the beginning of the default print message. Defaults to empty list if not provided.

  • extra_lines_after (list, optional) – Additional lines that should be added to the end of the default print message. Defaults to empty list if not provided.

Returns

Lines composing the status message and the

prefix string used for the last message.

Return type

tuple(list, prefix)

classmethod get_testing_options(table_example=False, array_columns=False, include_oldkws=False, table_string_type='bytes')[source]

Method to return a dictionary of testing options for this class.

Parameters
  • table_example (bool, optional) – If True, the returned options will be for an array of elements representing a table-like structure. Defaults to False.

  • array_columns (bool, optional) – If True, table_example is set to True and the returned options will be for an array data type where each element is an array representing a column Defaults to False.

  • include_oldkws (bool, optional) – If True, old-style keywords will be added to the returned options. This will only have an effect if table_example is True. Defaults to False.

  • table_string_type (str, optional) – Type that should be used for the string column in the table. Defaults to ‘bytes’.

Returns

Dictionary of variables to use for testing. Key/value pairs:

  • kwargs (dict): Keyword arguments for comms tested with the provided content.

  • empty (object): Object produced from deserializing an empty message.

  • objects (list): List of objects to be serialized/deserialized. extra_kwargs (dict): Extra keyword arguments not used to construct type definition.

  • typedef (dict): Type definition resulting from the supplied kwargs.

  • dtype (np.dtype): Numpy data types that is consistent with the determined type definition.

  • contents (bytes): Concatenated serialization that will result from deserializing the serialized objects.

  • contents_recv (list): List of objects that would be deserialized from contents.

Return type

dict

has_header = False
initialize_from_message(msg, **metadata)[source]

Initialize the serializer based on recieved message.

Parameters
  • msg (object) – Message that serializer should be initialized from.

  • **kwargs – Additional keyword arguments are treated as metadata that may contain additional information for initializing the serializer.

initialize_serializer(metadata, extract=False)[source]

Initialize a serializer based on received metadata. This method will exit early if the serializer has already been intialized.

Parameters
  • metadata (dict) – Header information including type info that should be used to initialize the serializer class.

  • extract (bool, optional) – If True, the type will be defined using a subset of the type information in metadata. If False, all of the type information will be used. Defaults to False.

property input_kwargs

Get the input keyword arguments used to create this class.

Type

dict

is_framed = False
is_initialized()[source]

Determine if the serializer has been initialized by comparing the current datatype against the default for the class.

Returns

True if the current datatype is different than the default,

False otherwise.

Return type

bool

property numpy_dtype

Corresponding structured data type. Will be None unless the type is an array of 1darrays.

Type

np.dtype

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

Convert a message object into an array.

Parameters
  • obj (object) – Object that would be serialized by this class and should be returned in an array form.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Array version of the provided object or None if one cannot

be created.

Return type

np.array

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

Convert a message object into a dictionary.

Parameters
  • obj (object) – Object that would be serialized by this class and should be returned in a dictionary form.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Dictionary version of the provided object.

Return type

dict

parse_header(msg)[source]

Extract header info from a message.

Parameters

msg (str) – Message to extract header from.

Returns

Message properties.

Return type

dict

property read_meth

Method that should be used to read data for deserialization.

Type

str

classmethod seri_kws()[source]

Get a list of valid keyword arguments.

serialize(args, header_kwargs=None, add_serializer_info=False, no_metadata=False, max_header_size=0)[source]

Serialize a message.

Parameters
  • args (obj) – List of arguments to be formatted or a ready made message.

  • header_kwargs (dict, optional) – Keyword arguments that should be added to the header. Defaults to None and no header is added.

  • add_serializer_info (bool, optional) – If True, serializer information will be added to the metadata. Defaults to False.

  • no_metadata (bool, optional) – If True, no metadata will be added to the serialized message. 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.

Returns

Serialized message.

Return type

bytes, str

Raises

TypeError – If returned msg is not bytes type (str on Python 2).

serialize_file_header()[source]

Return the serialized header information that should be prepended to files serialized using this class.

Returns

Header string that should be written to the file.

Return type

bytes

property serializer_info

Serializer info.

Type

dict

property typedef

Type definition.

Type

dict

update_serializer(extract=False, skip_type=False, **kwargs)[source]

Update serializer with provided information.

Parameters
  • extract (bool, optional) – If True, the updated typedef will be the bare minimum as extracted from total set of provided keywords, otherwise the entire set will be sued. Defaults to False.

  • skip_type (bool, optional) – If True, everything is updated except the data type. Defaults to False.

  • **kwargs – Additional keyword arguments are processed as part of they type definition and are parsed for old-style keywords.

Raises

RuntimeError – If there are keywords that are not valid typedef keywords (currect or old-style).

update_typedef_from_oldstyle(typedef)[source]

Update a given typedef using an old, table-style serialization spec. Existing typedef values are not overwritten and warnings are raised if the provided serialization spec is not compatible with the type definition.

Parameters

typedef (dict) – Type definition to update.

Returns

Updated typedef.

Return type

dict

yggdrasil.serialize.WOFOSTParamSerialize module

class yggdrasil.serialize.WOFOSTParamSerialize.WOFOSTParamSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.AsciiMapSerialize.AsciiMapSerialize

Class for serializing/deserializing WOFOST parameter files.

classmethod concatenate(objects, **kwargs)[source]

Concatenate objects to get object that would be recieved if the concatenated serialization were deserialized.

Parameters
  • objects (list) – Objects to be concatenated.

  • **kwargs – Additional keyword arguments are ignored.

Returns

Set of objects that results from concatenating those provided.

Return type

list

concats_as_str = True
default_datatype = {'type': 'object'}
func_deserialize(msg)[source]

Deserialize a message.

Parameters

msg (bytes) – Message to be deserialized.

Returns

Deserialized Python dictionary.

Return type

dict

func_serialize(args)[source]

Serialize a message.

Parameters

args (dict) – Python dictionary to be serialized.

Returns

Serialized message.

Return type

bytes, str

classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns

Dictionary of variables to use for testing.

Return type

dict

classmethod parse_units(x)[source]

Parse units.

Parameters

x (str) – Unit string.

Returns

Propertly formatted units.

Return type

str

yggdrasil.serialize.YAMLSerialize module

class yggdrasil.serialize.YAMLSerialize.YAMLSerialize(*args, **kwargs)[source]

Bases: yggdrasil.serialize.JSONSerialize.JSONSerialize

Class for serializing a python object into a bytes message using YAML.

Parameters
  • indent (str, int, optional) – String or number of spaces that should be used to indent each level within the seiralized structure. Defaults to ‘t’.

  • encoding (str, optional) – Encoding that should be used to serialize the object. Defaults to ‘utf-8’.

  • default_flow_style (bool, optional) – If True, nested collections will be serialized in the block style. If False, they will always be serialized in the flow style. See PyYAML Documentation.

func_deserialize(msg)[source]

Deserialize a message.

Parameters

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

Returns

Deserialized Python object.

Return type

obj

func_serialize(args)[source]

Serialize a message.

Parameters

args (obj) – Python object to be serialized.

Returns

Serialized message.

Return type

bytes, str

classmethod get_testing_options(**kwargs)[source]

Method to return a dictionary of testing options for this class.

Returns

Dictionary of variables to use for testing.

Return type

dict

Module contents