cis_interface.serialize package¶
Submodules¶
cis_interface.serialize.AsciiMapSerialize module¶
-
class
cis_interface.serialize.AsciiMapSerialize.
AsciiMapSerialize
(*args, **kwargs)[source]¶ Bases:
cis_interface.serialize.DefaultSerialize.DefaultSerialize
Class for serializing/deserializing name/value mapping.
Parameters: -
empty_msg
¶ obj – Object indicating empty message.
-
func_deserialize
(msg)[source]¶ Deserialize a message.
Parameters: msg (str, 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
-
serializer_type
¶ int – Type of serializer.
-
cis_interface.serialize.AsciiTableSerialize module¶
-
class
cis_interface.serialize.AsciiTableSerialize.
AsciiTableSerialize
(*args, **kwargs)[source]¶ Bases:
cis_interface.serialize.DefaultSerialize.DefaultSerialize
Class for serialize table output into bytes messages comprising a formatted ASCII table.
-
table
¶ AsciiTable – Table object used for formating/parsing table entries.
-
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
-
serializer_type
¶ int – Type of serializer.
-
table_info
¶ dict – Table format information.
-
cis_interface.serialize.DefaultSerialize module¶
-
class
cis_interface.serialize.DefaultSerialize.
DefaultSerialize
(format_str=None, as_array=False, field_names=None, field_units=None, func_serialize=None, func_deserialize=None, **kwargs)[source]¶ Bases:
object
Default class for serializing/deserializing a python object into/from a bytes message.
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.
- 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.
- 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.
- func_serialize (func, optional) – Callable object that takes python objects as input and returns a bytes string representation. Defaults to None.
- func_deserialize (func, optional) – Callable object that takes a bytes string as input and returns a deserialized python object. Defaults to None.
-
format_str
¶ str – Format string used to format/parse bytes messages from/to a list of arguments in C printf/scanf style.
-
as_array
¶ bool – True or False depending if serialized/deserialized python objects will be arrays or scalars.
-
field_names
¶ list – The names of fields in the format string.
-
field_units
¶ list – The units of fields in the format string.
-
func_serialize
[source]¶ func – Callable object that takes python object as input and returns a bytes string representation.
-
func_deserialize
[source]¶ func – Callable object that takes a bytes string as input and returns a deserialized python object.
-
deserialize
(msg)[source]¶ Deserialize a message.
Parameters: msg (str, bytes) – Message to be deserialized. Returns: Deserialized message and header information. Return type: tuple(obj, dict) Raises: TypeError
– If msg is not bytes type (str on Python 2).
-
empty_msg
¶ obj – Object indicating empty message.
-
field_formats
¶ list – Format codes for each field in the format string.
-
format_header
(header_info)[source]¶ Format header info to form a string that should prepend a message.
Parameters: header_info (dict) – Properties that should be included in the header. Returns: Message with header in front. Return type: str
-
func_deserialize
(msg)[source] Default method for deseserializing a message.
Parameters: msg (str, bytes) – Message to be deserialized. Returns: Deserialized message and header information. Return type: tuple(obj, dict)
-
func_serialize
(args)[source] Default method for serializing object into message.
Parameters: args (obj) – List of arguments to be formatted or a ready made message. Returns: Serialized message. Return type: bytes, str Raises: Exception
– If there is no format string and more than one argument is provided.
-
is_user_defined
¶ bool – True if serialization or deserialization function was user defined.
-
nfields
¶ int – Number of fields in the format string.
-
numpy_dtype
¶ np.dtype – Data type associated with the format string.
-
parse_header
(msg)[source]¶ Extract header info from a message.
Parameters: msg (str) – Message to extract header from. Returns: Message properties. Return type: dict
-
scanf_format_str
¶ str – Simplified format string for scanf.
-
serialize
(args, header_kwargs=None, add_serializer_info=False)[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, add enough information about this serializer to the header that the message can be recovered.
Returns: Serialized message.
Return type: Raises: TypeError
– If returned msg is not bytes type (str on Python 2).
-
serializer_info
¶ dict – Information about serializer required to reconstruct it.
-
serializer_type
¶ int – Type of serializer.
cis_interface.serialize.MatSerialize module¶
-
class
cis_interface.serialize.MatSerialize.
MatSerialize
(format_str=None, as_array=False, field_names=None, field_units=None, func_serialize=None, func_deserialize=None, **kwargs)[source]¶ Bases:
cis_interface.serialize.DefaultSerialize.DefaultSerialize
Class for serializing a python object into a bytes message using the Matlab .mat format.
-
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.
-
serializer_type
¶ int – Type of serializer.
-
cis_interface.serialize.ObjSerialize module¶
-
class
cis_interface.serialize.ObjSerialize.
ObjDict
(**kwargs)[source]¶ Bases:
cis_interface.serialize.PlySerialize.PlyDict
Class for storing obj information.
Parameters: - vertices (list, optional) – 3D positions of vertices comprising the 3D object. Defaults to [].
- faces (list, optional) – Indices of 3 or more vertices making up faces or a tuple containing the indices for the position, texture coordinate, and normal for each vertex in the face. This information can also be provided in their own lists, but there must be an entry for every face. Defaults to [].
- vertex_colors (list, optional) – RGB values for each of the vertices. If not provided, all vertices will be black. Defaults to [].
- material (str, optional) – Material to use for faces. Defaults to None.
- normals (list, optional) – 3D normals for vertices. Defaults to [].
- texcoords (list, optional) – 3D texture coordinates for vertices. Defaults to [].
- face_texcoords (list, optional) – Indices of texture coordinates for each vertex in the face. Entries of None are ignored. Defaults to [].
- face_normals (list, optional) – Indices of normals for each vertex in the face. Entries of None are ignored. Defaults to [].
-
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.
-
standardize
(no_copy=False)[source]¶ Put the dictionary in the standard format with face information split into separate fields.
Parameters: no_copy (bool, optional) – If True, the current dictionary will be updated. Otherwise a copy will be returned. Defaults to False. Returns: Standardized obj information. Return type: ObjDict
-
class
cis_interface.serialize.ObjSerialize.
ObjSerialize
(*args, **kwargs)[source]¶ Bases:
cis_interface.serialize.PlySerialize.PlySerialize
Class for serializing/deserializing .obj file formats. Reader adapted from https://www.pygame.org/wiki/OBJFileLoader.
-
func_deserialize
(msg, zero_indexed=True)[source]¶ Deserialize a message.
Parameters: Returns: Deserialized .obj information. The faces are zero indexed.
Return type:
-
func_serialize
(args, zero_indexed=True)[source]¶ Serialize a message.
Parameters: - args (ObjDict) – Dictionary of obj information.
- zero_indexed (bool, optional) – If True, the input indices are assumed to start at zero and they will be adjusted to start at one and conform with .obj format. If False, the input indices are assumed to start at one and they will not be adjusted. Defaults to True.
Returns: Serialized message.
Return type:
-
serializer_type
¶ int – Type of serializer.
-
cis_interface.serialize.PandasSerialize module¶
-
class
cis_interface.serialize.PandasSerialize.
PandasSerialize
(*args, **kwargs)[source]¶ Bases:
cis_interface.serialize.DefaultSerialize.DefaultSerialize
Class for serializing/deserializing Pandas data frames.
Parameters: -
empty_msg
¶ obj – Object indicating empty message.
-
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
-
serializer_type
¶ int – Type of serializer.
-
cis_interface.serialize.PickleSerialize module¶
-
class
cis_interface.serialize.PickleSerialize.
PickleSerialize
(format_str=None, as_array=False, field_names=None, field_units=None, func_serialize=None, func_deserialize=None, **kwargs)[source]¶ Bases:
cis_interface.serialize.DefaultSerialize.DefaultSerialize
Class for serializing a python object into a bytes message by pickling.
-
empty_msg
¶ obj – Object indicating empty message.
-
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
-
serializer_type
¶ int – Type of serializer.
-
cis_interface.serialize.PlySerialize module¶
-
class
cis_interface.serialize.PlySerialize.
PlyDict
(**kwargs)[source]¶ Bases:
dict
Class for storing ply information.
Parameters: - vertices (list, optional) – 3D positions of vertices comprising the 3D object. Defaults to [].
- faces (list, optional) – Indices of 3 or more vertices making up faces. Defaults to [].
- vertex_colors (list, optional) – RGB values for each of the vertices. If not provided, all vertices will be black. Defaults to [].
-
apply_scalar_map
(scalar_arr, color_map=None, vmin=None, vmax=None, scaling='linear', scale_by_area=False, no_copy=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:
-
bounds
¶ tuple – Minimums and maximums of vertices.
-
classmethod
from_scene
(scene, d=None, conversion=1.0, default_rgb=None)[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.
- default_rgb (list, optional) – Default color in RGB that should be used for missing colors. Defaults to [0, 0, 0].
-
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.
-
merge
(ply_list, no_copy=False, default_rgb=None)[source]¶ Merge a list of ply dictionaries.
Parameters: Returns: Merged ply dictionary.
Return type:
-
mesh
¶ list – Vertices for each face in the structure.
-
nface
¶ int – Number of faces.
-
nvert
¶ int – Number of vertices.
-
set_vertex_colors
(default_rgb=None)[source]¶ Set the vertex colors to a default if they are not yet set.
Parameters: default_rgb (list, optional) – Default color in RGB that should be used for missing colors. Defaults to [0, 0, 0].
-
to_geom_args
(conversion=1.0, name=None)[source]¶ Get arguments for creating a PlantGL geometry.
Parameters: Returns: Class, arguments and keyword arguments for PlantGL geometry.
Return type:
-
class
cis_interface.serialize.PlySerialize.
PlySerialize
(*args, **kwargs)[source]¶ Bases:
cis_interface.serialize.DefaultSerialize.DefaultSerialize
Class for serializing/deserializing .ply file formats.
Parameters: -
write_header
¶ bool – If True, headers will be added to serialized output.
-
newline
¶ str – String that should be used for new lines.
-
default_rgb
¶ list – Default color in RGB that should be used for missing colors.
-
empty_msg
¶ obj – Object indicating empty message.
-
func_deserialize
(msg, nvert=None, nface=None, do_vertex_colors=False)[source]¶ Deserialize a message.
Parameters: - msg (str, bytes) – Message to be deserialized.
- nvert (int, optional) – Number of vertices expected if the ply header is not in the message. Defaults to None.
- nface (int, optional) – Number of faces expected if the ply header is not in the message. Defaults to None.
- do_vertex_colors (bool, optional) – If True the vertex color will be contained in the vertex information if the ply header is not in the message. Defaults to False.
Returns: Deserialized .ply information.
Return type:
-
func_serialize
(args)[source]¶ Serialize a message.
Parameters: args (PlyDict) – Dictionary of ply information. Returns: Serialized message. Return type: bytes, str
-
serializer_type
¶ int – Type of serializer.
-