dantro package#
dantro provides a uniform interface for hierarchically structured
and semantically heterogeneous data.
It is built around three main features:
data handling: loading heterogeneous data into a tree-like data structure, providing a uniform interface to it
data transformation: performing arbitrary operations on the data, if necessary using lazy evaluation
data visualization: creating a visual representation of the processed data
Together, these stages constitute a data processing pipeline: an automated sequence of predefined, configurable operations.
See the user manual for more information.
- __version__ = '0.21.2'#
Package version
Subpackages#
- dantro.containers package
- Submodules
- dantro.containers._registry module
ContainerRegistryContainerRegistry._DESCContainerRegistry._SKIPContainerRegistry._OVERWRITEContainerRegistry._EXPECTED_TYPEContainerRegistry._check_object()ContainerRegistry._register_via_decorator()ContainerRegistry.__contains__()ContainerRegistry._decorator()ContainerRegistry._determine_name()ContainerRegistry.classnameContainerRegistry.descContainerRegistry.items()ContainerRegistry.keys()ContainerRegistry.register()ContainerRegistry.values()
CONTAINERSregister_container()is_container()
- dantro.containers.general module
ObjectContainerObjectContainer._format_info()ObjectContainer._ATTRS_CLSObjectContainer.__delitem__()ObjectContainer.__eq__()ObjectContainer.__format__()ObjectContainer.__getitem__()ObjectContainer.__init__()ObjectContainer.__repr__()ObjectContainer.__setitem__()ObjectContainer.__sizeof__()ObjectContainer.__str__()ObjectContainer._abc_implObjectContainer._attrsObjectContainer._check_data()ObjectContainer._check_name()ObjectContainer._format_cls_name()ObjectContainer._format_logstr()ObjectContainer._format_name()ObjectContainer._format_path()ObjectContainer._item_access_convert_list_key()ObjectContainer.attrsObjectContainer.classnameObjectContainer.dataObjectContainer.logstrObjectContainer.nameObjectContainer.parentObjectContainer.path
PassthroughContainerPassthroughContainer.FORWARD_ATTR_EXCLUDEPassthroughContainer.FORWARD_ATTR_ONLYPassthroughContainer.FORWARD_ATTR_TOPassthroughContainer._ATTRS_CLSPassthroughContainer.__delitem__()PassthroughContainer.__eq__()PassthroughContainer.__format__()PassthroughContainer.__getattr__()PassthroughContainer.__getitem__()PassthroughContainer.__getstate__()PassthroughContainer.__init__()PassthroughContainer.__repr__()PassthroughContainer.__setitem__()PassthroughContainer.__setstate__()PassthroughContainer.__sizeof__()PassthroughContainer.__str__()PassthroughContainer._abc_implPassthroughContainer._attrsPassthroughContainer._check_data()PassthroughContainer._check_name()PassthroughContainer._format_cls_name()PassthroughContainer._format_info()PassthroughContainer._format_logstr()PassthroughContainer._format_name()PassthroughContainer._format_path()PassthroughContainer._forward_attr_get_forwarding_target()PassthroughContainer._forward_attr_post_hook()PassthroughContainer._forward_attr_pre_hook()PassthroughContainer._item_access_convert_list_key()PassthroughContainer.attrsPassthroughContainer.classnamePassthroughContainer.dataPassthroughContainer.logstrPassthroughContainer.namePassthroughContainer.parentPassthroughContainer.path
MutableSequenceContainerMutableSequenceContainer.DATA_EXPECTED_TYPESMutableSequenceContainer.DATA_ALLOW_PROXYMutableSequenceContainer.DATA_UNEXPECTED_ACTIONMutableSequenceContainer.insert()MutableSequenceContainer._ATTRS_CLSMutableSequenceContainer.__contains__()MutableSequenceContainer.__delitem__()MutableSequenceContainer.__eq__()MutableSequenceContainer.__format__()MutableSequenceContainer.__getitem__()MutableSequenceContainer.__init__()MutableSequenceContainer.__iter__()MutableSequenceContainer.__len__()MutableSequenceContainer.__repr__()MutableSequenceContainer.__setitem__()MutableSequenceContainer.__sizeof__()MutableSequenceContainer.__str__()MutableSequenceContainer._abc_implMutableSequenceContainer._attrsMutableSequenceContainer._check_data()MutableSequenceContainer._check_name()MutableSequenceContainer._format_cls_name()MutableSequenceContainer._format_info()MutableSequenceContainer._format_logstr()MutableSequenceContainer._format_name()MutableSequenceContainer._format_path()MutableSequenceContainer._item_access_convert_list_key()MutableSequenceContainer.append()MutableSequenceContainer.attrsMutableSequenceContainer.classnameMutableSequenceContainer.clear()MutableSequenceContainer.count()MutableSequenceContainer.dataMutableSequenceContainer.extend()MutableSequenceContainer.index()MutableSequenceContainer.logstrMutableSequenceContainer.nameMutableSequenceContainer.parentMutableSequenceContainer.pathMutableSequenceContainer.pop()MutableSequenceContainer.remove()MutableSequenceContainer.reverse()
MutableMappingContainerMutableMappingContainer.DATA_EXPECTED_TYPESMutableMappingContainer.DATA_ALLOW_PROXYMutableMappingContainer.DATA_UNEXPECTED_ACTIONMutableMappingContainer.__init__()MutableMappingContainer._ATTRS_CLSMutableMappingContainer.__contains__()MutableMappingContainer.__delitem__()MutableMappingContainer.__eq__()MutableMappingContainer.__format__()MutableMappingContainer.__getitem__()MutableMappingContainer.__iter__()MutableMappingContainer.__len__()MutableMappingContainer.__repr__()MutableMappingContainer.__setitem__()MutableMappingContainer.__sizeof__()MutableMappingContainer.__str__()MutableMappingContainer._abc_implMutableMappingContainer._attrsMutableMappingContainer._check_data()MutableMappingContainer._check_name()MutableMappingContainer._format_cls_name()MutableMappingContainer._format_info()MutableMappingContainer._format_logstr()MutableMappingContainer._format_name()MutableMappingContainer._format_path()MutableMappingContainer._item_access_convert_list_key()MutableMappingContainer.attrsMutableMappingContainer.classnameMutableMappingContainer.clear()MutableMappingContainer.dataMutableMappingContainer.get()MutableMappingContainer.items()MutableMappingContainer.keys()MutableMappingContainer.logstrMutableMappingContainer.nameMutableMappingContainer.parentMutableMappingContainer.pathMutableMappingContainer.pop()MutableMappingContainer.popitem()MutableMappingContainer.setdefault()MutableMappingContainer.update()MutableMappingContainer.values()
StringContainerStringContainer.DATA_EXPECTED_TYPESStringContainer.DATA_ALLOW_PROXYStringContainer.DATA_UNEXPECTED_ACTIONStringContainer.FORWARD_ATTR_EXCLUDEStringContainer.FORWARD_ATTR_ONLYStringContainer.FORWARD_ATTR_TOStringContainer._ATTRS_CLSStringContainer.__contains__()StringContainer.__delitem__()StringContainer.__eq__()StringContainer.__format__()StringContainer.__getattr__()StringContainer.__getitem__()StringContainer.__getstate__()StringContainer.__init__()StringContainer.__iter__()StringContainer.__len__()StringContainer.__repr__()StringContainer.__setitem__()StringContainer.__setstate__()StringContainer.__sizeof__()StringContainer.__str__()StringContainer._abc_implStringContainer._attrsStringContainer._check_data()StringContainer._check_name()StringContainer._format_cls_name()StringContainer._format_info()StringContainer._format_logstr()StringContainer._format_name()StringContainer._format_path()StringContainer._forward_attr_get_forwarding_target()StringContainer._forward_attr_post_hook()StringContainer._forward_attr_pre_hook()StringContainer._item_access_convert_list_key()StringContainer.attrsStringContainer.classnameStringContainer.dataStringContainer.logstrStringContainer.nameStringContainer.parentStringContainer.path
- dantro.containers.link module
LinkContainerLinkContainer.DATA_EXPECTED_TYPESLinkContainer._format_info()LinkContainer.DATA_ALLOW_PROXYLinkContainer.DATA_UNEXPECTED_ACTIONLinkContainer.FORWARD_ATTR_EXCLUDELinkContainer.FORWARD_ATTR_ONLYLinkContainer.FORWARD_ATTR_TOLinkContainer._ATTRS_CLSLinkContainer.__delitem__()LinkContainer.__eq__()LinkContainer.__format__()LinkContainer.__getattr__()LinkContainer.__getitem__()LinkContainer.__getstate__()LinkContainer.__init__()LinkContainer.__repr__()LinkContainer.__setitem__()LinkContainer.__setstate__()LinkContainer.__sizeof__()LinkContainer.__str__()LinkContainer._abc_implLinkContainer._attrsLinkContainer._check_data()LinkContainer._check_name()LinkContainer._format_cls_name()LinkContainer._format_logstr()LinkContainer._format_name()LinkContainer._format_path()LinkContainer._forward_attr_get_forwarding_target()LinkContainer._forward_attr_post_hook()LinkContainer._forward_attr_pre_hook()LinkContainer._item_access_convert_list_key()LinkContainer.attrsLinkContainer.classnameLinkContainer.dataLinkContainer.logstrLinkContainer.nameLinkContainer.parentLinkContainer.path
- dantro.containers.numeric module
NumpyDataContainerNumpyDataContainer.DATA_EXPECTED_TYPESNumpyDataContainer.DATA_ALLOW_PROXYNumpyDataContainer.DATA_UNEXPECTED_ACTIONNumpyDataContainer.__init__()NumpyDataContainer._format_info()NumpyDataContainer.__len__()NumpyDataContainer.copy()NumpyDataContainer.save()NumpyDataContainer.FORWARD_ATTR_EXCLUDENumpyDataContainer.FORWARD_ATTR_ONLYNumpyDataContainer.FORWARD_ATTR_TONumpyDataContainer._ATTRS_CLSNumpyDataContainer.__abs__()NumpyDataContainer.__add__()NumpyDataContainer.__bool__()NumpyDataContainer.__ceil__()NumpyDataContainer.__delitem__()NumpyDataContainer.__divmod__()NumpyDataContainer.__eq__()NumpyDataContainer.__floor__()NumpyDataContainer.__floordiv__()NumpyDataContainer.__format__()NumpyDataContainer.__ge__()NumpyDataContainer.__getattr__()NumpyDataContainer.__getitem__()NumpyDataContainer.__getstate__()NumpyDataContainer.__gt__()NumpyDataContainer.__iadd__()NumpyDataContainer.__ifloordiv__()NumpyDataContainer.__imod__()NumpyDataContainer.__imul__()NumpyDataContainer.__invert__()NumpyDataContainer.__ipow__()NumpyDataContainer.__isub__()NumpyDataContainer.__itruediv__()NumpyDataContainer.__le__()NumpyDataContainer.__lt__()NumpyDataContainer.__mod__()NumpyDataContainer.__mul__()NumpyDataContainer.__ne__()NumpyDataContainer.__neg__()NumpyDataContainer.__pos__()NumpyDataContainer.__pow__()NumpyDataContainer.__repr__()NumpyDataContainer.__round__()NumpyDataContainer.__setitem__()NumpyDataContainer.__setstate__()NumpyDataContainer.__sizeof__()NumpyDataContainer.__str__()NumpyDataContainer.__sub__()NumpyDataContainer.__truediv__()NumpyDataContainer.__trunc__()NumpyDataContainer._abc_implNumpyDataContainer._attrsNumpyDataContainer._check_data()NumpyDataContainer._check_name()NumpyDataContainer._format_cls_name()NumpyDataContainer._format_logstr()NumpyDataContainer._format_name()NumpyDataContainer._format_path()NumpyDataContainer._forward_attr_get_forwarding_target()NumpyDataContainer._forward_attr_post_hook()NumpyDataContainer._forward_attr_pre_hook()NumpyDataContainer._item_access_convert_list_key()NumpyDataContainer.attrsNumpyDataContainer.classnameNumpyDataContainer.dataNumpyDataContainer.logstrNumpyDataContainer.nameNumpyDataContainer.parentNumpyDataContainer.path
- dantro.containers.path module
PathContainerPathContainer.__init__()PathContainer.fs_pathPathContainer.FORWARD_ATTR_EXCLUDEPathContainer.FORWARD_ATTR_ONLYPathContainer.FORWARD_ATTR_TOPathContainer._ATTRS_CLSPathContainer.__eq__()PathContainer.__format__()PathContainer.__getattr__()PathContainer.__getstate__()PathContainer.__repr__()PathContainer.__setstate__()PathContainer.__sizeof__()PathContainer.__str__()PathContainer._abc_implPathContainer._attrsPathContainer._check_data()PathContainer._check_name()PathContainer._format_cls_name()PathContainer._format_info()PathContainer._format_logstr()PathContainer._format_name()PathContainer._format_path()PathContainer._forward_attr_get_forwarding_target()PathContainer._forward_attr_post_hook()PathContainer._forward_attr_pre_hook()PathContainer.attrsPathContainer.classnamePathContainer.dataPathContainer.logstrPathContainer.namePathContainer.parentPathContainer.path
- dantro.containers.xr module
XrDataContainerXrDataContainer.DATA_EXPECTED_TYPESXrDataContainer.DATA_ALLOW_PROXYXrDataContainer.DATA_UNEXPECTED_ACTIONXrDataContainer._XRC_DIMS_ATTRXrDataContainer._XRC_DIM_NAME_PREFIXXrDataContainer._XRC_COORDS_ATTR_PREFIXXrDataContainer._XRC_COORDS_MODE_DEFAULTXrDataContainer._XRC_COORDS_MODE_ATTR_PREFIXXrDataContainer._XRC_INHERIT_CONTAINER_ATTRIBUTESXrDataContainer._XRC_STRICT_ATTR_CHECKINGXrDataContainer.__init__()XrDataContainer._format_info()XrDataContainer._format_shape()XrDataContainer.__len__()XrDataContainer.FORWARD_ATTR_EXCLUDEXrDataContainer.FORWARD_ATTR_ONLYXrDataContainer.FORWARD_ATTR_TOXrDataContainer._ATTRS_CLSXrDataContainer.__abs__()XrDataContainer.__add__()XrDataContainer.__bool__()XrDataContainer.__ceil__()XrDataContainer.__delitem__()XrDataContainer.__divmod__()XrDataContainer.__eq__()XrDataContainer.__floor__()XrDataContainer.__floordiv__()XrDataContainer.__format__()XrDataContainer.__ge__()XrDataContainer.__getattr__()XrDataContainer.__getitem__()XrDataContainer.__getstate__()XrDataContainer.__gt__()XrDataContainer.__iadd__()XrDataContainer.__ifloordiv__()XrDataContainer.__imod__()XrDataContainer.__imul__()XrDataContainer.__invert__()XrDataContainer.__ipow__()XrDataContainer.__isub__()XrDataContainer.__itruediv__()XrDataContainer.__le__()XrDataContainer.__lt__()XrDataContainer.__mod__()XrDataContainer.__mul__()XrDataContainer.__ne__()XrDataContainer.__neg__()XrDataContainer.__pos__()XrDataContainer.__pow__()XrDataContainer.__repr__()XrDataContainer.__round__()XrDataContainer.__setitem__()XrDataContainer.__setstate__()XrDataContainer.__sizeof__()XrDataContainer.__str__()XrDataContainer.__sub__()XrDataContainer.__truediv__()XrDataContainer.__trunc__()XrDataContainer._abc_implXrDataContainer._attrsXrDataContainer._check_data()XrDataContainer._check_name()XrDataContainer._format_cls_name()XrDataContainer._format_logstr()XrDataContainer._format_name()XrDataContainer._format_path()XrDataContainer._forward_attr_get_forwarding_target()XrDataContainer._forward_attr_post_hook()XrDataContainer._forward_attr_pre_hook()XrDataContainer._item_access_convert_list_key()XrDataContainer.attrsXrDataContainer.classnameXrDataContainer.copy()XrDataContainer.dataXrDataContainer.logstrXrDataContainer.nameXrDataContainer.parentXrDataContainer.pathXrDataContainer.save()XrDataContainer._extract_metadata()XrDataContainer._inherit_attrs()XrDataContainer._apply_metadata()XrDataContainer._postprocess_proxy_resolution()XrDataContainer._parse_sizes_from_metadata()
- dantro.data_loaders package
AllAvailableLoadersMixinAllAvailableLoadersMixin._HDF5_DECODE_ATTR_BYTESTRINGSAllAvailableLoadersMixin._HDF5_DSET_DEFAULT_CLSAllAvailableLoadersMixin._HDF5_DSET_MAPAllAvailableLoadersMixin._HDF5_GROUP_MAPAllAvailableLoadersMixin._HDF5_MAP_FROM_ATTRAllAvailableLoadersMixin._container_from_h5dataset()AllAvailableLoadersMixin._decode_attr_val()AllAvailableLoadersMixin._evaluate_type_mapping()AllAvailableLoadersMixin._group_from_h5group()AllAvailableLoadersMixin._load_fspath()AllAvailableLoadersMixin._load_fstree()AllAvailableLoadersMixin._load_hdf5()AllAvailableLoadersMixin._load_hdf5_as_dask()AllAvailableLoadersMixin._load_hdf5_proxy()AllAvailableLoadersMixin._load_numpy()AllAvailableLoadersMixin._load_numpy_binary()AllAvailableLoadersMixin._load_numpy_txt()AllAvailableLoadersMixin._load_pandas_csv()AllAvailableLoadersMixin._load_pandas_generic()AllAvailableLoadersMixin._load_pickle()AllAvailableLoadersMixin._load_plain_text()AllAvailableLoadersMixin._load_xr_dataarray()AllAvailableLoadersMixin._load_xr_dataset()AllAvailableLoadersMixin._load_yaml()AllAvailableLoadersMixin._load_yaml_to_object()AllAvailableLoadersMixin._recursively_load_hdf5()
LOADER_BY_FILE_EXT- Submodules
- dantro.data_loaders._registry module
LOAD_FUNC_PREFIXDataLoaderRegistryDataLoaderRegistry._DESCDataLoaderRegistry._SKIPDataLoaderRegistry._OVERWRITEDataLoaderRegistry._EXPECTED_TYPEDataLoaderRegistry.__contains__()DataLoaderRegistry._check_object()DataLoaderRegistry._decorator()DataLoaderRegistry._determine_name()DataLoaderRegistry._register_via_decorator()DataLoaderRegistry.classnameDataLoaderRegistry.descDataLoaderRegistry.items()DataLoaderRegistry.keys()DataLoaderRegistry.register()DataLoaderRegistry.values()
DATA_LOADERS_register_loader()add_loader()
- dantro.data_loaders.fspath module
- dantro.data_loaders.hdf5 module
Hdf5LoaderMixinHdf5LoaderMixin._HDF5_DSET_DEFAULT_CLSHdf5LoaderMixin._HDF5_GROUP_MAPHdf5LoaderMixin._HDF5_DSET_MAPHdf5LoaderMixin._HDF5_MAP_FROM_ATTRHdf5LoaderMixin._HDF5_DECODE_ATTR_BYTESTRINGSHdf5LoaderMixin._load_hdf5()Hdf5LoaderMixin._load_hdf5_proxy()Hdf5LoaderMixin._load_hdf5_as_dask()Hdf5LoaderMixin._recursively_load_hdf5()Hdf5LoaderMixin._group_from_h5group()Hdf5LoaderMixin._container_from_h5dataset()Hdf5LoaderMixin._decode_attr_val()Hdf5LoaderMixin._evaluate_type_mapping()
- dantro.data_loaders.numpy module
- dantro.data_loaders.pandas module
- dantro.data_loaders.pickle module
- dantro.data_loaders.text module
- dantro.data_loaders.xarray module
- dantro.data_loaders.yaml module
- dantro.data_ops package
- dantro.groups package
- Submodules
- dantro.groups._registry module
GroupRegistryGroupRegistry._DESCGroupRegistry._SKIPGroupRegistry._OVERWRITEGroupRegistry._EXPECTED_TYPEGroupRegistry._check_object()GroupRegistry._register_via_decorator()GroupRegistry.__contains__()GroupRegistry._decorator()GroupRegistry._determine_name()GroupRegistry.classnameGroupRegistry.descGroupRegistry.items()GroupRegistry.keys()GroupRegistry.register()GroupRegistry.values()
GROUPSregister_group()is_group()
- dantro.groups.dirpath module
DirectoryGroupDirectoryGroup._NEW_CONTAINER_CLSDirectoryGroup.__init__()DirectoryGroup._ALLOWED_CONT_TYPESDirectoryGroup._ATTRS_CLSDirectoryGroup._COND_TREE_CONDENSE_THRESHDirectoryGroup._COND_TREE_MAX_LEVELDirectoryGroup._DATA_CONTAINER_CLASSESDirectoryGroup._DATA_GROUP_CLASSESDirectoryGroup._NEW_GROUP_CLSDirectoryGroup._STORAGE_CLSDirectoryGroup.__contains__()DirectoryGroup.__delitem__()DirectoryGroup.__eq__()DirectoryGroup.__format__()DirectoryGroup.__getitem__()DirectoryGroup.__iter__()DirectoryGroup.__len__()DirectoryGroup.__repr__()DirectoryGroup.__setitem__()DirectoryGroup.__sizeof__()DirectoryGroup.__str__()DirectoryGroup._abc_implDirectoryGroup._add_container()DirectoryGroup._add_container_callback()DirectoryGroup._add_container_to_data()DirectoryGroup._attrsDirectoryGroup._check_cont()DirectoryGroup._check_data()DirectoryGroup._check_name()DirectoryGroup._determine_container_type()DirectoryGroup._determine_group_type()DirectoryGroup._determine_type()DirectoryGroup._direct_insertion_mode()DirectoryGroup._enter_direct_insertion_mode()DirectoryGroup._exit_direct_insertion_mode()DirectoryGroup._format_cls_name()DirectoryGroup._format_info()DirectoryGroup._format_logstr()DirectoryGroup._format_name()DirectoryGroup._format_path()DirectoryGroup._format_tree()DirectoryGroup._format_tree_condensed()DirectoryGroup._ipython_key_completions_()DirectoryGroup._link_child()DirectoryGroup._lock_hook()DirectoryGroup._tree_repr()DirectoryGroup._unlink_child()DirectoryGroup._unlock_hook()DirectoryGroup.add()DirectoryGroup.attrsDirectoryGroup.classnameDirectoryGroup.clear()DirectoryGroup.dataDirectoryGroup.fs_pathDirectoryGroup.get()DirectoryGroup.items()DirectoryGroup.keys()DirectoryGroup.lock()DirectoryGroup.lockedDirectoryGroup.logstrDirectoryGroup.nameDirectoryGroup.new_container()DirectoryGroup.new_group()DirectoryGroup.parentDirectoryGroup.pathDirectoryGroup.pop()DirectoryGroup.popitem()DirectoryGroup.raise_if_locked()DirectoryGroup.recursive_update()DirectoryGroup.setdefault()DirectoryGroup.treeDirectoryGroup.tree_condensedDirectoryGroup.unlock()DirectoryGroup.update()DirectoryGroup.values()DirectoryGroup.with_direct_insertionDirectoryGroup.__lockedDirectoryGroup.__in_direct_insertion_mode
- dantro.groups.graph module
GraphGroupGraphGroup._ALLOWED_CONT_TYPESGraphGroup._GG_node_containerGraphGroup._GG_edge_containerGraphGroup._GG_attr_directedGraphGroup._GG_attr_parallelGraphGroup._GG_attr_edge_container_is_transposedGraphGroup._GG_attr_keep_dimGraphGroup._GG_WARN_UPON_BAD_ALIGNGraphGroup.__init__()GraphGroup.property_mapsGraphGroup.node_containerGraphGroup.edge_containerGraphGroup.default_keep_dimGraphGroup._get_item_or_pmap()GraphGroup._get_data_at()GraphGroup._prepare_edge_data()GraphGroup._prepare_property_data()GraphGroup._check_alignment()GraphGroup.register_property_map()GraphGroup.create_graph()GraphGroup.set_node_property()GraphGroup.set_edge_property()GraphGroup._ATTRS_CLSGraphGroup._COND_TREE_CONDENSE_THRESHGraphGroup._COND_TREE_MAX_LEVELGraphGroup._DATA_CONTAINER_CLASSESGraphGroup._DATA_GROUP_CLASSESGraphGroup._NEW_CONTAINER_CLSGraphGroup._NEW_GROUP_CLSGraphGroup._STORAGE_CLSGraphGroup.__contains__()GraphGroup.__delitem__()GraphGroup.__eq__()GraphGroup.__format__()GraphGroup.__getitem__()GraphGroup.__iter__()GraphGroup.__len__()GraphGroup.__repr__()GraphGroup.__setitem__()GraphGroup.__sizeof__()GraphGroup.__str__()GraphGroup._abc_implGraphGroup._add_container()GraphGroup._add_container_callback()GraphGroup._add_container_to_data()GraphGroup._attrsGraphGroup._check_cont()GraphGroup._check_data()GraphGroup._check_name()GraphGroup._determine_container_type()GraphGroup._determine_group_type()GraphGroup._determine_type()GraphGroup._direct_insertion_mode()GraphGroup._enter_direct_insertion_mode()GraphGroup._exit_direct_insertion_mode()GraphGroup._format_cls_name()GraphGroup._format_info()GraphGroup._format_logstr()GraphGroup._format_name()GraphGroup._format_path()GraphGroup._format_tree()GraphGroup._format_tree_condensed()GraphGroup._ipython_key_completions_()GraphGroup._link_child()GraphGroup._lock_hook()GraphGroup._tree_repr()GraphGroup._unlink_child()GraphGroup._unlock_hook()GraphGroup.add()GraphGroup.attrsGraphGroup.classnameGraphGroup.clear()GraphGroup.dataGraphGroup.get()GraphGroup.items()GraphGroup.keys()GraphGroup.lock()GraphGroup.lockedGraphGroup.logstrGraphGroup.nameGraphGroup.new_container()GraphGroup.new_group()GraphGroup.parentGraphGroup.pathGraphGroup.pop()GraphGroup.popitem()GraphGroup.raise_if_locked()GraphGroup.recursive_update()GraphGroup.setdefault()GraphGroup.treeGraphGroup.tree_condensedGraphGroup.unlock()GraphGroup.update()GraphGroup.values()GraphGroup.with_direct_insertionGraphGroup.__lockedGraphGroup.__in_direct_insertion_mode
- dantro.groups.labelled module
LabelledDataGroupLabelledDataGroup._NEW_CONTAINER_CLSLabelledDataGroup.LDG_ALLOW_DEEP_SELECTIONLabelledDataGroup.LDG_DIMSLabelledDataGroup.LDG_EXTRACT_COORDS_FROMLabelledDataGroup.LDG_COORDS_ATTR_PREFIXLabelledDataGroup.LDG_COORDS_MODE_ATTR_PREFIXLabelledDataGroup.LDG_COORDS_MODE_DEFAULTLabelledDataGroup.LDG_STRICT_ATTR_CHECKINGLabelledDataGroup.LDG_COORDS_SEPARATOR_IN_NAMELabelledDataGroup._COLLECTIVE_SELECT_THRESHOLDLabelledDataGroup.__init__()LabelledDataGroup.dimsLabelledDataGroup.ndimLabelledDataGroup.coordsLabelledDataGroup.shapeLabelledDataGroup.allow_deep_selectionLabelledDataGroup.member_mapLabelledDataGroup.member_map_availableLabelledDataGroup.isel()LabelledDataGroup.sel()LabelledDataGroup._get_coords_of()LabelledDataGroup._add_container_callback()LabelledDataGroup._parse_indexers()LabelledDataGroup._get_cont()LabelledDataGroup._process_cont()LabelledDataGroup._select()LabelledDataGroup._select_single()LabelledDataGroup._select_all_merge()LabelledDataGroup._ALLOWED_CONT_TYPESLabelledDataGroup._ATTRS_CLSLabelledDataGroup._COND_TREE_CONDENSE_THRESHLabelledDataGroup._COND_TREE_MAX_LEVELLabelledDataGroup._DATA_CONTAINER_CLASSESLabelledDataGroup._DATA_GROUP_CLASSESLabelledDataGroup._NEW_GROUP_CLSLabelledDataGroup._STORAGE_CLSLabelledDataGroup.__contains__()LabelledDataGroup.__delitem__()LabelledDataGroup.__eq__()LabelledDataGroup.__format__()LabelledDataGroup.__getitem__()LabelledDataGroup.__iter__()LabelledDataGroup.__len__()LabelledDataGroup.__repr__()LabelledDataGroup.__setitem__()LabelledDataGroup.__sizeof__()LabelledDataGroup.__str__()LabelledDataGroup._abc_implLabelledDataGroup._add_container()LabelledDataGroup._add_container_to_data()LabelledDataGroup._attrsLabelledDataGroup._check_cont()LabelledDataGroup._check_data()LabelledDataGroup._check_name()LabelledDataGroup._determine_container_type()LabelledDataGroup._determine_group_type()LabelledDataGroup._determine_type()LabelledDataGroup._direct_insertion_mode()LabelledDataGroup._enter_direct_insertion_mode()LabelledDataGroup._exit_direct_insertion_mode()LabelledDataGroup._format_cls_name()LabelledDataGroup._format_info()LabelledDataGroup._format_logstr()LabelledDataGroup._format_name()LabelledDataGroup._format_path()LabelledDataGroup._format_tree()LabelledDataGroup._format_tree_condensed()LabelledDataGroup._ipython_key_completions_()LabelledDataGroup._link_child()LabelledDataGroup._lock_hook()LabelledDataGroup._select_generic()LabelledDataGroup._tree_repr()LabelledDataGroup._unlink_child()LabelledDataGroup._unlock_hook()LabelledDataGroup.add()LabelledDataGroup.attrsLabelledDataGroup.classnameLabelledDataGroup.clear()LabelledDataGroup.dataLabelledDataGroup.get()LabelledDataGroup.items()LabelledDataGroup.keys()LabelledDataGroup.lock()LabelledDataGroup.lockedLabelledDataGroup.logstrLabelledDataGroup.nameLabelledDataGroup.new_container()LabelledDataGroup.new_group()LabelledDataGroup.parentLabelledDataGroup.pathLabelledDataGroup.pop()LabelledDataGroup.popitem()LabelledDataGroup.raise_if_locked()LabelledDataGroup.recursive_update()LabelledDataGroup.setdefault()LabelledDataGroup.treeLabelledDataGroup.tree_condensedLabelledDataGroup.unlock()LabelledDataGroup.update()LabelledDataGroup.values()LabelledDataGroup.with_direct_insertionLabelledDataGroup.__lockedLabelledDataGroup.__in_direct_insertion_modeLabelledDataGroup._combine_by_merge()LabelledDataGroup._combine_by_concatenation()
- dantro.groups.ordered module
OrderedDataGroupOrderedDataGroup._STORAGE_CLSOrderedDataGroup._ALLOWED_CONT_TYPESOrderedDataGroup._ATTRS_CLSOrderedDataGroup._COND_TREE_CONDENSE_THRESHOrderedDataGroup._COND_TREE_MAX_LEVELOrderedDataGroup._DATA_CONTAINER_CLASSESOrderedDataGroup._DATA_GROUP_CLASSESOrderedDataGroup._NEW_CONTAINER_CLSOrderedDataGroup._NEW_GROUP_CLSOrderedDataGroup.__contains__()OrderedDataGroup.__delitem__()OrderedDataGroup.__eq__()OrderedDataGroup.__format__()OrderedDataGroup.__getitem__()OrderedDataGroup.__init__()OrderedDataGroup.__iter__()OrderedDataGroup.__len__()OrderedDataGroup.__repr__()OrderedDataGroup.__setitem__()OrderedDataGroup.__sizeof__()OrderedDataGroup.__str__()OrderedDataGroup._abc_implOrderedDataGroup._add_container()OrderedDataGroup._add_container_callback()OrderedDataGroup._add_container_to_data()OrderedDataGroup._attrsOrderedDataGroup._check_cont()OrderedDataGroup._check_data()OrderedDataGroup._check_name()OrderedDataGroup._determine_container_type()OrderedDataGroup._determine_group_type()OrderedDataGroup._determine_type()OrderedDataGroup._direct_insertion_mode()OrderedDataGroup._enter_direct_insertion_mode()OrderedDataGroup._exit_direct_insertion_mode()OrderedDataGroup._format_cls_name()OrderedDataGroup._format_info()OrderedDataGroup._format_logstr()OrderedDataGroup._format_name()OrderedDataGroup._format_path()OrderedDataGroup._format_tree()OrderedDataGroup._format_tree_condensed()OrderedDataGroup._ipython_key_completions_()OrderedDataGroup._link_child()OrderedDataGroup._lock_hook()OrderedDataGroup._tree_repr()OrderedDataGroup._unlink_child()OrderedDataGroup._unlock_hook()OrderedDataGroup.add()OrderedDataGroup.attrsOrderedDataGroup.classnameOrderedDataGroup.clear()OrderedDataGroup.dataOrderedDataGroup.get()OrderedDataGroup.items()OrderedDataGroup.keys()OrderedDataGroup.lock()OrderedDataGroup.lockedOrderedDataGroup.logstrOrderedDataGroup.nameOrderedDataGroup.new_container()OrderedDataGroup.new_group()OrderedDataGroup.parentOrderedDataGroup.pathOrderedDataGroup.pop()OrderedDataGroup.popitem()OrderedDataGroup.raise_if_locked()OrderedDataGroup.recursive_update()OrderedDataGroup.setdefault()OrderedDataGroup.treeOrderedDataGroup.tree_condensedOrderedDataGroup.unlock()OrderedDataGroup.update()OrderedDataGroup.values()OrderedDataGroup.with_direct_insertionOrderedDataGroup.__lockedOrderedDataGroup.__in_direct_insertion_mode
IndexedDataGroupIndexedDataGroup.__last_keysIndexedDataGroup._STORAGE_CLSIndexedDataGroup._NEW_GROUP_CLSIndexedDataGroup.key_at_idx()IndexedDataGroup.keys_as_int()IndexedDataGroup._add_container_to_data()IndexedDataGroup._ipython_key_completions_()IndexedDataGroup._ALLOWED_CONT_TYPESIndexedDataGroup._ATTRS_CLSIndexedDataGroup._COND_TREE_CONDENSE_THRESHIndexedDataGroup._COND_TREE_MAX_LEVELIndexedDataGroup._DATA_CONTAINER_CLASSESIndexedDataGroup._DATA_GROUP_CLASSESIndexedDataGroup._NEW_CONTAINER_CLSIndexedDataGroup.__contains__()IndexedDataGroup.__delitem__()IndexedDataGroup.__eq__()IndexedDataGroup.__format__()IndexedDataGroup.__getitem__()IndexedDataGroup.__init__()IndexedDataGroup.__iter__()IndexedDataGroup.__len__()IndexedDataGroup.__repr__()IndexedDataGroup.__setitem__()IndexedDataGroup.__sizeof__()IndexedDataGroup.__str__()IndexedDataGroup._abc_implIndexedDataGroup._add_container()IndexedDataGroup._add_container_callback()IndexedDataGroup._attrsIndexedDataGroup._check_cont()IndexedDataGroup._check_data()IndexedDataGroup._check_name()IndexedDataGroup._determine_container_type()IndexedDataGroup._determine_group_type()IndexedDataGroup._determine_type()IndexedDataGroup._direct_insertion_mode()IndexedDataGroup._enter_direct_insertion_mode()IndexedDataGroup._exit_direct_insertion_mode()IndexedDataGroup._format_cls_name()IndexedDataGroup._format_info()IndexedDataGroup._format_logstr()IndexedDataGroup._format_name()IndexedDataGroup._format_path()IndexedDataGroup._format_tree()IndexedDataGroup._format_tree_condensed()IndexedDataGroup._link_child()IndexedDataGroup._lock_hook()IndexedDataGroup._parse_key()IndexedDataGroup._tree_repr()IndexedDataGroup._unlink_child()IndexedDataGroup._unlock_hook()IndexedDataGroup.add()IndexedDataGroup.attrsIndexedDataGroup.classnameIndexedDataGroup.clear()IndexedDataGroup.dataIndexedDataGroup.get()IndexedDataGroup.items()IndexedDataGroup.keys()IndexedDataGroup.lock()IndexedDataGroup.lockedIndexedDataGroup.logstrIndexedDataGroup.nameIndexedDataGroup.new_container()IndexedDataGroup.new_group()IndexedDataGroup.parentIndexedDataGroup.pathIndexedDataGroup.pop()IndexedDataGroup.popitem()IndexedDataGroup.raise_if_locked()IndexedDataGroup.recursive_update()IndexedDataGroup.setdefault()IndexedDataGroup.treeIndexedDataGroup.tree_condensedIndexedDataGroup.unlock()IndexedDataGroup.update()IndexedDataGroup.values()IndexedDataGroup.with_direct_insertionIndexedDataGroup.__lockedIndexedDataGroup.__in_direct_insertion_mode
- dantro.groups.psp module
ParamSpaceStateGroupParamSpaceStateGroup._NEW_GROUP_CLSParamSpaceStateGroup._check_name()ParamSpaceStateGroup.coordsParamSpaceStateGroup._ALLOWED_CONT_TYPESParamSpaceStateGroup._ATTRS_CLSParamSpaceStateGroup._COND_TREE_CONDENSE_THRESHParamSpaceStateGroup._COND_TREE_MAX_LEVELParamSpaceStateGroup._DATA_CONTAINER_CLASSESParamSpaceStateGroup._DATA_GROUP_CLASSESParamSpaceStateGroup._NEW_CONTAINER_CLSParamSpaceStateGroup._STORAGE_CLSParamSpaceStateGroup.__contains__()ParamSpaceStateGroup.__delitem__()ParamSpaceStateGroup.__eq__()ParamSpaceStateGroup.__format__()ParamSpaceStateGroup.__getitem__()ParamSpaceStateGroup.__init__()ParamSpaceStateGroup.__iter__()ParamSpaceStateGroup.__len__()ParamSpaceStateGroup.__repr__()ParamSpaceStateGroup.__setitem__()ParamSpaceStateGroup.__sizeof__()ParamSpaceStateGroup.__str__()ParamSpaceStateGroup._abc_implParamSpaceStateGroup._add_container()ParamSpaceStateGroup._add_container_callback()ParamSpaceStateGroup._add_container_to_data()ParamSpaceStateGroup._attrsParamSpaceStateGroup._check_cont()ParamSpaceStateGroup._check_data()ParamSpaceStateGroup._determine_container_type()ParamSpaceStateGroup._determine_group_type()ParamSpaceStateGroup._determine_type()ParamSpaceStateGroup._direct_insertion_mode()ParamSpaceStateGroup._enter_direct_insertion_mode()ParamSpaceStateGroup._exit_direct_insertion_mode()ParamSpaceStateGroup._format_cls_name()ParamSpaceStateGroup._format_info()ParamSpaceStateGroup._format_logstr()ParamSpaceStateGroup._format_name()ParamSpaceStateGroup._format_path()ParamSpaceStateGroup._format_tree()ParamSpaceStateGroup._format_tree_condensed()ParamSpaceStateGroup._ipython_key_completions_()ParamSpaceStateGroup._link_child()ParamSpaceStateGroup._lock_hook()ParamSpaceStateGroup._tree_repr()ParamSpaceStateGroup._unlink_child()ParamSpaceStateGroup._unlock_hook()ParamSpaceStateGroup.add()ParamSpaceStateGroup.attrsParamSpaceStateGroup.classnameParamSpaceStateGroup.clear()ParamSpaceStateGroup.dataParamSpaceStateGroup.get()ParamSpaceStateGroup.items()ParamSpaceStateGroup.keys()ParamSpaceStateGroup.lock()ParamSpaceStateGroup.lockedParamSpaceStateGroup.logstrParamSpaceStateGroup.nameParamSpaceStateGroup.new_container()ParamSpaceStateGroup.new_group()ParamSpaceStateGroup.parentParamSpaceStateGroup.pathParamSpaceStateGroup.pop()ParamSpaceStateGroup.popitem()ParamSpaceStateGroup.raise_if_locked()ParamSpaceStateGroup.recursive_update()ParamSpaceStateGroup.setdefault()ParamSpaceStateGroup.treeParamSpaceStateGroup.tree_condensedParamSpaceStateGroup.unlock()ParamSpaceStateGroup.update()ParamSpaceStateGroup.values()ParamSpaceStateGroup.with_direct_insertionParamSpaceStateGroup.__lockedParamSpaceStateGroup.__in_direct_insertion_mode
ParamSpaceGroupParamSpaceGroup._PSPGRP_PSPACE_ATTR_NAMEParamSpaceGroup._PSPGRP_TRANSFORMATORParamSpaceGroup._NEW_GROUP_CLSParamSpaceGroup._ALLOWED_CONT_TYPESParamSpaceGroup.__init__()ParamSpaceGroup.pspaceParamSpaceGroup._ATTRS_CLSParamSpaceGroup._COND_TREE_CONDENSE_THRESHParamSpaceGroup._COND_TREE_MAX_LEVELParamSpaceGroup._DATA_CONTAINER_CLASSESParamSpaceGroup._DATA_GROUP_CLASSESParamSpaceGroup._NEW_CONTAINER_CLSParamSpaceGroup._PADDED_INT_FSTRParamSpaceGroup._PADDED_INT_KEY_WIDTHParamSpaceGroup._PADDED_INT_MAX_VALParamSpaceGroup._PADDED_INT_STRICT_CHECKINGParamSpaceGroup._STORAGE_CLSParamSpaceGroup.__contains__()ParamSpaceGroup.__delitem__()ParamSpaceGroup.__eq__()ParamSpaceGroup.__format__()ParamSpaceGroup.__getitem__()ParamSpaceGroup.__iter__()ParamSpaceGroup.__len__()ParamSpaceGroup.__repr__()ParamSpaceGroup.__setitem__()ParamSpaceGroup.__sizeof__()ParamSpaceGroup.__str__()ParamSpaceGroup._abc_implParamSpaceGroup._add_container()ParamSpaceGroup._add_container_callback()ParamSpaceGroup._add_container_to_data()ParamSpaceGroup._attrsParamSpaceGroup._check_cont()ParamSpaceGroup._check_data()ParamSpaceGroup._check_name()ParamSpaceGroup._determine_container_type()ParamSpaceGroup._determine_group_type()ParamSpaceGroup._determine_type()ParamSpaceGroup._direct_insertion_mode()ParamSpaceGroup._enter_direct_insertion_mode()ParamSpaceGroup._exit_direct_insertion_mode()ParamSpaceGroup._format_cls_name()ParamSpaceGroup._format_info()ParamSpaceGroup._format_logstr()ParamSpaceGroup._format_name()ParamSpaceGroup._format_path()ParamSpaceGroup._format_tree()ParamSpaceGroup._format_tree_condensed()ParamSpaceGroup._ipython_key_completions_()ParamSpaceGroup._link_child()ParamSpaceGroup._lock_hook()ParamSpaceGroup._parse_key()ParamSpaceGroup._tree_repr()ParamSpaceGroup._unlink_child()ParamSpaceGroup._unlock_hook()ParamSpaceGroup.add()ParamSpaceGroup.attrsParamSpaceGroup.classnameParamSpaceGroup.clear()ParamSpaceGroup.dataParamSpaceGroup.get()ParamSpaceGroup.items()ParamSpaceGroup.key_at_idx()ParamSpaceGroup.keys()ParamSpaceGroup.keys_as_int()ParamSpaceGroup.lock()ParamSpaceGroup.lockedParamSpaceGroup.logstrParamSpaceGroup.nameParamSpaceGroup.new_container()ParamSpaceGroup.new_group()ParamSpaceGroup.only_default_data_presentParamSpaceGroup.padded_int_key_widthParamSpaceGroup.parentParamSpaceGroup.pathParamSpaceGroup.pop()ParamSpaceGroup.popitem()ParamSpaceGroup.raise_if_locked()ParamSpaceGroup.recursive_update()ParamSpaceGroup.setdefault()ParamSpaceGroup.treeParamSpaceGroup.tree_condensedParamSpaceGroup.unlock()ParamSpaceGroup.update()ParamSpaceGroup.values()ParamSpaceGroup.with_direct_insertionParamSpaceGroup.__last_keysParamSpaceGroup.__lockedParamSpaceGroup.__in_direct_insertion_modeParamSpaceGroup.select()
- dantro.groups.time_series module
TimeSeriesGroupTimeSeriesGroup.LDG_DIMSTimeSeriesGroup.LDG_EXTRACT_COORDS_FROMTimeSeriesGroup.LDG_ALLOW_DEEP_SELECTIONTimeSeriesGroup.LDG_COORDS_ATTR_PREFIXTimeSeriesGroup.LDG_COORDS_MODE_ATTR_PREFIXTimeSeriesGroup.LDG_COORDS_MODE_DEFAULTTimeSeriesGroup.LDG_COORDS_SEPARATOR_IN_NAMETimeSeriesGroup.LDG_STRICT_ATTR_CHECKINGTimeSeriesGroup._ALLOWED_CONT_TYPESTimeSeriesGroup._ATTRS_CLSTimeSeriesGroup._COLLECTIVE_SELECT_THRESHOLDTimeSeriesGroup._COND_TREE_CONDENSE_THRESHTimeSeriesGroup._COND_TREE_MAX_LEVELTimeSeriesGroup._DATA_CONTAINER_CLASSESTimeSeriesGroup._DATA_GROUP_CLASSESTimeSeriesGroup._NEW_CONTAINER_CLSTimeSeriesGroup._NEW_GROUP_CLSTimeSeriesGroup._STORAGE_CLSTimeSeriesGroup.__contains__()TimeSeriesGroup.__delitem__()TimeSeriesGroup.__eq__()TimeSeriesGroup.__format__()TimeSeriesGroup.__getitem__()TimeSeriesGroup.__init__()TimeSeriesGroup.__iter__()TimeSeriesGroup.__len__()TimeSeriesGroup.__repr__()TimeSeriesGroup.__setitem__()TimeSeriesGroup.__sizeof__()TimeSeriesGroup.__str__()TimeSeriesGroup._abc_implTimeSeriesGroup._add_container()TimeSeriesGroup._add_container_callback()TimeSeriesGroup._add_container_to_data()TimeSeriesGroup._attrsTimeSeriesGroup._check_cont()TimeSeriesGroup._check_data()TimeSeriesGroup._check_name()TimeSeriesGroup._combine_by_concatenation()TimeSeriesGroup._combine_by_merge()TimeSeriesGroup._determine_container_type()TimeSeriesGroup._determine_group_type()TimeSeriesGroup._determine_type()TimeSeriesGroup._direct_insertion_mode()TimeSeriesGroup._enter_direct_insertion_mode()TimeSeriesGroup._exit_direct_insertion_mode()TimeSeriesGroup._format_cls_name()TimeSeriesGroup._format_info()TimeSeriesGroup._format_logstr()TimeSeriesGroup._format_name()TimeSeriesGroup._format_path()TimeSeriesGroup._format_tree()TimeSeriesGroup._format_tree_condensed()TimeSeriesGroup._get_cont()TimeSeriesGroup._get_coords_of()TimeSeriesGroup._ipython_key_completions_()TimeSeriesGroup._link_child()TimeSeriesGroup._lock_hook()TimeSeriesGroup._parse_indexers()TimeSeriesGroup._parse_key()TimeSeriesGroup._process_cont()TimeSeriesGroup._select()TimeSeriesGroup._select_all_merge()TimeSeriesGroup._select_generic()TimeSeriesGroup._select_single()TimeSeriesGroup._tree_repr()TimeSeriesGroup._unlink_child()TimeSeriesGroup._unlock_hook()TimeSeriesGroup.add()TimeSeriesGroup.allow_deep_selectionTimeSeriesGroup.attrsTimeSeriesGroup.classnameTimeSeriesGroup.clear()TimeSeriesGroup.coordsTimeSeriesGroup.dataTimeSeriesGroup.dimsTimeSeriesGroup.get()TimeSeriesGroup.isel()TimeSeriesGroup.items()TimeSeriesGroup.key_at_idx()TimeSeriesGroup.keys()TimeSeriesGroup.keys_as_int()TimeSeriesGroup.lock()TimeSeriesGroup.lockedTimeSeriesGroup.logstrTimeSeriesGroup.member_mapTimeSeriesGroup.member_map_availableTimeSeriesGroup.nameTimeSeriesGroup.ndimTimeSeriesGroup.new_container()TimeSeriesGroup.new_group()TimeSeriesGroup.parentTimeSeriesGroup.pathTimeSeriesGroup.pop()TimeSeriesGroup.popitem()TimeSeriesGroup.raise_if_locked()TimeSeriesGroup.recursive_update()TimeSeriesGroup.sel()TimeSeriesGroup.setdefault()TimeSeriesGroup.shapeTimeSeriesGroup.treeTimeSeriesGroup.tree_condensedTimeSeriesGroup.unlock()TimeSeriesGroup.update()TimeSeriesGroup.values()TimeSeriesGroup.with_direct_insertionTimeSeriesGroup.__last_keysTimeSeriesGroup.__lockedTimeSeriesGroup.__in_direct_insertion_mode
HeterogeneousTimeSeriesGroupHeterogeneousTimeSeriesGroup.LDG_ALLOW_DEEP_SELECTIONHeterogeneousTimeSeriesGroup.LDG_COORDS_ATTR_PREFIXHeterogeneousTimeSeriesGroup.LDG_COORDS_MODE_ATTR_PREFIXHeterogeneousTimeSeriesGroup.LDG_COORDS_MODE_DEFAULTHeterogeneousTimeSeriesGroup.LDG_COORDS_SEPARATOR_IN_NAMEHeterogeneousTimeSeriesGroup.LDG_DIMSHeterogeneousTimeSeriesGroup.LDG_STRICT_ATTR_CHECKINGHeterogeneousTimeSeriesGroup._ALLOWED_CONT_TYPESHeterogeneousTimeSeriesGroup._ATTRS_CLSHeterogeneousTimeSeriesGroup._COLLECTIVE_SELECT_THRESHOLDHeterogeneousTimeSeriesGroup._COND_TREE_CONDENSE_THRESHHeterogeneousTimeSeriesGroup._COND_TREE_MAX_LEVELHeterogeneousTimeSeriesGroup._DATA_CONTAINER_CLASSESHeterogeneousTimeSeriesGroup._DATA_GROUP_CLASSESHeterogeneousTimeSeriesGroup._NEW_CONTAINER_CLSHeterogeneousTimeSeriesGroup._NEW_GROUP_CLSHeterogeneousTimeSeriesGroup._STORAGE_CLSHeterogeneousTimeSeriesGroup.__contains__()HeterogeneousTimeSeriesGroup.__delitem__()HeterogeneousTimeSeriesGroup.__eq__()HeterogeneousTimeSeriesGroup.__format__()HeterogeneousTimeSeriesGroup.__getitem__()HeterogeneousTimeSeriesGroup.__init__()HeterogeneousTimeSeriesGroup.__iter__()HeterogeneousTimeSeriesGroup.__len__()HeterogeneousTimeSeriesGroup.__repr__()HeterogeneousTimeSeriesGroup.__setitem__()HeterogeneousTimeSeriesGroup.__sizeof__()HeterogeneousTimeSeriesGroup.__str__()HeterogeneousTimeSeriesGroup._abc_implHeterogeneousTimeSeriesGroup._add_container()HeterogeneousTimeSeriesGroup._add_container_callback()HeterogeneousTimeSeriesGroup._add_container_to_data()HeterogeneousTimeSeriesGroup._attrsHeterogeneousTimeSeriesGroup._check_cont()HeterogeneousTimeSeriesGroup._check_data()HeterogeneousTimeSeriesGroup._check_name()HeterogeneousTimeSeriesGroup._combine_by_concatenation()HeterogeneousTimeSeriesGroup._combine_by_merge()HeterogeneousTimeSeriesGroup._determine_container_type()HeterogeneousTimeSeriesGroup._determine_group_type()HeterogeneousTimeSeriesGroup._determine_type()HeterogeneousTimeSeriesGroup._direct_insertion_mode()HeterogeneousTimeSeriesGroup._enter_direct_insertion_mode()HeterogeneousTimeSeriesGroup._exit_direct_insertion_mode()HeterogeneousTimeSeriesGroup._format_cls_name()HeterogeneousTimeSeriesGroup._format_info()HeterogeneousTimeSeriesGroup._format_logstr()HeterogeneousTimeSeriesGroup._format_name()HeterogeneousTimeSeriesGroup._format_path()HeterogeneousTimeSeriesGroup._format_tree()HeterogeneousTimeSeriesGroup._format_tree_condensed()HeterogeneousTimeSeriesGroup._get_cont()HeterogeneousTimeSeriesGroup._get_coords_of()HeterogeneousTimeSeriesGroup._ipython_key_completions_()HeterogeneousTimeSeriesGroup._link_child()HeterogeneousTimeSeriesGroup._lock_hook()HeterogeneousTimeSeriesGroup._parse_indexers()HeterogeneousTimeSeriesGroup._parse_key()HeterogeneousTimeSeriesGroup._process_cont()HeterogeneousTimeSeriesGroup._select()HeterogeneousTimeSeriesGroup._select_all_merge()HeterogeneousTimeSeriesGroup._select_generic()HeterogeneousTimeSeriesGroup._select_single()HeterogeneousTimeSeriesGroup._tree_repr()HeterogeneousTimeSeriesGroup._unlink_child()HeterogeneousTimeSeriesGroup._unlock_hook()HeterogeneousTimeSeriesGroup.add()HeterogeneousTimeSeriesGroup.allow_deep_selectionHeterogeneousTimeSeriesGroup.attrsHeterogeneousTimeSeriesGroup.classnameHeterogeneousTimeSeriesGroup.clear()HeterogeneousTimeSeriesGroup.coordsHeterogeneousTimeSeriesGroup.dataHeterogeneousTimeSeriesGroup.dimsHeterogeneousTimeSeriesGroup.get()HeterogeneousTimeSeriesGroup.isel()HeterogeneousTimeSeriesGroup.items()HeterogeneousTimeSeriesGroup.key_at_idx()HeterogeneousTimeSeriesGroup.keys()HeterogeneousTimeSeriesGroup.keys_as_int()HeterogeneousTimeSeriesGroup.lock()HeterogeneousTimeSeriesGroup.lockedHeterogeneousTimeSeriesGroup.logstrHeterogeneousTimeSeriesGroup.member_mapHeterogeneousTimeSeriesGroup.member_map_availableHeterogeneousTimeSeriesGroup.nameHeterogeneousTimeSeriesGroup.ndimHeterogeneousTimeSeriesGroup.new_container()HeterogeneousTimeSeriesGroup.new_group()HeterogeneousTimeSeriesGroup.parentHeterogeneousTimeSeriesGroup.pathHeterogeneousTimeSeriesGroup.pop()HeterogeneousTimeSeriesGroup.popitem()HeterogeneousTimeSeriesGroup.raise_if_locked()HeterogeneousTimeSeriesGroup.recursive_update()HeterogeneousTimeSeriesGroup.sel()HeterogeneousTimeSeriesGroup.setdefault()HeterogeneousTimeSeriesGroup.shapeHeterogeneousTimeSeriesGroup.treeHeterogeneousTimeSeriesGroup.tree_condensedHeterogeneousTimeSeriesGroup.unlock()HeterogeneousTimeSeriesGroup.update()HeterogeneousTimeSeriesGroup.values()HeterogeneousTimeSeriesGroup.with_direct_insertionHeterogeneousTimeSeriesGroup.__last_keysHeterogeneousTimeSeriesGroup.__lockedHeterogeneousTimeSeriesGroup.__in_direct_insertion_modeHeterogeneousTimeSeriesGroup.LDG_EXTRACT_COORDS_FROM
- dantro.mixins package
- Submodules
- dantro.mixins.base module
AttrsMixinSizeOfMixinLockDataMixinBasicComparisonMixinCollectionMixinItemAccessMixinMappingAccessMixinMappingAccessMixin.keys()MappingAccessMixin.values()MappingAccessMixin.items()MappingAccessMixin.get()MappingAccessMixin.__contains__()MappingAccessMixin.__delitem__()MappingAccessMixin.__getitem__()MappingAccessMixin.__iter__()MappingAccessMixin.__len__()MappingAccessMixin.__setitem__()MappingAccessMixin._item_access_convert_list_key()
CheckDataMixinDirectInsertionModeMixin
- dantro.mixins.general module
ForwardAttrsMixinForwardAttrsMixin.FORWARD_ATTR_TOForwardAttrsMixin.FORWARD_ATTR_ONLYForwardAttrsMixin.FORWARD_ATTR_EXCLUDEForwardAttrsMixin.__getstate__()ForwardAttrsMixin.__setstate__()ForwardAttrsMixin.__getattr__()ForwardAttrsMixin._forward_attr_pre_hook()ForwardAttrsMixin._forward_attr_get_forwarding_target()ForwardAttrsMixin._forward_attr_post_hook()
ForwardAttrsToDataMixinForwardAttrsToDataMixin.FORWARD_ATTR_EXCLUDEForwardAttrsToDataMixin.FORWARD_ATTR_ONLYForwardAttrsToDataMixin.__getattr__()ForwardAttrsToDataMixin.__getstate__()ForwardAttrsToDataMixin.__setstate__()ForwardAttrsToDataMixin._forward_attr_get_forwarding_target()ForwardAttrsToDataMixin._forward_attr_post_hook()ForwardAttrsToDataMixin._forward_attr_pre_hook()ForwardAttrsToDataMixin.FORWARD_ATTR_TO
- dantro.mixins.indexing module
IntegerItemAccessMixinPaddedIntegerItemAccessMixinPaddedIntegerItemAccessMixin._PADDED_INT_KEY_WIDTHPaddedIntegerItemAccessMixin._PADDED_INT_FSTRPaddedIntegerItemAccessMixin._PADDED_INT_STRICT_CHECKINGPaddedIntegerItemAccessMixin._PADDED_INT_MAX_VALPaddedIntegerItemAccessMixin.__contains__()PaddedIntegerItemAccessMixin.__delitem__()PaddedIntegerItemAccessMixin.__getitem__()PaddedIntegerItemAccessMixin.__setitem__()PaddedIntegerItemAccessMixin.padded_int_key_widthPaddedIntegerItemAccessMixin._parse_key()PaddedIntegerItemAccessMixin._check_cont()
- dantro.mixins.numeric module
UnaryOperationsMixinNumbersMixinNumbersMixin.__add__()NumbersMixin.__sub__()NumbersMixin.__mul__()NumbersMixin.__truediv__()NumbersMixin.__floordiv__()NumbersMixin.__mod__()NumbersMixin.__divmod__()NumbersMixin.__pow__()NumbersMixin.__iadd__()NumbersMixin.__isub__()NumbersMixin.__imul__()NumbersMixin.__itruediv__()NumbersMixin.__ifloordiv__()NumbersMixin.__imod__()NumbersMixin.__ipow__()NumbersMixin.__abs__()NumbersMixin.__ceil__()NumbersMixin.__floor__()NumbersMixin.__invert__()NumbersMixin.__neg__()NumbersMixin.__pos__()NumbersMixin.__round__()NumbersMixin.__trunc__()
ComparisonMixinget_data()apply_func_to_copy()apply_func_inplace()
- dantro.mixins.proxy_support module
ProxySupportMixinProxySupportMixin.DATA_ALLOW_PROXYProxySupportMixin.PROXY_RESOLVE_ASTYPEProxySupportMixin.PROXY_RETAINProxySupportMixin.PROXY_REINSTATE_FAIL_ACTIONProxySupportMixin.PROXY_REINSTATE_FOR_PICKLINGProxySupportMixin._retained_proxyProxySupportMixin.__getstate__()ProxySupportMixin.dataProxySupportMixin.data_is_proxyProxySupportMixin.proxyProxySupportMixin.reinstate_proxy()ProxySupportMixin._format_info()
Hdf5ProxySupportMixinHdf5ProxySupportMixin.dtypeHdf5ProxySupportMixin.DATA_ALLOW_PROXYHdf5ProxySupportMixin.PROXY_REINSTATE_FAIL_ACTIONHdf5ProxySupportMixin.PROXY_REINSTATE_FOR_PICKLINGHdf5ProxySupportMixin.PROXY_RESOLVE_ASTYPEHdf5ProxySupportMixin.PROXY_RETAINHdf5ProxySupportMixin.__getstate__()Hdf5ProxySupportMixin._format_info()Hdf5ProxySupportMixin._retained_proxyHdf5ProxySupportMixin.dataHdf5ProxySupportMixin.data_is_proxyHdf5ProxySupportMixin.proxyHdf5ProxySupportMixin.reinstate_proxy()Hdf5ProxySupportMixin.shapeHdf5ProxySupportMixin.ndimHdf5ProxySupportMixin.sizeHdf5ProxySupportMixin.chunks
- dantro.plot package
- Subpackages
- Submodules
- dantro.plot._cfg module
- dantro.plot.plot_helper module
temporarily_changed_axis_coords_match()PlotHelperPlotHelper._SPECIAL_CFG_KEYSPlotHelper._FIGURE_HELPERSPlotHelper.__init__()PlotHelper._axis_cfgPlotHelper.axis_cfgPlotHelper.base_cfgPlotHelper.figPlotHelper.axPlotHelper.ax_coordsPlotHelper.axesPlotHelper.available_helpersPlotHelper.enabled_helpersPlotHelper.enabled_figure_helpersPlotHelper.out_pathPlotHelper.animation_enabledPlotHelper.animation_updatePlotHelper.invoke_before_grabPlotHelper.raise_on_errorPlotHelper.axis_handles_labelsPlotHelper.all_handles_labelsPlotHelper.axis_is_emptyPlotHelper.attach_figure_and_axes()PlotHelper.setup_figure()PlotHelper.save_figure()PlotHelper.close_figure()PlotHelper.select_axis()PlotHelper.coords_iter()PlotHelper._invoke_helper()PlotHelper.invoke_helper()PlotHelper.invoke_helpers()PlotHelper.invoke_enabled()PlotHelper.provide_defaults()PlotHelper.mark_enabled()PlotHelper.mark_disabled()PlotHelper.track_handles_labels()PlotHelper.register_animation_update()PlotHelper.enable_animation()PlotHelper.disable_animation()PlotHelper._compile_axis_specific_cfg()PlotHelper._raise_on_invalid_helper_name()PlotHelper._handle_errors()PlotHelper._find_axis_coords()PlotHelper._hlpr_align_labels()PlotHelper._hlpr_set_suptitle()PlotHelper._hlpr_set_figlegend()PlotHelper._hlpr_subplots_adjust()PlotHelper._hlpr_figcall()PlotHelper._hlpr_autofmt_xdate()PlotHelper._hlpr_set_title()PlotHelper._hlpr_set_labels()PlotHelper._hlpr_set_limits()PlotHelper._hlpr_set_margins()PlotHelper._hlpr_set_legend()PlotHelper._hlpr_set_texts()PlotHelper._hlpr_annotate()PlotHelper._hlpr_set_hv_lines()PlotHelper._hlpr_set_scales()PlotHelper._hlpr_set_ticks()PlotHelper._hlpr_set_tick_locators()PlotHelper._hlpr_set_tick_formatters()PlotHelper._hlpr_call()PlotHelper._hlpr_despine()
- dantro.proxy package
- dantro.utils package
- Submodules
- dantro.utils.coords module
- dantro.utils.link module
LinkLink._REF_TYPELink.FORWARD_ATTR_TOLink.__init__()Link.__eq__()Link.target_weakrefLink.target_objectLink.anchor_weakrefLink.anchor_objectLink.target_rel_pathLink.__resolve_target_ref()Link._forward_attr_get_forwarding_target()Link.FORWARD_ATTR_EXCLUDELink.FORWARD_ATTR_ONLYLink.__getattr__()Link.__getstate__()Link.__setstate__()Link._forward_attr_post_hook()Link._forward_attr_pre_hook()
_strongrefStrongLinkStrongLink.FORWARD_ATTR_EXCLUDEStrongLink.FORWARD_ATTR_ONLYStrongLink.FORWARD_ATTR_TOStrongLink.__eq__()StrongLink.__getattr__()StrongLink.__getstate__()StrongLink.__init__()StrongLink.__setstate__()StrongLink._forward_attr_get_forwarding_target()StrongLink._forward_attr_post_hook()StrongLink._forward_attr_pre_hook()StrongLink.anchor_objectStrongLink.anchor_weakrefStrongLink.target_objectStrongLink.target_rel_pathStrongLink.target_weakrefStrongLink._REF_TYPE
- dantro.utils.nx module
- dantro.utils.ordereddict module
KeyOrderedDictKeyOrderedDict.__num_comparisonsKeyOrderedDict.DEFAULT_KEY_COMPARATOR()KeyOrderedDict.__init__()KeyOrderedDict._key_comp_lt()KeyOrderedDict.__setitem__()KeyOrderedDict.insert()KeyOrderedDict.__find_element_to_insert_after()KeyOrderedDict._num_comparisonsKeyOrderedDict.__delitem__()KeyOrderedDict.__iter__()KeyOrderedDict.__reversed__()KeyOrderedDict.clear()KeyOrderedDict.__sizeof__()KeyOrderedDict.update()KeyOrderedDict.__update()KeyOrderedDict.keys()KeyOrderedDict.items()KeyOrderedDict.values()KeyOrderedDict.__markerKeyOrderedDict.pop()KeyOrderedDict.setdefault()KeyOrderedDict.__reduce__()KeyOrderedDict.copy()KeyOrderedDict.fromkeys()KeyOrderedDict.__eq__()KeyOrderedDict.get()KeyOrderedDict.popitem()
IntOrderedDictIntOrderedDict.DEFAULT_KEY_COMPARATOR()IntOrderedDict.__delitem__()IntOrderedDict.__eq__()IntOrderedDict.__init__()IntOrderedDict.__iter__()IntOrderedDict.__reduce__()IntOrderedDict.__reversed__()IntOrderedDict.__setitem__()IntOrderedDict.__sizeof__()IntOrderedDict._key_comp_lt()IntOrderedDict._num_comparisonsIntOrderedDict.clear()IntOrderedDict.copy()IntOrderedDict.fromkeys()IntOrderedDict.get()IntOrderedDict.insert()IntOrderedDict.items()IntOrderedDict.keys()IntOrderedDict.pop()IntOrderedDict.popitem()IntOrderedDict.setdefault()IntOrderedDict.update()IntOrderedDict.values()
Submodules#
dantro._copy module#
Custom, optimized copying functions used thoughout dantro
- _shallowcopy(x)#
An alias for a shallow copy function used throughout dantro, currently pointing to
copy.copy().
- _deepcopy(obj: Any) Any[source]#
A pickle-based deep-copy overload, that uses
copy.deepcopy()only as a fallback option if serialization was not possible.Calls
pickle.loads()on the output ofpickle.dumps()of the given object.The pickling approach being based on a C implementation, this can easily be many times faster than the pure-Python-based
copy.deepcopy().
dantro._dag_utils module#
Private low-level helper classes and functions used in dantro.dag.
For more information, see data transformation framework.
- class Placeholder(data: Any)[source]#
Bases:
objectA generic placeholder class for use in the data transformation framework.
Objects of this class or derived classes are yaml-representable and thus hashable after a parent object created a YAML representation. In addition, the
__hash__()method can be used to generate a “hash” that is implemented simply via the string representation of this object.There are a number of derived classes that play a role as providing references within the
TransformationDAG:DAGReference,DAGTag, andDAGNode.In the context of meta operations, there are placeholder classes for positional and keyword arguments:
PositionalArgumentandKeywordArgument.- _data#
- __eq__(other) bool[source]#
Only objects with exactly the same type and data are regarded as equal; specifically, this makes instances of subclasses always unequal to instances of this base class.
- yaml_tag = '!dag_placeholder'#
- classmethod to_yaml(representer, node)[source]#
Create a YAML representation of a Placeholder, carrying only the
_dataattribute over…As YAML expects scalar data to be str-like, a type cast is done. The subclasses that rely on certain argument types should take care that their
__init__method can parse arguments that are str-like.
- class ResultPlaceholder(data: Any)[source]#
Bases:
PlaceholderA placeholder class for a data transformation result.
This is used in the plotting framework to inject data transformation results into plot arguments.
- yaml_tag = '!dag_result'#
- __eq__(other) bool#
Only objects with exactly the same type and data are regarded as equal; specifically, this makes instances of subclasses always unequal to instances of this base class.
- _data#
- classmethod from_yaml(constructor, node)#
Construct a Placeholder from a scalar YAML node
- classmethod to_yaml(representer, node)#
Create a YAML representation of a Placeholder, carrying only the
_dataattribute over…As YAML expects scalar data to be str-like, a type cast is done. The subclasses that rely on certain argument types should take care that their
__init__method can parse arguments that are str-like.
- resolve_placeholders(d: dict, *, dag: TransformationDAG, Cls: type = <class 'dantro._dag_utils.ResultPlaceholder'>, **compute_kwargs) dict[source]#
Recursively replaces placeholder objects throughout the given dict.
Computes
TransformationDAGresults and replaces the placeholder objects with entries from the results dict, thereby making it possible to compute configuration values using results of the data transformation framework <dag_framework>, for example as done in the plotting framework; see Using data transformation results in the plot configuration.Warning
While this function has a return value, it resolves the placeholders in-place, such that the given
dwill be mutated even if the return value is ignored on the calling site.- Parameters:
d (dict) – The object to replace placeholders in. Will recursively walk through all dict- and list-like objects to find placeholders.
dag (TransformationDAG) – The data transformation tree to resolve the placeholders’ results from.
Cls (type, optional) – The expected type of the placeholders.
**compute_kwargs – Passed on to
compute().
- class PlaceholderWithFallback(data: Any, *args)[source]#
Bases:
PlaceholderA class expanding
Placeholderthat adds the ability to read and store a fallback value.- _fallback#
- _has_fallback#
- classmethod from_yaml(constructor, node)[source]#
Constructs a placeholder object from a YAML node.
For a sequence node, will interpret it as (data, fallback). With a scalar node, will not have a fallback.
- classmethod to_yaml(representer, node)[source]#
Create a YAML representation of a Placeholder, creating a sequence representation in case a fallback value was defined.
- __eq__(other) bool#
Only objects with exactly the same type and data are regarded as equal; specifically, this makes instances of subclasses always unequal to instances of this base class.
- _data#
- yaml_tag = '!dag_placeholder'#
- class PositionalArgument(pos: int, *args)[source]#
Bases:
PlaceholderWithFallbackA PositionalArgument is a placeholder that holds as payload a positional argument’s position. This is used, e.g., for meta-operation specification.
- yaml_tag = '!arg'#
- __eq__(other) bool#
Only objects with exactly the same type and data are regarded as equal; specifically, this makes instances of subclasses always unequal to instances of this base class.
- _data#
- _fallback#
- _has_fallback#
- classmethod from_yaml(constructor, node)#
Constructs a placeholder object from a YAML node.
For a sequence node, will interpret it as (data, fallback). With a scalar node, will not have a fallback.
- classmethod to_yaml(representer, node)#
Create a YAML representation of a Placeholder, creating a sequence representation in case a fallback value was defined.
- class KeywordArgument(name: str, *args)[source]#
Bases:
PlaceholderWithFallbackA KeywordArgument is a placeholder that holds as payload the name of a keyword argument. This is used, e.g., for meta-operation specification.
- yaml_tag = '!kwarg'#
- __eq__(other) bool#
Only objects with exactly the same type and data are regarded as equal; specifically, this makes instances of subclasses always unequal to instances of this base class.
- _data#
- _fallback#
- _has_fallback#
- classmethod from_yaml(constructor, node)#
Constructs a placeholder object from a YAML node.
For a sequence node, will interpret it as (data, fallback). With a scalar node, will not have a fallback.
- classmethod to_yaml(representer, node)#
Create a YAML representation of a Placeholder, creating a sequence representation in case a fallback value was defined.
- class DAGReference(ref: str)[source]#
Bases:
PlaceholderThe DAGReference class is the base class of all DAG reference objects. It extends the generic Placeholder class with the ability to resolve references within a
TransformationDAG.- yaml_tag = '!dag_ref'#
- _data#
- _resolve_ref(*, dag: TransformationDAG) str[source]#
Return the hash reference; for the base class, the data is already the hash reference, so no DAG is needed. Derived classes _might_ need the DAG to resolve their reference hash.
- convert_to_ref(*, dag: TransformationDAG) DAGReference[source]#
Create a new object that is a hash ref to the same object this tag refers to.
- resolve_object(*, dag: TransformationDAG) Any[source]#
Resolve the object by looking up the reference in the DAG’s object database.
- __eq__(other) bool#
Only objects with exactly the same type and data are regarded as equal; specifically, this makes instances of subclasses always unequal to instances of this base class.
- classmethod from_yaml(constructor, node)#
Construct a Placeholder from a scalar YAML node
- classmethod to_yaml(representer, node)#
Create a YAML representation of a Placeholder, carrying only the
_dataattribute over…As YAML expects scalar data to be str-like, a type cast is done. The subclasses that rely on certain argument types should take care that their
__init__method can parse arguments that are str-like.
- class DAGTag(name: str)[source]#
Bases:
DAGReferenceA DAGTag object stores a name of a tag, which serves as a named reference to some object in the DAG.
- yaml_tag = '!dag_tag'#
- _data#
- _resolve_ref(*, dag: TransformationDAG) str[source]#
Return the hash reference by looking up the tag in the DAG
- __eq__(other) bool#
Only objects with exactly the same type and data are regarded as equal; specifically, this makes instances of subclasses always unequal to instances of this base class.
- convert_to_ref(*, dag: TransformationDAG) DAGReference#
Create a new object that is a hash ref to the same object this tag refers to.
- classmethod from_yaml(constructor, node)#
Construct a Placeholder from a scalar YAML node
- resolve_object(*, dag: TransformationDAG) Any#
Resolve the object by looking up the reference in the DAG’s object database.
- classmethod to_yaml(representer, node)#
Create a YAML representation of a Placeholder, carrying only the
_dataattribute over…As YAML expects scalar data to be str-like, a type cast is done. The subclasses that rely on certain argument types should take care that their
__init__method can parse arguments that are str-like.
- class DAGMetaOperationTag(name: str)[source]#
Bases:
DAGTagA DAGMetaOperationTag stores a name of a tag, just as DAGTag, but can only be used inside a meta-operation. When resolving this tag’s reference, the target is looked up from the stack of the TransformationDAG.
- yaml_tag = '!mop_tag'#
- SPLIT_STR: str = '::'#
The string by which to split off the meta-operation name from the fully qualified tag name.
- __init__(name: str)[source]#
Initialize the DAGMetaOperationTag object.
The
nameneeds to be of the<meta-operation name>::<tag name>pattern and thereby include information on the name of the meta-operation this tag is used in.
- _data#
- _resolve_ref(*, dag: TransformationDAG) str[source]#
Return the hash reference by looking it up in the reference stacks of the specified TransformationDAG. The last entry always refers to the currently active meta-operation.
- classmethod make_name(meta_operation: str, *, tag: str) str[source]#
Given a meta-operation name and a tag name, generates the name of this meta-operation tag.
- classmethod from_names(meta_operation: str, *, tag: str) DAGMetaOperationTag[source]#
Generates a DAGMetaOperationTag using the names of a meta-operation and the name of a tag.
- __eq__(other) bool#
Only objects with exactly the same type and data are regarded as equal; specifically, this makes instances of subclasses always unequal to instances of this base class.
- convert_to_ref(*, dag: TransformationDAG) DAGReference#
Create a new object that is a hash ref to the same object this tag refers to.
- classmethod from_yaml(constructor, node)#
Construct a Placeholder from a scalar YAML node
- resolve_object(*, dag: TransformationDAG) Any#
Resolve the object by looking up the reference in the DAG’s object database.
- classmethod to_yaml(representer, node)#
Create a YAML representation of a Placeholder, carrying only the
_dataattribute over…As YAML expects scalar data to be str-like, a type cast is done. The subclasses that rely on certain argument types should take care that their
__init__method can parse arguments that are str-like.
- class DAGNode(idx: int)[source]#
Bases:
DAGReferenceA DAGNode is a reference by the index within the DAG’s node list.
- yaml_tag = '!dag_node'#
- _data#
- _resolve_ref(*, dag: TransformationDAG) str[source]#
Return the hash reference by looking up the node index in the DAG
- __eq__(other) bool#
Only objects with exactly the same type and data are regarded as equal; specifically, this makes instances of subclasses always unequal to instances of this base class.
- convert_to_ref(*, dag: TransformationDAG) DAGReference#
Create a new object that is a hash ref to the same object this tag refers to.
- classmethod from_yaml(constructor, node)#
Construct a Placeholder from a scalar YAML node
- resolve_object(*, dag: TransformationDAG) Any#
Resolve the object by looking up the reference in the DAG’s object database.
- classmethod to_yaml(representer, node)#
Create a YAML representation of a Placeholder, carrying only the
_dataattribute over…As YAML expects scalar data to be str-like, a type cast is done. The subclasses that rely on certain argument types should take care that their
__init__method can parse arguments that are str-like.
- class DAGObjects[source]#
Bases:
objectAn objects database for the DAG framework.
It uses a flat dict containing (hash, object ref) pairs. The interface is slightly restricted compared to a regular dict; especially, item deletion is not made available.
Objects are added to the database via the
add_objectmethod. They need to have ahashstrproperty, which returns a hash string deterministically representing the object; note that this is not equivalent to the Python builtinhash()function which invokes the magic__hash__method of an object.- add_object(obj, *, custom_hash: str | None = None) str[source]#
Add an object to the object database, storing it under its hash.
Note that the object cannot be just any object that is hashable but it needs to return a string-based hash via the
hashstrproperty. This is a dantro DAG framework-internal interface.Also note that the object will NOT be added if an object with the same hash is already present. The object itself is of no importance, only the returned hash is.
- Parameters:
obj – Some object that has the
hashstrproperty, i.e. is hashable as required by the DAG interfacecustom_hash (str, optional) – A custom hash to use instead of the hash extracted from
obj. Can only be given whenobjdoes not have ahashstrproperty.
- Returns:
- The hash string of the given object. If a custom hash string
was given, it is also the return value
- Return type:
- Raises:
TypeError – When attempting to pass
custom_hashwhileobjhas ahashstrpropertyValueError – If the given
custom_hashalready exists.
- parse_dag_minimal_syntax(params: str | dict, *, with_previous_result: bool = True) dict[source]#
Parses the minimal syntax parameters, effectively translating a string- like argument to a dict with the string specified as the
operationkey.
- parse_dag_syntax(*, operation: str | None = None, args: list | None = None, kwargs: dict | None = None, tag: str | None = None, force_compute: bool | None = None, with_previous_result: bool = False, salt: int | None = None, memory_cache: bool | None = None, file_cache: dict | None = None, ignore_hooks: bool = False, allow_failure: bool | str | None = None, fallback: Any | None = None, context: dict | None = None, **ops) dict[source]#
Given the parameters of a transform operation, possibly in a shorthand notation, returns a dict with normalized content by expanding the shorthand notation. The return value is then suited to initialize a
Transformationobject.- Keys that will always be available in the resulting dict:
operation,args,kwargs,tag.- Optionally available keys:
salt,file_cache,allow_failure,fallback,context.
- Parameters:
operation (str, optional) – Which operation to carry out; can only be specified if there is no
opsargument.args (list, optional) – Positional arguments for the operation; can only be specified if there is no
opsargument.kwargs (dict, optional) – Keyword arguments for the operation; can only be specified if there is no
opsargument.tag (str, optional) – The tag to attach to this transformation
force_compute (bool, optional) – Whether to force computation for this node.
with_previous_result (bool, optional) – Whether the result of the previous transformation is to be used as first positional argument of this transformation.
salt (int, optional) – A salt to the Transformation object, thereby changing its hash.
file_cache (dict, optional) – File cache parameters
ignore_hooks (bool, optional) – If True, there will be no lookup in the operation hooks. See DAG Syntax Operation Hooks for more info.
allow_failure (Union[bool, str], optional) – Whether this Transformation allows failure during computation. See Error Handling.
fallback (Any, optional) – The fallback value to use in case of failure.
context (dict, optional) – Context information, which may be a dict containing any form of data and which is carried through to the
contextattribute.**ops – The operation that is to be carried out. May contain one and only one operation where the key refers to the name of the operation and the value refers to positional or keyword arguments, depending on type.
- Returns:
- The normalized dict of transform parameters, suitable for
initializing a
Transformationobject.
- Return type:
- Raises:
ValueError – For invalid notation, e.g. unambiguous specification of arguments or the operation.
dantro._hash module#
This module implements a deterministic hash function to use within dantro.
It is mainly used for all things related to the TransformationDAG.
dantro._import_tools module#
Tools for module importing, e.g. lazy imports.
- class added_sys_path(path: str)[source]#
Bases:
objectA
sys.pathcontext manager temporarily adding a path and removing it again upon exiting. If the given path already exists in :py:data`sys.path`, it is neither added nor removed and :py:data`sys.path` remains unchanged.Todo
Expand to allow multiple paths being added
- class temporary_sys_modules(*, reset_only_on_fail: bool = False)[source]#
Bases:
objectA context manager for the
sys.modulescache, ensuring that it is in the same state after exiting as it was before entering the context.Note
This works solely on module names, not on the module objects! If a module object itself is overwritten, this context manager is not able to discern that as long as the key does not change.
- __init__(*, reset_only_on_fail: bool = False)[source]#
Set up the context manager for a temporary
sys.modulescache.- Parameters:
reset_only_on_fail (bool, optional) – If True, will reset the cache only in case the context is exited with an exception.
- get_resource_path(mod: str | ModuleType, path: str) str[source]#
Returns a path of a resource within a specified module.
- get_from_module(mod: ModuleType, *, name: str)[source]#
Retrieves an attribute from a module, if necessary traversing along the module string.
- Parameters:
mod (ModuleType) – Module to start looking at
name (str) – The
.-separated module string leading to the desired object.
- import_module_or_object(module: str | None = None, name: str | None = None, *, package: str = 'dantro') Any[source]#
Imports a module or an object using the specified module string and the object name. Uses
importlib.import_module()to retrieve the module and then usesget_from_module()for getting thenamefrom that module (if given).- Parameters:
module (str, optional) – A module string, e.g.
numpy.random. If this is not given, it will import from the :py:mod`builtins` module. If this is a relative module string, will resolve starting frompackage.name (str, optional) – The name of the object to retrieve from the chosen module and return. This may also be a dot-separated sequence of attribute names which can be used to traverse along attributes, which uses
get_from_module().package (str, optional) – Where to import from if
modulewas a relative module string, e.g..data_mngr, which would lead to resolving the module from<package><module>.
- Returns:
- The chosen module or object, i.e. the object found at
<module>.<name>
- Return type:
Any
- Raises:
AttributeError – In cases where part of the
nameargument could not be resolved due to a bad attribute name.
- import_name(modstr: str)[source]#
Given a module string, import a name, treating the last segment of the module string as the name.
Note
If the last segment of
modstris not the name, useimport_module_or_object()instead of this function.- Parameters:
modstr (str) – A module string, e.g.
numpy.random.randint, whererandintwill be the name to import.
- import_module_from_path(*, mod_path: str, mod_str: str, debug: bool = True) None | ModuleType[source]#
Helper function to import a module that is importable only when adding the module’s parent directory to
sys.path.Note
The
mod_pathdirectory needs to contain an__init__.pyfile. If that is not the case, you cannot use this function, because the directory does not represent a valid Python module.Alternatively, a single file can be imported as a module using
import_module_from_file().- Parameters:
mod_path (str) – Path to the module’s root directory,
~expandedmod_str (str) – Name under which the module can be imported with
mod_pathbeing insys.path. This is also used to add the module to thesys.modulescache.debug (bool, optional) – Whether to raise exceptions if import failed
- Returns:
- The imported module or None, if importing
failed and
debugevaluated to False.
- Return type:
Union[None, ModuleType]
- Raises:
ImportError – If
debugis set and import failed for whatever reasonFileNotFoundError – If
mod_pathdid not point to an existing directory
- import_module_from_file(mod_file: str, *, base_dir: str | None = None, mod_name_fstr: str = 'from_file.{filename:}') ModuleType[source]#
Returns the module corresponding to the file at the given
mod_file.This uses
importlib.util.spec_from_file_location()andimportlib.util.module_from_spec()to construct a module from the given file, regardless of whether there is a__init__.pyfile beside the file or not.- Parameters:
- Returns:
The imported module
- Return type:
ModuleType
- Raises:
ValueError – If
mod_filewas a relative path but nobase_dirwas given.
- class LazyLoader(mod_name: str, *, _depth: int = 0)[source]#
Bases:
objectDelays import until the module’s attributes are accessed.
This is inspired by an implementation by Dboy Liao, see here.
It extends on it by allowing a
depthuntil which loading will be lazy.- __init__(mod_name: str, *, _depth: int = 0)[source]#
Initialize a placeholder for a module.
Warning
Values of
_depth > 0may lead to unexpected behaviour of the root module, i.e. this object, because attribute calls do not yield an actual object. Only use this in scenarios where you are in full control over the attribute calls.We furthermore suggest to not make the LazyLoader instance publicly available in such cases.
- Parameters:
- resolve_lazy_imports(d: dict, *, recursive: bool = True) dict[source]#
In-place resolves lazy imports in the given dict, recursively.
Warning
Only recurses on dicts, not on other mutable objects!
- remove_from_sys_modules(cond: Callable)[source]#
Removes cached module imports from
sys.modulesif their fully qualified module name fulfills a certain condition.- Parameters:
cond (Callable) – A unary function expecting a single
strargument, the module name, e.g.numpy.random. If the function returns True, will remove that module.
dantro._registry module#
Implements an object registry that can be specialized for certain use cases, e.g. to store all available container types.
- class ObjectRegistry[source]#
Bases:
object- __contains__(obj_or_key: Any | str) bool[source]#
Whether the given argument is part of the keys or values of this registry.
- _determine_name(obj: Any, *, name: str | None) str[source]#
Determines the object name, using a potentially given name
- _check_object(obj: Any) None[source]#
Checks whether the object is valid. If not, raises
InvalidRegistryEntry.
- register(obj: Any, name: str | None = None, *, skip_existing: bool | None = None, overwrite_existing: bool | None = None) str[source]#
Adds an entry to the registry.
- Parameters:
obj (Any) – The object to add to the registry.
name (Optional[str], optional) – The name to use. If not given, will deduce a name from the given object.
skip_existing (bool, optional) – Whether to skip registration if an object of that name already exists. If None, the classes default behavior (see
_SKIP) is used.overwrite_existing (bool, optional) – Whether to overwrite an entry if an object with that name already exists. If None, the classes default behavior (see
_OVERWRITE) is used.
- _register_via_decorator(obj, name: str | None = None, **kws)[source]#
Performs the registration operations when the decorator is used to register an object.
- _decorator(arg: Any | str | None = None, /, **kws)[source]#
Method that can be used as a decorator for registering objects with this registry.
- Parameters:
arg (Union[Any, str], optional) – The name that should be used or the object that is to be added. If not a string, this refers to the
@is_containercall syntax**kws – Passed to
register()
dantro._yaml module#
Takes care of all YAML-related imports and configuration
The ruamel.yaml.YAML object used here is imported from yayaml
and specialized such that it can load and dump dantro classes.
- cmap_constructor(loader, node) Colormap[source]#
Constructs a
matplotlib.colors.Colormapobject for use in plots. Uses theColorManagerand directly resolves the colormap object from it.
- cmap_norm_constructor(loader, node) Colormap[source]#
Constructs a
matplotlib.colors.Colormapobject for use in plots. Uses theColorManagerand directly resolves the colormap object from it.
dantro.abc module#
This module holds the abstract base classes needed for dantro
- PATH_JOIN_CHAR = '/'#
The character used for separating hierarchies in the path
- BAD_NAME_CHARS = ('*', '?', '[', ']', '!', ':', '(', ')', '/', '\\')#
Substrings that may not appear in names of data containers
- class AbstractDataContainer(*, name: str, data: Any, parent: AbstractDataGroup | None = None)[source]#
Bases:
objectThe AbstractDataContainer is the class defining the data container interface. It holds the bare basics of methods and attributes that _all_ dantro data tree classes should have in common: a name, some data, and some association with others via an optional parent object.
Via the parent and the name, path capabilities are provided. Thereby, each object in a data tree has some information about its location relative to a root object. Objects that have no parent are regarded to be an object that is located “next to” root, i.e. having the path
/<container_name>.- abstract __init__(*, name: str, data: Any, parent: AbstractDataGroup | None = None)[source]#
Initialize the AbstractDataContainer, which implements the bare essentials of what a data container should be.
- Parameters:
name (str) – The name of this container
data (Any) – The data that is to be stored
parent (AbstractDataGroup, optional) –
If given, this is supposed to be the parent group for this container.
Note
This will not be used for setting the actual parent! The group takes care of that once the container is added to it.
- property parent#
The associated parent of this container or group
- _check_name(new_name: str) None[source]#
Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters:
new_name (str) – The new name, which is to be checked.
- _check_data(data: Any) None[source]#
This method can be used to check the data provided to this container
It is called before the data is stored in the
__init__method and should raise an exception or create a warning if the data is not as desired.This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using
super().Note
The
CheckDataMixinprovides a generalised implementation of this method to perform some type checks and react to unexpected types.- Parameters:
data (Any) – The data to check
- __str__() str[source]#
An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
- __format__(spec_str: str) str[source]#
Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_.
- _format_logstr() str[source]#
A __format__ helper function: returns the log string, a combination of class name and name
- abstract _format_info() str[source]#
A __format__ helper function: returns an info string that is used to characterise this object. Should NOT include name and classname!
- _abc_impl = <_abc._abc_data object>#
- class AbstractDataGroup(*, name: str, data: Any, parent: AbstractDataGroup | None = None)[source]#
Bases:
AbstractDataContainer,MutableMappingThe AbstractDataGroup is the abstract basis of all data groups.
It enforces a MutableMapping interface with a focus on _setting_ abilities and less so on deletion.
- property data#
The stored data.
- abstract __contains__(cont: str | AbstractDataContainer) bool[source]#
Whether the given container is a member of this group
- abstract get(key, default=None)[source]#
Return the container at key, or default if container with name key is not available.
- abstract setdefault(key, default=None)[source]#
If key is in the dictionary, return its value. If not, insert key with a value of default and return default. default defaults to None.
- abstract _format_tree() str[source]#
A __format__ helper function: tree representation of this group
- abstract _tree_repr(level: int = 0) str[source]#
Recursively creates a multi-line string tree representation of this group. This is used by, e.g., the _format_tree method.
- __format__(spec_str: str) str#
Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_.
- abstract __getitem__(key)#
Gets an item from the container.
- abstract __init__(*, name: str, data: Any, parent: AbstractDataGroup | None = None)#
Initialize the AbstractDataContainer, which implements the bare essentials of what a data container should be.
- Parameters:
name (str) – The name of this container
data (Any) – The data that is to be stored
parent (AbstractDataGroup, optional) –
If given, this is supposed to be the parent group for this container.
Note
This will not be used for setting the actual parent! The group takes care of that once the container is added to it.
- __str__() str#
An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
- _abc_impl = <_abc._abc_data object>#
- _check_data(data: Any) None#
This method can be used to check the data provided to this container
It is called before the data is stored in the
__init__method and should raise an exception or create a warning if the data is not as desired.This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using
super().Note
The
CheckDataMixinprovides a generalised implementation of this method to perform some type checks and react to unexpected types.- Parameters:
data (Any) – The data to check
- _check_name(new_name: str) None#
Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters:
new_name (str) – The new name, which is to be checked.
- abstract _format_info() str#
A __format__ helper function: returns an info string that is used to characterise this object. Should NOT include name and classname!
- _format_logstr() str#
A __format__ helper function: returns the log string, a combination of class name and name
- clear() None. Remove all items from D.#
- property parent#
The associated parent of this container or group
- pop(k[, d]) v, remove specified key and return the corresponding value.#
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair#
as a 2-tuple; but raise KeyError if D is empty.
- update([E, ]**F) None. Update D from mapping/iterable E and F.#
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- class AbstractDataAttrs(*, name: str, data: Any, parent: AbstractDataGroup | None = None)[source]#
Bases:
Mapping,AbstractDataContainerThe BaseDataAttrs class defines the interface for the .attrs attribute of a data container.
This class derives from the abstract class as otherwise there would be circular inheritance. It stores the attributes as mapping and need not be subclassed.
- __format__(spec_str: str) str#
Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_.
- abstract __init__(*, name: str, data: Any, parent: AbstractDataGroup | None = None)#
Initialize the AbstractDataContainer, which implements the bare essentials of what a data container should be.
- Parameters:
name (str) – The name of this container
data (Any) – The data that is to be stored
parent (AbstractDataGroup, optional) –
If given, this is supposed to be the parent group for this container.
Note
This will not be used for setting the actual parent! The group takes care of that once the container is added to it.
- __str__() str#
An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
- _abc_impl = <_abc._abc_data object>#
- _check_data(data: Any) None#
This method can be used to check the data provided to this container
It is called before the data is stored in the
__init__method and should raise an exception or create a warning if the data is not as desired.This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using
super().Note
The
CheckDataMixinprovides a generalised implementation of this method to perform some type checks and react to unexpected types.- Parameters:
data (Any) – The data to check
- _check_name(new_name: str) None#
Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters:
new_name (str) – The new name, which is to be checked.
- abstract _format_info() str#
A __format__ helper function: returns an info string that is used to characterise this object. Should NOT include name and classname!
- _format_logstr() str#
A __format__ helper function: returns the log string, a combination of class name and name
- get(k[, d]) D[k] if k in D, else d. d defaults to None.#
- property parent#
The associated parent of this container or group
- class AbstractDataProxy(obj: Any | None = None)[source]#
Bases:
objectA data proxy fills in for the place of a data container, e.g. if data should only be loaded on demand. It needs to supply the resolve method.
- abstract __init__(obj: Any | None = None)[source]#
Initialize the proxy object, being supplied with the object that this proxy is to be proxy for.
- abstract resolve(*, astype: type | None = None)[source]#
Get the data that this proxy is a placeholder for and return it.
Note that this method does not place the resolved data in the container of which this proxy object is a placeholder for! This only returns the data.
- _abc_impl = <_abc._abc_data object>#
- class AbstractPlotCreator(name: str, *, dm: DataManager, **plot_cfg)[source]#
Bases:
objectThis class defines the interface for PlotCreator classes
- abstract __init__(name: str, *, dm: DataManager, **plot_cfg)[source]#
Initialize the plot creator, given a
DataManager, the plot name, and the default plot configuration.
- abstract __call__(*, out_path: str | None = None, **update_plot_cfg)[source]#
Perform the plot, updating the configuration passed to __init__ with the given values and then calling
plot().This method essentially takes care of parsing the configuration, while
plot()expects parsed arguments.
- _abc_impl = <_abc._abc_data object>#
- abstract plot(*, out_path: str | None = None, **cfg) None[source]#
Given a specific configuration, performs a plot.
To parse plot configuration arguments, use
__call__(), which will call this method.
- abstract prepare_cfg(*, plot_cfg: dict, pspace: ParamSpace) tuple[source]#
Prepares the plot configuration for the plot.
This function is called by the plot manager before the first plot is created.
The base implementation just passes the given arguments through. However, it can be re-implemented by derived classes to change the behaviour of the plot manager, e.g. by converting a plot configuration to a
ParamSpace.
- abstract _prepare_path(out_path: str) str[source]#
Prepares the output path, creating directories if needed, then returning the full absolute path.
This is called from
__call__()and is meant to postpone directory creation as far as possible.
dantro.base module#
This module implements the base classes of dantro, based on the abstract
classes implemented in dantro.abc.
The base classes are classes that combine features of the abstract classes.
For example, the data group gains attribute functionality by being a
combination of the AbstractDataGroup and the
BaseDataContainer. In turn, the BaseDataContainer
uses the BaseDataAttrs class as an attribute and thereby extends
the AbstractDataContainer class.
Note
These classes are not meant to be instantiated but used as a basis to
implement more specialized BaseDataGroup- or
BaseDataContainer-derived classes.
- class BaseDataProxy(obj: Any | None = None)[source]#
Bases:
AbstractDataProxyThe base class for data proxies.
Note
This is still an abstract class and needs to be subclassed.
- _tags: tuple = ()#
Associated tags.
These are empty by default and may also be overwritten in the object.
- _abc_impl = <_abc._abc_data object>#
- class BaseDataAttrs(attrs: Dict[str, Any] | None = None, **dc_kwargs)[source]#
Bases:
MappingAccessMixin,AbstractDataAttrsA class to store attributes that belong to a data container.
This implements a dict-like interface and serves as default attribute class.
Note
Unlike the other base classes, this can already be instantiated. That is required as it is needed in BaseDataContainer where no previous subclassing or mixin is reasonable.
- __init__(attrs: Dict[str, Any] | None = None, **dc_kwargs)[source]#
Initialize a DataAttributes object.
- Parameters:
attrs (Dict[str, Any], optional) – The attributes to store
**dc_kwargs – Further kwargs to the parent DataContainer
- __delitem__(key)#
Deletes an item
- __format__(spec_str: str) str#
Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_.
- __getitem__(key)#
Returns an item.
- __iter__()#
Iterates over the items.
- __setitem__(key, val)#
Sets an item.
- __str__() str#
An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
- _abc_impl = <_abc._abc_data object>#
- _check_data(data: Any) None#
This method can be used to check the data provided to this container
It is called before the data is stored in the
__init__method and should raise an exception or create a warning if the data is not as desired.This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using
super().Note
The
CheckDataMixinprovides a generalised implementation of this method to perform some type checks and react to unexpected types.- Parameters:
data (Any) – The data to check
- _check_name(new_name: str) None#
Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters:
new_name (str) – The new name, which is to be checked.
- _format_logstr() str#
A __format__ helper function: returns the log string, a combination of class name and name
- _item_access_convert_list_key(key)#
If given something that is not a list, just return that key
- get(key, default=None)#
Return the value at
key, ordefaultifkeyis not available.
- items()#
Returns an iterator over data’s
(key, value)tuples
- keys()#
Returns an iterator over the data’s keys.
- property parent#
The associated parent of this container or group
- values()#
Returns an iterator over the data’s values.
- class BaseDataContainer(*, name: str, data: Any, attrs: Dict[str, Any] | None = None, parent: AbstractDataGroup | None = None)[source]#
Bases:
AttrsMixin,SizeOfMixin,BasicComparisonMixin,AbstractDataContainerThe BaseDataContainer extends the abstract base class by the ability to hold attributes and be path-aware.
- _ATTRS_CLS#
The class to use for storing attributes
alias of
BaseDataAttrs
- __init__(*, name: str, data: Any, attrs: Dict[str, Any] | None = None, parent: AbstractDataGroup | None = None)[source]#
Initialize a BaseDataContainer, which can store data and attributes.
- Parameters:
name (str) – The name of this data container
data (Any) – The data to store in this container
attrs (Dict[str, Any], optional) – A mapping that is stored as data attributes.
parent (AbstractDataGroup, optional) – If known, the parent group, which can be used to extract information during initialization. Note that linking occurs only after the container was added to the parent group using the
add()method. The child object is not responsible of linking or adding itself to the group.
- property attrs#
The container attributes.
- _format_info() str[source]#
A __format__ helper function: returns info about the content of this data container.
- __eq__(other) bool#
Evaluates equality by making the following comparisons: identity, strict type equality, and finally: equality of the
_dataand_attrsattributes, i.e. the private attribute. This ensures that comparison does not trigger any downstream effects like resolution of proxies.If types do not match exactly,
NotImplementedis returned, thus referring the comparison to the other side of the==.
- __format__(spec_str: str) str#
Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_.
- abstract __getitem__(key)#
Gets an item from the container.
- __sizeof__() int#
Returns the size of the data (in bytes) stored in this container’s data and its attributes.
Note that this value is approximate. It is computed by calling the
sys.getsizeof()function on the data, the attributes, the name and some caching attributes that each dantro data tree class contains. Importantly, this is not a recursive algorithm.Also, derived classes might implement further attributes that are not taken into account either. To be more precise in a subclass, create a specific __sizeof__ method and invoke this parent method additionally.
- __str__() str#
An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
- _abc_impl = <_abc._abc_data object>#
- _attrs = None#
The attribute that data attributes will be stored to
- _check_data(data: Any) None#
This method can be used to check the data provided to this container
It is called before the data is stored in the
__init__method and should raise an exception or create a warning if the data is not as desired.This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using
super().Note
The
CheckDataMixinprovides a generalised implementation of this method to perform some type checks and react to unexpected types.- Parameters:
data (Any) – The data to check
- _check_name(new_name: str) None#
Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters:
new_name (str) – The new name, which is to be checked.
- _format_logstr() str#
A __format__ helper function: returns the log string, a combination of class name and name
- property parent#
The associated parent of this container or group
- class BaseDataGroup(*, name: str, containers: list | None = None, attrs=None, parent: AbstractDataGroup | None = None)[source]#
Bases:
LockDataMixin,AttrsMixin,SizeOfMixin,BasicComparisonMixin,DirectInsertionModeMixin,AbstractDataGroupThe BaseDataGroup serves as base group for all data groups.
It implements all functionality expected of a group, which is much more than what is expected of a general container.
- _ATTRS_CLS#
Which class to use for storing attributes
alias of
BaseDataAttrs
- _NEW_GROUP_CLS: type = None#
Which class to use when creating a new group via
new_group(). If None, the type of the current instance is used for the new group.
- _NEW_CONTAINER_CLS: type = None#
Which class to use for creating a new container via call to the
new_container()method. If None, the type needs to be specified explicitly in the method call.
- _DATA_GROUP_CLASSES: Dict[str, type] = None#
Mapping from strings to available data group types. Used in string-based lookup of group types in
new_group().
- _DATA_CONTAINER_CLASSES: Dict[str, type] = None#
Mapping from strings to available data container types. Used in string-based lookup of container types in
new_container().
- _ALLOWED_CONT_TYPES: tuple | None = None#
The types that are allowed to be stored in this group. If None, all types derived from the dantro base classes are allowed. This applies to both containers and groups that are added to this group.
Hint
To add the type of the current object, add a string entry
selfto the tuple. This will be resolved totype(self)at invocation.
- _COND_TREE_MAX_LEVEL = 10#
Condensed tree representation maximum level
- _COND_TREE_CONDENSE_THRESH = 10#
Condensed tree representation threshold parameter
- __init__(*, name: str, containers: list | None = None, attrs=None, parent: AbstractDataGroup | None = None)[source]#
Initialize a BaseDataGroup, which can store other containers and attributes.
- Parameters:
name (str) – The name of this data container
containers (list, optional) – The containers that are to be stored as members of this group. If given, these are added one by one using the .add method.
attrs (None, optional) – A mapping that is stored as attributes
parent (AbstractDataGroup, optional) – If known, the parent group, which can be used to extract information during initialization. Note that linking occurs only after the group was added to the parent group, i.e. after initialization finished.
- property attrs#
The container attributes.
- __getitem__(key: str | List[str]) AbstractDataContainer[source]#
Looks up the given key and returns the corresponding item.
This supports recursive relative lookups in two ways:
By supplying a path as a string that includes the path separator. For example,
foo/bar/spamwalks down the tree along the given path segments.By directly supplying a key sequence, i.e. a list or tuple of key strings.
With the last path segment, it is possible to access an element that is no longer part of the data tree; successive lookups thus need to use the interface of the corresponding leaf object of the data tree.
Absolute lookups, i.e. from path
/foo/bar, are not possible!Lookup complexity is that of the underlying data structure: for groups based on dict-like storage containers, lookups happen in constant time.
Note
This method aims to replicate the behavior of POSIX paths.
Thus, it can also be used to access the element itself or the parent element: Use
.to refer to this object and..to access this object’sparent.- Parameters:
key (Union[str, List[str]]) – The name of the object to retrieve or a path via which it can be found in the data tree.
- Returns:
- The object at
key, which concurs to the dantro tree interface.
- The object at
- Return type:
- Raises:
ItemAccessError – If no object could be found at the given
keyor if an absolute lookup, starting with/, was attempted.
- __setitem__(key: str | List[str], val: BaseDataContainer) None[source]#
This method is used to allow access to the content of containers of this group. For adding an element to this group, use the add method!
- Parameters:
key (Union[str, List[str]]) – The key to which to set the value. If this is a path, will recurse down to the lowest level. Note that all intermediate keys need to be present.
val (BaseDataContainer) – The value to set
- Returns:
None
- Raises:
ValueError – If trying to add an element to this group, which should be done via the add method.
- _add_container(cont, *, overwrite: bool)[source]#
Private helper method to add a container to this group.
- _check_cont(cont) None[source]#
Can be used by a subclass to check a container before adding it to this group. Is called by _add_container before checking whether the object exists or not.
This is not expected to return, but can raise errors, if something did not work out as expected.
- Parameters:
cont – The container to check
- _add_container_to_data(cont: AbstractDataContainer) None[source]#
Performs the operation of adding the container to the _data. This can be used by subclasses to make more elaborate things while adding data, e.g. specify ordering …
- NOTE This method should NEVER be called on its own, but only via the
_add_container method, which takes care of properly linking the container that is to be added.
NOTE After adding, the container need be reachable under its .name!
- Parameters:
cont – The container to add
- new_container(path: str | List[str], *, Cls: type | str | None = None, GroupCls: type | str | None = None, _target_is_group: bool = False, **kwargs) BaseDataContainer[source]#
Creates a new container of type
Clsand adds it at the given path relative to this group.If needed, intermediate groups are automatically created.
- Parameters:
Cls (Union[type, str], optional) – The type of the target container (or group) that is to be added. If None, will use the type set in
_NEW_CONTAINER_CLSclass variable. If a string is given, the type is looked up in the container type registry.GroupCls (Union[type, str], optional) – Like
Clsbut used for intermediate group types only._target_is_group (bool, optional) – Internally used variable. If True, will look up the
Clstype via_determine_group_type()instead of_determine_container_type().**kwargs – passed on to
Cls.__init__
- Returns:
The created container of type
Cls- Return type:
- new_group(path: str | List[str], *, Cls: type | str | None = None, GroupCls: type | str | None = None, **kwargs) BaseDataGroup[source]#
Creates a new group at the given path.
- Parameters:
path (Union[str, List[str]]) – The path to create the group at. If necessary, intermediate paths will be created.
Cls (Union[type, str], optional) –
If given, use this type to create the target group. If not given, uses the class specified in the
_NEW_GROUP_CLSclass variable or (if a string) the one from the group type registry.Note
This argument is evaluated at each segment of the
pathby the corresponding object in the tree. Subsequently, the types need to be available at the desiredGroupCls (Union[type, str], optional) – Like
Cls, but this applies only to the creation of intermediate groups.**kwargs – Passed on to
Cls.__init__
- Returns:
The created group of type
Cls- Return type:
- recursive_update(other, *, overwrite: bool = True)[source]#
Recursively updates the contents of this data group with the entries of the given data group
Note
This will create shallow copies of those elements in
otherthat are added to this object.- Parameters:
other (BaseDataGroup) – The group to update with
overwrite (bool, optional) – Whether to overwrite already existing object. If False, a conflict will lead to an error being raised and the update being stopped.
- Raises:
TypeError – If
otherwas of invalid type
- clear()[source]#
Clears all containers from this group.
This is done by unlinking all children and then overwriting
_datawith an empty_STORAGE_CLSobject.
- _determine_container_type(Cls: type | str) type[source]#
Helper function to determine the type to use for a new container.
- Parameters:
Cls (Union[type, str]) – If None, uses the
_NEW_CONTAINER_CLSclass variable. If a string, tries to extract it from the class variable_DATA_CONTAINER_CLASSESdict. Otherwise, assumes this is already a type.- Returns:
The container class to use
- Return type:
- Raises:
ValueError – If the string class name was not registered
AttributeError – If no default class variable was set
- _determine_group_type(Cls: type | str) type[source]#
Helper function to determine the type to use for a new group.
- Parameters:
Cls (Union[type, str]) – If None, uses the
_NEW_GROUP_CLSclass variable. If that one is not set, usestype(self). If a string, tries to extract it from the class variable_DATA_GROUP_CLASSESdict. Otherwise, assumesClsis already a type.- Returns:
The group class to use
- Return type:
- Raises:
ValueError – If the string class name was not registered
AttributeError – If no default class variable was set
- _determine_type(T: type | str, *, default: type, registry: Dict[str, type]) type[source]#
Helper function to determine a type by name, falling back to a default type or looking it up from a dict-like registry if it is a string.
- _link_child(*, new_child: BaseDataContainer, old_child: BaseDataContainer | None = None)[source]#
Links the new_child to this class, unlinking the old one.
This method should be called from any method that changes which items are associated with this group.
- _unlink_child(child: BaseDataContainer)[source]#
Unlink a child from this class.
This method should be called from any method that removes an item from this group, be it through deletion or through
- __contains__(cont: str | AbstractDataContainer) bool[source]#
Whether the given container is in this group or not.
If this is a data tree object, it will be checked whether this specific instance is part of the group, using
is-comparison.Otherwise, assumes that
contis a valid argument to the__getitem__()method (a key or key sequence) and tries to access the item at that path, returningTrueif this succeeds andFalseif not.Lookup complexity is that of item lookup (scalar) for both name and object lookup.
- Parameters:
cont (Union[str, AbstractDataContainer]) – The name of the container, a path, or an object to check via identity comparison.
- Returns:
- Whether the given container object is part of this group or
whether the given path is accessible from this group.
- Return type:
- _ipython_key_completions_() List[str][source]#
For ipython integration, return a list of available keys
- __eq__(other) bool#
Evaluates equality by making the following comparisons: identity, strict type equality, and finally: equality of the
_dataand_attrsattributes, i.e. the private attribute. This ensures that comparison does not trigger any downstream effects like resolution of proxies.If types do not match exactly,
NotImplementedis returned, thus referring the comparison to the other side of the==.
- __format__(spec_str: str) str#
Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_.
- __sizeof__() int#
Returns the size of the data (in bytes) stored in this container’s data and its attributes.
Note that this value is approximate. It is computed by calling the
sys.getsizeof()function on the data, the attributes, the name and some caching attributes that each dantro data tree class contains. Importantly, this is not a recursive algorithm.Also, derived classes might implement further attributes that are not taken into account either. To be more precise in a subclass, create a specific __sizeof__ method and invoke this parent method additionally.
- __str__() str#
An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
- _abc_impl = <_abc._abc_data object>#
- _attrs = None#
The attribute that data attributes will be stored to
- _check_data(data: Any) None#
This method can be used to check the data provided to this container
It is called before the data is stored in the
__init__method and should raise an exception or create a warning if the data is not as desired.This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using
super().Note
The
CheckDataMixinprovides a generalised implementation of this method to perform some type checks and react to unexpected types.- Parameters:
data (Any) – The data to check
- _check_name(new_name: str) None#
Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters:
new_name (str) – The new name, which is to be checked.
- _direct_insertion_mode(*, enabled: bool = True)#
A context manager that brings the class this mixin is used in into direct insertion mode. While in that mode, the
with_direct_insertion()property will return true.This context manager additionally invokes two callback functions, which can be specialized to perform certain operations when entering or exiting direct insertion mode: Before entering,
_enter_direct_insertion_mode()is called. After exiting,_exit_direct_insertion_mode()is called.- Parameters:
enabled (bool, optional) – whether to actually use direct insertion mode. If False, will yield directly without setting the toggle. This is equivalent to a null-context.
- _enter_direct_insertion_mode()#
Called after entering direct insertion mode; can be overwritten to attach additional behaviour.
- _exit_direct_insertion_mode()#
Called before exiting direct insertion mode; can be overwritten to attach additional behaviour.
- _format_logstr() str#
A __format__ helper function: returns the log string, a combination of class name and name
- _lock_hook()#
Invoked upon locking.
- _unlock_hook()#
Invoked upon unlocking.
- property data#
The stored data.
- lock()#
Locks the data of this object
- property parent#
The associated parent of this container or group
- pop(k[, d]) v, remove specified key and return the corresponding value.#
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair#
as a 2-tuple; but raise KeyError if D is empty.
- raise_if_locked(*, prefix: str | None = None)#
Raises an exception if this object is locked; does nothing otherwise
- unlock()#
Unlocks the data of this object
- update([E, ]**F) None. Update D from mapping/iterable E and F.#
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- property with_direct_insertion: bool#
Whether the class this mixin is mixed into is currently in direct insertion mode.
- __locked#
Whether the data is regarded as locked. Note name-mangling here.
- __in_direct_insertion_mode#
A name-mangled state flag that determines the state of the object.
- get(key, default=None)[source]#
Return the container at key, or default if container with name key is not available.
- property tree_condensed: str#
Returns the condensed tree representation of this group. Uses the
_COND_TREE_*prefixed class attributes as parameters.
- _format_info() str[source]#
A __format__ helper function: returns an info string that is used to characterize this object. Does NOT include name and classname!
- _format_tree() str[source]#
Returns the default tree representation of this group by invoking the .tree property
- _format_tree_condensed() str[source]#
Returns the default tree representation of this group by invoking the .tree property
- _tree_repr(*, level: int = 0, max_level: int | None = None, info_fstr='<{:cls_name,info}>', info_ratio: float = 0.6, condense_thresh: int | Callable[[int, int], int] | None = None, total_item_count: int = 0) str | List[str][source]#
Recursively creates a multi-line string tree representation of this group. This is used by, e.g., the _format_tree method.
- Parameters:
level (int, optional) – The depth within the tree
max_level (int, optional) – The maximum depth within the tree; recursion is not continued beyond this level.
info_fstr (str, optional) – The format string for the info string
info_ratio (float, optional) – The width ratio of the whole line width that the info string takes
condense_thresh (Union[int, Callable[[int, int], int]], optional) – If given, this specifies the threshold beyond which the tree view for the current element becomes condensed by hiding the output for some elements. The minimum value for this is 3, indicating that there should be at most 3 lines be generated from this level (excluding the lines coming from recursion), i.e.: two elements and one line for indicating how many values are hidden. If a smaller value is given, this is silently brought up to 3. Half of the elements are taken from the beginning of the item iteration, the other half from the end. If given as integer, that number is used. If a callable is given, the callable will be invoked with the current level, number of elements to be added at this level, and the current total item count along this recursion branch. The callable should then return the number of lines to be shown for the current element.
total_item_count (int, optional) – The total number of items already created in this recursive tree representation call. Passed on between recursive calls.
- Returns:
- The (multi-line) tree representation of
this group. If this method was invoked with
level == 0, a string will be returned; otherwise, a list of strings will be returned.
- Return type:
dantro.dag module#
This is an implementation of a DAG for transformations on dantro objects. It revolves around two main classes:
Transformationthat represents a data transformation.TransformationDAGthat aggregates those transformations into a directed acyclic graph.
For more information, see data transformation framework.
- DAG_CACHE_DM_PATH: str = 'cache/dag'#
The path within the
TransformationDAGassociatedDataManagerto which caches are loaded
- DAG_CACHE_CONTAINER_TYPES_TO_UNPACK: Tuple[Type, ...] = (<class 'dantro.containers.general.ObjectContainer'>, <class 'dantro.containers.xr.XrDataContainer'>)#
Types of containers that should be unpacked after loading from cache because having them wrapped into a dantro object is not desirable after loading them from cache (e.g. because the name attribute is shadowed by tree objects …)
- DAG_CACHE_RESULT_SAVE_FUNCS: Dict[Tuple[Type, ...], Callable] = {('xarray.DataArray',): <function <lambda>>, ('xarray.Dataset',): <function <lambda>>, (<class 'dantro.containers.numeric.NumpyDataContainer'>,): <function <lambda>>, (<class 'dantro.containers.xr.XrDataContainer'>,): <function <lambda>>, (<class 'numpy.ndarray'>,): <function <lambda>>}#
Functions that can store the DAG computation result objects, distinguishing by their type.
- class Transformation(*, operation: str, args: Sequence[DAGReference | Any], kwargs: Dict[str, DAGReference | Any], dag: TransformationDAG | None = None, salt: int | None = None, allow_failure: bool | str | None = None, fallback: Any | None = None, memory_cache: bool = True, file_cache: bool | dict | None = None, context: dict | None = None)[source]#
Bases:
objectA transformation is the collection of an N-ary operation and its inputs.
Transformation objects store the name of the operation that is to be carried out and the arguments that are to be fed to that operation. After a Transformation is defined, the only interaction with them is via the
compute()method.For computation, the arguments are recursively inspected for whether there are any DAGReference-derived objects; these need to be resolved first, meaning they are looked up in the DAG’s object database and – if they are another Transformation object – their result is computed. This can lead to a traversal along the DAG.
Warning
Objects of this class should under no circumstances be changed after they were created! For performance reasons, the
hashstrproperty is cached; thus, changing attributes that are included into the hash computation will not lead to a new hash, hence silently creating wrong behaviour.All relevant attributes (
operation,args,kwargs,salt) are thus set read-only. This should be respected!- __init__(*, operation: str, args: Sequence[DAGReference | Any], kwargs: Dict[str, DAGReference | Any], dag: TransformationDAG | None = None, salt: int | None = None, allow_failure: bool | str | None = None, fallback: Any | None = None, memory_cache: bool = True, file_cache: bool | dict | None = None, context: dict | None = None)[source]#
Initialize a Transformation object.
- Parameters:
operation (str) – The operation that is to be carried out.
args (Sequence[Union[DAGReference, Any]]) – Positional arguments for the operation.
kwargs (Dict[str, Union[DAGReference, Any]]) – Keyword arguments for the operation. These are internally stored as a
KeyOrderedDict.dag (TransformationDAG, optional) – An associated DAG that is needed for object lookup. Without an associated DAG, args or kwargs may NOT contain any object references.
salt (int, optional) – A hashing salt that can be used to let this specific Transformation object have a different hash than other objects, thus leading to cache misses.
allow_failure (Union[bool, str], optional) – Whether the computation of this operation or its arguments may fail. In case of failure, the
fallbackvalue is used. IfTrueor'log', will emit a log message upon failure. If'warn', will issue a warning. If'silent', will use the fallback without any notification of failure. Note that the failure may occur not only during computation of this transformation’s operation, but also during the recursive computation of the referenced arguments. In other words, if the computation of an upstream dependency failed, the fallback will be used as well.fallback (Any, optional) – If
allow_failurewas set, specifies the alternative value to use for this operation. This may in turn be a reference to another DAG node.memory_cache (bool, optional) – Whether to use the memory cache. If false, will re-compute results each time if the result is not read from the file cache.
file_cache (dict, optional) –
File cache options. Expected keys are
write(boolean or dict) andread(boolean or dict).Note
The options given here are NOT reflected in the hash of the object!
The following arguments are possible under the
readkey:- enabled (bool, optional):
Whether it should be attempted to read from the file cache.
- always (bool, optional): If given, will always read from
file and ignore the memory cache. Note that this requires that a cache file was written before or will be written as part of the computation of this node.
- load_options (dict, optional):
Passed on to the method that loads the cache,
load().
Under the
writekey, the following arguments are possible. They are evaluated in the order that they are listed here. See_cache_result()for more information.- enabled (bool, optional):
Whether writing is enabled at all
- always (bool, optional):
If given, will always write.
- allow_overwrite (bool, optional):
If False, will not write a cache file if one already exists. If True, a cache file might be written, although one already exists. This is still conditional on the evaluation of the other arguments.
- min_size (int, optional):
The minimum size of the result object that allows writing the cache.
- max_size (int, optional):
The maximum size of the result object that allows writing the cache.
- min_compute_time (float, optional):
The minimal individual computation time of this node that is needed in order for the file cache to be written. Note that this value can be lower if the node result is not computed but looked up from the cache.
- min_cumulative_compute_time (float, optional):
The minimal cumulative computation time of this node and all its dependencies that is needed in order for the file cache to be written. Note that this value can be lower if the node result is not computed but looked up from the cache.
- storage_options (dict, optional):
Passed on to the cache storage method,
_write_to_cache_file(). The following arguments are available:- ignore_groups (bool, optional):
Whether to store groups. Disabled by default.
- attempt_pickling (bool, optional):
Whether it should be attempted to store results that could not be stored via a dedicated storage function by pickling them. Enabled by default.
- raise_on_error (bool, optional):
Whether to raise on error to store a result. Disabled by default; it is useful to enable this when debugging.
- pkl_kwargs (dict, optional):
Arguments passed on to the pickle.dump function.
- further keyword arguments:
Passed on to the chosen storage method.
context (dict, optional) – Some meta-data stored alongside the Transformation, e.g. containing information about the context it was created in. This is not taken into account for the hash.
- _operation#
- _args#
- _kwargs#
- _dag#
- _salt#
- _allow_failure#
- _fallback#
- _hashstr#
- _status#
- _layer#
- _context#
- _profile#
- _mc_opts#
- _cache#
- _fc_opts#
- _exclude_from_cache#
- __repr__() str[source]#
A deterministic string representation of this transformation.
Note
This is also used for hash creation, thus it does not include the attributes that are set via the initialization arguments
dagandfile_cache.Warning
Changing this method will lead to cache invalidations!
- property hashstr: str#
Computes the hash of this Transformation by creating a deterministic representation of this Transformation using
__repr__and then applying a checksum hash function to it.Note that this does NOT rely on the built-in hash function but on the custom dantro
_hashfunction which produces a platform-independent and deterministic hash. As this is a string-based (rather than an integer-based) hash, it is not implemented as the__hash__magic method but as this separate property.- Returns:
The hash string for this transformation
- Return type:
- __hash__() int[source]#
Computes the python-compatible integer hash of this object from the string-based hash of this Transformation.
- property dag: TransformationDAG#
The associated TransformationDAG; used for object lookup
- property dependencies: Set[DAGReference]#
Recursively collects the references that are found in the positional and keyword arguments of this Transformation as well as in the fallback value.
- property resolved_dependencies: Set[Transformation]#
Transformation objects that this Transformation depends on
- property has_result: bool#
Whether there is a memory-cached result available for this transformation.
- property exclude_from_cache: bool#
Whether the result needs to be excluded from memory and file cache, e.g. because it is a non-pickleable object that creates problems in other places.
- property status: str#
Return this Transformation’s status which is one of:
initialized: set after initializationqueued: queued for computationcomputed: successfully computedused_fallback: if a fallback value was used insteadlooked_up: after file cache lookupfailed_here: if computation failed in this nodefailed_in_dependency: if computation failed in a dependency
- property layer: int#
Returns the layer this node can be placed at within the DAG by recursively going over dependencies and setting the layer to the maximum layer of the dependencies plus one.
Computation occurs upon first invocation, afterwards the cached value is returned.
Note
Transformations without dependencies have a level of zero.
- property context: dict#
Returns a dict that holds information about the context this transformation was created in.
- yaml_tag = '!dag_trf'#
- classmethod to_yaml(representer, node)[source]#
A YAML representation of this Transformation, including all its arguments (which must again be YAML-representable). In essence, this returns a YAML mapping that has the
!dag_trfYAML tag prefixed, such that reading it in will lead to thefrom_yamlmethod being invoked.Note
The YAML representation does not include the
file_cacheparameters.
- compute() Any[source]#
Computes the result of this transformation by recursively resolving objects and carrying out operations.
This method can also be called if the result is already computed; this will lead only to a cache-lookup, not a re-computation.
- Returns:
The result of the operation
- Return type:
Any
- _perform_operation(*, args: list, kwargs: dict) Any[source]#
Perform the operation, updating the profiling info on the side
- Parameters:
- Returns:
The result of the operation
- Return type:
Any
- Raises:
BadOperationName – Upon bad operation or meta-operation name
DataOperationFailed – Upon failure to perform the operation
- _resolve_refs(cont: Sequence) Sequence[source]#
Resolves DAG references within a deepcopy of the given container by iterating over it and computing the referenced nodes.
- Parameters:
cont (Sequence) – The container containing the references to resolve
- _handle_error_and_fallback(err: Exception, *, context: str) Any[source]#
Handles an error that occured during application of the operation or during resolving of arguments (and the recursively invoked computations on dependent nodes).
Without error handling enabled, this will directly re-raise the active exception. Otherwise, it will generate a log message and will resolve the fallback value.
- _update_profile(*, cumulative_compute: float | None = None, **times) None[source]#
Given some new profiling times, updates the profiling information.
- Parameters:
cumulative_compute (float, optional) – The cumulative computation time; if given, additionally computes the computation time for this individual node.
**times – Valid profiling data.
- _lookup_result() Tuple[bool, Any][source]#
Look up the transformation result to spare re-computation
- _lookup_result_from_file() Tuple[bool, Any][source]#
Looks up a cached result from file.
Note
Unlike the more general
_lookup_result(), this one does not check whether reading from cache is enabled or disabled.
- class TransformationDAG(*, dm: DataManager, define: Dict[str, List[dict] | Any] = None, select: dict = None, transform: Sequence[dict] = None, cache_dir: str = '.cache', file_cache_defaults: dict = None, base_transform: Sequence[Transformation] = None, select_base: DAGReference | str = None, select_path_prefix: str = None, meta_operations: Dict[str, list | dict] = None, exclude_from_all: List[str] = None, verbosity: int = 1)[source]#
Bases:
objectThis class collects
Transformationobjects that are (already by their own structure) connected into a directed acyclic graph. The aim of this class is to maintain base objects, manage references, and allow operations on the DAG, the most central of which is computing the result of a node.Furthermore, this class also implements caching of transformations, such that operations that take very long can be stored (in memory or on disk) to speed up future operations.
Objects of this class are initialized with dict-like arguments which specify the transformation operations. There are some shorthands that allow a simple definition syntax, for example the
selectsyntax, which takes care of selecting a basic set of data from the associatedDataManager.See Data Transformation Framework for more information and examples.
- NODE_ATTR_DEFAULT_MAPPERS: Dict[str, str] = {'description': 'attr_mapper.dag.get_description', 'layer': 'attr_mapper.dag.get_layer', 'operation': 'attr_mapper.dag.get_operation', 'status': 'attr_mapper.dag.get_status'}#
The default node attribute mappers when
generating a graph object from the DAG. These are passed to themap_node_attrsargument ofmanipulate_attributes().
- __init__(*, dm: DataManager, define: Dict[str, List[dict] | Any] = None, select: dict = None, transform: Sequence[dict] = None, cache_dir: str = '.cache', file_cache_defaults: dict = None, base_transform: Sequence[Transformation] = None, select_base: DAGReference | str = None, select_path_prefix: str = None, meta_operations: Dict[str, list | dict] = None, exclude_from_all: List[str] = None, verbosity: int = 1)[source]#
Initialize a TransformationDAG by loading the specified transformations configuration into it, creating a directed acyclic graph of
Transformationobjects.See Data Transformation Framework for more information and examples.
- Parameters:
dm (DataManager) – The associated data manager which is made available as a special node in the DAG.
define (Dict[str, Union[List[dict], Any]], optional) – Definitions of tags. This can happen in two ways: If the given entries contain a list or tuple, they are interpreted as sequences of transformations which are subsequently added to the DAG, the tag being attached to the last transformation of each sequence. If the entries contain objects of any other type, including
dict(!), they will be added to the DAG via a single node that uses thedefineoperation. This argument can be helpful to define inputs or variables which may then be used in the transformations added via theselectortransformarguments. See The define interface for more information and examples.select (dict, optional) – Selection specifications, which are translated into regular transformations based on
getitemoperations. Thebase_transformandselect_basearguments can be used to define from which object to select. By default, selection happens from the associated DataManager.transform (Sequence[dict], optional) – Transform specifications.
cache_dir (str, optional) – The name of the cache directory to create if file caching is enabled. If this is a relative path, it is interpreted relative to the associated data manager’s data directory. If it is absolute, the absolute path is used. The directory is only created if it is needed.
file_cache_defaults (dict, optional) – Default arguments for file caching behaviour. This is recursively updated with the arguments given in each individual select or transform specification.
base_transform (Sequence[Transformation], optional) – A sequence of transform specifications that are added to the DAG prior to those added via
define,selectandtransform. These can be used to create some other object from the data manager which should be used as the basis ofselectoperations. These transformations should be kept as simple as possible and ideally be only used to traverse through the data tree.select_base (Union[DAGReference, str], optional) – Which tag to base the
selectoperations on. If None, will use the (always-registered) tag for the data manager,dm. This attribute can also be set via theselect_baseproperty.select_path_prefix (str, optional) – If given, this path is prefixed to all
pathspecifications made within theselectargument. Note that unlike setting theselect_basethis merely joins the given prefix to the given paths, thus leading to repeated path resolution. For that reason, using theselect_baseargument is generally preferred and theselect_path_prefixshould only be used ifselect_baseis already in use. If this path ends with a/, it is directly prepended. If not, the/is added before adjoining it to the other path.meta_operations (dict, optional) – Meta-operations are basically function definitions using the language of the transformation framework; for information on how to define and use them, see Meta-Operations.
exclude_from_all (List[str], optional) – Tag names that should not be defined as
compute()targets ifcompute_only: allis set there. Note that, alternatively, tags can be named starting with.or_to exclude them from that list.verbosity (str, optional) –
Logging verbosity during computation. This mostly pertains to the extent of statistics being emitted through the logger.
0: No statistics1: Per-node statistics (mean, std, min, max)2: Total effective time for the 5 slowest operations3: Same as2but for all operations
- property dm: DataManager#
The associated DataManager
- property hashstr: str#
Returns the hash of this DAG, which depends solely on the hash of the associated DataManager.
- property objects: DAGObjects#
The object database
- property tags: Dict[str, str]#
A mapping from tags to objects’ hashes; the hashes can be looked up in the object database to get to the objects.
- property ref_stacks: Dict[str, List[str]]#
Named reference stacks, e.g. for resolving tags that were defined ´ inside meta-operations.
- property meta_operations: List[str]#
The names of all registered meta-operations.
To register new meta-operations, use the dedicated registration method,
register_meta_operation().
- property cache_dir: str#
The path to the cache directory that is associated with the DataManager that is coupled to this DAG. Note that the directory might not exist yet!
- property cache_files: Dict[str, Tuple[str, str]]#
Scans the cache directory for cache files and returns a dict that has as keys the hash strings and as values a tuple of full path and file extension.
- property select_base: DAGReference#
The reference to the object that is used for select operations
- property profile_extended: Dict[str, float | Dict[str, float]]#
Builds an extended profile that includes the profiles from all transformations and some aggregated information.
This is calculated anew upon each invocation; the result is not cached.
The extended profile contains the following information:
tags: profiles for each tag, stored under the tagaggregated: aggregated statistics of all nodes with profile information on compute time, cache lookup, cache writingsorted: individual profiling times, with NaN values set to 0
- register_meta_operation(name: str, *, select: dict | None = None, transform: Sequence[dict] | None = None) None[source]#
Registers a new meta-operation, i.e. a transformation sequence with placeholders for the required positional and keyword arguments. After registration, these operations are available in the same way as other operations; unlike non-meta-operations, they will lead to multiple nodes being added to the DAG.
See Meta-Operations for more information.
- add_node(*, operation: str, args: list | None = None, kwargs: dict | None = None, tag: str | None = None, force_compute: bool | None = None, file_cache: dict | None = None, fallback: Any | None = None, **trf_kwargs) DAGReference[source]#
Add a new node by creating a new
Transformationobject and adding it to the node list.In case of
operationbeing a meta-operation, this method will add multiple Transformation objects to the node list. Thetagand thefile_cacheargument then refer to the result node of the meta- operation, while the**trf_kwargsare passed to all these nodes. For more information, see Meta-Operations.- Parameters:
operation (str) – The name of the operation or meta-operation.
args (list, optional) – Positional arguments to the operation
kwargs (dict, optional) – Keyword arguments to the operation
tag (str, optional) – The tag the transformation should be made available as.
force_compute (bool, optional) – If True, the result of this node will always be computed as part of
compute().file_cache (dict, optional) – File cache options for this node. If defaults were given during initialization, those defaults will be updated with the given dict.
fallback – (Any, optional): The fallback value in case that the computation of this node fails.
**trf_kwargs – Passed on to
__init__()
- Raises:
ValueError – If the tag already exists
- Returns:
- The reference to the created node. In case of the
operation being a meta operation, the return value is a reference to the result node of the meta-operation.
- Return type:
- add_nodes(*, define: Dict[str, List[dict] | Any] | None = None, select: dict | None = None, transform: Sequence[dict] | None = None)[source]#
Adds multiple nodes by parsing the specification given via the
define,select, andtransformarguments (in that order).Note
The current
select_baseproperty value is used as basis for allgetitemoperations.- Parameters:
define (Dict[str, Union[List[dict], Any]], optional) – Definitions of tags. This can happen in two ways: If the given entries contain a list or tuple, they are interpreted as sequences of transformations which are subsequently added to the DAG, the tag being attached to the last transformation of each sequence. If the entries contain objects of any other type, including
dict(!), they will be added to the DAG via a single node that uses thedefineoperation. This argument can be helpful to define inputs or variables which may then be used in the transformations added via theselectortransformarguments. See The define interface for more information and examples.select (dict, optional) – Selection specifications, which are translated into regular transformations based on
getitemoperations. Thebase_transformandselect_basearguments can be used to define from which object to select. By default, selection happens from the associated DataManager.transform (Sequence[dict], optional) – Transform specifications.
- compute(*, compute_only: Sequence[str] | None = None, verbosity: int | None = None) Dict[str, Any][source]#
Computes all specified tags and returns a result dict.
Depending on the
verbosityattribute, a varying level of profiling statistics will be emitted via the logger.- Parameters:
compute_only (Sequence[str], optional) – The tags to compute. If
None, will compute all non-private tags: all tags not starting with.or_that are not included in theTransformationDAG.exclude_from_alllist.- Returns:
A mapping from tags to fully computed results.
- Return type:
Dict[str, Any]
- generate_nx_graph(*, tags_to_include: str | Sequence[str] = 'all', manipulate_attrs: dict = {}, include_results: bool = False, lookup_tags: bool = True, edges_as_flow: bool = True) DiGraph[source]#
Generates a representation of the DAG as a
networkx.DiGraphobject, which can be useful for debugging.Nodes represent
Transformationsand are identified by theirhashstr(). TheTransformationobjects are added as node propertyobjand potentially existing tags are added astag.Edges represent dependencies between nodes. They can be visualized in two ways:
With
edges_as_flow: true, edges point in the direction of results being computed, representing a flow of results.With
edges_as_flow: false, edges point towards the dependency of a node that needs to be computed before the node itself can be computed.
See Graph representation and visualization for more information.
Note
The returned graph data structure is not used internally but is a representation that is generated from the internally used data structures. Subsequently, changes to the graph structure will not have an effect on this
TransformationDAG.Hint
Use
visualize()to generate a visual output. For processing the DAG representation elsewhere, you can use theexport_graph()function.Warning
Do not modify the associated
Transformationobjects!These objects are not deep-copied into the graph’s node properties. Thus, changes to these objects will reflect on the state of the
TransformationDAGwhich may have unexpected effects, e.g. because the hash will not be updated.- Parameters:
tags_to_include (Union[str, Sequence[str]], optional) – Which tags to include into the directed graph. Can be
allto include all tags.manipulate_attrs (Dict[str, Union[str, dict]], optional) –
Allows to manipulate node and edge attributes. See
manipulate_attributes()for more information.By default, this includes a number of default node attribute mappers, defined in
NODE_ATTR_DEFAULT_MAPPERS. These can be overwritten or extended via themap_node_attrskey within this argument.Note
This method registers specialized data operations with the operations database that are meant for handling the case where node attributes are associated with
Transformationobjects.Available operations (with prefix
attr_mapper):{prefix}.get_operationreturns the operation associated with a node.{prefix}.get_operationgenerates a string from the positional and keyword arguments to a node.{prefix}.get_layerreturns the layer, i.e. the distance from the farthest dependency; nodes without dependencies have layer 0. Seedantro.dag.Transformation.layer.{prefix}.get_descriptioncreates a description string that is useful for visualization (e.g. as node label).
To implement your own operation, take care to follow the syntax of
map_attributes().Note
By default, there are no attributes associated with the edges of the DAG.
include_results (bool, optional) –
Whether to include results into the node attributes.
Note
These will all be
Noneunlesscompute()was invoked before generating the graph.lookup_tags (bool, optional) – Whether to lookup tags for each node, storing it in the
tagnode attribute. The tags intags_to_includeare always included, but the reverse lookup of tags can be costly, in which case this should be disabled.edges_as_flow (bool, optional) – If true, edges point from a node towards the nodes that require the computed result; if false, they point towards the dependency of a node.
- visualize(*, out_path: str, g: DiGraph = None, generation: dict = {}, drawing: dict = {}, use_defaults=True, scale_figsize: bool | Tuple[float, float] = (0.25, 0.2), show_node_status: bool = True, node_status_color: dict = None, layout: dict = {}, figure_kwargs: dict = {}, annotate_kwargs: dict = {}, save_kwargs: dict = {}) DiGraph[source]#
Uses
generate_nx_graph()to generate a DAG representation as anetworkx.DiGraphand then creates a visualization.Warning
The plotted graph may contain overlapping edges or nodes, depending on the size and structure of your DAG. This is less pronounced if pygraphviz is installed, which provides vastly more capable layouting algorithms.
To alleviate this, the default layouting and drawing arguments will generate a graph with partly transparent nodes and edges and wiggle node positions around, thus making edges more discernible.
- Parameters:
out_path (str) – Where to store the output
g (DiGraph, optional) – If given, will use this graph instead of generating a new one.
generation (dict, optional) – Arguments for graph generation, passed on to
generate_nx_graph(). Not allowed ifgwas given.drawing (dict, optional) – Drawing arguments, containing the
nodes,edgesandlabelskeys. Thelabelskey can contain thefrom_attrkey which will read the attribute specified there and use it for the label.use_defaults (dict, optional) – Whether to use default drawing arguments which are optimized for a simple representation. These are recursively updated by the ones given in
drawing. Set to false to use the networkx defaults instead.scale_figsize (Union[bool, Tuple[float, float]], optional) –
If True or a tuple, will set the figure size according to:
(width_0 * max_occup. * s_w, height_0 * max_level * s_h)wheres_wands_hare the scaling factors. The maximum occupation refers to the highest number of nodes on a single layer. This figure size scaling avoids nodes overlapping for larger graphs.Note
The default values here are a heuristic and depend very much on the size of the node labels and the font size.
show_node_status (bool, optional) –
If true, will color-code the node status (computed, not computed, failed), setting the
nodes.node_colorkey correspondingly.Note
Node color is plotted behind labels, thus requiring some transparency for the labels.
node_status_color (dict, optional) – If
show_node_statusis set, will use this map to determine the node colours. It should contain keys for all possible values ofdantro.dag.Transformation.status. In addition, there needs to be afallbackkey that is used for nodes where no status can be determined.layout (dict, optional) – Passed to (currently hard-coded) layouting functions.
figure_kwargs (dict, optional) – Passed to
matplotlib.pyplot.figure()for setting up the figureannotate_kwargs (dict, optional) – Used for annotating the graph with a title and a legend (for
show_node_status). Supported keys:title,title_kwargs,add_legend,legend_kwargs,handle_kwargs.save_kwargs (dict, optional) – Passed to
matplotlib.pyplot.savefig()for saving the figure
- Returns:
The passed or generated graph object.
- Return type:
- _parse_trfs(*, select: dict, transform: Sequence[dict], define: dict | None = None) Sequence[dict][source]#
Parse the given arguments to bring them into a uniform format: a sequence of parameters for transformation operations. The arguments are parsed starting with the
definetags, followed by theselectand thetransformargument.- Parameters:
select (dict) – The shorthand to select certain objects from the DataManager. These may also include transformations.
transform (Sequence[dict]) – Actual transformation operations, carried out afterwards.
define (dict, optional) – Each entry corresponds either to a transformation sequence (if type is list or tuple) where the key is used as the tag and attached to the last transformation of each sequence. For any other type, will add a single transformation directly with the content of each entry.
- Returns:
- A sequence of transformation parameters that was
brought into a uniform structure.
- Return type:
Sequence[dict]
- Raises:
TypeError – On invalid type within entry of
selectValueError – When
file_cacheis given for selection from base
- _add_meta_operation_nodes(operation: str, *, args: list | None = None, kwargs: dict | None = None, tag: str | None = None, force_compute: bool | None = None, file_cache: dict | None = None, allow_failure: bool | str | None = None, fallback: Any | None = None, **trf_kwargs) DAGReference[source]#
Adds Transformation nodes for meta-operations
This method resolves the placeholder references in the specified meta- operation such that they point to the
argsandkwargs. It then callsadd_node()repeatedly to add the actual nodes.Note
The last node added by this method is considered the “result” of the selected meta-operation. Subsequently, the arguments
tag,file_cache,allow_failureandfallbackare only applied to this last node.The
trf_kwargs(which include thesalt) on the other hand are passed to all transformations of the meta-operation.- Parameters:
operation (str) – The meta-operation to add nodes for
args (list, optional) – Positional arguments to the meta-operation
kwargs (dict, optional) – Keyword arguments to the meta-operation
tag (str, optional) – The tag that is to be attached to the result of this meta-operation.
file_cache (dict, optional) – File caching options for the result.
allow_failure (Union[bool, str], optional) – Specifies the error handling for the result node of this meta-operation.
fallback (Any, optional) – Specifies the fallback for the result node of this meta-operation.
**trf_kwargs – Transformation keyword arguments, passed on to all transformations that are to be added.
- _update_profile(**times)[source]#
Updates profiling information by adding the given time to the matching key.
- _parse_compute_only(compute_only: str | List[str]) List[str][source]#
Prepares the
compute_onlyargument for use incompute().
- _find_tag(trf: Transformation | str) str | None[source]#
Looks up a tag given a transformation or its hashstr.
If no tag is associated returns None. If multiple tags are associated, returns only the first.
- Parameters:
trf (Union[Transformation, str]) – The transformation, either as the object or as its hashstr.
- _retrieve_from_cache_file(trf_hash: str, *, always_from_file: bool = False, unpack: bool | None = None, **load_kwargs) Tuple[bool, Any][source]#
Retrieves a transformation’s result from a cache file and stores it in the data manager’s cache group.
Note
If a file was already loaded from the cache, it will not be loaded again. Thus, the DataManager acts as a persistent storage for loaded cache files. Consequently, these are shared among all TransformationDAG objects.
- Parameters:
trf_hash (str) – The hash to use for lookup
always_from_file (bool, optional) – If set, will always load from file instead of using a potentially existing already loaded object in the data manager.
unpack (Optional[bool], optional) – Whether to unpack the data from the container. If None, will only do so for certain types, see
DAG_CACHE_CONTAINER_TYPES_TO_UNPACK.**load_kwargs – Passed on to load function of associated DataManager
- _write_to_cache_file(trf_hash: str, *, result: Any, ignore_groups: bool = True, attempt_pickling: bool = True, raise_on_error: bool = False, pkl_kwargs: dict | None = None, **save_kwargs) bool[source]#
Writes the given result object to a hash file, overwriting existing ones.
- Parameters:
trf_hash (str) – The hash; will be used for the file name
result (Any) – The result object to write as a cache file
ignore_groups (bool, optional) – Whether to store groups. Disabled by default.
attempt_pickling (bool, optional) – Whether it should be attempted to store results that could not be stored via a dedicated storage function by pickling them. Enabled by default.
raise_on_error (bool, optional) – Whether to raise on error to store a result. Disabled by default; it is useful to enable this when debugging.
pkl_kwargs (dict, optional) – Arguments passed on to the pickle.dump function.
**save_kwargs – Passed on to the chosen storage method.
- Returns:
Whether a cache file was saved
- Return type:
- Raises:
NotImplementedError – When attempting to store instances of
BaseDataGroupor a derived classRuntimeError – When
raise_on_errorwas given and there was an error during saving.
dantro.data_mngr module#
This module implements the DataManager class, the root of the data tree.
- DATA_TREE_DUMP_EXT = '.d3'#
File extension for data cache file
- _fmt_time(seconds)#
Locally used time formatting function
- _load_file_wrapper(filepath: str, *, dm: DataManager, loader: str, **kwargs) Tuple[BaseDataGroup, str][source]#
A wrapper around
_load_file()that is used for parallel loading via multiprocessing.Pool. It takes care of resolving the loader function and instantiating the file- loading method.This function needs to be on the module scope such that it is pickleable. For that reason, loader resolution also takes place here, because pickling the load function may be problematic.
- Parameters:
filepath (str) – The path of the file to load data from
dm (DataManager) – The DataManager instance to resolve the loader from
loader (str) – The namer of the loader
**kwargs – Any further loading arguments.
- Returns:
- The return value of
- Return type:
Tuple[BaseDataContainer, str]
- _parse_parallel_opts(files: List[str], *, enabled: bool = True, processes: int | None = None, min_files: int = 2, min_total_size: int | None = None, cpu_count: int = 2) int[source]#
Parser function for the parallel file loading options dict
- Parameters:
files (List[str]) – List of files that are to be loaded
enabled (bool, optional) – Whether to use parallel loading. If True, the threshold arguments will still need to be fulfilled.
processes (int, optional) – The number of processors to use; if this is a negative integer, will deduce from available CPU count.
min_files (int, optional) – If there are fewer files to load than this number, will not use parallel loading.
min_total_size (int, optional) – If the total file size is smaller than this file size (in bytes), will not use parallel loading.
cpu_count (int, optional) – Number of CPUs to consider “available”. Defaults to
os.cpu_count(), i.e. the number of actually available CPUs.
- Returns:
- number of processes to use. Will return 1 if loading should not
happen in parallel. Additionally, this number will never be larger than the number of files in order to prevent unnecessary processes.
- Return type:
- class DataManager(data_dir: str, *, name: str | None = None, load_cfg: dict | str | None = None, out_dir: str | bool = '_output/{timestamp:}', out_dir_kwargs: dict | None = None, create_groups: List[str | dict] | None = None, condensed_tree_params: dict | None = None, default_tree_cache_path: str | None = None)[source]#
Bases:
OrderedDataGroupThe DataManager is the root of a data tree, coupled to a specific data directory.
It handles the loading of data and can be used for interactive work with the data.
- _BASE_LOAD_CFG = None#
- _DEFAULT_GROUPS = None#
- _NEW_GROUP_CLS#
alias of
OrderedDataGroup
- _DEFAULT_TREE_CACHE_PATH = '.tree_cache.d3'#
- __init__(data_dir: str, *, name: str | None = None, load_cfg: dict | str | None = None, out_dir: str | bool = '_output/{timestamp:}', out_dir_kwargs: dict | None = None, create_groups: List[str | dict] | None = None, condensed_tree_params: dict | None = None, default_tree_cache_path: str | None = None)[source]#
Initializes a DataManager for the specified data directory.
- Parameters:
data_dir (str) – the directory the data can be found in. If this is a relative path, it is considered relative to the current working directory.
name (str, optional) – which name to give to the DataManager. If no name is given, the data directories basename will be used
load_cfg (Union[dict, str], optional) – The base configuration used for loading data. If a string is given, assumes it to be the path to a YAML file and loads it using the
load_yml()function. If None is given, it can still be supplied to theload()method later on.out_dir (Union[str, bool], optional) – where output is written to. If this is given as a relative path, it is considered relative to the
data_dir. A formatting operation with the keystimestampandnameis performed on this, where the latter is the name of the data manager. If set to False, no output directory is created.out_dir_kwargs (dict, optional) – Additional arguments that affect how the output directory is created.
create_groups (List[Union[str, dict]], optional) – If given, these groups will be created after initialization. If the list entries are strings, the default group class will be used; if they are dicts, the name key specifies the name of the group and the Cls key specifies the type. If a string is given instead of a type, the lookup happens from the
_DATA_GROUP_CLASSESvariable.condensed_tree_params (dict, optional) – If given, will set the parameters used for the condensed tree representation. Available options:
max_levelandcondense_thresh, where the latter may be a callable. Seedantro.base.BaseDataGroup._tree_repr()for more information.default_tree_cache_path (str, optional) – The path to the default tree cache file. If not given, uses the value from the class variable
_DEFAULT_TREE_CACHE_PATH. Whichever value was chosen is then prepared using the_parse_file_path()method, which regards relative paths as being relative to the associated data directory.
- _init_dirs(*, data_dir: str, out_dir: str | bool, timestamp: float | None = None, timefstr: str = '%y%m%d-%H%M%S', exist_ok: bool = False) Dict[str, str][source]#
Initializes the directories managed by this DataManager and returns a dictionary that stores the absolute paths to these directories.
If they do not exist, they will be created.
- Parameters:
data_dir (str) – the directory the data can be found in. If this is a relative path, it is considered relative to the current working directory.
out_dir (Union[str, bool]) – where output is written to. If this is given as a relative path, it is considered relative to the data directory. A formatting operation with the keys
timestampandnameis performed on this, where the latter is the name of the data manager. If set to False, no output directory is created.timestamp (float, optional) – If given, use this time to generate the date format string key. If not, uses the current time.
timefstr (str, optional) – Format string to use for generating the string representation of the current timestamp
exist_ok (bool, optional) – Whether the output directory may exist. Note that it only makes sense to set this to True if you can be sure that there will be no file conflicts! Otherwise the errors will just occur at a later stage.
- Returns:
- The directory paths registered under certain keys,
e.g.
dataandout.
- Return type:
- property hashstr: str#
The hash of a DataManager is computed from its name and the coupled data directory, which are regarded as the relevant parts. While other parts of the DataManager are not invariant, it is characterized most by the directory it is associated with. On all operating systems the Posix representation of the path is used for consistency purposes.
As this is a string-based hash, it is not implemented as the __hash__ magic method but as a separate property.
- WARNING Changing how the hash is computed for the DataManager will
invalidate all TransformationDAG caches.
- property _loader_registry: DataLoaderRegistry#
Retrieves the data loader registry
- load_from_cfg(*, load_cfg: dict | None = None, update_load_cfg: dict | None = None, exists_action: str = 'raise', print_tree: bool | str = False) None[source]#
Load multiple data entries using the specified load configuration.
- Parameters:
load_cfg (dict, optional) – The load configuration to use. If not given, the one specified during initialization is used.
update_load_cfg (dict, optional) – If given, it is used to update the load configuration recursively
exists_action (str, optional) – The behaviour upon existing data. Can be:
raise(default),skip,skip_nowarn,overwrite,overwrite_nowarn. With the*_nowarnvalues, no warning is given if an entry already existed.print_tree (Union[bool, str], optional) – If True, the full tree representation of the DataManager is printed after the data was loaded. If
'condensed', the condensed tree will be printed.
- Raises:
TypeError – Raised if a given configuration entry was of invalid type, i.e. not a dict
- load(entry_name: str, *, loader: str, enabled: bool = True, glob_str: str | List[str], base_path: str | None = None, target_group: str | None = None, target_path: str | None = None, print_tree: bool | str = False, load_as_attr: bool = False, parallel: bool | dict = False, **load_params) None[source]#
Performs a single load operation.
- Parameters:
entry_name (str) – Name of this entry; will also be the name of the created group or container, unless
target_basenameis givenloader (str) – The name of the loader to use
enabled (bool, optional) – Whether the load operation is enabled. If not, simply returns without loading any data or performing any further checks.
glob_str (Union[str, List[str]]) – A glob string or a list of glob strings by which to identify the files within
data_dirthat are to be loaded using the given loader functionbase_path (str, optional) – The base directory to concatenate the glob string to; if None, will use the DataManager’s data directory. With this option, it becomes possible to load data from a path outside the associated data directory.
target_group (str, optional) – If given, the files to be loaded will be stored in this group. This may only be given if the argument target_path is not given.
target_path (str, optional) – The path to write the data to. This can be a format string. It is evaluated for each file that has been matched. If it is not given, the content is loaded to a group with the name of this entry at the root level. Available keys are:
basename,match(ifpath_regexis used, see**load_params)print_tree (Union[bool, str], optional) – If True, the full tree representation of the DataManager is printed after the data was loaded. If
'condensed', the condensed tree will be printed.load_as_attr (bool, optional) – If True, the loaded entry will be added not as a new DataContainer or DataGroup, but as an attribute to an (already existing) object at
target_path. The name of the attribute will be theentry_name.parallel (Union[bool, dict]) –
If True, data is loaded in parallel. If a dict, can supply more options:
enabled: whether to use parallel loadingprocesses: how many processes to use; if None, will use as many as are available. For negative integers, will useos.cpu_count() + processesprocesses.min_files: if given, will fall back to non-parallel loading if fewer than the given number of files were matched byglob_strmin_size: if given, specifies the minimum total size of all matched files (in bytes) below which to fall back to non-parallel loading
Note that a single file will never be loaded in parallel and there will never be more processes used than files that were selected to be loaded. Parallel loading incurs a constant overhead and is typically only speeding up data loading if the task is CPU-bound. Also, it requires the data tree to be fully serializable.
**load_params –
Further loading parameters, all optional. These are evaluated by
_load().- ignore (list):
The exact file names in this list will be ignored during loading. Paths are seen as elative to the data directory of the data manager.
- required (bool):
If True, will raise an error if no files were found. Default: False.
- path_regex (str):
This pattern can be used to match a part of the file path that is being loaded. The match result is available to the format string under the
matchkey. See_prepare_target_path()for more information.- exists_action (str):
The behaviour upon existing data. Can be:
raise(default),skip,skip_nowarn,overwrite,overwrite_nowarn. With*_nowarnvalues, no warning is given if an entry already existed. Note that this is ignored when theload_as_attrargument is given.- unpack_data (bool, optional):
If True, and
load_as_attris active, not the DataContainer or DataGroup itself will be stored in the attribute, but the content of its.dataattribute.- progress_indicator (bool):
Whether to print a progress indicator or not. Default: True
- any further kwargs:
passed on to the loader function
- Returns:
None
- Raises:
ValueError – Upon invalid combination of
target_groupandtarget_patharguments
- _load(*, target_path: str, loader: str, glob_str: str | List[str], include_files: bool = True, include_directories: bool = True, load_as_attr: str | None = False, base_path: str | None = None, ignore: List[str] | None = None, required: bool = False, path_regex: str | None = None, exists_action: str = 'raise', unpack_data: bool = False, progress_indicator: bool = True, parallel: bool | dict = False, **loader_kwargs) Tuple[int, int][source]#
Helper function that loads a data entry to the specified path.
- Parameters:
target_path (str) – The path to load the result of the loader to. This can be a format string; it is evaluated for each file. Available keys are: basename, match (if
path_regexis given)loader (str) – The loader to use
glob_str (Union[str, List[str]]) – A glob string or a list of glob strings to match files in the data directory
include_files (bool, optional) – If false, will exclude paths that point to files.
include_directories (bool, optional) – If false, will exclude paths that point to directories.
load_as_attr (Union[str, None], optional) – If a string, the entry will be loaded into the object at
target_pathunder a new attribute with this name.base_path (str, optional) – The base directory to concatenate the glob string to; if None, will use the DataManager’s data directory. With this option, it becomes possible to load data from a path outside the associated data directory.
ignore (List[str], optional) – The exact file names in this list will be ignored during loading. Paths are seen as relative to the data directory.
required (bool, optional) – If True, will raise an error if no files were found or if loading of a file failed.
path_regex (str, optional) – The regex applied to the relative path of the files that were found. It is used to generate the name of the target container. If not given, the basename is used.
exists_action (str, optional) – The behaviour upon existing data. Can be:
raise(default),skip,skip_nowarn,overwrite,overwrite_nowarn. With*_nowarnvalues, no warning is given if an entry already existed. Note that this is ignored ifload_as_attris given.unpack_data (bool, optional) – If True, and
load_as_attris active, not the DataContainer or DataGroup itself will be stored in the attribute, but the content of its.dataattribute.progress_indicator (bool, optional) – Whether to print a progress indicator or not
parallel (Union[bool, dict], optional) –
If True, data is loaded in parallel. If a dict, can supply more options:
enabled: whether to use parallel loadingprocesses: how many processes to use; if None, will use as many as are available. For negative integers, will useos.cpu_count() + processesprocesses.min_files: if given, will fall back to non-parallel loading if fewer than the given number of files were matched byglob_strmin_size: if given, specifies the minimum total size of all matched files (in bytes) below which to fall back to non-parallel loading
Note that a single file will never be loaded in parallel and there will never be more processes used than files that were selected to be loaded. Parallel loading incurs a constant overhead and is typically only speeding up data loading if the task is CPU-bound. Also, it requires the data tree to be fully serializable.
**loader_kwargs – passed on to the loader function
- No Longer Returned:
- Tuple[int, int]: Tuple of number of files that matched the glob
strings, including those that may have been skipped, and number of successfully loaded and stored entries
- _load_file(filepath: str, *, loader: str, load_func: Callable, target_path: str, path_sre: Pattern | None, load_as_attr: str, TargetCls: type, required: bool, _base_path: str, target_path_kwargs: dict | None = None, **loader_kwargs) Tuple[None | BaseDataContainer, List[str]][source]#
Loads the data of a single file into a dantro object and returns the loaded object (or None) and the parsed target path key sequence.
- _resolve_loader(loader: str) Tuple[Callable, type][source]#
Resolves the loader function and returns a 2-tuple containing the load function and the declared dantro target type to load data to.
- _resolve_path_list(*, glob_str: str | List[str], ignore: str | List[str] | None = None, base_path: str | None = None, required: bool = False, **glob_kwargs) List[str][source]#
Create the list of file or directory paths to load.
Internally, this uses a set, thus ensuring that the paths are unique. The set is converted to a list before returning.
Note
Paths may refer to file and directory paths.
- Parameters:
glob_str (Union[str, List[str]]) – The glob pattern or a list of glob patterns to use for searching for files. Relative paths will be seen as relative to
base_path.ignore (List[str]) – A list of paths to ignore. Relative paths will be seen as relative to
base_path. Supports glob patterns.base_path (str, optional) – The base path for the glob pattern. If not given, will use the
datadirectory.required (bool, optional) – If true, will raise an error if at least one matching path is required.
**glob_kwargs – Passed on to
dantro.tools.glob_paths(). See there for more available parameters.
- Returns:
The (file or directory) paths to load.
- Return type:
List[str]
- Raises:
MissingDataError – If no files could be matched.
RequiredDataMissingError – If no files could be matched but were required.
- _prepare_target_path(target_path: str, *, filepath: str, base_path: str, path_sre: Pattern | None = None, join_char_replacement: str = '__', **fstr_params) List[str][source]#
Prepare the target path within the data tree where the loader’s output is to be placed.
The
target_pathargument can be a format string. The following keys are available:dirname: the directory path relative to the selected base directory (typically the data directory).basename: the lower-case base name of the file, without extensionext: the lower-case extension of the file, without leading dotrelpath: The full (relative) path (without extension)dirname_cleanedandrelpath_cleaned: like above but with the path join character (/) replaced byjoin_char_replacement.
If
path_sreis given, will additionally have the following keys available as result of callingre.Pattern.search()on the givenfilepath:match: the first matched group, named or unnamed. This is equivalent togroups[0]. If no match is made, will warn and fall back to thebasename.groups: the sequence of matched groups; individual groups can be accessed via the expanded formatting syntax, where{groups[1]:}will access the second match. Not available if there was no match.named: contains the matches for named groups; individual groups can be accessed via{named[foo]:}, wherefoois the name of the group. Not available if there was no match.
For more information on how to define named groups, refer to the Python docs.
Hint
For more complex target path format strings, use the
namedmatches for higher robustness.Examples (using
path_regexinstead ofpath_sre):# Without pattern matching filepath: data/some_file.ext target_path: target/{ext}/{basename} # -> target/ext/some_file # With simple pattern matching path_regex: data/uni(\d+)/data.h5 filepath: data/uni01234/data.h5 # matches 01234 target_path: multiverse/{match}/data # -> multiverse/01234/data # With pattern matching that uses named groups path_regex: data/no(?P<num>\d+)/data.h5 filepath: data/no123/data.h5 # matches 123 target_path: target/{named[num]} # -> target/123
- Parameters:
target_path (str) – The target path
format()string, which may contain placeholders that are replaced in this method. For instance, these placeholders may be those from the path regex pattern specified inpath_sre, see above.filepath (str) – The actual path of the file, used as input to the regex pattern.
base_path (str) – The base path used when determining the
filepathand from which a relative path can be computed. Available as format keysrelnameandrelname_cleaned.path_sre (Pattern, optional) – The regex pattern that is used to generate additional arguments that are useable in the format string.
join_char_replacement (str, optional) – The string to use to replace the
PATH_JOIN_CHAR(/) in the relative paths**fstr_params – Made available to the formatting operation
- Returns:
Path sequence that represents the target path within the data tree where the loaded data is to be placed.
- Return type:
List[str]
- _skip_path(path: str, *, exists_action: str) bool[source]#
Check whether a given path exists and — depending on the
exists_action– decides whether to skip this path or not.- Parameters:
- Returns:
Whether to skip this path
- Return type:
- Raises:
ExistingDataError – Raised when exists_action == ‘raise’
ValueError – Raised for invalid exists_action value
- _store_object(obj: BaseDataGroup | BaseDataContainer, *, target_path: List[str], as_attr: str | None, unpack_data: bool, exists_action: str) bool[source]#
Store the given
objat the suppliedtarget_path.Note that this will automatically overwrite, assuming that all checks have been made prior to the call to this function.
- Parameters:
obj (Union[BaseDataGroup, BaseDataContainer]) – Object to store
target_path (List[str]) – The path to store the object at
as_attr (Union[str, None]) – If a string, store the object in the attributes of the container or group at target_path
unpack_data (bool) – Description
exists_action (str) – Description
- Returns:
- Whether storing was successful. May be False in case the
target path already existed and
exists_actionspecifies that it is to be skipped, or if the object was None.
- Return type:
- Raises:
ExistingDataError – If non-group-like data already existed at that path
RequiredDataMissingError – If storing as attribute was selected but there was no object at the given target_path
- _ALLOWED_CONT_TYPES: tuple | None = None#
The types that are allowed to be stored in this group. If None, all types derived from the dantro base classes are allowed. This applies to both containers and groups that are added to this group.
Hint
To add the type of the current object, add a string entry
selfto the tuple. This will be resolved totype(self)at invocation.
- _ATTRS_CLS#
alias of
BaseDataAttrs
- _COND_TREE_CONDENSE_THRESH = 10#
Condensed tree representation threshold parameter
- _COND_TREE_MAX_LEVEL = 10#
Condensed tree representation maximum level
- _DATA_CONTAINER_CLASSES: Dict[str, type] = None#
Mapping from strings to available data container types. Used in string-based lookup of container types in
new_container().
- _DATA_GROUP_CLASSES: Dict[str, type] = None#
Mapping from strings to available data group types. Used in string-based lookup of group types in
new_group().
- _NEW_CONTAINER_CLS: type = None#
Which class to use for creating a new container via call to the
new_container()method. If None, the type needs to be specified explicitly in the method call.
- _STORAGE_CLS#
alias of
OrderedDict
- __contains__(cont: str | AbstractDataContainer) bool#
Whether the given container is in this group or not.
If this is a data tree object, it will be checked whether this specific instance is part of the group, using
is-comparison.Otherwise, assumes that
contis a valid argument to the__getitem__()method (a key or key sequence) and tries to access the item at that path, returningTrueif this succeeds andFalseif not.Lookup complexity is that of item lookup (scalar) for both name and object lookup.
- Parameters:
cont (Union[str, AbstractDataContainer]) – The name of the container, a path, or an object to check via identity comparison.
- Returns:
- Whether the given container object is part of this group or
whether the given path is accessible from this group.
- Return type:
- __eq__(other) bool#
Evaluates equality by making the following comparisons: identity, strict type equality, and finally: equality of the
_dataand_attrsattributes, i.e. the private attribute. This ensures that comparison does not trigger any downstream effects like resolution of proxies.If types do not match exactly,
NotImplementedis returned, thus referring the comparison to the other side of the==.
- __format__(spec_str: str) str#
Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_.
- __getitem__(key: str | List[str]) AbstractDataContainer#
Looks up the given key and returns the corresponding item.
This supports recursive relative lookups in two ways:
By supplying a path as a string that includes the path separator. For example,
foo/bar/spamwalks down the tree along the given path segments.By directly supplying a key sequence, i.e. a list or tuple of key strings.
With the last path segment, it is possible to access an element that is no longer part of the data tree; successive lookups thus need to use the interface of the corresponding leaf object of the data tree.
Absolute lookups, i.e. from path
/foo/bar, are not possible!Lookup complexity is that of the underlying data structure: for groups based on dict-like storage containers, lookups happen in constant time.
Note
This method aims to replicate the behavior of POSIX paths.
Thus, it can also be used to access the element itself or the parent element: Use
.to refer to this object and..to access this object’sparent.- Parameters:
key (Union[str, List[str]]) – The name of the object to retrieve or a path via which it can be found in the data tree.
- Returns:
- The object at
key, which concurs to the dantro tree interface.
- The object at
- Return type:
- Raises:
ItemAccessError – If no object could be found at the given
keyor if an absolute lookup, starting with/, was attempted.
- __iter__()#
Returns an iterator over the OrderedDict
- __setitem__(key: str | List[str], val: BaseDataContainer) None#
This method is used to allow access to the content of containers of this group. For adding an element to this group, use the add method!
- Parameters:
key (Union[str, List[str]]) – The key to which to set the value. If this is a path, will recurse down to the lowest level. Note that all intermediate keys need to be present.
val (BaseDataContainer) – The value to set
- Returns:
None
- Raises:
ValueError – If trying to add an element to this group, which should be done via the add method.
- __sizeof__() int#
Returns the size of the data (in bytes) stored in this container’s data and its attributes.
Note that this value is approximate. It is computed by calling the
sys.getsizeof()function on the data, the attributes, the name and some caching attributes that each dantro data tree class contains. Importantly, this is not a recursive algorithm.Also, derived classes might implement further attributes that are not taken into account either. To be more precise in a subclass, create a specific __sizeof__ method and invoke this parent method additionally.
- __str__() str#
An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
- _abc_impl = <_abc._abc_data object>#
- _add_container_to_data(cont: AbstractDataContainer) None#
Performs the operation of adding the container to the _data. This can be used by subclasses to make more elaborate things while adding data, e.g. specify ordering …
- NOTE This method should NEVER be called on its own, but only via the
_add_container method, which takes care of properly linking the container that is to be added.
NOTE After adding, the container need be reachable under its .name!
- Parameters:
cont – The container to add
- _attrs = None#
The attribute that data attributes will be stored to
- _check_cont(cont) None#
Can be used by a subclass to check a container before adding it to this group. Is called by _add_container before checking whether the object exists or not.
This is not expected to return, but can raise errors, if something did not work out as expected.
- Parameters:
cont – The container to check
- _check_data(data: Any) None#
This method can be used to check the data provided to this container
It is called before the data is stored in the
__init__method and should raise an exception or create a warning if the data is not as desired.This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using
super().Note
The
CheckDataMixinprovides a generalised implementation of this method to perform some type checks and react to unexpected types.- Parameters:
data (Any) – The data to check
- _check_name(new_name: str) None#
Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters:
new_name (str) – The new name, which is to be checked.
- _determine_container_type(Cls: type | str) type#
Helper function to determine the type to use for a new container.
- Parameters:
Cls (Union[type, str]) – If None, uses the
_NEW_CONTAINER_CLSclass variable. If a string, tries to extract it from the class variable_DATA_CONTAINER_CLASSESdict. Otherwise, assumes this is already a type.- Returns:
The container class to use
- Return type:
- Raises:
ValueError – If the string class name was not registered
AttributeError – If no default class variable was set
- _determine_group_type(Cls: type | str) type#
Helper function to determine the type to use for a new group.
- Parameters:
Cls (Union[type, str]) – If None, uses the
_NEW_GROUP_CLSclass variable. If that one is not set, usestype(self). If a string, tries to extract it from the class variable_DATA_GROUP_CLASSESdict. Otherwise, assumesClsis already a type.- Returns:
The group class to use
- Return type:
- Raises:
ValueError – If the string class name was not registered
AttributeError – If no default class variable was set
- _determine_type(T: type | str, *, default: type, registry: Dict[str, type]) type#
Helper function to determine a type by name, falling back to a default type or looking it up from a dict-like registry if it is a string.
- _direct_insertion_mode(*, enabled: bool = True)#
A context manager that brings the class this mixin is used in into direct insertion mode. While in that mode, the
with_direct_insertion()property will return true.This context manager additionally invokes two callback functions, which can be specialized to perform certain operations when entering or exiting direct insertion mode: Before entering,
_enter_direct_insertion_mode()is called. After exiting,_exit_direct_insertion_mode()is called.- Parameters:
enabled (bool, optional) – whether to actually use direct insertion mode. If False, will yield directly without setting the toggle. This is equivalent to a null-context.
- _enter_direct_insertion_mode()#
Called after entering direct insertion mode; can be overwritten to attach additional behaviour.
- _exit_direct_insertion_mode()#
Called before exiting direct insertion mode; can be overwritten to attach additional behaviour.
- _format_info() str#
A __format__ helper function: returns an info string that is used to characterize this object. Does NOT include name and classname!
- _format_logstr() str#
A __format__ helper function: returns the log string, a combination of class name and name
- _format_tree() str#
Returns the default tree representation of this group by invoking the .tree property
- _format_tree_condensed() str#
Returns the default tree representation of this group by invoking the .tree property
- _link_child(*, new_child: BaseDataContainer, old_child: BaseDataContainer | None = None)#
Links the new_child to this class, unlinking the old one.
This method should be called from any method that changes which items are associated with this group.
- _lock_hook()#
Invoked upon locking.
- _parse_file_path(path: str, *, default_ext=None) str[source]#
Parses a file path: if it is a relative path, makes it relative to the associated data directory. If a default extension is specified and the path does not contain one, that extension is added.
This helper method is used as part of dumping and storing the data tree, i.e. in the
dump()andrestore()methods.
- _tree_repr(*, level: int = 0, max_level: int | None = None, info_fstr='<{:cls_name,info}>', info_ratio: float = 0.6, condense_thresh: int | Callable[[int, int], int] | None = None, total_item_count: int = 0) str | List[str]#
Recursively creates a multi-line string tree representation of this group. This is used by, e.g., the _format_tree method.
- Parameters:
level (int, optional) – The depth within the tree
max_level (int, optional) – The maximum depth within the tree; recursion is not continued beyond this level.
info_fstr (str, optional) – The format string for the info string
info_ratio (float, optional) – The width ratio of the whole line width that the info string takes
condense_thresh (Union[int, Callable[[int, int], int]], optional) – If given, this specifies the threshold beyond which the tree view for the current element becomes condensed by hiding the output for some elements. The minimum value for this is 3, indicating that there should be at most 3 lines be generated from this level (excluding the lines coming from recursion), i.e.: two elements and one line for indicating how many values are hidden. If a smaller value is given, this is silently brought up to 3. Half of the elements are taken from the beginning of the item iteration, the other half from the end. If given as integer, that number is used. If a callable is given, the callable will be invoked with the current level, number of elements to be added at this level, and the current total item count along this recursion branch. The callable should then return the number of lines to be shown for the current element.
total_item_count (int, optional) – The total number of items already created in this recursive tree representation call. Passed on between recursive calls.
- Returns:
- The (multi-line) tree representation of
this group. If this method was invoked with
level == 0, a string will be returned; otherwise, a list of strings will be returned.
- Return type:
- _unlink_child(child: BaseDataContainer)#
Unlink a child from this class.
This method should be called from any method that removes an item from this group, be it through deletion or through
- _unlock_hook()#
Invoked upon unlocking.
- property attrs#
The container attributes.
- clear()#
Clears all containers from this group.
This is done by unlinking all children and then overwriting
_datawith an empty_STORAGE_CLSobject.
- property data#
The stored data.
- get(key, default=None)#
Return the container at key, or default if container with name key is not available.
- items()#
Returns an iterator over the (name, data container) tuple of this group.
- keys()#
Returns an iterator over the container names in this group.
- lock()#
Locks the data of this object
- new_container(path: str | List[str], *, Cls: type | str | None = None, GroupCls: type | str | None = None, _target_is_group: bool = False, **kwargs) BaseDataContainer#
Creates a new container of type
Clsand adds it at the given path relative to this group.If needed, intermediate groups are automatically created.
- Parameters:
Cls (Union[type, str], optional) – The type of the target container (or group) that is to be added. If None, will use the type set in
_NEW_CONTAINER_CLSclass variable. If a string is given, the type is looked up in the container type registry.GroupCls (Union[type, str], optional) – Like
Clsbut used for intermediate group types only._target_is_group (bool, optional) – Internally used variable. If True, will look up the
Clstype via_determine_group_type()instead of_determine_container_type().**kwargs – passed on to
Cls.__init__
- Returns:
The created container of type
Cls- Return type:
- new_group(path: str | List[str], *, Cls: type | str | None = None, GroupCls: type | str | None = None, **kwargs) BaseDataGroup#
Creates a new group at the given path.
- Parameters:
path (Union[str, List[str]]) – The path to create the group at. If necessary, intermediate paths will be created.
Cls (Union[type, str], optional) –
If given, use this type to create the target group. If not given, uses the class specified in the
_NEW_GROUP_CLSclass variable or (if a string) the one from the group type registry.Note
This argument is evaluated at each segment of the
pathby the corresponding object in the tree. Subsequently, the types need to be available at the desiredGroupCls (Union[type, str], optional) – Like
Cls, but this applies only to the creation of intermediate groups.**kwargs – Passed on to
Cls.__init__
- Returns:
The created group of type
Cls- Return type:
- property parent#
The associated parent of this container or group
- pop(k[, d]) v, remove specified key and return the corresponding value.#
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair#
as a 2-tuple; but raise KeyError if D is empty.
- raise_if_locked(*, prefix: str | None = None)#
Raises an exception if this object is locked; does nothing otherwise
- recursive_update(other, *, overwrite: bool = True)#
Recursively updates the contents of this data group with the entries of the given data group
Note
This will create shallow copies of those elements in
otherthat are added to this object.- Parameters:
other (BaseDataGroup) – The group to update with
overwrite (bool, optional) – Whether to overwrite already existing object. If False, a conflict will lead to an error being raised and the update being stopped.
- Raises:
TypeError – If
otherwas of invalid type
- setdefault(key, default=None)#
This method is not supported for a data group
- property tree_condensed: str#
Returns the condensed tree representation of this group. Uses the
_COND_TREE_*prefixed class attributes as parameters.
- unlock()#
Unlocks the data of this object
- update([E, ]**F) None. Update D from mapping/iterable E and F.#
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values()#
Returns an iterator over the containers in this group.
- property with_direct_insertion: bool#
Whether the class this mixin is mixed into is currently in direct insertion mode.
- __locked#
Whether the data is regarded as locked. Note name-mangling here.
- __in_direct_insertion_mode#
A name-mangled state flag that determines the state of the object.
- dump(*, path: str | None = None, **dump_kwargs) str[source]#
Dumps the data tree to a new file at the given path, creating any necessary intermediate data directories.
For restoring, use
restore().- Parameters:
path (str, optional) – The path to store this file at. If this is not given, use the default tree cache path that was set up during initialization. If it is given and a relative path, it is assumed relative to the data directory. If the path does not end with an extension, the
.d3(read: “data tree”) extension is automatically added.**dump_kwargs – Passed on to
pkl.dump
- Returns:
The path that was used for dumping the tree file
- Return type:
- restore(*, from_path: str | None = None, merge: bool = False, **load_kwargs)[source]#
Restores the data tree from a dump.
For dumping, use
dump().- Parameters:
from_path (str, optional) – The path to restore this DataManager from. If it is not given, uses the default tree cache path that was set up at initialization. If it is a relative path, it is assumed relative to the data directory. Take care to add the corresponding file extension.
merge (bool, optional) – If True, uses a recursive update to merge the current tree with the restored tree. If False, uses
clear()to clear the current tree and then re-populates it with the restored tree.**load_kwargs – Passed on to
pkl.load
- Raises:
FileNotFoundError – If no file is found at the (expanded) path.
dantro.exceptions module#
Custom dantro exception classes.
- exception DantroError[source]#
Bases:
ExceptionBase class for all dantro-related errors
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception DantroWarning[source]#
Bases:
UserWarningBase class for all dantro-related warnings
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception DantroMessagingException[source]#
Bases:
DantroErrorBase class for exceptions that are used for messaging
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception UnexpectedTypeWarning[source]#
Bases:
DantroWarningGiven when there was an unexpected type passed to a data container.
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception ItemAccessError(obj: AbstractDataContainer, *, key: str, show_hints: bool = True, prefix: str = None, suffix: str = None)[source]#
Bases:
KeyError,IndexError,DantroErrorRaised upon bad access via __getitem__ or similar magic methods.
This derives from both native exceptions KeyError and IndexError as these errors may be equivalent in the context of the dantro data tree, which is averse to the underlying storage container.
See
BaseDataGroupfor example usage.- __init__(obj: AbstractDataContainer, *, key: str, show_hints: bool = True, prefix: str = None, suffix: str = None)[source]#
Set up an ItemAccessError object, storing some metadata that is used to create a helpful error message.
- Parameters:
obj (AbstractDataContainer) – The object from which item access was attempted but failed
key (str) – The key with which
__getitem__was calledshow_hints (bool, optional) – Whether to show hints in the error message, e.g. available keys or “Did you mean …?”
prefix (str, optional) – A prefix string for the error message
suffix (str, optional) – A suffix string for the error message
- Raises:
TypeError – Upon
objwithout attributeslogstrandpath; orkeynot being a string.
- __str__() str[source]#
Parse an error message, using the additional information to give hints on where the error occurred and how it can be resolved.
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception DataOperationWarning[source]#
Bases:
DantroWarningBase class for warnings related to data operations
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception DataOperationError[source]#
Bases:
DantroErrorBase class for errors related to data operations
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception BadOperationName[source]#
Bases:
DataOperationError,ValueErrorRaised upon bad data operation name
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception DataOperationFailed[source]#
Bases:
DataOperationError,RuntimeErrorRaised upon failure to apply a data operation
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MetaOperationError[source]#
Bases:
DataOperationErrorBase class for errors related to meta operations
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MetaOperationSignatureError[source]#
Bases:
MetaOperationErrorIf the meta-operation signature was erroneous
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MetaOperationInvocationError[source]#
Bases:
MetaOperationError,ValueErrorIf the invocation of the meta-operation was erroneous
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception DAGError[source]#
Bases:
DantroErrorFor errors in the data transformation framework
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MissingDAGReference[source]#
Bases:
DAGError,ValueErrorIf there was a missing DAG reference
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MissingDAGTag[source]#
Bases:
MissingDAGReference,ValueErrorRaised upon bad tag names
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MissingDAGNode[source]#
Bases:
MissingDAGReference,ValueErrorRaised upon bad node index
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception DataManagerError[source]#
Bases:
DantroErrorAll DataManager exceptions derive from this one
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception RequiredDataMissingError[source]#
Bases:
DataManagerErrorRaised if required data was missing.
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MissingDataError[source]#
Bases:
DataManagerErrorRaised if data was missing, but is not required.
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception ExistingDataError[source]#
Bases:
DataManagerErrorRaised if data already existed.
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception ExistingGroupError[source]#
Bases:
DataManagerErrorRaised if a group already existed.
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception LoaderError[source]#
Bases:
DataManagerErrorRaised if a data loader was not available
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception DataLoadingError[source]#
Bases:
DataManagerErrorRaised if loading data failed for some reason
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MissingDataWarning[source]#
Bases:
DantroWarningUsed as warning instead of MissingDataError
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception ExistingDataWarning[source]#
Bases:
DantroWarningIf there was data already existing …
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception NoMatchWarning[source]#
Bases:
DantroWarningIf there was no regex match
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception PlottingError[source]#
Bases:
DantroErrorCustom exception class for all plotting errors
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception PlotConfigError[source]#
Bases:
ValueError,PlottingErrorRaised when there were errors in the plot configuration
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception InvalidCreator[source]#
Bases:
ValueError,PlottingErrorRaised when an invalid creator was specified
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception PlotCreatorError[source]#
Bases:
PlottingErrorRaised when an error occured in a plot creator
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception ParallelPlottingError(excs: dict, *, create_summary: bool = True)[source]#
Bases:
PlottingErrorRaised upon error(s) in parallel plotting processes
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception SkipPlot(what: str = '')[source]#
Bases:
DantroMessagingExceptionA custom exception class that denotes that a plot is to be skipped.
This is typically handled by the
PlotManagerand can thus be raised anywhere below it: in the plot creators, in the user-defined plotting functions, …- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception UpdatePlotConfig(context: str | None = None, **plot_cfg_updates)[source]#
Bases:
DantroMessagingExceptionA custom exception class that allows to update the plot configuration from a lower level and causes the plot to start over with dynamically updated parameters. The exception itself is handled in
dantro.plot_mngr.PlotManager.plot()and can thus be raised anywhere below it: in the plot creators, in the user-defined plotting functions, …- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception EnterAnimationMode[source]#
Bases:
DantroMessagingExceptionAn exception that is used to convey to any
PyPlotCreatoror derived creator that animation mode is to be entered instead of a regular single-file plot.It can and should be invoked via
enable_animation().This exception can be raised from within a plot function to dynamically decide whether animation should happen or not. Its counterpart is
ExitAnimationMode.- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception ExitAnimationMode[source]#
Bases:
DantroMessagingExceptionAn exception that is used to convey to any
PyPlotCreatoror derived creator that animation mode is to be exited and a regular single-file plot should be carried out.It can and should be invoked via
disable_animation().This exception can be raised from within a plot function to dynamically decide whether animation should happen or not. Its counterpart is
ExitAnimationMode.- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception PlotHelperError(upstream_error: Exception, *, name: str, params: dict, ax_coords: Tuple[int, int] | None = None)[source]#
Bases:
PlotConfigErrorRaised upon failure to invoke a specific plot helper function, this custom exception type stores metadata on the helper invocation in order to generate a useful error message.
- __init__(upstream_error: Exception, *, name: str, params: dict, ax_coords: Tuple[int, int] | None = None)[source]#
Initializes a PlotHelperError
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception PlotHelperErrors(*errors, show_docstrings: bool = True)[source]#
Bases:
ValueErrorThis custom exception type gathers multiple individual instances of
PlotHelperError.- __init__(*errors, show_docstrings: bool = True)[source]#
Bundle multiple PlotHelperErrors together
- Parameters:
*errors – The individual instances of
PlotHelperErrorshow_docstrings (bool, optional) – Whether to show docstrings in the error message.
- property errors#
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MissingRegistryEntry[source]#
Bases:
ValueError,IndexError,KeyError,DantroErrorAn error that is raised when trying to access an entry in
ObjectRegistrythat does not exist.- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MissingNameError[source]#
Bases:
ValueError,DantroErrorAn error that is raised when a name is required but was not given for
ObjectRegistryregistration.- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception RegistryEntryExists[source]#
Bases:
ValueError,DantroErrorAn error that is raised when trying to set an entry in
ObjectRegistrythat already exist.- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception InvalidRegistryEntry[source]#
Bases:
TypeError,ValueError,DantroErrorAn error that is raised when trying to set an invalid entry in
ObjectRegistry.- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
dantro.logging module#
Configures the DantroLogger for the whole package
- _LOG_SETTINGS = {'divert_to': None, 'suppress_in_child_process': False}#
A mutable object allowing to dynamically change some log settings
- class DantroLogger(name, level=0)[source]#
Bases:
LoggerThe custom dantro logging class with additional log levels
- _log(lvl, msg, *args, **kwargs)[source]#
Low-level logging routine which creates a LogRecord and then calls all the handlers of this logger to handle the record.
- addFilter(filter)#
Add the specified filter to this handler.
- addHandler(hdlr)#
Add the specified handler to this logger.
- callHandlers(record)#
Pass a record to all relevant handlers.
Loop through all handlers for this logger and its parents in the logger hierarchy. If no handler was found, output a one-off error message to sys.stderr. Stop searching up the hierarchy whenever a logger with the “propagate” attribute set to zero is found - that will be the last logger whose handlers are called.
- critical(msg, *args, **kwargs)#
Log ‘msg % args’ with severity ‘CRITICAL’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
logger.critical(“Houston, we have a %s”, “major disaster”, exc_info=1)
- debug(msg, *args, **kwargs)#
Log ‘msg % args’ with severity ‘DEBUG’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
logger.debug(“Houston, we have a %s”, “thorny problem”, exc_info=1)
- error(msg, *args, **kwargs)#
Log ‘msg % args’ with severity ‘ERROR’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
logger.error(“Houston, we have a %s”, “major problem”, exc_info=1)
- exception(msg, *args, exc_info=True, **kwargs)#
Convenience method for logging an ERROR with exception information.
- fatal(msg, *args, **kwargs)#
Don’t use this method, use critical() instead.
- filter(record)#
Determine if a record is loggable by consulting all the filters.
The default is to allow the record to be logged; any filter can veto this and the record is then dropped. Returns a zero value if a record is to be dropped, else non-zero.
Changed in version 3.2: Allow filters to be just callables.
- findCaller(stack_info=False, stacklevel=1)#
Find the stack frame of the caller so that we can note the source file name, line number and function name.
- getChild(suffix)#
Get a logger which is a descendant to this one.
This is a convenience method, such that
logging.getLogger(‘abc’).getChild(‘def.ghi’)
is the same as
logging.getLogger(‘abc.def.ghi’)
It’s useful, for example, when the parent logger is named using __name__ rather than a literal string.
- getEffectiveLevel()#
Get the effective level for this logger.
Loop through this logger and its parents in the logger hierarchy, looking for a non-zero logging level. Return the first one found.
- handle(record)#
Call the handlers for the specified record.
This method is used for unpickled records received from a socket, as well as those created locally. Logger-level filtering is applied.
- hasHandlers()#
See if this logger has any handlers configured.
Loop through all handlers for this logger and its parents in the logger hierarchy. Return True if a handler was found, else False. Stop searching up the hierarchy whenever a logger with the “propagate” attribute set to zero is found - that will be the last logger which is checked for the existence of handlers.
- info(msg, *args, **kwargs)#
Log ‘msg % args’ with severity ‘INFO’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
logger.info(“Houston, we have a %s”, “interesting problem”, exc_info=1)
- isEnabledFor(level)#
Is this logger enabled for level ‘level’?
- log(level, msg, *args, **kwargs)#
Log ‘msg % args’ with the integer severity ‘level’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
logger.log(level, “We have a %s”, “mysterious problem”, exc_info=1)
- makeRecord(name, level, fn, lno, msg, args, exc_info, func=None, extra=None, sinfo=None)#
A factory method which can be overridden in subclasses to create specialized LogRecords.
- manager = <logging.Manager object>#
- removeFilter(filter)#
Remove the specified filter from this handler.
- removeHandler(hdlr)#
Remove the specified handler from this logger.
- root = <RootLogger root (WARNING)>#
- setLevel(level)#
Set the logging level of this logger. level must be an int or a str.
- warn(msg, *args, **kwargs)#
- warning(msg, *args, **kwargs)#
Log ‘msg % args’ with severity ‘WARNING’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
logger.warning(“Houston, we have a %s”, “bit of a problem”, exc_info=1)
dantro.plot_mngr module#
Implements the PlotManager, which handles the
configuration of multiple plots and prepares the data and configuration to pass
to the respective plot creators.
See the user manual for more information.
- BAD_PLOT_NAME_CHARS = ('*', '?', '[', ']', '!', ':', '(', ')', '\\', '.')#
Substrings that may not appear in plot names.
Unlike the
BAD_NAME_CHARS, these allow the/char (such that new directories can be created) and disallows the.character (in order to not get confused with file extensions).
- BASE_PLOTS_CFG_PATH: str = '/home/docs/checkouts/readthedocs.org/user_builds/dantro/checkouts/latest/dantro/cfg/base_plots.yml'#
The path to the base plot configurations pool for dantro.
If the
use_dantro_base_cfg_poolflag is set when initializing aPlotManager, this file will be used as the first entry in the sequence of config pools.Also see dantro base plot configuration pool for more information.
- class PlotManager(*, dm: DataManager, default_plots_cfg: dict | str | None = None, out_dir: str | None = '{timestamp:}/', base_cfg_pools: Sequence[Tuple[str, dict | str]] = (), use_dantro_base_cfg_pool: bool = True, out_fstrs: dict | None = None, plot_func_resolver_init_kwargs: dict | None = None, shared_creator_init_kwargs: dict | None = None, creator_init_kwargs: Dict[str, dict] | None = None, default_creator: str | None = None, save_plot_cfg: bool = True, raise_exc: bool = False, cfg_exists_action: str = 'raise')[source]#
Bases:
objectThe PlotManager takes care of configuring plots and calling the selected plot creators that then actually carry out the plotting operation.
It is a high-level class that is aware of a larger plot configuration and aggregates all general capabilities needed to configure and carry out plots using the plotting framework.
See the user manual for more information.
- PLOT_FUNC_RESOLVER#
The class to use for resolving plot function objects
alias of
PlotFuncResolver
- CREATORS: Dict[str, type] = {'base': <class 'dantro.plot.creators.base.BasePlotCreator'>, 'external': <class 'dantro.plot.creators.pyplot.PyPlotCreator'>, 'multiverse': <class 'dantro.plot.creators.psp.MultiversePlotCreator'>, 'pyplot': <class 'dantro.plot.creators.pyplot.PyPlotCreator'>, 'universe': <class 'dantro.plot.creators.psp.UniversePlotCreator'>}#
The mapping of creator names to classes. By default, all available dantro plot creators are registered.
When subclassing PlotManager and desiring to extend the creator mapping, use
dict(**dantro.plot.creators.ALL, my_new_creator=MyNewCreator)to include the default creator mapping.
- DEFAULT_OUT_FSTRS: Dict[str, str] = {'path': '{name:}{ext:}', 'plot_cfg': '{basename:}_cfg.yml', 'plot_cfg_sweep': '{name:}/sweep_cfg.yml', 'state': '{name:}_{val:}', 'state_join_char': '__', 'state_name_replace_chars': [], 'state_no': '{no:0{digits:d}d}', 'state_val_replace_chars': [('/', '-')], 'state_vector_join_char': '-', 'sweep': '{name:}/{state_no:}__{state:}{ext:}', 'timestamp': '%y%m%d-%H%M%S'}#
The default values for the output format strings, used when composing the file name of a plot.
- SPECIAL_BASE_CFG_POOL_LABELS: Sequence[str] = ('plot', 'plot_from_cfg', 'plot_from_cfg_unused', 'plot_pspace')#
Special keys that may not be used as labels for the base configuration pools.
- __init__(*, dm: DataManager, default_plots_cfg: dict | str | None = None, out_dir: str | None = '{timestamp:}/', base_cfg_pools: Sequence[Tuple[str, dict | str]] = (), use_dantro_base_cfg_pool: bool = True, out_fstrs: dict | None = None, plot_func_resolver_init_kwargs: dict | None = None, shared_creator_init_kwargs: dict | None = None, creator_init_kwargs: Dict[str, dict] | None = None, default_creator: str | None = None, save_plot_cfg: bool = True, raise_exc: bool = False, cfg_exists_action: str = 'raise')[source]#
Initialize a PlotManager, which provides a uniform configuration interface for creating plots and passes tasks on to the respective plot creators.
To avoid copy-paste of plot configurations, the PlotManager comes with versatile capabilities to define default plots and re-use other plots.
The
default_plots_cfgspecifies plot configurations that are to be carried out by default when calling the plotting methodplot_from_cfg().When calling any of the plot methods
plot_from_cfg()orplot(), there is the possibility to update the existing configuration dict with new entries.At each stage, the
based_onfeature allows to make a plot configuration inherit entries from an existing configuration. These are looked up from thebase_cfg_poolsfollowing the rules described inresolve_based_on().
For more information on how the plot configuration can be defined, see Plot Configuration Inheritance.
- Parameters:
dm (DataManager) – The DataManager-derived object to read the plot data from.
default_plots_cfg (Union[dict, str], optional) – The default plots config or a path to a YAML file to import. Used as defaults when calling
plot_from_cfg()out_dir (Union[str, None], optional) – If given, will use this output directory as basis for the output path for each plot. The path can be a format-string; it is evaluated upon call to the plot command. Available keys:
timestamp,name, … For a relative path, this will be relative to the DataManager’s output directory. Absolute paths remain absolute. If this argument evaluates to False, the DataManager’s output directory will be the output directory.base_cfg_pools (Sequence[Tuple[str, Union[dict, str]]], optional) – The base configuration pools are used to perform the lookups of
based_onentries, see Plot Configuration Inheritance. The tuples in these sequence consist of(label, plots_cfg)pairs and are fed toadd_base_cfg_pool(); see there for more information.use_dantro_base_cfg_pool (bool, optional) – If set, will use dantro’s own base plot configuration pool as the first entry in the pool sequence. Refer to the corresponding documentation page for more information on available entries.
out_fstrs (dict, optional) –
Format strings that define how the output path is generated. The dict given here updates the
DEFAULT_OUT_FSTRSclass variable which holds the default values.Keys:
timestamp(%-style),path,sweep,state,plot_cfg,state,state_no,state_join_char,state_vector_join_char.Available keys for
path:name,timestamp,ext.- Additionally, for
sweep:state_no,state_vector, state.
- Additionally, for
plot_func_resolver_init_kwargs (dict, optional) – Initialization arguments for the plot function resolver, by default
PlotFuncResolver.shared_creator_init_kwargs (dict, optional) – Initialization arguments to the plot creator that are passed to all creators regardless of type (in contrast to
creator_init_kwargs).creator_init_kwargs (Dict[str, dict], optional) – If given, these kwargs are passed to the initialization calls of the respective creator classes. These are resolved by the names given in the
CREATORSclass variable and are passed to theBasePlotCreatoror the respective derived class.default_creator (str, optional) – If given, a plot without explicit
creatordeclaration will use this creator as default.save_plot_cfg (bool, optional) – If True, the plot configuration is saved to a yaml file alongside the created plot.
raise_exc (bool, optional) – Whether to raise exceptions if there are errors raised from the plot creator or errors in the plot configuration. If False, the errors will only be logged.
cfg_exists_action (str, optional) – Behaviour when a config file already exists. Can be:
raise(default),skip,append,overwrite, oroverwrite_nowarn.
- property base_cfg_pools: OrderedDict#
The base plot configuration pools, used for lookup the
based_onentry in plot configurations.The order of the entries in the pool is relevant, with later entries taking precedence over previous ones. See Plot Configuration Inheritance for a more detailed description.
- add_base_cfg_pool(*, label: str, plots_cfg: str | dict)[source]#
Adds a base configuration pool entry, allowing for the
plots_cfgto be a path to a YAML configuration file which is then loaded.The new pool is used for
based_onlookups and takes precedence over existing entries. For more information on lookup rules, seeresolve_based_on()and Plot Configuration Inheritance.- Parameters:
- Raises:
ValueError – If
labelalready exists or is a special label.
- static _prepare_cfg(s: str | dict) Dict[str, dict][source]#
Prepares a plots configuration by either loading it from a YAML file if the given argument is a string or returning a deep copy of the given dict-like object.
- _handle_exception(exc: Exception, *, pc: ~dantro.plot.creators.base.BasePlotCreator, debug: bool | None = None, ExcCls: type = <class 'dantro.exceptions.PlottingError'>)[source]#
Helper for handling exceptions from the plot creator
- _parse_out_dir(fstr: str, *, name: str) str[source]#
Evaluates the format string to create an output directory path.
Note that the directories are _not_ created; this is outsourced to the plot creator such that it happens as late as possible.
- _parse_out_path(creator: BasePlotCreator, *, name: str, out_dir: str, file_ext: str | None = None, state_no: int | None = None, state_no_max: int | None = None, state_vector: Tuple[int] | None = None, dims: dict | None = None) str[source]#
Given a creator and (optionally) parameter sweep information, a full and absolute output path is generated, including the file extension.
Note that the directories are _not_ created; this is outsourced to the plot creator such that it happens as late as possible.
- Parameters:
creator (BasePlotCreator) – The creator instance, used to extract information on the file extension.
name (str) – The name of the plot
out_dir (str) – The absolute output directory, prepended to all generated paths
file_ext (str, optional) – The file extension to use
state_no (int, optional) – The state number, starting with 0
state_no_max (int, optional) – The maximum state number
state_vector (Tuple[int], optional) – The state vector with info on how far each state dimension has progressed in the sweep
dims (dict, optional) – The dict of parameter dimensions of the sweep that is carried out.
- Returns:
The fully parsed output path for this plot
- Return type:
- _get_plot_func(**resolver_kwargs) Callable[source]#
Instantiates a plot function resolver,
PlotFuncResolver, and uses it to get the desired plot function callable.
- _get_plot_func_resolver(**init_kwargs) PlotFuncResolver[source]#
Instantiates the plot function resolver object with the given initialization arguments.
This method is called from
_get_plot_func()and can be used for more conveniently controlling how the resolver is set up. By default, theinit_kwargswill be equivalent to theplot_func_resolver_init_kwargsgiven to__init__().
- _get_plot_creator(*, creator: str | Callable, plot_func: Callable, name: str, init_kwargs: dict) BasePlotCreator[source]#
Determines which plot creator to use by looking at the given arguments and the plotting function.
Then, sets up the corresponding creator and returns it.
This method is called from
_plot().- Parameters:
creator (Union[str, Callable]) – The name of the creator to be looked up in
CREATORS. Can also be None, in which case it is attempted to look it up from theplot_func‘screatorattribute. If that was not possible either, thedefault_creatoris used. If a callable is given, will use that as a factory to construct the creator instance.name (str) – The name that will be used for the plot creator, typically the plot name itself.
init_kwargs (dict) – Additional creator initialization parameters
- Returns:
The selected creator object, fully initialized.
- Return type:
- _invoke_plot_creation(plot_creator: BasePlotCreator, *, out_path: str, debug: bool | None = None, **plot_cfg) bool | str[source]#
This method wraps the plot creator’s
__call__and is the last PlotManager method that is called prior to handing over to the selected plot creator. It takes care of invoking the plot creator’s__call__method and handling potential error messages and return values.- Parameters:
plot_creator (BasePlotCreator) – The currently used creator object
out_path (str) – The plot output path
debug (bool, optional) – If given, this overwrites the
raise_excoption specified during initialization.**plot_cfg – The plot configuration
- Returns:
- Whether the plot was carried out successfully.
Returns the string
'skipped'if the plot was skipped via aSkipPlotexception.
- Return type:
- Raises:
PlotCreatorError – On error within the plot creator. This is only raised if either
debug is Trueordebug is None and self.raise_exc. Otherwise, the error message is merely logged.
- _invoke_parallel_plot_creation(*, task_key: Any, plot_creator: BasePlotCreator, out_path: str, cfg: dict, plot_cfg: dict) Tuple[int, str, str, bool | str][source]#
Shallow wrapper around plot creator invocation, preparing arguments for invocation in the context of parallel execution.
- Returns:
Tuple of (task_key, captured_stdout, captured_stderr, return_value)
- _invoke_parallel_executor_benchmark() bool[source]#
A method that is passed to a parallel executor for benchmarking how long it takes to spin up a new thread or process. This is especially relevant for processes, because they require that the PlotManager and all accompanying objects are pickled and passed to the child process, which can take a long time …
The method itself does not perform any actions.
- _parse_parallel_plotting_kwargs(*, enabled: bool, executor: Literal['thread', 'process'] = 'process', max_workers: int | float | None = None, fallback_on_fail: bool = False, benchmark_overhead: bool | int = 5, **executor_kwargs) dict[source]#
Prepares arguments for parallel plotting
- _parallel_executor(executor_name: str, *, max_workers: int = None, **executor_kwargs) Executor[source]#
- _handle_UpdatePlotConfig(upc: UpdatePlotConfig, plot_cfg: dict) dict[source]#
Updates the plot configuration with the given updates.
- _store_plot_info(name: str, *, plot_cfg: dict, plot_cfg_extras: dict, creator_name: str, save: bool, target_dir: str, part_of_sweep: bool = False, **info)[source]#
Stores all plot information in the plot_info list and, if
saveis set, also saves it using_save_plot_cfg().
- _save_plot_cfg(cfg: dict, *, name: str, target_dir: str, exists_action: str | None = None, is_sweep: bool = False, **plot_cfg_extras) str[source]#
Saves the given configuration under the top-level entry
nameto a yaml file.- Parameters:
cfg (dict) – The plot configuration to save
name (str) – The name of the plot
target_dir (str) – The directory path to store the file in
exists_action (str, optional) – What to do if a plot configuration already exists. Can be:
overwrite,overwrite_nowarn,skip,append,raise. If None, uses the value of thecfg_exists_actionargument given during initialization.is_sweep (bool, optional) – Set if the configuration refers to a plot in sweep mode, for which a different format string is used
**plot_cfg_extras – Added to the plot configuration via recursive update.
- Returns:
The path the config was saved at (mainly used for testing)
- Return type:
- Raises:
ValueError – For invalid
exists_actionargument
- plot_from_cfg(*, plots_cfg: dict | str | None = None, plot_only: List[str] | None = None, out_dir: str | None = None, resolve_based_on: bool = True, **update_plots_cfg) None[source]#
Create multiple plots from a configuration, either a given one or the one passed during initialization.
This is mostly a wrapper around the plot function, allowing additional ways of how to configure and create plots.
- Parameters:
plots_cfg (Union[dict, str], optional) – The plots configuration to use. If not given, the
default_plots_cfgspecified during initialization is used. If a string is given, will assume it is a path and load the file.plot_only (List[str], optional) – If given, create only those plots from the resulting configuration that match these names. This will lead to the enabled key being ignored, regardless of its value. The strings given here may also include Unix shell-like wildcards like
*and? ``, which are matched using the Python ``fnmatchmodule.out_dir (str, optional) – A different output directory; will use the one passed at initialization if the given argument evaluates to False.
resolve_based_on (bool, optional) – Whether to resolve the
based_onentries inplots_cfghere. If false, will postpone this toplot(), thus not including the rest of theplots_cfgin the base configuration pool for name resolution. Lookups happen frombase_cfg_poolsfollowing the rules described inresolve_based_on().**update_plots_cfg – If given, it is used to update the plots_cfg recursively. Note that on the top level the _names_ of the plots are placed; this cannot be used to make all plots have a common property. Furthermore, this update happens before the
based_onentries are resolved.
- Raises:
PlotConfigError – Empty or invalid plot configuration
ValueError – Bad
plot_onlyargument, e.g. not matching any of the available plot names.
- plot(name: str, *, based_on: str | Tuple[str] | None = None, from_pspace: dict | ParamSpace | None = None, **plot_cfg) BasePlotCreator[source]#
Create plot(s) from a single configuration entry.
A call to this function resolves the
based_onfeature and passes the derived plot configuration to_plot(), which actually carries out the plotting. See there for documentation of further arguments.Note that more than one plot can result from a single configuration entry, e.g. when plots were configured that have more dimensions than representable in a single file.
For
- Parameters:
name (str) – The name of this plot. This will be used for generating an output file path later on. Some characters are not allowed, e.g.
*and?, but a/can be used to store the plot output in a subdirectory.based_on (Union[str, Tuple[str]], optional) – A key or a sequence of keys of entries in the base pool that should be used as the basis of this plot. The given plot configuration is then used to recursively update (a copy of) those base configuration entries. Lookups happen from
base_cfg_poolsfollowing the rules described inresolve_based_on().from_pspace (Union[dict, ParamSpace], optional) – If given, execute a parameter sweep over these parameters, re-using the same creator instance. If this is a dict, a ParamSpace is created from it.
**plot_cfg – The plot configuration, including some parameters that the plot manager will evaluate (and consequently: does not pass on to the plot creator). If using
from_pspace, parameters given here will recursively update those given infrom_pspace.
- Returns:
The PlotCreator used for these plots
- Return type:
- _plot(name: str, *, plot_func: str | Callable | None = None, module: str | None = None, module_file: str | None = None, creator: str | Callable | None = None, out_dir: str | None = None, default_out_dir: str | None = None, file_ext: str | None = None, save_plot_cfg: bool | None = None, creator_init_kwargs: dict | None = None, from_pspace: dict | None = None, parallel: bool | dict | None = None, **plot_cfg) BasePlotCreator[source]#
Create plot(s) from a single configuration entry.
This first resolves the plot function using the plot function resolver class:
PlotFuncResolveror a derived class (depending on thePLOT_FUNC_RESOLVER).A call to this function creates a plot creator, which is also returned after all plots are finished.
Note that more than one plot can result from a single configuration entry, e.g. when plots were configured that have more dimensions than representable in a single file or when using
from_pspace.- Parameters:
name (str) – The name of this plot
plot_func (Union[str, Callable], optional) – The name or module string of the plot function as it can be imported from
module. If this is a callable will directly return that callable. This argument needs be given.module (str) – If
plot_funcwas the name of the plot function, this needs to be the name of the module to import that name from.module_file (str) – Path to the file to load and look for the
plot_funcin. Ifbase_module_file_diris given during initialization, this can also be a path relative to that directory.creator (Union[str, Callable]) – The name of the creator to be looked up in
CREATORS. Can also be None, in which case it is attempted to look it up from theplot_func‘screatorattribute. If that was not possible either, thedefault_creatoris used. If a callable is given, will use that as a factory to set up the creator.out_dir (str, optional) – If given, will use this directory as out directory. If not, will use the default value given by
default_out_diror that given at initialization.default_out_dir (str, optional) – An output directory that was determined in the calling context and which should be used as default if no
out_dirwas given explicitly.file_ext (str, optional) – The file extension to use, including the leading dot!
save_plot_cfg (bool, optional) – Whether to save the plot config. If not given, uses the default value from initialization.
creator_init_kwargs (dict, optional) – Passed to the plot creator during initialization. Note that the arguments given at initialization of the PlotManager are updated by this.
from_pspace (dict, optional) – If given, execute a parameter sweep over this parameter space, re-using the same creator instance. Each point in parameter space will end up calling this method with arguments unpacked to the
plot_cfgargument.**plot_cfg – The plot configuration to pass on to the plot creator. This may be completely empty if
from_pspaceis used!
- Returns:
- The PlotCreator used for these plots. This will
also be returned in case the plot failed!
- Return type:
- Raises:
PlotConfigError – If no out directory was specified here or at initialization.
PlotCreatorError – In case the preparation or execution of the plot failed for whatever reason. Not raised if not in debug mode.
- _plot_pspace(from_pspace: ParamSpace, *, name: str, creator_name: str, plot_creator: BasePlotCreator, out_dir: str, file_ext: str, plot_cfg: dict, plot_cfg_extras: dict, save_plot_cfg: bool, t0: float, psp_vol: int, psp_dims: list, n_max: int) dict[source]#
Performs parameter sweep plots in sequence.
- _plot_pspace_parallel(from_pspace: ParamSpace, *, name: str, creator_name: str, plot_creator: BasePlotCreator, out_dir: str, file_ext: str, plot_cfg: dict, plot_cfg_extras: dict, save_plot_cfg: bool, t0: float, psp_vol: int, psp_dims: list, n_max: int, executor_name: Literal['thread', 'process'], benchmark_overhead: int | bool, show_exception_summary: bool = True, **executor_kwargs) dict[source]#
Performs parameter sweep plots in sequence.
dantro.tools module#
This module implements tools that are generally useful in dantro
- TERMINAL_INFO = {'columns': 80, 'is_a_tty': False, 'lines': 24}#
Holds information about the size and properties of the used terminal.
Warning
Do not update this manually, call
update_terminal_info()instead.
- update_terminal_info() dict[source]#
Updates the
TERMINAL_INFOconstant with information about the number of columns, lines, and whether the terminal is a TTY terminal.If retrieving the properties via
shutil.get_terminal_size()fails for whatever reason, will not apply any changes.
- IS_A_TTY = False#
Whether the used terminal is a TTY terminal
Deprecated since version v0.18: Use the
dantro.tools.TERMINAL_INFO["is_a_tty"]entry instead.
- TTY_COLS = 80#
Number of columns in a TTY terminal
Deprecated since version v0.18: Use the
dantro.tools.TERMINAL_INFO["columns"]entry instead.
- recursive_update(d: dict, u: dict) dict[source]#
Recursively updates the Mapping-like object
dwith the Mapping-like objectuand returns it. Note that this does not create a copy ofd, but changes it mutably!
- recursive_getitem(obj: Mapping | Sequence, keys: Sequence)[source]#
Go along the sequence of
keysthroughobjand return the target item.- Parameters:
obj (Union[Mapping, Sequence]) – The object to get the item from
keys (Sequence) – The sequence of keys to follow
- Returns:
The target item from
obj, specified bykeys- Raises:
ValueError – If any index or key in the key sequence was not available
- clear_line(only_in_tty=True, break_if_not_tty=True)[source]#
Clears the current terminal line and resets the cursor to the first position using a POSIX command.
- fill_line(s: str, *, num_cols: int | None = None, fill_char: str = ' ', align: str = 'left') str[source]#
Extends the given string such that it fills a whole line of num_cols columns.
- Parameters:
s (str) – The string to extend to a whole line
num_cols (int, optional) – The number of colums of the line; defaults to the number of terminal columns.
fill_char (str, optional) – The fill character
align (str, optional) – The alignment. Can be: ‘left’, ‘right’, ‘center’ or the one-letter equivalents.
- Returns:
The string of length num_cols
- Return type:
- Raises:
ValueError – For invalid align or fill_char argument
- print_line(s: str, *, end='\r', **kwargs)[source]#
Wrapper around
fill_line()that also prints a line with carriage return (without new line) as end character. This is useful for progress report lines that overwrite the previously printed content repetitively.
- center_in_line(s: str, *, num_cols: int | None = None, fill_char: str = '·', spacing: int = 1) str[source]#
Shortcut for a common fill_line use case.
- Parameters:
- Returns:
The string centered in the line
- Return type:
- make_columns(items: List[str], *, wrap_width: int | None = None, fstr: str = ' {item:<{width:}s} ') str[source]#
Given a sequence of string items, returns a string with these items spread out over several columns. Iteration is first within the row and then into the next row.
The number of columns is determined automatically from the wrap width, the length of the longest item in the items list, and the length of the evaluated format string.
- Parameters:
items (List[str]) – The string items to represent in columns.
wrap_width (int, optional) – The maximum width of each full row. If not given will determine it automatically
fstr (str, optional) – The format string to use. Needs to accept the keys
itemandwidth, the latter of which will be used for padding. The format string should lead to strings of equal length, otherwise the column layout will be messed up!
- decode_bytestrings(obj) str[source]#
Checks whether the given attribute value is or contains byte strings and if so, decodes it to a python string.
- Parameters:
obj – The object to try to decode into holding python strings
- Returns:
Either the unchanged object or the decoded one
- Return type:
- DoNothingContext#
An alias for a context … that does nothing
- is_unpickleable_function(f) bool[source]#
Checks whether a function is (typically) unpickleable, which is relevant when using multiprocessing.
Returns True if
fis any of the following:A
lambdafunction (has no qualified name or global reference)A function defined in the
__main__module (not importable from subprocesses)A nested function (its
__qualname__includes a dot, indicating it’s scoped inside another function or method)A function with a closure (i.e. it captures variables from an outer scope)
These functions are typically unpickleable by the standard pickle module (which is the one used in
multiprocessingandfutures) and will raisePicklingErrorwhen passed to multiprocessing-based executors, e.g.ProcessPoolExecutor.Note
For performance and reliablity reasons, we avoid using pickle directly and instead check the function type and metadata.
- Parameters:
f – The function to check
- Returns:
- True if it is a (typically) unpickleable function-like object,
False otherwise.
- Return type:
- try_conversion(c: str) bool | int | float | complex | str | None[source]#
Given a string, attempts to convert it to a numerical value or a bool.
- parse_str_to_args_and_kwargs(s: str, *, sep: str) Tuple[list, dict][source]#
Parses strings like
65,0,sep=12into a positional arguments list and a keyword arguments dict.Behavior:
Positional arguments are all arguments that do not include
=. Keyword arguments are those that do include=.Will use
try_conversion()to convert argument values.Trailing and leading white space on argument names and values is stripped away using
strip().
Warning
Cannot handle string arguments that include
sepor=!Cannot handle arguments that define lists, tuples or other more complex objects.
Hint
For more complex argument parsing, consider using a YAML parser instead of this (rather simple) function!
- class adjusted_log_levels(*new_levels: Sequence[Tuple[str, int]])[source]#
Bases:
objectA context manager that temporarily adjusts log levels
- format_bytesize(num: int, *, precision: int = 1) str[source]#
Formats a size in bytes to a human readable (binary) format.
Stripped down from https://stackoverflow.com/a/63839503/1827608 .
- format_time(duration: float | timedelta, *, ms_precision: int = 0, max_num_parts: int | None = None) str[source]#
Given a duration (in seconds), formats it into a string.
The formatting divisors are: days, hours, minutes, seconds
If
ms_precision> 0 andduration< 60, decimal places will be shown for the seconds.- Parameters:
duration (Union[float, timedelta]) – The duration in seconds to format into a duration string; it can also be a timedelta object.
ms_precision (int, optional) – The precision of the seconds slot
max_num_parts (int, optional) – How many parts to include when creating the formatted time string. For example, if the time consists of the parts seconds, minutes, and hours, and the argument is
2, only the hours and minutes parts will be shown, thus reducing the precision of the overall representation ofduration. If None, all parts are included.
- Returns:
The formatted duration string
- Return type:
- ensure_posix_path_on_windows(p: str) str[source]#
Prepares a path for use on Windows platform via
pathlib.PureWindowsPathand itsas_posixmethod.
- glob_paths(glob_str: str | List[str], *, ignore: List[str] | None = None, base_path: str | None = None, sort: bool = False, recursive: bool = True, include_files: bool = True, include_directories: bool = True) List[str][source]#
Generates a list of paths from a glob string and a number of additional options.
Paths may refer to file and directory paths. Uses
glob.glob()for matching glob strings.Note
Internally, this uses a set, thus ensuring that there are no duplicate paths in the returned list.
- Parameters:
glob_str (Union[str, List[str]]) – The glob pattern or a list of glob patterns to use for searching for files. Relative paths will be seen as relative to
base_path.ignore (List[str]) – A list of paths to ignore. Relative paths will be seen as relative to
base_path. Supports glob patterns.base_path (str, optional) – The base path for the glob pattern. If not given, will use the current working directory.
sort (bool, optional) – If true, sorts the list before returning.
recursive (bool, optional) – If true, will activate recursive glob patterns (see
glob.glob()).include_files (bool, optional) – If false, will remove file paths from the set of paths.
include_directories (bool, optional) – If false, will remove directory paths from the set of paths.
- Returns:
The file or directory paths that matched
glob_strand were not filtered out by the other options.- Return type:
List[str]
- Raises:
ValueError – If the given
base_pathwas not absolute.