Hydration

Functions to be able to make sending and recreating autopilot objects by sending compressed representations of their instantiation.

Examples

>>> import autopilot
>>> from pprint import pprint
>>> Noise = autopilot.get('sound', 'Noise')
>>> a_noise = Noise(duration=1000, amplitude=0.01, fs=44100)
>>> dehydrated_noise = dehydrate(a_noise)
>>> pprint(dehydrated_noise)
{'class': 'autopilot.stim.sound.sounds.Noise',
 'kwargs': {'amplitude': 0.01,
            'channel': None,
            'duration': 1000,
            'fs': 44100}}
>>> b_noise = hydrate(dehydrated_noise)
>>> a_noise
<autopilot.stim.sound.sounds.Noise object at 0x12d76f400>
>>> b_noise
<autopilot.stim.sound.sounds.Noise object at 0x12d690310>
>>> a_noise._introspect['__init__']
{'fs': 44100, 'duration': 1000, 'amplitude': 0.01, 'channel': None}
>>> b_noise._introspect['__init__']
{'fs': 44100, 'duration': 1000, 'amplitude': 0.01, 'channel': None}

Functions:

dehydrate(obj)

Get a dehydrated version of an object that has its __init__ method wrapped with

hydrate(obj_dict)

Rehydrate an object description from dehydrate()

dehydrate(obj) dict[source]
Get a dehydrated version of an object that has its __init__ method wrapped with

utils.decorators.Introspect for sending across the wire/easier reinstantiation and provenance.

Parameters:

obj – The (instantiated) object to dehydrate

Returns:

a dictionary that can be used with hydrate(), of the form:

{
    'class': 'autopilot.submodule.Class',
    'kwargs': {'kwarg_1': 'value1', ... }
}

Return type:

dict

hydrate(obj_dict: dict)[source]

Rehydrate an object description from dehydrate()