def test_10_01_issue_422(self):
        # Regression test of issue # 422
        #
        # If no operation is chosen, get_measurement_columns and
        # get_categories report measurements for both operands when
        # they should report for only a single one
        #
        module = C.CalculateMath()
        module.operation.value = C.O_NONE
        module.operands[0].operand_objects.value = OBJECT[0]
        module.operands[1].operand_objects.value = OBJECT[1]
        module.operands[0].operand_choice.value = C.MC_OBJECT
        module.operands[1].operand_choice.value = C.MC_OBJECT
        module.output_feature_name.value = OUTPUT_MEASUREMENTS

        c = module.get_measurement_columns(None)
        self.assertEqual(len(c), 1)
        self.assertEqual(c[0][0], OBJECT[0])
        self.assertEqual(c[0][1], MATH_OUTPUT_MEASUREMENTS)

        self.assertEqual(len(module.get_categories(None, OBJECT[0])), 1)
        self.assertEqual(len(module.get_categories(None, OBJECT[1])), 0)

        self.assertEqual(
            len(module.get_measurements(None, OBJECT[0], C.C_MATH)), 1)
        self.assertEqual(
            len(module.get_measurements(None, OBJECT[1], C.C_MATH)), 0)
Ejemplo n.º 2
0
 def test_05_01_measurement_columns_image(self):
     module = C.CalculateMath()
     module.output_feature_name.value = OUTPUT_MEASUREMENTS
     for operand in module.operands:
         operand.operand_choice.value = C.MC_IMAGE
     columns = module.get_measurement_columns(None)
     self.assertEqual(len(columns),1)
     self.assertEqual(columns[0][0], cpmeas.IMAGE)
     self.assertEqual(columns[0][1], MATH_OUTPUT_MEASUREMENTS)
     self.assertEqual(columns[0][2], cpmeas.COLTYPE_FLOAT)
     self.assertEqual(module.get_categories(None,cpmeas.IMAGE)[0], "Math")
     self.assertEqual(module.get_measurements(None, cpmeas.IMAGE, "Math")[0], 
                      OUTPUT_MEASUREMENTS)
Ejemplo n.º 3
0
 def test_05_03_measurement_columns_object_image(self):
     module = C.CalculateMath()
     module.output_feature_name.value = OUTPUT_MEASUREMENTS
     module.operands[0].operand_choice.value = C.MC_OBJECT
     module.operands[1].operand_choice.value = C.MC_IMAGE
     module.operands[0].operand_objects.value = OBJECT[0]
     columns = module.get_measurement_columns(None)
     self.assertEqual(len(columns),1)
     self.assertEqual(columns[0][0], OBJECT[0])
     self.assertEqual(columns[0][1], MATH_OUTPUT_MEASUREMENTS)
     self.assertEqual(columns[0][2], cpmeas.COLTYPE_FLOAT)
     self.assertEqual(module.get_categories(None,OBJECT[0])[0], "Math")
     self.assertEqual(module.get_measurements(None, OBJECT[0], "Math")[0], 
                      OUTPUT_MEASUREMENTS)
     self.assertEqual(len(module.get_categories(None,cpmeas.IMAGE)), 0)
Ejemplo n.º 4
0
    def run_workspace(
        self,
        operation,
        m1_is_image_measurement,
        m1_data,
        m2_is_image_measurement,
        m2_data,
        setup_fn=None,
    ):
        """Create and run a workspace, returning the measurements

        m<n>_is_image_measurement - true for an image measurement, false
                                    for object
        m<n>_data - either a single value or an array
        setup_fn - this gets called with the module before running
        """
        module = C.CalculateMath()
        module.operation.value = operation
        measurements = cpmeas.Measurements()
        for i, operand, is_image_measurement, data in (
            (0, module.operands[0], m1_is_image_measurement, m1_data),
            (1, module.operands[1], m2_is_image_measurement, m2_data),
        ):
            measurement = "measurement%d" % i
            if is_image_measurement:
                operand.operand_choice.value = C.MC_IMAGE
                measurements.add_image_measurement(measurement, data)
            else:
                operand.operand_choice.value = C.MC_OBJECT
                operand.operand_objects.value = OBJECT[i]
                measurements.add_measurement(OBJECT[i], measurement, data)
            operand.operand_measurement.value = measurement
        module.output_feature_name.value = OUTPUT_MEASUREMENTS
        pipeline = cpp.Pipeline()
        image_set_list = cpi.ImageSetList()
        workspace = cpw.Workspace(
            pipeline,
            module,
            image_set_list.get_image_set(0),
            cpo.ObjectSet(),
            measurements,
            image_set_list,
        )
        if setup_fn is not None:
            setup_fn(module, workspace)
        module.run(workspace)
        return measurements
    def test_09_01_img_919(self):
        '''Regression test: one measurement, but both operands are from same object
        
        The bug was that the measurement gets added twice. It was fixed in run
        but not in get_measurement_columns
        '''
        def fn(module):
            module.operands[1].operand_objects.value = OBJECT[0]
            module.operands[1].operand_measurement.value = "measurement0"

        module = C.CalculateMath()
        module.output_feature_name.value = OUTPUT_MEASUREMENTS
        module.operands[0].operand_choice.value = C.MC_OBJECT
        module.operands[1].operand_choice.value = C.MC_OBJECT
        module.operands[0].operand_objects.value = OBJECT[0]
        module.operands[1].operand_objects.value = OBJECT[0]
        columns = module.get_measurement_columns(None)
        self.assertEqual(columns[0][0], OBJECT[0])
        self.assertEqual(len(columns), 1)
Ejemplo n.º 6
0
 def test_05_04_measurement_columns_object_object(self):
     module = C.CalculateMath()
     module.output_feature_name.value = OUTPUT_MEASUREMENTS
     module.operands[0].operand_choice.value = C.MC_OBJECT
     module.operands[1].operand_choice.value = C.MC_OBJECT
     module.operands[0].operand_objects.value = OBJECT[0]
     module.operands[1].operand_objects.value = OBJECT[1]
     columns = list(module.get_measurement_columns(None))
     self.assertEqual(len(columns),2)
     if columns[0][0] == OBJECT[1]:
         columns = [columns[1],columns[0]]
     for i in range(2):
         self.assertEqual(columns[i][0], OBJECT[i])
         self.assertEqual(columns[i][1], MATH_OUTPUT_MEASUREMENTS)
         self.assertEqual(columns[i][2], cpmeas.COLTYPE_FLOAT)
         self.assertEqual(module.get_categories(None,OBJECT[i])[0], "Math")
         self.assertEqual(module.get_measurements(None, OBJECT[i],"Math")[0], 
                          OUTPUT_MEASUREMENTS)
     self.assertEqual(len(module.get_categories(None,cpmeas.IMAGE)), 0)