dcnum.meta.ppid =============== .. py:module:: dcnum.meta.ppid Attributes ---------- .. autoapisummary:: dcnum.meta.ppid.DCNUM_PPID_GENERATION Classes ------- .. autoapisummary:: dcnum.meta.ppid.ClassWithPPIDCapabilities dcnum.meta.ppid.AbrvStr Functions --------- .. autoapisummary:: dcnum.meta.ppid.compute_pipeline_hash dcnum.meta.ppid.convert_to_dtype dcnum.meta.ppid.get_class_method_info dcnum.meta.ppid.kwargs_to_ppid dcnum.meta.ppid.ppid_to_kwargs dcnum.meta.ppid.simple_type_eval dcnum.meta.ppid.get_unique_prefix Module Contents --------------- .. py:data:: DCNUM_PPID_GENERATION :value: '13' The dcnum pipeline generation. Increment this string if there are breaking changes that make previous pipelines unreproducible. .. py:class:: ClassWithPPIDCapabilities Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto(Protocol[T]): def meth(self) -> T: ... .. py:method:: get_ppid() -> str full pipeline identifier for the class (instance method) .. py:method:: get_ppid_code() -> str string representing the class in the pipeline (classmethod) .. py:method:: get_ppid_from_ppkw() -> str pipeline identifier from specific pipeline keywords (classmethod) .. py:method:: get_ppkw_from_ppid() -> dict class keywords from full pipeline identifier (staticmethod) .. py:function:: compute_pipeline_hash(*, bg_id, seg_id, feat_id, gate_id, dat_id='unknown', gen_id=DCNUM_PPID_GENERATION) .. py:function:: convert_to_dtype(value, dtype) Convert an object to the correct dtype If `dtype` is a Union of types, or a list of types, the first non-NoneType type is used for conversion. .. py:function:: get_class_method_info(class_obj: ClassWithPPIDCapabilities, static_kw_methods: list | None = None, static_kw_defaults: dict | None = None) -> dict[str, Any] Return dictionary of class info with static keyword methods docs :param class_obj: Class to inspect, must implement the `key` method. :type class_obj: object :param static_kw_methods: The methods to inspect; all kwargs-only keyword arguments are extracted. :type static_kw_methods: list of callable :param static_kw_defaults: If a key in this dictionary matches an item in `static_kw_methods`, then these are the default values returned in the "defaults" dictionary. This is used in cases where a base class does implement some annotations, but the subclass does not actually use them, because e.g. they are taken from a property such as is the case for the mask postprocessing of segmenter classes. :type static_kw_defaults: dict .. py:function:: kwargs_to_ppid(cls: ClassWithPPIDCapabilities, method: str, kwargs: dict, allow_invalid_keys: bool = True) .. py:function:: ppid_to_kwargs(cls, method, ppid) Convert pipeline method id to method keyword arguments .. rubric:: Notes Keep in mind that when a `method` is changed in a later version, new keyword arguments should always be put AT THE VERY END of the keyword list. Otherwise, might will be ambiguities regarding the abbreviated keys! .. py:function:: simple_type_eval(type_string: str | type) -> str | type | list Return the type encoded by a string, e.g. "bool" -> bool If `type_string` is already a type, it is passed through. If there is no rule to convert `type_string` to a type, `type_string` is returned as-is. If `type_string` represents a union of types (using '|'), then a list of types is returned. .. py:class:: AbrvStr(string) .. py:attribute:: string .. py:attribute:: abrv_lengths :value: [1] .. py:method:: __getitem__(item) .. py:property:: abrv .. py:method:: meet(other) .. py:function:: get_unique_prefix(str_list) Find unique prefix for a list of strings :param str_list: List of strings to abbreviate :type str_list: list of str