def test_set_project_with_history_components_fail(self, stack_settings, stack_segmentation1, mask_property): seg2 = dataclasses.replace( stack_segmentation1, history=[ create_history_element_from_segmentation_tuple( dataclasses.replace(stack_segmentation1, selected_components=[1]), mask_property ) ], selected_components=[1], ) seg3 = dataclasses.replace( stack_segmentation1, history=[ create_history_element_from_segmentation_tuple( dataclasses.replace(stack_segmentation1, selected_components=[1, 2]), mask_property ) ], selected_components=[2], ) stack_settings.set_project_info(seg2) assert stack_settings.chosen_components() == [1] stack_settings.set_project_info(seg3) assert stack_settings.chosen_components() == [2] stack_settings.keep_chosen_components = True with pytest.raises(HistoryProblem): stack_settings.set_project_info(seg2)
def test_load_project_with_history(self, tmp_path, stack_segmentation1, mask_property): image_location = tmp_path / "test1.tif" SaveAsTiff.save(image_location, stack_segmentation1) seg2 = dataclasses.replace( stack_segmentation1, history=[ create_history_element_from_segmentation_tuple( stack_segmentation1, mask_property) ], selected_components=[1], mask=stack_segmentation1.segmentation, image=stack_segmentation1.image.substitute( file_path=image_location), file_path=image_location, ) SaveSegmentation.save(tmp_path / "test1.seg", seg2, {"relative_path": False}) res = LoadSegmentation.load([tmp_path / "test1.seg"]) assert res.image == str(image_location) assert res.mask is not None assert len(res.history) == 1 assert res.history[0].mask_property == mask_property cmp_dict = { str(k): v for k, v in stack_segmentation1.segmentation_parameters.items() } assert str( res.history[0].segmentation_parameters["parameters"]) == str( cmp_dict)
def test_save_project_with_history(self, tmp_path, stack_segmentation1, mask_property): SaveROI.save(tmp_path / "test1.seg", stack_segmentation1, {"relative_path": False}) seg2 = dataclasses.replace( stack_segmentation1, history=[create_history_element_from_segmentation_tuple(stack_segmentation1, mask_property)], selected_components=[1], mask=stack_segmentation1.roi, ) SaveROI.save(tmp_path / "test1.seg", seg2, {"relative_path": False}) with tarfile.open(tmp_path / "test1.seg", "r") as tf: tf.getmember("mask.tif") tf.getmember("segmentation.tif") tf.getmember("history/history.json") tf.getmember("history/arrays_0.npz")
def next_mask(self): project_info: MaskProjectTuple = self.settings.get_project_info() mask_property = self.mask_widget.get_mask_property() self.settings.set("mask_manager.mask_property", mask_property) mask = calculate_mask_from_project(mask_description=mask_property, project=project_info) self.settings.add_history_element( create_history_element_from_segmentation_tuple( project_info, mask_property, )) self.settings.mask = mask self.settings.chosen_components_widget.un_check_all() self.close()