예제 #1
0
    def test_04_01_run_group(self):
        pipeline = cpp.Pipeline()
        load_images = LoadImages()
        load_images.module_num = 1
        load_images.images[0].channels[0].image_name.value = "Foo"
        pipeline.add_module(load_images)
        identify = IdentifyPrimaryObjects()
        identify.module_num = 2
        identify.image_name.value = "Foo"
        identify.object_name.value = "dizzy"
        identify.threshold_scope.value = TS_MANUAL
        identify.manual_threshold.value = 0.5
        identify.exclude_size.value = False
        pipeline.add_module(identify)

        pipeline_txt = StringIO()
        pipeline.savetxt(pipeline_txt)

        image = np.zeros((2, 11, 17))
        image[0, 2:-2, 2:-2] = 1
        image[1, 2:-2, 2:7] = 1
        image[1, 2:-2, 10:-2] = 1

        image_metadata = [
            [
                "Foo",
                [
                    ["Z", image.shape[0], image.strides[0] / 8],
                    ["Y", image.shape[1], image.strides[1] / 8],
                    ["X", image.shape[2], image.strides[2] / 8],
                ],
            ]
        ]
        message = [
            zmq.Frame(self.session_id),
            zmq.Frame(),
            zmq.Frame(RUN_GROUP_REQ_1),
            zmq.Frame(pipeline_txt.getvalue()),
            zmq.Frame(json.dumps(image_metadata)),
            zmq.Frame(image),
        ]
        self.socket.send_multipart(message)
        response = self.socket.recv_multipart()
        self.assertEqual(response.pop(0), self.session_id)
        self.assertEqual(response.pop(0), "")
        self.assertEqual(response.pop(0), RUN_REPLY_1)
        metadata = json.loads(response.pop(0))
        data = response.pop(0)
        measurements = self.decode_measurements(metadata, data)
        self.assertEqual(len(measurements[cpmeas.IMAGE][cpmeas.IMAGE_NUMBER]), 2)
        self.assertEqual(measurements[cpmeas.IMAGE]["Count_dizzy"][0], 1)
        self.assertEqual(measurements[cpmeas.IMAGE]["Count_dizzy"][1], 2)
        self.assertEqual(measurements["dizzy"]["Location_Center_Y"][0], 5)
예제 #2
0
    def test_04_01_run_group(self):
        pipeline = cpp.Pipeline()
        load_images = LoadImages()
        load_images.module_num = 1
        load_images.images[0].channels[0].image_name.value = "Foo"
        pipeline.add_module(load_images)
        identify = IdentifyPrimaryObjects()
        identify.use_advanced.value = True
        identify.module_num = 2
        identify.x_name.value = "Foo"
        identify.y_name.value = "dizzy"
        identify.threshold.threshold_scope.value = TS_GLOBAL
        identify.threshold.global_operation.value = TM_MANUAL
        identify.threshold.manual_threshold.value = .5
        identify.exclude_size.value = False
        pipeline.add_module(identify)

        pipeline_txt = StringIO()
        pipeline.savetxt(pipeline_txt)

        image = np.zeros((2, 11, 17))
        image[0, 2:-2, 2:-2] = 1
        image[1, 2:-2, 2:7] = 1
        image[1, 2:-2, 10:-2] = 1

        image_metadata = [[
            "Foo",
            [["Z", image.shape[0], image.strides[0] / 8],
             ["Y", image.shape[1], image.strides[1] / 8],
             ["X", image.shape[2], image.strides[2] / 8]]
        ]]
        message = [
            zmq.Frame(self.session_id),
            zmq.Frame(),
            zmq.Frame(RUN_GROUP_REQ_1),
            zmq.Frame(pipeline_txt.getvalue()),
            zmq.Frame(json.dumps(image_metadata)),
            zmq.Frame(image)
        ]
        self.socket.send_multipart(message)
        response = self.socket.recv_multipart()
        self.assertEqual(response.pop(0), self.session_id)
        self.assertEqual(response.pop(0), "")
        self.assertEqual(response.pop(0), RUN_REPLY_1)
        metadata = json.loads(response.pop(0))
        data = response.pop(0)
        measurements = self.decode_measurements(metadata, data)
        self.assertEqual(len(measurements[cpmeas.IMAGE][cpmeas.IMAGE_NUMBER]),
                         2)
        self.assertEqual(measurements[cpmeas.IMAGE]["Count_dizzy"][0], 1)
        self.assertEqual(measurements[cpmeas.IMAGE]["Count_dizzy"][1], 2)
        self.assertEqual(measurements["dizzy"]["Location_Center_Y"][0], 5)
예제 #3
0
    def test_02_01_pipeline_info(self):
        pipeline = cpp.Pipeline()
        load_images = LoadImages()
        load_images.module_num = 1
        load_images.add_imagecb()
        load_images.images[0].channels[0].image_name.value = "Foo"
        load_images.images[1].channels[0].image_name.value = "Bar"
        pipeline.add_module(load_images)
        identify = IdentifyPrimaryObjects()
        identify.module_num = 2
        identify.x_name.value = "Foo"
        identify.y_name.value = "dizzy"
        pipeline.add_module(identify)

        pipeline_txt = StringIO()
        pipeline.savetxt(pipeline_txt)
        message = [
            zmq.Frame(self.session_id),
            zmq.Frame(),
            zmq.Frame(PIPELINE_INFO_REQ_1),
            zmq.Frame(pipeline_txt.getvalue())
        ]
        self.socket.send_multipart(message)
        message = self.socket.recv_multipart()
        self.assertEqual(message.pop(0), self.session_id)
        self.assertEqual(message.pop(0), "")
        self.assertEqual(message.pop(0), PIPELINE_INFO_REPLY_1)
        body = json.loads(message.pop(0))
        self.assertEqual(len(body), 3)
        channels, type_names, measurements = body
        self.assertTrue("Foo" in channels)
        self.assertTrue("Bar" in channels)
        self.assertTrue("dizzy" in measurements)
        found_location = False
        found_object_number = False
        for feature, idx in measurements['dizzy']:
            if feature == "Location_Center_X":
                self.assertEqual('java.lang.Double', type_names[idx])
                found_location = True
            elif feature == "Number_Object_Number":
                self.assertEqual('java.lang.Integer', type_names[idx])
                found_object_number = True
        self.assertTrue(found_location)
        self.assertTrue(found_object_number)
    def test_03_01_run_something(self):
        pipeline = cpp.Pipeline()
        load_images = LoadImages()
        load_images.module_num = 1
        load_images.images[0].channels[0].image_name.value = "Foo"
        pipeline.add_module(load_images)
        identify = IdentifyPrimaryObjects()
        identify.use_advanced.value = True
        identify.module_num = 2
        identify.x_name.value = "Foo"
        identify.y_name.value = "dizzy"
        identify.threshold.threshold_scope.value = TS_GLOBAL
        identify.threshold.global_operation.value = TM_MANUAL
        identify.threshold.manual_threshold.value = .5
        identify.exclude_size.value = False
        pipeline.add_module(identify)

        pipeline_txt = StringIO()
        pipeline.savetxt(pipeline_txt)

        image = np.zeros((11, 17))
        image[2:-2, 2:-2] = 1

        image_metadata = [
            ["Foo",
             [["Y", image.shape[0], image.strides[0] / 8],
              ["X", image.shape[1], image.strides[1] / 8]]]]
        message = [
            zmq.Frame(self.session_id),
            zmq.Frame(),
            zmq.Frame(RUN_REQ_1),
            zmq.Frame(pipeline_txt.getvalue()),
            zmq.Frame(json.dumps(image_metadata)),
            zmq.Frame(image)]
        self.socket.send_multipart(message)
        response = self.socket.recv_multipart()
        self.assertEqual(response.pop(0), self.session_id)
        self.assertEqual(response.pop(0), "")
        self.assertEqual(response.pop(0), RUN_REPLY_1)
        metadata = json.loads(response.pop(0))
        data = response.pop(0)
        measurements = self.decode_measurements(metadata, data)
        self.assertEqual(measurements[cpmeas.IMAGE]["Count_dizzy"][0], 1)
        self.assertEqual(measurements["dizzy"]["Location_Center_Y"][0], 5)
예제 #5
0
    def test_02_01_pipeline_info(self):
        pipeline = cpp.Pipeline()
        load_images = LoadImages()
        load_images.module_num = 1
        load_images.add_imagecb()
        load_images.images[0].channels[0].image_name.value = "Foo"
        load_images.images[1].channels[0].image_name.value = "Bar"
        pipeline.add_module(load_images)
        identify = IdentifyPrimaryObjects()
        identify.module_num = 2
        identify.image_name.value = "Foo"
        identify.object_name.value = "dizzy"
        pipeline.add_module(identify)

        pipeline_txt = StringIO()
        pipeline.savetxt(pipeline_txt)
        message = [
            zmq.Frame(self.session_id),
            zmq.Frame(),
            zmq.Frame(PIPELINE_INFO_REQ_1),
            zmq.Frame(pipeline_txt.getvalue()),
        ]
        self.socket.send_multipart(message)
        message = self.socket.recv_multipart()
        self.assertEqual(message.pop(0), self.session_id)
        self.assertEqual(message.pop(0), "")
        self.assertEqual(message.pop(0), PIPELINE_INFO_REPLY_1)
        body = json.loads(message.pop(0))
        self.assertEqual(len(body), 3)
        channels, type_names, measurements = body
        self.assertTrue("Foo" in channels)
        self.assertTrue("Bar" in channels)
        self.assertTrue("dizzy" in measurements)
        found_location = False
        found_object_number = False
        for feature, idx in measurements["dizzy"]:
            if feature == "Location_Center_X":
                self.assertEqual("java.lang.Double", type_names[idx])
                found_location = True
            elif feature == "Number_Object_Number":
                self.assertEqual("java.lang.Integer", type_names[idx])
                found_object_number = True
        self.assertTrue(found_location)
        self.assertTrue(found_object_number)
예제 #6
0
 def test_02_03_clean_pipeline(self):
     pipeline = cpp.Pipeline()
     load_images = LoadImages()
     load_images.module_num = 1
     load_images.add_imagecb()
     load_images.images[0].channels[0].image_name.value = "Foo"
     load_images.images[1].channels[0].image_name.value = "Bar"
     pipeline.add_module(load_images)
     identify = IdentifyPrimaryObjects()
     identify.module_num = 2
     identify.x_name.value = "Foo"
     identify.y_name.value = "dizzy"
     pipeline.add_module(identify)
     saveimages = SaveImages()
     saveimages.module_num = 3
     saveimages.image_name.value = "Foo"
     pipeline.add_module(saveimages)
     measureobjectsizeshape = MeasureObjectSizeShape()
     measureobjectsizeshape.module_num = 4
     measureobjectsizeshape.object_groups[0].name.value = "dizzy"
     pipeline.add_module(measureobjectsizeshape)
     pipeline_txt = StringIO()
     pipeline.savetxt(pipeline_txt)
     module_names = json.dumps([SaveImages.module_name])
     message = [
         zmq.Frame(self.session_id),
         zmq.Frame(),
         zmq.Frame(CLEAN_PIPELINE_REQ_1),
         zmq.Frame(pipeline_txt.getvalue()),
         zmq.Frame(module_names)
     ]
     self.socket.send_multipart(message)
     message = self.socket.recv_multipart()
     self.assertEqual(message.pop(0), self.session_id)
     self.assertEqual(message.pop(0), "")
     self.assertEqual(message.pop(0), CLEAN_PIPELINE_REPLY_1)
     pipeline_txt = message.pop(0)
     pipeline = cpp.Pipeline()
     pipeline.loadtxt(StringIO(pipeline_txt))
     self.assertEqual(len(pipeline.modules()), 3)
     self.assertIsInstance(pipeline.modules()[0], LoadImages)
     self.assertIsInstance(pipeline.modules()[1], IdentifyPrimaryObjects)
     self.assertIsInstance(pipeline.modules()[2], MeasureObjectSizeShape)
예제 #7
0
 def test_02_03_clean_pipeline(self):
     pipeline = cpp.Pipeline()
     load_images = LoadImages()
     load_images.module_num = 1
     load_images.add_imagecb()
     load_images.images[0].channels[0].image_name.value = "Foo"
     load_images.images[1].channels[0].image_name.value = "Bar"
     pipeline.add_module(load_images)
     identify = IdentifyPrimaryObjects()
     identify.module_num = 2
     identify.image_name.value = "Foo"
     identify.object_name.value = "dizzy"
     pipeline.add_module(identify)
     saveimages = SaveImages()
     saveimages.module_num = 3
     saveimages.image_name.value = "Foo"
     pipeline.add_module(saveimages)
     measureobjectsizeshape = MeasureObjectSizeShape()
     measureobjectsizeshape.module_num = 4
     measureobjectsizeshape.object_groups[0].name.value = "dizzy"
     pipeline.add_module(measureobjectsizeshape)
     pipeline_txt = StringIO()
     pipeline.savetxt(pipeline_txt)
     module_names = json.dumps([SaveImages.module_name])
     message = [
         zmq.Frame(self.session_id),
         zmq.Frame(),
         zmq.Frame(CLEAN_PIPELINE_REQ_1),
         zmq.Frame(pipeline_txt.getvalue()),
         zmq.Frame(module_names),
     ]
     self.socket.send_multipart(message)
     message = self.socket.recv_multipart()
     self.assertEqual(message.pop(0), self.session_id)
     self.assertEqual(message.pop(0), "")
     self.assertEqual(message.pop(0), CLEAN_PIPELINE_REPLY_1)
     pipeline_txt = message.pop(0)
     pipeline = cpp.Pipeline()
     pipeline.loadtxt(StringIO(pipeline_txt))
     self.assertEqual(len(pipeline.modules()), 3)
     self.assertIsInstance(pipeline.modules()[0], LoadImages)
     self.assertIsInstance(pipeline.modules()[1], IdentifyPrimaryObjects)
     self.assertIsInstance(pipeline.modules()[2], MeasureObjectSizeShape)
예제 #8
0
    def test_04_02_bad_cellprofiler(self):
        pipeline = cpp.Pipeline()
        load_images = LoadImages()
        load_images.module_num = 1
        load_images.images[0].channels[0].image_name.value = "Foo"
        pipeline.add_module(load_images)
        identify = IdentifyPrimaryObjects()
        identify.module_num = 2
        identify.x_name.value = "Foo"
        identify.y_name.value = "dizzy"
        identify.threshold.threshold_scope.value = TS_GLOBAL
        identify.threshold.global_operation.value = TM_MANUAL
        identify.threshold.manual_threshold.value = .5
        identify.exclude_size.value = False
        pipeline.add_module(identify)

        pipeline_txt = StringIO()
        pipeline.savetxt(pipeline_txt)

        image = np.zeros((11, 17))
        image[2:-2, 2:-2] = 1

        # Get the strides wrong (I broke it accidentally this way before...)
        # And there's more wrong in this one.
        image_metadata = [[
            "Foo",
            [["Y", image.shape[0], image.strides[0]],
             ["X", image.shape[1], image.strides[1]]]
        ]]
        message = [
            zmq.Frame(self.session_id),
            zmq.Frame(),
            zmq.Frame(RUN_GROUP_REQ_1),
            zmq.Frame(pipeline_txt.getvalue()),
            zmq.Frame(json.dumps(image_metadata)),
            zmq.Frame(image)
        ]
        self.socket.send_multipart(message)
        response = self.socket.recv_multipart()
        self.assertEqual(response.pop(0), self.session_id)
        self.assertEqual(response.pop(0), "")
        self.assertEqual(response.pop(0), CELLPROFILER_EXCEPTION_1)
    def test_04_02_bad_cellprofiler(self):
        pipeline = cpp.Pipeline()
        load_images = LoadImages()
        load_images.module_num = 1
        load_images.images[0].channels[0].image_name.value = "Foo"
        pipeline.add_module(load_images)
        identify = IdentifyPrimaryObjects()
        identify.module_num = 2
        identify.x_name.value = "Foo"
        identify.y_name.value = "dizzy"
        identify.threshold.threshold_scope.value = TS_GLOBAL
        identify.threshold.global_operation.value = TM_MANUAL
        identify.threshold.manual_threshold.value = .5
        identify.exclude_size.value = False
        pipeline.add_module(identify)

        pipeline_txt = StringIO()
        pipeline.savetxt(pipeline_txt)

        image = np.zeros((11, 17))
        image[2:-2, 2:-2] = 1

        # Get the strides wrong (I broke it accidentally this way before...)
        # And there's more wrong in this one.
        image_metadata = [
            ["Foo",
             [["Y", image.shape[0], image.strides[0]],
              ["X", image.shape[1], image.strides[1]]]]]
        message = [
            zmq.Frame(self.session_id),
            zmq.Frame(),
            zmq.Frame(RUN_GROUP_REQ_1),
            zmq.Frame(pipeline_txt.getvalue()),
            zmq.Frame(json.dumps(image_metadata)),
            zmq.Frame(image)]
        self.socket.send_multipart(message)
        response = self.socket.recv_multipart()
        self.assertEqual(response.pop(0), self.session_id)
        self.assertEqual(response.pop(0), "")
        self.assertEqual(response.pop(0), CELLPROFILER_EXCEPTION_1)
예제 #10
0
    def test_03_03_run_missing_measurement(self):
        # Regression test of knime-bridge issue #6
        #
        # Missing measurement causes exception
        #
        pipeline = cpp.Pipeline()
        load_images = LoadImages()
        load_images.module_num = 1
        load_images.images[0].channels[0].image_name.value = "Foo"
        pipeline.add_module(load_images)
        identify = IdentifyPrimaryObjects()
        identify.module_num = 2
        identify.use_advanced.value = True
        identify.x_name.value = "Foo"
        identify.y_name.value = "dizzy"
        identify.threshold.threshold_scope.value = TS_GLOBAL
        identify.threshold.global_operation.value = TM_MANUAL
        identify.threshold.manual_threshold.value = .5
        identify.exclude_size.value = False
        pipeline.add_module(identify)

        flag_module = FlagImage()
        flag_module.module_num = 3
        flag = flag_module.flags[0]
        flag.wants_skip.value = True
        criterion = flag.measurement_settings[0]
        criterion.source_choice.value = S_IMAGE
        criterion.measurement.value = "Count_dizzy"
        criterion.wants_minimum.value = True
        criterion.minimum_value.value = 1000
        pipeline.add_module(flag_module)

        measureobjectsizeshape = MeasureObjectSizeShape()
        measureobjectsizeshape.module_num = 4
        measureobjectsizeshape.object_groups[0].name.value = "dizzy"
        pipeline.add_module(measureobjectsizeshape)

        pipeline_txt = StringIO()
        pipeline.savetxt(pipeline_txt)

        image = np.zeros((11, 17))
        image[2:-2, 2:-2] = 1

        image_metadata = [[
            "Foo",
            [["Y", image.shape[0], image.strides[0] / 8],
             ["X", image.shape[1], image.strides[1] / 8]]
        ]]
        message = [
            zmq.Frame(self.session_id),
            zmq.Frame(),
            zmq.Frame(RUN_REQ_1),
            zmq.Frame(pipeline_txt.getvalue()),
            zmq.Frame(json.dumps(image_metadata)),
            zmq.Frame(image)
        ]
        self.socket.send_multipart(message)
        response = self.socket.recv_multipart()
        self.assertEqual(response.pop(0), self.session_id)
        self.assertEqual(response.pop(0), "")
        self.assertEqual(response.pop(0), RUN_REPLY_1)
        metadata = json.loads(response.pop(0))
        data = response.pop(0)
        measurements = self.decode_measurements(metadata, data)
        self.assertEqual(measurements[cpmeas.IMAGE]["Count_dizzy"][0], 1)
        self.assertEqual(measurements["dizzy"]["Location_Center_Y"][0], 5)
        self.assertEqual(len(measurements["dizzy"]["AreaShape_Area"]), 0)
예제 #11
0
    def test_03_03_run_missing_measurement(self):
        # Regression test of knime-bridge issue #6
        #
        # Missing measurement causes exception
        #
        pipeline = cpp.Pipeline()
        load_images = LoadImages()
        load_images.module_num = 1
        load_images.images[0].channels[0].image_name.value = "Foo"
        pipeline.add_module(load_images)
        identify = IdentifyPrimaryObjects()
        identify.module_num = 2
        identify.use_advanced.value = True
        identify.x_name.value = "Foo"
        identify.y_name.value = "dizzy"
        identify.threshold.threshold_scope.value = TS_GLOBAL
        identify.threshold.global_operation.value = TM_MANUAL
        identify.threshold.manual_threshold.value = .5
        identify.exclude_size.value = False
        pipeline.add_module(identify)

        flag_module = FlagImage()
        flag_module.module_num = 3
        flag = flag_module.flags[0]
        flag.wants_skip.value = True
        criterion = flag.measurement_settings[0]
        criterion.source_choice.value = S_IMAGE
        criterion.measurement.value = "Count_dizzy"
        criterion.wants_minimum.value = True
        criterion.minimum_value.value = 1000
        pipeline.add_module(flag_module)

        measureobjectsizeshape = MeasureObjectSizeShape()
        measureobjectsizeshape.module_num = 4
        measureobjectsizeshape.object_groups[0].name.value = "dizzy"
        pipeline.add_module(measureobjectsizeshape)

        pipeline_txt = StringIO()
        pipeline.savetxt(pipeline_txt)

        image = np.zeros((11, 17))
        image[2:-2, 2:-2] = 1

        image_metadata = [
            ["Foo",
             [["Y", image.shape[0], image.strides[0] / 8],
              ["X", image.shape[1], image.strides[1] / 8]]]]
        message = [
            zmq.Frame(self.session_id),
            zmq.Frame(),
            zmq.Frame(RUN_REQ_1),
            zmq.Frame(pipeline_txt.getvalue()),
            zmq.Frame(json.dumps(image_metadata)),
            zmq.Frame(image)]
        self.socket.send_multipart(message)
        response = self.socket.recv_multipart()
        self.assertEqual(response.pop(0), self.session_id)
        self.assertEqual(response.pop(0), "")
        self.assertEqual(response.pop(0), RUN_REPLY_1)
        metadata = json.loads(response.pop(0))
        data = response.pop(0)
        measurements = self.decode_measurements(metadata, data)
        self.assertEqual(measurements[cpmeas.IMAGE]["Count_dizzy"][0], 1)
        self.assertEqual(measurements["dizzy"]["Location_Center_Y"][0], 5)
        self.assertEqual(len(measurements["dizzy"]["AreaShape_Area"]), 0)