Core Tools (internal classes)#

The submodule pysdic.core contains the internal building blocks shared by the objects of the package.

Important

These classes are internal: they are not exported in the pysdic namespace (from pysdic import PropertyContainer fails, except pysdic.DisflowConfig) and are not meant to be instantiated directly by the users. They are documented because their methods are available on the public objects that use or inherit from them (for example the serialization methods to_json_file, from_hdf5_file, … of the transformations and parametrizations).

If needed, they can still be imported from pysdic.core:

from pysdic.core import PropertyContainer, LockableMixin
from pysdic.core import SerializerMixin, JsonSerializerMixin, NpzSerializerMixin, Hdf5SerializerMixin

Property container#

A container of named arrays sharing the same first dimension \(N\) (the number of entities, for example the points of a point cloud), with a dictionary-like interface and validated shapes.

  • PropertyContainer: Container of properties of shape \((N, \dots)\) associated with \(N\) entities.

DIS configuration#

The parameters of the optical flow of pysdic.compute_optical_flow(), based on the OpenCV DIS (Dense Inverse Search) algorithm. Defined in pysdic.core, the class is also exported as pysdic.DisflowConfig.

Serialization mixins#

The serialization mixins add the methods to save and load an object in several file formats. A class inheriting from them only implements to_dict and from_dict, and the mixins convert this dictionary to and from the files:

Mixin

Methods

Notes

JsonSerializerMixin

to_json_string, from_json_string, to_json_file, from_json_file

Arrays are converted to lists.

Hdf5SerializerMixin

to_hdf5_file, from_hdf5_file

Requires h5py. Nested dictionaries are stored as groups.

NpzSerializerMixin

to_npz_file, from_npz_file

Flat dictionaries only, without pickle.

  • SerializerMixin: Abstract base class of the serialization mixins (to_dict and from_dict).

All the file methods accept make_dirs=True to create the missing parent directories.

Lock mixin#

The lock mixin adds a lock to an object: a locked object can still be read, copied and saved, but the methods that modify it in place raise a RuntimeError, with a message explaining why the object is locked and what to do instead. The lock is set by the objects of the package that own another object (for example a ReparametrizedTransformation owns its transformation and its parametrization): there is no public method to lock or unlock an object, and a copy is always unlocked. Some methods offer an explicit bypass, e.g. Transformation.set_parameters(..., override_lock=True).

  • LockableMixin: Mixin adding is_locked and locked_message to an object (and the internal _set_locked and _check_unlocked).