def test_pipeline_saving(self, qtbot, tmp_path, image, algorithm_parameters, mask_property): settings = PartSettings(tmp_path) settings.image = image settings.last_executed_algorithm = algorithm_parameters["algorithm_name"] algorithm = analysis_algorithm_dict[algorithm_parameters["algorithm_name"]]() algorithm.set_image(settings.image) algorithm.set_parameters(**algorithm_parameters["values"]) result = algorithm.calculation_run(lambda x, y: None) settings.set_segmentation_result(result) project_info = settings.get_project_info() mask = calculate_mask_from_project(mask_property, settings.get_project_info()) settings.add_history_element( create_history_element_from_project( project_info, mask_property, ) ) settings.mask = mask calculate_mask_from_project(mask_property, settings.get_project_info()) algorithm_parameters["values"]["channel"] = 1 algorithm.set_parameters(**algorithm_parameters["values"]) algorithm.set_mask(settings.mask) result2 = algorithm.calculation_run(lambda x, y: None) assert np.max(result2.roi) == 2 settings.set_segmentation_result(result2) project_info = settings.get_project_info() SaveProject.save(tmp_path / "project.tgz", project_info) assert os.path.exists(tmp_path / "project.tgz") loaded = LoadProject.load([tmp_path / "project.tgz"]) assert np.all(loaded.roi == result2.roi) assert len(loaded.history) == 1
def test_pipeline(image, algorithm_parameters, mask_property, tmp_path): elem = SegmentationPipelineElement( segmentation=SegmentationProfile( name="", algorithm=algorithm_parameters["algorithm_name"], values=algorithm_parameters["values"]), mask_property=mask_property, ) algorithm_parameters = deepcopy(algorithm_parameters) algorithm_parameters["values"]["channel"] = 1 pipeline = SegmentationPipeline( name="", segmentation=SegmentationProfile( name="", algorithm=algorithm_parameters["algorithm_name"], values=algorithm_parameters["values"]), mask_history=[elem], ) result = calculate_pipeline(image, None, pipeline, lambda x, y: None) assert np.max(result.segmentation) == 2 pt = ProjectTuple( file_path=image.file_path, image=image, segmentation=result.segmentation, mask=result.mask, history=result.history, algorithm_parameters=algorithm_parameters, ) SaveProject.save(tmp_path / "project.tgz", pt) assert os.path.exists(tmp_path / "project.tgz") loaded = LoadProject.load([tmp_path / "project.tgz"]) assert np.all(loaded.segmentation == result.segmentation)
def test_pipeline(image, algorithm_parameters, mask_property, tmp_path, use_mask): elem = SegmentationPipelineElement( segmentation=ROIExtractionProfile( name="", algorithm=algorithm_parameters["algorithm_name"], values=algorithm_parameters["values"]), mask_property=mask_property, ) algorithm_parameters = deepcopy(algorithm_parameters) algorithm_parameters["values"]["channel"] = 1 pipeline = SegmentationPipeline( name="", segmentation=ROIExtractionProfile( name="", algorithm=algorithm_parameters["algorithm_name"], values=algorithm_parameters["values"]), mask_history=[elem], ) mask = np.ones(image.get_channel(0).shape, dtype=np.uint8) if use_mask else None result = calculate_pipeline(image, mask, pipeline, lambda x, y: None) assert np.max(result.roi) == 2 pt = ProjectTuple( file_path=image.file_path, image=image, roi=result.roi, mask=result.mask, history=result.history, algorithm_parameters=algorithm_parameters, ) SaveProject.save(tmp_path / "project.tgz", pt) assert os.path.exists(tmp_path / "project.tgz") loaded = LoadProject.load([tmp_path / "project.tgz"]) assert np.all(loaded.roi == result.roi)
def test_save_project(self, tmpdir, analysis_project): SaveProject.save(os.path.join(tmpdir, "test1.tgz"), analysis_project) assert os.path.exists(os.path.join(tmpdir, "test1.tgz")) LoadProject.load([os.path.join(tmpdir, "test1.tgz")])