def setUpClass(cls): maybe_download_sbs() cls.test_folder = "loaddata" cls.test_path = os.path.join( example_images_directory(), cls.test_folder) cls.test_filename = "image.tif" cls.test_shape = (13, 15) path = maybe_download_example_image([cls.test_folder], cls.test_filename, shape=cls.test_shape) with open(path, "rb") as fd: cls.test_md5 = hashlib.md5(fd.read()).hexdigest()
def test_03_01_save_and_load(self): """Save a pipeline to batch data, open it to check and load it""" data = ("eJztWW1PGkEQXhC1WtPYTzb9tB+llROoGiWNgi9NSYUSIbZGbbvCApvu7ZJ7" "UWlj0o/9Wf1J/QndxTs4tsoBRS3JHbkcMzfPPDOzs8uxl8uU9jPbcFWLw1ym" "FKsSimGBIqvKDT0FmbUEdwyMLFyBnKVgycYwY9dgIgET8dTqRmolCZPx+AYY" "7ghlc0/EJf4cgClxfSTOsHNr0pFDnlPKRWxZhNXMSRABzxz9L3EeIoOgM4oP" "EbWx2aFw9VlW5aVmo30rxys2xXmke43Fkbf1M2yY76su0LldIJeYFsk3rKTg" "mh3gc2ISzhy841/Vtnm5pfDKOhTmOnUIKXWQdVnw6KX9W9Cxj9xQt6ce+3lH" "JqxCzknFRhQSHdXaUbTGwcffRJe/CXAk0BKX9sHNK3HIs4QvrdjeJSpbUEdW" "uS79rPv4mVb8SLmcOrGw3ugr/lAXPgRe9Zl3uAsXBnkO+sp7VolXyrscMm5B" "28T91/02/lHgphSce7i4GdCJ0y/fOSVfKe9RE1/UsYE1TXP91H38rCh+pCzG" "uYwpbRhcLlHGiWXY7OuJaCC9ISZ3q5NdqbhdzLZb+yH4hpmXy3I2ioVtGTFE" "myYZxbwcdpzvu68eku8+cGmf/GZAdz9IeaeOGMM0ERtx3P30z24+c6d86jqc" "uOP8Il18EdE/DP8L3w8fvnegezyl/Glxq/BaPljhTe1l9LOUPoj15YBfbB5n" "YoXTqKvZ4dTW2eZxPLZx+j2xlLy6Ni4SgWwpozfmPUj8fuvhuhK/lGUMRxgZ" "TmArV9GYVOU4s+qOLunodlGzo3mgeZMcxbwZir9p8QZFpj4C/kHnUfKO+YJ5" "NJ7z6OPsYP8rxuV3NcAFuAAX4P43XNqD63c/pLUZUzO43YCEVXBjnPINcOON" "S4OgXwPc8DipvO35Ut2/kfZfQO9+ewG6+03K3s04TW9topsa5ahyvYut7Yuv" "Wc+Gdj/P52sKz9ptPOXWK5AzuU8tb5ja9TuRbal4Q1rvCNT6zdzA561DWHwW" "pnvXXa13Zxx+bw3DFwn9zffYBxdxKidxP8Fg47zYw97NbVj7P/nFW+E=") def callback(caller, event): self.assertFalse(isinstance(event, cpp.LoadExceptionEvent)) self.assertFalse(isinstance(event, cpp.RunExceptionEvent)) T.maybe_download_sbs() for windows_mode in ((False, True) if sys.platform.startswith("win") else (False, )): pipeline = cpp.Pipeline() pipeline.add_listener(callback) pipeline.load(StringIO(zlib.decompress(base64.b64decode(data)))) ipath = os.path.join(T.example_images_directory(), "ExampleSBSImages") bpath = tempfile.mkdtemp() bfile = os.path.join(bpath, C.F_BATCH_DATA) hfile = os.path.join(bpath, C.F_BATCH_DATA_H5) try: li = pipeline.modules()[0] self.assertTrue(isinstance(li, LI.LoadImages)) module = pipeline.modules()[1] self.assertTrue(isinstance(module, C.CreateBatchFiles)) li.location.dir_choice = cps.ABSOLUTE_FOLDER_NAME li.location.custom_path = ipath module.wants_default_output_directory.value = False module.custom_output_directory.value = bpath module.remote_host_is_windows.value = windows_mode self.assertEqual(len(module.mappings), 1) mapping = module.mappings[0] mapping.local_directory.value = ipath self.assertFalse(pipeline.in_batch_mode()) measurements = cpmeas.Measurements(mode="memory") image_set_list = cpi.ImageSetList() result = pipeline.prepare_run( cpw.Workspace(pipeline, None, None, None, measurements, image_set_list)) self.assertFalse(pipeline.in_batch_mode()) self.assertFalse(result) self.assertFalse(module.batch_mode.value) self.assertTrue( measurements.has_feature(cpmeas.EXPERIMENT, cpp.M_PIPELINE)) pipeline = cpp.Pipeline() pipeline.add_listener(callback) image_set_list = cpi.ImageSetList() measurements = cpmeas.Measurements(mode="memory") workspace = cpw.Workspace(pipeline, None, None, None, cpmeas.Measurements(), image_set_list) workspace.load(hfile, True) measurements = workspace.measurements self.assertTrue(pipeline.in_batch_mode()) module = pipeline.modules()[1] self.assertTrue(isinstance(module, C.CreateBatchFiles)) self.assertTrue(module.batch_mode.value) image_numbers = measurements.get_image_numbers() self.assertTrue( [x == i + 1 for i, x in enumerate(image_numbers)]) pipeline.prepare_run(workspace) pipeline.prepare_group(workspace, {}, list(range(1, 97))) for i in range(96): image_set = image_set_list.get_image_set(i) for image_name in ("DNA", "Cytoplasm"): pathname = measurements.get_measurement( cpmeas.IMAGE, "PathName_" + image_name, i + 1) self.assertEqual( pathname, "\\imaging\\analysis" if windows_mode else "/imaging/analysis", ) measurements.close() finally: if os.path.exists(bfile): os.unlink(bfile) if os.path.exists(hfile): os.unlink(hfile) os.rmdir(bpath)
def test_03_01_save_and_load(self): '''Save a pipeline to batch data, open it to check and load it''' data = ('eJztWW1PGkEQXhC1WtPYTzb9tB+llROoGiWNgi9NSYUSIbZGbbvCApvu7ZJ7' 'UWlj0o/9Wf1J/QndxTs4tsoBRS3JHbkcMzfPPDOzs8uxl8uU9jPbcFWLw1ym' 'FKsSimGBIqvKDT0FmbUEdwyMLFyBnKVgycYwY9dgIgET8dTqRmolCZPx+AYY' '7ghlc0/EJf4cgClxfSTOsHNr0pFDnlPKRWxZhNXMSRABzxz9L3EeIoOgM4oP' 'EbWx2aFw9VlW5aVmo30rxys2xXmke43Fkbf1M2yY76su0LldIJeYFsk3rKTg' 'mh3gc2ISzhy841/Vtnm5pfDKOhTmOnUIKXWQdVnw6KX9W9Cxj9xQt6ce+3lH' 'JqxCzknFRhQSHdXaUbTGwcffRJe/CXAk0BKX9sHNK3HIs4QvrdjeJSpbUEdW' 'uS79rPv4mVb8SLmcOrGw3ugr/lAXPgRe9Zl3uAsXBnkO+sp7VolXyrscMm5B' '28T91/02/lHgphSce7i4GdCJ0y/fOSVfKe9RE1/UsYE1TXP91H38rCh+pCzG' 'uYwpbRhcLlHGiWXY7OuJaCC9ISZ3q5NdqbhdzLZb+yH4hpmXy3I2ioVtGTFE' 'myYZxbwcdpzvu68eku8+cGmf/GZAdz9IeaeOGMM0ERtx3P30z24+c6d86jqc' 'uOP8Il18EdE/DP8L3w8fvnegezyl/Glxq/BaPljhTe1l9LOUPoj15YBfbB5n' 'YoXTqKvZ4dTW2eZxPLZx+j2xlLy6Ni4SgWwpozfmPUj8fuvhuhK/lGUMRxgZ' 'TmArV9GYVOU4s+qOLunodlGzo3mgeZMcxbwZir9p8QZFpj4C/kHnUfKO+YJ5' 'NJ7z6OPsYP8rxuV3NcAFuAAX4P43XNqD63c/pLUZUzO43YCEVXBjnPINcOON' 'S4OgXwPc8DipvO35Ut2/kfZfQO9+ewG6+03K3s04TW9topsa5ahyvYut7Yuv' 'Wc+Gdj/P52sKz9ptPOXWK5AzuU8tb5ja9TuRbal4Q1rvCNT6zdzA561DWHwW' 'pnvXXa13Zxx+bw3DFwn9zffYBxdxKidxP8Fg47zYw97NbVj7P/nFW+E=') def callback(caller, event): self.assertFalse(isinstance(event, cpp.LoadExceptionEvent)) self.assertFalse(isinstance(event, cpp.RunExceptionEvent)) T.maybe_download_sbs() for windows_mode in ((False, True) if sys.platform.startswith("win") else (False,)): pipeline = cpp.Pipeline() pipeline.add_listener(callback) pipeline.load(StringIO(zlib.decompress(base64.b64decode(data)))) ipath = os.path.join(T.example_images_directory(), 'ExampleSBSImages') bpath = tempfile.mkdtemp() bfile = os.path.join(bpath, C.F_BATCH_DATA) hfile = os.path.join(bpath, C.F_BATCH_DATA_H5) try: li = pipeline.modules()[0] self.assertTrue(isinstance(li, LI.LoadImages)) module = pipeline.modules()[1] self.assertTrue(isinstance(module, C.CreateBatchFiles)) li.location.dir_choice = LI.ABSOLUTE_FOLDER_NAME li.location.custom_path = ipath module.wants_default_output_directory.value = False module.custom_output_directory.value = bpath module.remote_host_is_windows.value = windows_mode self.assertEqual(len(module.mappings), 1) mapping = module.mappings[0] mapping.local_directory.value = ipath self.assertFalse(pipeline.in_batch_mode()) measurements = cpmeas.Measurements(mode="memory") image_set_list = cpi.ImageSetList() result = pipeline.prepare_run( cpw.Workspace(pipeline, None, None, None, measurements, image_set_list)) self.assertFalse(pipeline.in_batch_mode()) self.assertFalse(result) self.assertFalse(module.batch_mode.value) self.assertTrue(measurements.has_feature( cpmeas.EXPERIMENT, cpp.M_PIPELINE)) pipeline = cpp.Pipeline() pipeline.add_listener(callback) image_set_list = cpi.ImageSetList() measurements = cpmeas.Measurements(mode="memory") workspace = cpw.Workspace(pipeline, None, None, None, cpmeas.Measurements(), image_set_list) workspace.load(hfile, True) measurements = workspace.measurements self.assertTrue(pipeline.in_batch_mode()) module = pipeline.modules()[1] self.assertTrue(isinstance(module, C.CreateBatchFiles)) self.assertTrue(module.batch_mode.value) image_numbers = measurements.get_image_numbers() self.assertTrue([x == i + 1 for i, x in enumerate(image_numbers)]) pipeline.prepare_run(workspace) pipeline.prepare_group(workspace, {}, range(1, 97)) for i in range(96): image_set = image_set_list.get_image_set(i) for image_name in ('DNA', 'Cytoplasm'): pathname = measurements.get_measurement( cpmeas.IMAGE, "PathName_" + image_name, i + 1) self.assertEqual(pathname, '\\imaging\\analysis' if windows_mode else '/imaging/analysis') measurements.close() finally: if os.path.exists(bfile): os.unlink(bfile) if os.path.exists(hfile): os.unlink(hfile) os.rmdir(bpath)