Exemplo n.º 1
0
 def __init__(self, json_path):
     super().__init__(json_path)
     self._mask = None
     self.compare_segmentation = None
     self.segmentation_pipelines_dict = ProfileDict()
     self.segmentation_profiles_dict = ProfileDict()
     self.batch_plans_dict = ProfileDict()
     self.measurement_profiles_dict = ProfileDict()
Exemplo n.º 2
0
    def test_callback(self):
        def dummy_call():
            receiver.dummy()

        receiver = MagicMock()

        dkt = ProfileDict()
        dkt.connect("", receiver.empty)
        dkt.connect("", dummy_call)
        dkt.connect("b", receiver.b)
        dkt.connect(["d", "c"], receiver.dc)

        dkt.set("test.a", 1)
        assert receiver.empty.call_count == 1
        assert receiver.dummy.call_count == 1
        receiver.empty.assert_called_with("a")
        receiver.dummy.assert_called_with()
        dkt.set("test.a", 1)
        assert receiver.empty.call_count == 1
        receiver.b.assert_not_called()
        dkt.set("test2.a", 1)
        assert receiver.empty.call_count == 2
        receiver.b.assert_not_called()
        dkt.set(["test", "b"], 1)
        assert receiver.empty.call_count == 3
        assert receiver.b.call_count == 1
        dkt.set("test.d.c", 1)
        receiver.dc.assert_called_once()
        dkt.set("test.a", 2)
        assert receiver.empty.call_count == 5
Exemplo n.º 3
0
 def __init__(self, json_path, profile_name="default"):
     super().__init__(json_path, profile_name)
     self._mask = None
     self.compare_segmentation = None
     self._segmentation_pipelines_dict = ProfileDict()
     self._segmentation_profiles_dict = ProfileDict()
     self._batch_plans_dict = ProfileDict()
     self._measurement_profiles_dict = ProfileDict()
     self._segmentation_profiles_dict.connect(
         "", self.roi_profiles_changed.emit, maxargs=0)
     self._segmentation_pipelines_dict.connect(
         "", self.roi_pipelines_changed.emit, maxargs=0)
     self._measurement_profiles_dict.connect(
         "", self.measurement_profiles_changed.emit, maxargs=0)
     self._batch_plans_dict.connect("",
                                    self.batch_plans_changed.emit,
                                    maxargs=0)
Exemplo n.º 4
0
 def test_dump_custom_types(self):
     prof_dict = ProfileDict()
     prof_dict.set("a.b.c", 1)
     data = {"a": RadiusType.R2D, "b": prof_dict}
     text = json.dumps(data, cls=ProfileEncoder)
     loaded = json.loads(text, object_hook=profile_hook)
     assert loaded["a"] == RadiusType.R2D
     assert loaded["b"].get("a.b.c") == 1
Exemplo n.º 5
0
 def __init__(self, json_path):
     super().__init__()
     self.current_segmentation_dict = "default"
     self.segmentation_dict = ProfileDict()
     self.json_folder_path = json_path
     self.last_executed_algorithm = ""
     self.history: List[HistoryElement] = []
     self.history_index = -1
Exemplo n.º 6
0
 def __init__(self):
     super().__init__()
     self.color_map = []
     self.border_val = []
     self.current_profile_dict = "default"
     self.view_settings_dict = ProfileDict()
     self.colormap_dict = ColormapDict(self.get_from_profile("custom_colormap", {}))
     self.label_color_dict = LabelColorDict(self.get_from_profile("custom_label_colors", {}))
     self.cached_labels: Optional[Tuple[str, np.ndarray]] = None
Exemplo n.º 7
0
    def test_serialize(self, tmp_path):
        dkt = ProfileDict()
        dkt.set("a.b.c", 1)
        dkt.set("a.b.a", 2)
        with open(tmp_path / "test.json", "w") as f_p:
            json.dump(dkt, f_p, cls=ProfileEncoder)
        with open(tmp_path / "test.json") as f_p:
            dkt2 = json.load(f_p, object_hook=profile_hook)

        assert dkt.my_dict == dkt2.my_dict
Exemplo n.º 8
0
 def test_update(self):
     dkt = ProfileDict()
     dkt.update(a=1, b=2, c=3)
     assert dkt.my_dict == {"a": 1, "b": 2, "c": 3}
     dkt2 = ProfileDict()
     dkt2.update(c=4, d={"a": 2, "e": 7})
     assert dkt2.get("d.e") == 7
     dkt.update(dkt2)
     assert dkt.get("d.e") == 7
     assert dkt.get("c") == 4
     dkt.update({"g": 1, "h": 4})
     assert dkt.get("g") == 1
     dkt.update({"w": 1, "z": 4}, w=3)
     assert dkt.get("w") == 3
     assert dkt.verify_data()
     assert dkt.filter_data() == []
     dkt.set("e.h.l", {"aaa": 1, "__error__": True})
     assert not dkt.verify_data()
     assert dkt.filter_data() == ["e.h"]
Exemplo n.º 9
0
 def test_simple(self):
     dkt = ProfileDict()
     dkt.set("a.b.c", 1)
     dkt.set("a.b.a", 2)
     assert dkt.get("a.b.c") == 1
     with pytest.raises(KeyError):
         dkt.get("a.b.d")
     dkt.get("a.b.d", 3)
     assert dkt.get("a.b.d") == 3
     assert dkt.get("a.b") == {"a": 2, "c": 1, "d": 3}
     with pytest.raises(TypeError):
         dkt.set("a.b.c.d", 3)
Exemplo n.º 10
0
 def __init__(self,
              json_path: Union[Path, str],
              profile_name: str = "default"):
     """
     :param json_path: path to store
     :param profile_name: name of profile to be used. default value is "default"
     """
     super().__init__()
     napari_path = os.path.dirname(json_path) if os.path.basename(
         json_path) in ["analysis", "mask"] else json_path
     self.napari_settings: "NapariSettings" = napari_get_settings(
         napari_path)
     self._current_roi_dict = profile_name
     self._roi_dict = ProfileDict()
     self.json_folder_path = json_path
     self.last_executed_algorithm = ""
     self.history: List[HistoryElement] = []
     self.history_index = -1
     self.last_executed_algorithm = ""
     self._points = None
Exemplo n.º 11
0
 def change_profile(self, name):
     self.current_profile_dict = name
     if self.current_profile_dict not in self.view_settings_dict:
         self.view_settings_dict = {
             self.current_profile_dict: ProfileDict()
         }