Data Utils

GitHub Link to Code.

Utility functions for saving and loading Python objects with memmap support.

This module provides utility class for saving and loading Python objects with memmap support. Works with any Python object, not just TrajectoryData. Preserves memmap properties correctly.

class mdxplain.utils.data_utils.DataUtils

Utility class for saving and loading Python objects with memory-mapped array support.

Provides methods to serialize and deserialize Python objects that contain memory-mapped numpy arrays while preserving memmap properties and file references. Works with any Python object, not just mdxplain classes.

Examples

>>> # Save any object with memmap support
>>> DataUtils.save_object(my_object, 'data/my_object.pkl')
>>> # Load into existing object
>>> new_object = MyClass()
>>> DataUtils.load_object(new_object, 'data/my_object.pkl')
static save_object(obj: Any, save_path: str) None

Save any Python object while preserving memory-mapped array properties.

Parameters

objobject

Python object to save (can contain memmap arrays and DaskMDTrajectory objects)

save_pathstr

File path for saving (should end with .pkl or .npy)

Returns

None

Saves object to disk using numpy.save with pickle support

Examples

>>> # Save TrajectoryData object
>>> DataUtils.save_object(traj_data, 'analysis/results.pkl')
>>> # Save any custom object with memmaps
>>> DataUtils.save_object(my_analysis, 'outputs/analysis.pkl')
static load_object(obj: Any, load_path: str) None

Load data into existing Python object while restoring memmap properties.

Parameters

objobject

Existing Python object to load data into (will be modified in-place)

load_pathstr

Path to saved object file (.pkl or .npy)

Returns

None

Modifies obj in-place, restoring attributes and memmap connections

Examples

>>> # Load into TrajectoryData object
>>> traj = TrajectoryData()
>>> DataUtils.load_object(traj, 'analysis/results.pkl')
>>> # Load into custom object
>>> my_obj = MyAnalysisClass()
>>> DataUtils.load_object(my_obj, 'outputs/analysis.pkl')
static get_type_key(type_obj: str | type | object) str

Get the type key from a type object.

This utility method handles conversion of various type formats (instances, classes, strings) to their string identifier. It is specially used for the conventions inside this software.

Parameters

type_objstr, class, or instance

Type object to get key for (e.g., decomposition type, feature type)

Returns

str

Type key string identifier

Examples

>>> DataUtils.get_type_key("pca")
'pca'
>>> DataUtils.get_type_key(PCA())
'pca'
>>> DataUtils.get_type_key(PCA)
'pca'