Esempio n. 1
0
    def test_json_load(self):
        class Test(Enum):
            test0 = 0
            test1 = 1
            test2 = 2

        test_json = json.dumps(Test.test0, cls=PartEncoder)

        assert not check_loaded_dict(json.loads(test_json, object_hook=part_hook))

        enum_register.register_class(Test)
        assert isinstance(json.loads(test_json, object_hook=part_hook), Test)
Esempio n. 2
0
class NeighType(Enum):
    sides = 6
    edges = 18
    vertex = 26

    def __str__(self):
        return self.name


try:
    # noinspection PyUnresolvedReferences,PyUnboundLocalVariable
    reloading
except NameError:
    reloading = False  # means the module is being imported firs time
    enum_register.register_class(NeighType)


def calculate_distances_array(spacing, neigh_type: NeighType):
    """
    :param spacing: image spacing
    :param neigh_type: neigbourhood type
    :return: neighbourhood array, distance array
    """
    min_dist = min(spacing)
    normalized_spacing = [x / min_dist for x in spacing]
    if len(normalized_spacing) == 2:
        neighbourhood_array = neighbourhood2d
        if neigh_type == NeighType.sides:
            neighbourhood_array = neighbourhood_array[:4]
        normalized_spacing = [0] + normalized_spacing
Esempio n. 3
0
# coding=utf-8
from enum import Enum

from PartSegCore.class_generator import enum_register


# noinspection NonAsciiCharacters
class Units(Enum):
    mm = 0
    µm = 1
    nm = 2
    pm = 3

    def __str__(self):
        return self.name.replace("_", " ")


enum_register.register_class(Units)

_UNITS_LIST = ["mm", "µm", "nm", "pm"]
UNIT_SCALE = [10 ** 3, 10 ** 6, 10 ** 9, 10 ** 12]
Esempio n. 4
0
            data,
            colormap=param.colormaps[i],
            visible=param.visibility[i],
            blending=blending,
            scale=param.scaling,
            contrast_limits=lim,
            gamma=param.gamma[i],
            name=f"channel {i}; {param.layers + i}",
        )
        image_layers.append(layer)
    return ImageInfo(image, image_layers, []), replace


prepare_layers = thread_worker(_prepare_layers)


def _print_dict(dkt: MutableMapping, indent="") -> str:
    if not isinstance(dkt, MutableMapping):
        logging.error(f"{type(dkt)} instead of dict passed to _print_dict")
        return indent + str(dkt)
    res = []
    for k, v in dkt.items():
        if isinstance(v, MutableMapping):
            res.append(f"{indent}{k}:\n{_print_dict(v, indent+'  ')}")
        else:
            res.append(f"{indent}{k}: {v}")
    return "\n".join(res)


enum_register.register_class(LabelEnum)