pyrfume.datajoint_tools module

Convenience functions for working with DataJoint

pyrfume.datajoint_tools.create_quantity_adapter() → None[source]

Create an datajoint adapter class, QuantityAdapter, that puts and gets Python Quantity objects to and from the datajoint database server. The adapter will be assigned to the global variable QUANTITY_ADAPTER in this module.

pyrfume.datajoint_tools.handle_dict(cls, _type_map: dict, attr: Any, type_hint: _GenericAlias)[source]
Using master-part relation to store a dict. It is assumed that

the type of keys have corresponding tables in the database.

It is assumed that values of the dict are: primitive type which is in _type_map OR quantities.Quantity instance.

Args:

_type_map (dict): A map that maps type hint to data type that accepted by datajoint. attr (Any): Variable name of the dict. type_hint (typing._GenericAlias): Required to be a type hint like Dict[TypeA, int].

A type hint of dict will cause an exception.
Returns:
type: cls that contains a part class for the keys of the dict.
pyrfume.datajoint_tools.import_classes(module_name: str, match: str = None) → dict[source]

Import all classes from the named module’

Params:
module_name (str): Name of the module (e.g. ‘pyrfume.odorants’) match (str): Optional regex string for class names to match.
Returns:
dict: A dictionary of full class names and the classes themselves
pyrfume.datajoint_tools.schematize(cls, schema: datajoint.schemas.Schema)[source]

Take a Python class and build a Datajoint table from it.

Params:
cls: The class to convert into a DataJoint table schema: The schema in which to add the table
Returns:
cls: The schematized class (now for use with DataJoint)
pyrfume.datajoint_tools.set_dj_definition(cls, type_map: dict = None) → None[source]

Set the definition property of a class by inspecting its attributes.

Params:
cls: The class whose definition attribute should be set type_map: Optional additional type mappings