dcnum.meta.ppid

Attributes

DCNUM_PPID_GENERATION

The dcnum pipeline generation.

Classes

ClassWithPPIDCapabilities

Base class for protocol classes.

AbrvStr

Functions

compute_pipeline_hash(*, bg_id, seg_id, feat_id, gate_id)

convert_to_dtype(value, dtype)

Convert an object to the correct dtype

get_class_method_info(→ dict[str, Any])

Return dictionary of class info with static keyword methods docs

kwargs_to_ppid(cls, method, kwargs[, allow_invalid_keys])

ppid_to_kwargs(cls, method, ppid)

Convert pipeline method id to method keyword arguments

simple_type_eval(→ str | type | list)

Return the type encoded by a string, e.g. "bool" -> bool

get_unique_prefix(str_list)

Find unique prefix for a list of strings

Module Contents

dcnum.meta.ppid.DCNUM_PPID_GENERATION = '13'

The dcnum pipeline generation. Increment this string if there are breaking changes that make previous pipelines unreproducible.

class dcnum.meta.ppid.ClassWithPPIDCapabilities[source]

Bases: 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:
        ...
get_ppid() str[source]

full pipeline identifier for the class (instance method)

get_ppid_code() str[source]

string representing the class in the pipeline (classmethod)

get_ppid_from_ppkw() str[source]

pipeline identifier from specific pipeline keywords (classmethod)

get_ppkw_from_ppid() dict[source]

class keywords from full pipeline identifier (staticmethod)

dcnum.meta.ppid.compute_pipeline_hash(*, bg_id, seg_id, feat_id, gate_id, dat_id='unknown', gen_id=DCNUM_PPID_GENERATION)[source]
dcnum.meta.ppid.convert_to_dtype(value, dtype)[source]

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.

dcnum.meta.ppid.get_class_method_info(class_obj: ClassWithPPIDCapabilities, static_kw_methods: list | None = None, static_kw_defaults: dict | None = None) dict[str, Any][source]

Return dictionary of class info with static keyword methods docs

Parameters:
  • class_obj (object) – Class to inspect, must implement the key method.

  • static_kw_methods (list of callable) – The methods to inspect; all kwargs-only keyword arguments are extracted.

  • static_kw_defaults (dict) – 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.

dcnum.meta.ppid.kwargs_to_ppid(cls: ClassWithPPIDCapabilities, method: str, kwargs: dict, allow_invalid_keys: bool = True)[source]
dcnum.meta.ppid.ppid_to_kwargs(cls, method, ppid)[source]

Convert pipeline method id to method keyword arguments

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!

dcnum.meta.ppid.simple_type_eval(type_string: str | type) str | type | list[source]

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.

class dcnum.meta.ppid.AbrvStr(string)[source]
string
abrv_lengths = [1]
__getitem__(item)[source]
property abrv
meet(other)[source]
dcnum.meta.ppid.get_unique_prefix(str_list)[source]

Find unique prefix for a list of strings

Parameters:

str_list (list of str) – List of strings to abbreviate