<s> '''<STR_LIT>''' <EOL> import base64 <EOL> import unittest <EOL> import zlib <EOL> from StringIO import StringIO <EOL> import numpy as np <EOL> from cellprofiler . preferences import set_headless <EOL> set_headless ( ) <EOL> import cellprofiler . workspace as cpw <EOL> import cellprofiler . cpgridinfo as cpg <EOL> import cellprofiler . cpimage as cpi <EOL> import cellprofiler . cpmodule as cpm <EOL> import cellprofiler . objects as cpo <EOL> import cellprofiler . measurements as cpmeas <EOL> import cellprofiler . pipeline as cpp <EOL> import cellprofiler . modules . classifyobjects as C <EOL> OBJECTS_NAME = "<STR_LIT>" <EOL> MEASUREMENT_NAME_1 = "<STR_LIT>" <EOL> MEASUREMENT_NAME_2 = "<STR_LIT>" <EOL> IMAGE_NAME = "<STR_LIT:image>" <EOL> class TestClassifyObjects ( unittest . TestCase ) : <EOL> def test_01_01_load_matlab_classify_objects ( self ) : <EOL> data = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . LoadExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . load ( StringIO ( zlib . decompress ( base64 . b64decode ( data ) ) ) ) <EOL> module = pipeline . modules ( ) [ - <NUM_LIT:1> ] <EOL> self . assertTrue ( isinstance ( module , C . ClassifyObjects ) ) <EOL> self . assertEqual ( module . contrast_choice , C . BY_SINGLE_MEASUREMENT ) <EOL> self . assertEqual ( len ( module . single_measurements ) , <NUM_LIT:1> ) <EOL> group = module . single_measurements [ <NUM_LIT:0> ] <EOL> self . assertEqual ( group . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( group . measurement , "<STR_LIT>" ) <EOL> self . assertEqual ( group . bin_choice , C . BC_EVEN ) <EOL> self . assertEqual ( group . bin_count , <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( group . low_threshold . value , <NUM_LIT> ) <EOL> self . assertFalse ( group . wants_low_bin ) <EOL> self . assertAlmostEqual ( group . high_threshold . value , <NUM_LIT> ) <EOL> self . assertFalse ( group . wants_high_bin ) <EOL> self . assertFalse ( group . wants_custom_names ) <EOL> self . assertFalse ( group . wants_images ) <EOL> def test_01_02_load_matlab_classify_by_two_measurements ( self ) : <EOL> data = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . LoadExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . load ( StringIO ( zlib . decompress ( base64 . b64decode ( data ) ) ) ) <EOL> self . assertEqual ( len ( pipeline . modules ( ) ) , <NUM_LIT:4> ) <EOL> module = pipeline . modules ( ) [ - <NUM_LIT:1> ] <EOL> self . assertTrue ( isinstance ( module , C . ClassifyObjects ) ) <EOL> self . assertEqual ( module . contrast_choice , C . BY_TWO_MEASUREMENTS ) <EOL> self . assertEqual ( module . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( module . first_measurement , "<STR_LIT>" ) <EOL> self . assertEqual ( module . second_measurement , "<STR_LIT>" ) <EOL> self . assertEqual ( module . first_threshold_method , C . TM_MEAN ) <EOL> self . assertEqual ( module . second_threshold_method , C . TM_MEAN ) <EOL> self . assertFalse ( module . wants_custom_names ) <EOL> self . assertFalse ( module . wants_image ) <EOL> def test_01_03_load_v1 ( self ) : <EOL> data = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . LoadExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . load ( StringIO ( zlib . decompress ( base64 . b64decode ( data ) ) ) ) <EOL> self . assertEqual ( len ( pipeline . modules ( ) ) , <NUM_LIT:5> ) <EOL> module = pipeline . modules ( ) [ - <NUM_LIT:2> ] <EOL> self . assertTrue ( isinstance ( module , C . ClassifyObjects ) ) <EOL> self . assertEqual ( module . contrast_choice . value , C . BY_SINGLE_MEASUREMENT ) <EOL> self . assertEqual ( len ( module . single_measurements ) , <NUM_LIT:2> ) <EOL> group = module . single_measurements [ <NUM_LIT:0> ] <EOL> self . assertEqual ( group . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( group . measurement . value , "<STR_LIT>" ) <EOL> self . assertEqual ( group . bin_choice , C . BC_EVEN ) <EOL> self . assertEqual ( group . bin_count , <NUM_LIT:3> ) <EOL> self . assertAlmostEqual ( group . low_threshold . value , <NUM_LIT> ) <EOL> self . assertTrue ( group . wants_low_bin ) <EOL> self . assertAlmostEqual ( group . high_threshold . value , <NUM_LIT> ) <EOL> self . assertTrue ( group . wants_high_bin ) <EOL> self . assertTrue ( group . wants_custom_names ) <EOL> for name , expected in zip ( group . bin_names . value . split ( '<STR_LIT:U+002C>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> self . assertEqual ( name , expected ) <EOL> self . assertTrue ( group . wants_images ) <EOL> self . assertEqual ( group . image_name , "<STR_LIT>" ) <EOL> group = module . single_measurements [ <NUM_LIT:1> ] <EOL> self . assertEqual ( group . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( group . measurement . value , "<STR_LIT>" ) <EOL> self . assertEqual ( group . bin_choice , C . BC_CUSTOM ) <EOL> self . assertEqual ( group . custom_thresholds , "<STR_LIT>" ) <EOL> self . assertFalse ( group . wants_custom_names ) <EOL> self . assertFalse ( group . wants_images ) <EOL> module = pipeline . modules ( ) [ - <NUM_LIT:1> ] <EOL> self . assertTrue ( isinstance ( module , C . ClassifyObjects ) ) <EOL> self . assertEqual ( module . contrast_choice , C . BY_TWO_MEASUREMENTS ) <EOL> self . assertEqual ( module . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( module . first_measurement , "<STR_LIT>" ) <EOL> self . assertEqual ( module . first_threshold_method , C . TM_MEDIAN ) <EOL> self . assertEqual ( module . second_measurement , "<STR_LIT>" ) <EOL> self . assertEqual ( module . second_threshold_method , C . TM_MEDIAN ) <EOL> def test_01_04_load_v2 ( self ) : <EOL> data = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . LoadExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . load ( StringIO ( zlib . decompress ( base64 . b64decode ( data ) ) ) ) <EOL> self . assertEqual ( len ( pipeline . modules ( ) ) , <NUM_LIT:5> ) <EOL> module = pipeline . modules ( ) [ - <NUM_LIT:2> ] <EOL> self . assertTrue ( isinstance ( module , C . ClassifyObjects ) ) <EOL> self . assertEqual ( module . contrast_choice . value , C . BY_SINGLE_MEASUREMENT ) <EOL> self . assertEqual ( len ( module . single_measurements ) , <NUM_LIT:2> ) <EOL> group = module . single_measurements [ <NUM_LIT:0> ] <EOL> self . assertEqual ( group . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( group . measurement . value , "<STR_LIT>" ) <EOL> self . assertEqual ( group . bin_choice , C . BC_EVEN ) <EOL> self . assertEqual ( group . bin_count , <NUM_LIT:3> ) <EOL> self . assertAlmostEqual ( group . low_threshold . value , <NUM_LIT> ) <EOL> self . assertTrue ( group . wants_low_bin ) <EOL> self . assertAlmostEqual ( group . high_threshold . value , <NUM_LIT> ) <EOL> self . assertTrue ( group . wants_high_bin ) <EOL> self . assertTrue ( group . wants_custom_names ) <EOL> for name , expected in zip ( group . bin_names . value . split ( '<STR_LIT:U+002C>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> self . assertEqual ( name , expected ) <EOL> self . assertTrue ( group . wants_images ) <EOL> self . assertEqual ( group . image_name , "<STR_LIT>" ) <EOL> group = module . single_measurements [ <NUM_LIT:1> ] <EOL> self . assertEqual ( group . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( group . measurement . value , "<STR_LIT>" ) <EOL> self . assertEqual ( group . bin_choice , C . BC_CUSTOM ) <EOL> self . assertEqual ( group . custom_thresholds , "<STR_LIT>" ) <EOL> self . assertFalse ( group . wants_custom_names ) <EOL> self . assertFalse ( group . wants_images ) <EOL> module = pipeline . modules ( ) [ - <NUM_LIT:1> ] <EOL> self . assertTrue ( isinstance ( module , C . ClassifyObjects ) ) <EOL> self . assertEqual ( module . contrast_choice , C . BY_TWO_MEASUREMENTS ) <EOL> self . assertEqual ( module . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( module . first_measurement , "<STR_LIT>" ) <EOL> self . assertEqual ( module . first_threshold_method , C . TM_MEDIAN ) <EOL> self . assertEqual ( module . second_measurement , "<STR_LIT>" ) <EOL> self . assertEqual ( module . second_threshold_method , C . TM_CUSTOM ) <EOL> self . assertAlmostEqual ( module . second_threshold . value , <NUM_LIT> ) <EOL> def make_workspace ( self , labels , contrast_choice , <EOL> measurement1 = None , measurement2 = None ) : <EOL> object_set = cpo . ObjectSet ( ) <EOL> objects = cpo . Objects ( ) <EOL> objects . segmented = labels <EOL> object_set . add_objects ( objects , OBJECTS_NAME ) <EOL> measurements = cpmeas . Measurements ( ) <EOL> module = C . ClassifyObjects ( ) <EOL> m_names = [ ] <EOL> if measurement1 is not None : <EOL> measurements . add_measurement ( OBJECTS_NAME , MEASUREMENT_NAME_1 , <EOL> measurement1 ) <EOL> m_names . append ( MEASUREMENT_NAME_1 ) <EOL> if measurement2 is not None : <EOL> measurements . add_measurement ( OBJECTS_NAME , MEASUREMENT_NAME_2 , <EOL> measurement2 ) <EOL> module . add_single_measurement ( ) <EOL> m_names . append ( MEASUREMENT_NAME_2 ) <EOL> image_set_list = cpi . ImageSetList ( ) <EOL> image_set = image_set_list . get_image_set ( <NUM_LIT:0> ) <EOL> module . contrast_choice . value = contrast_choice <EOL> if module . contrast_choice == C . BY_SINGLE_MEASUREMENT : <EOL> for i , m in enumerate ( m_names ) : <EOL> group = module . single_measurements [ i ] <EOL> group . object_name . value = OBJECTS_NAME <EOL> group . measurement . value = m <EOL> group . image_name . value = IMAGE_NAME <EOL> else : <EOL> module . object_name . value = OBJECTS_NAME <EOL> module . image_name . value = IMAGE_NAME <EOL> module . first_measurement . value = MEASUREMENT_NAME_1 <EOL> module . second_measurement . value = MEASUREMENT_NAME_2 <EOL> module . module_num = <NUM_LIT:1> <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . RunExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . add_module ( module ) <EOL> workspace = cpw . Workspace ( pipeline , module , image_set , <EOL> object_set , measurements , <EOL> image_set_list ) <EOL> return workspace , module <EOL> def test_02_01_classify_single_none ( self ) : <EOL> '''<STR_LIT>''' <EOL> workspace , module = self . make_workspace ( <EOL> np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , int ) , <EOL> C . BY_SINGLE_MEASUREMENT , <EOL> np . zeros ( ( <NUM_LIT:0> , ) , float ) ) <EOL> module . run ( workspace ) <EOL> for m_name in ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) : <EOL> m = workspace . measurements . get_current_measurement ( OBJECTS_NAME , <EOL> m_name ) <EOL> self . assertEqual ( len ( m ) , <NUM_LIT:0> ) <EOL> def test_02_02_classify_single_even ( self ) : <EOL> m = np . array ( ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> labels = np . zeros ( ( <NUM_LIT:20> , <NUM_LIT:10> ) , int ) <EOL> labels [ <NUM_LIT:2> : <NUM_LIT:5> , <NUM_LIT:3> : <NUM_LIT:7> ] = <NUM_LIT:1> <EOL> labels [ <NUM_LIT:12> : <NUM_LIT:15> , <NUM_LIT:1> : <NUM_LIT:4> ] = <NUM_LIT:2> <EOL> labels [ <NUM_LIT:6> : <NUM_LIT:11> , <NUM_LIT:5> : <NUM_LIT:9> ] = <NUM_LIT:3> <EOL> labels [ <NUM_LIT:16> : <NUM_LIT> , <NUM_LIT:5> : <NUM_LIT:9> ] = <NUM_LIT:4> <EOL> workspace , module = self . make_workspace ( labels , <EOL> C . BY_SINGLE_MEASUREMENT , m ) <EOL> module . single_measurements [ <NUM_LIT:0> ] . bin_choice . value = C . BC_EVEN <EOL> module . single_measurements [ <NUM_LIT:0> ] . low_threshold . value = <NUM_LIT> <EOL> module . single_measurements [ <NUM_LIT:0> ] . high_threshold . value = <NUM_LIT> <EOL> module . single_measurements [ <NUM_LIT:0> ] . bin_count . value = <NUM_LIT:1> <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_low_bin . value = True <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_high_bin . value = True <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_images . value = True <EOL> expected_obj = dict ( Classify_Measurement1_Bin_1 = ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> Classify_Measurement1_Bin_2 = ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> Classify_Measurement1_Bin_3 = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> expected_img = dict ( Classify_Measurement1_Bin_1_NumObjectsPerBin = <NUM_LIT:2> , <EOL> Classify_Measurement1_Bin_2_NumObjectsPerBin = <NUM_LIT:1> , <EOL> Classify_Measurement1_Bin_3_NumObjectsPerBin = <NUM_LIT:1> , <EOL> Classify_Measurement1_Bin_1_PctObjectsPerBin = <NUM_LIT> , <EOL> Classify_Measurement1_Bin_2_PctObjectsPerBin = <NUM_LIT> , <EOL> Classify_Measurement1_Bin_3_PctObjectsPerBin = <NUM_LIT> ) <EOL> module . run ( workspace ) <EOL> for measurement , expected_values in expected_obj . iteritems ( ) : <EOL> values = workspace . measurements . get_current_measurement ( OBJECTS_NAME , <EOL> measurement ) <EOL> self . assertEqual ( len ( values ) , <NUM_LIT:4> ) <EOL> self . assertTrue ( np . all ( values == np . array ( expected_values ) ) ) <EOL> for measurement , expected_values in expected_img . iteritems ( ) : <EOL> values = workspace . measurements . get_current_measurement ( cpmeas . IMAGE , <EOL> measurement ) <EOL> self . assertTrue ( values == expected_values ) <EOL> image = workspace . image_set . get_image ( IMAGE_NAME ) <EOL> pixel_data = image . pixel_data <EOL> self . assertTrue ( np . all ( pixel_data [ labels == <NUM_LIT:0> , : ] == <NUM_LIT:0> ) ) <EOL> colors = [ pixel_data [ x , y , : ] for x , y in ( ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:12> , <NUM_LIT:1> ) , ( <NUM_LIT:6> , <NUM_LIT:5> ) ) ] <EOL> for i , color in enumerate ( colors + [ colors [ <NUM_LIT:1> ] ] ) : <EOL> self . assertTrue ( np . all ( pixel_data [ labels == i + <NUM_LIT:1> , : ] == color ) ) <EOL> columns = module . get_measurement_columns ( None ) <EOL> self . assertEqual ( len ( columns ) , <NUM_LIT:9> ) <EOL> self . assertEqual ( len ( set ( [ column [ <NUM_LIT:1> ] for column in columns ] ) ) , <NUM_LIT:9> ) <EOL> for column in columns : <EOL> if column [ <NUM_LIT:0> ] != OBJECTS_NAME : <EOL> self . assertEqual ( column [ <NUM_LIT:0> ] , cpmeas . IMAGE ) <EOL> self . assertTrue ( column [ <NUM_LIT:1> ] in expected_img . keys ( ) ) <EOL> self . assertTrue ( column [ <NUM_LIT:2> ] == cpmeas . COLTYPE_INTEGER if column [ <NUM_LIT:1> ] . endswith ( <EOL> C . F_NUM_PER_BIN ) else cpmeas . COLTYPE_FLOAT ) <EOL> else : <EOL> self . assertEqual ( column [ <NUM_LIT:0> ] , OBJECTS_NAME ) <EOL> self . assertTrue ( column [ <NUM_LIT:1> ] in expected_obj . keys ( ) ) <EOL> self . assertTrue ( column [ <NUM_LIT:2> ] == cpmeas . COLTYPE_INTEGER ) <EOL> categories = module . get_categories ( None , cpmeas . IMAGE ) <EOL> self . assertEqual ( len ( categories ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( categories [ <NUM_LIT:0> ] , C . M_CATEGORY ) <EOL> names = module . get_measurements ( None , cpmeas . IMAGE , "<STR_LIT:foo>" ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:0> ) <EOL> categories = module . get_categories ( None , OBJECTS_NAME ) <EOL> self . assertEqual ( len ( categories ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( categories [ <NUM_LIT:0> ] , C . M_CATEGORY ) <EOL> names = module . get_measurements ( None , OBJECTS_NAME , "<STR_LIT:foo>" ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:0> ) <EOL> names = module . get_measurements ( None , "<STR_LIT:foo>" , C . M_CATEGORY ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:0> ) <EOL> names = module . get_measurements ( None , OBJECTS_NAME , C . M_CATEGORY ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( len ( set ( names ) ) , <NUM_LIT:3> ) <EOL> self . assertTrue ( all ( [ '<STR_LIT:_>' . join ( ( C . M_CATEGORY , name ) ) in expected_obj . keys ( ) <EOL> for name in names ] ) ) <EOL> names = module . get_measurements ( None , cpmeas . IMAGE , C . M_CATEGORY ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( len ( set ( names ) ) , <NUM_LIT:6> ) <EOL> self . assertTrue ( all ( [ '<STR_LIT:_>' . join ( ( C . M_CATEGORY , name ) ) in expected_img . keys ( ) <EOL> for name in names ] ) ) <EOL> def test_02_03_classify_single_custom ( self ) : <EOL> m = np . array ( ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> labels = np . zeros ( ( <NUM_LIT:20> , <NUM_LIT:10> ) , int ) <EOL> labels [ <NUM_LIT:2> : <NUM_LIT:5> , <NUM_LIT:3> : <NUM_LIT:7> ] = <NUM_LIT:1> <EOL> labels [ <NUM_LIT:12> : <NUM_LIT:15> , <NUM_LIT:1> : <NUM_LIT:4> ] = <NUM_LIT:2> <EOL> labels [ <NUM_LIT:6> : <NUM_LIT:11> , <NUM_LIT:5> : <NUM_LIT:9> ] = <NUM_LIT:3> <EOL> labels [ <NUM_LIT:16> : <NUM_LIT> , <NUM_LIT:5> : <NUM_LIT:9> ] = <NUM_LIT:4> <EOL> workspace , module = self . make_workspace ( labels , <EOL> C . BY_SINGLE_MEASUREMENT , m ) <EOL> module . single_measurements [ <NUM_LIT:0> ] . bin_choice . value = C . BC_CUSTOM <EOL> module . single_measurements [ <NUM_LIT:0> ] . custom_thresholds . value = "<STR_LIT>" <EOL> module . single_measurements [ <NUM_LIT:0> ] . bin_count . value = <NUM_LIT> <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_custom_names . value = True <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_low_bin . value = True <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_high_bin . value = True <EOL> module . single_measurements [ <NUM_LIT:0> ] . bin_names . value = "<STR_LIT>" <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_images . value = True <EOL> expected_img = dict ( Classify_Three_NumObjectsPerBin = <NUM_LIT:2> , <EOL> Classify_Three_PctObjectsPerBin = <NUM_LIT> , <EOL> Classify_Blind_NumObjectsPerBin = <NUM_LIT:1> , <EOL> Classify_Blind_PctObjectsPerBin = <NUM_LIT> , <EOL> Classify_Mice_NumObjectsPerBin = <NUM_LIT:1> , <EOL> Classify_Mice_PctObjectsPerBin = <NUM_LIT> ) <EOL> expected_obj = dict ( Classify_Three = ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> Classify_Blind = ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> Classify_Mice = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> module . run ( workspace ) <EOL> for measurement , expected_values in expected_obj . iteritems ( ) : <EOL> values = workspace . measurements . get_current_measurement ( OBJECTS_NAME , <EOL> measurement ) <EOL> self . assertEqual ( len ( values ) , <NUM_LIT:4> ) <EOL> self . assertTrue ( np . all ( values == np . array ( expected_values ) ) ) <EOL> for measurement , expected_values in expected_img . iteritems ( ) : <EOL> values = workspace . measurements . get_current_measurement ( cpmeas . IMAGE , <EOL> measurement ) <EOL> self . assertTrue ( values == expected_values ) <EOL> image = workspace . image_set . get_image ( IMAGE_NAME ) <EOL> pixel_data = image . pixel_data <EOL> self . assertTrue ( np . all ( pixel_data [ labels == <NUM_LIT:0> , : ] == <NUM_LIT:0> ) ) <EOL> colors = [ pixel_data [ x , y , : ] for x , y in ( ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:12> , <NUM_LIT:1> ) , ( <NUM_LIT:6> , <NUM_LIT:5> ) ) ] <EOL> for i , color in enumerate ( colors + [ colors [ <NUM_LIT:1> ] ] ) : <EOL> self . assertTrue ( np . all ( pixel_data [ labels == i + <NUM_LIT:1> , : ] == color ) ) <EOL> columns = module . get_measurement_columns ( None ) <EOL> self . assertEqual ( len ( columns ) , <NUM_LIT:9> ) <EOL> self . assertEqual ( len ( set ( [ column [ <NUM_LIT:1> ] for column in columns ] ) ) , <NUM_LIT:9> ) <EOL> for column in columns : <EOL> if column [ <NUM_LIT:0> ] != OBJECTS_NAME : <EOL> self . assertEqual ( column [ <NUM_LIT:0> ] , cpmeas . IMAGE ) <EOL> self . assertTrue ( column [ <NUM_LIT:1> ] in expected_img . keys ( ) ) <EOL> self . assertTrue ( column [ <NUM_LIT:2> ] == cpmeas . COLTYPE_INTEGER if column [ <NUM_LIT:1> ] . endswith ( <EOL> C . F_NUM_PER_BIN ) else cpmeas . COLTYPE_FLOAT ) <EOL> else : <EOL> self . assertEqual ( column [ <NUM_LIT:0> ] , OBJECTS_NAME ) <EOL> self . assertTrue ( column [ <NUM_LIT:1> ] in expected_obj . keys ( ) ) <EOL> self . assertTrue ( column [ <NUM_LIT:2> ] == cpmeas . COLTYPE_INTEGER ) <EOL> categories = module . get_categories ( None , cpmeas . IMAGE ) <EOL> self . assertEqual ( len ( categories ) , <NUM_LIT:1> ) <EOL> categories = module . get_categories ( None , OBJECTS_NAME ) <EOL> self . assertEqual ( len ( categories ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( categories [ <NUM_LIT:0> ] , C . M_CATEGORY ) <EOL> names = module . get_measurements ( None , OBJECTS_NAME , "<STR_LIT:foo>" ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:0> ) <EOL> names = module . get_measurements ( None , "<STR_LIT:foo>" , C . M_CATEGORY ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:0> ) <EOL> names = module . get_measurements ( None , OBJECTS_NAME , C . M_CATEGORY ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( len ( set ( names ) ) , <NUM_LIT:3> ) <EOL> self . assertTrue ( all ( [ '<STR_LIT:_>' . join ( ( C . M_CATEGORY , name ) ) in expected_obj . keys ( ) <EOL> for name in names ] ) ) <EOL> names = module . get_measurements ( None , cpmeas . IMAGE , C . M_CATEGORY ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( len ( set ( names ) ) , <NUM_LIT:6> ) <EOL> self . assertTrue ( all ( [ '<STR_LIT:_>' . join ( ( C . M_CATEGORY , name ) ) in expected_img . keys ( ) <EOL> for name in names ] ) ) <EOL> def test_02_04_last_is_nan ( self ) : <EOL> for leave_last_out in ( False , True ) : <EOL> m = np . array ( ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> , np . NaN ) ) <EOL> if leave_last_out : <EOL> m = m [ : - <NUM_LIT:1> ] <EOL> labels = np . zeros ( ( <NUM_LIT:20> , <NUM_LIT:10> ) , int ) <EOL> labels [ <NUM_LIT:2> : <NUM_LIT:5> , <NUM_LIT:3> : <NUM_LIT:7> ] = <NUM_LIT:1> <EOL> labels [ <NUM_LIT:12> : <NUM_LIT:15> , <NUM_LIT:1> : <NUM_LIT:4> ] = <NUM_LIT:2> <EOL> labels [ <NUM_LIT:6> : <NUM_LIT:11> , <NUM_LIT:5> : <NUM_LIT:9> ] = <NUM_LIT:3> <EOL> labels [ <NUM_LIT:16> : <NUM_LIT> , <NUM_LIT:5> : <NUM_LIT:9> ] = <NUM_LIT:4> <EOL> workspace , module = self . make_workspace ( <EOL> labels , C . BY_SINGLE_MEASUREMENT , m ) <EOL> module . single_measurements [ <NUM_LIT:0> ] . bin_choice . value = C . BC_CUSTOM <EOL> module . single_measurements [ <NUM_LIT:0> ] . custom_thresholds . value = "<STR_LIT>" <EOL> module . single_measurements [ <NUM_LIT:0> ] . bin_count . value = <NUM_LIT> <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_custom_names . value = True <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_low_bin . value = True <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_high_bin . value = True <EOL> module . single_measurements [ <NUM_LIT:0> ] . bin_names . value = "<STR_LIT>" <EOL> module . single_measurements [ <NUM_LIT:0> ] . wants_images . value = True <EOL> expected_img = dict ( Classify_Three_NumObjectsPerBin = <NUM_LIT:1> , <EOL> Classify_Three_PctObjectsPerBin = <NUM_LIT> , <EOL> Classify_Blind_NumObjectsPerBin = <NUM_LIT:1> , <EOL> Classify_Blind_PctObjectsPerBin = <NUM_LIT> , <EOL> Classify_Mice_NumObjectsPerBin = <NUM_LIT:1> , <EOL> Classify_Mice_PctObjectsPerBin = <NUM_LIT> ) <EOL> expected_obj = dict ( Classify_Three = ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> Classify_Blind = ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> Classify_Mice = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> module . run ( workspace ) <EOL> for measurement , expected_values in expected_obj . iteritems ( ) : <EOL> values = workspace . measurements . get_current_measurement ( <EOL> OBJECTS_NAME , measurement ) <EOL> self . assertEqual ( len ( values ) , <NUM_LIT:4> ) <EOL> self . assertTrue ( np . all ( values == np . array ( expected_values ) ) ) <EOL> for measurement , expected_values in expected_img . iteritems ( ) : <EOL> values = workspace . measurements . get_current_measurement ( <EOL> cpmeas . IMAGE , measurement ) <EOL> self . assertTrue ( values == expected_values ) <EOL> image = workspace . image_set . get_image ( IMAGE_NAME ) <EOL> pixel_data = image . pixel_data <EOL> self . assertTrue ( np . all ( pixel_data [ labels == <NUM_LIT:0> , : ] == <NUM_LIT:0> ) ) <EOL> colors = [ pixel_data [ x , y , : ] for x , y in <EOL> ( ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:12> , <NUM_LIT:1> ) , ( <NUM_LIT:6> , <NUM_LIT:5> ) , ( <NUM_LIT:16> , <NUM_LIT:5> ) ) ] <EOL> for i , color in enumerate ( colors + [ colors [ <NUM_LIT:1> ] ] ) : <EOL> self . assertTrue ( np . all ( pixel_data [ labels == i + <NUM_LIT:1> , : ] == color ) ) <EOL> def test_03_01_two_none ( self ) : <EOL> workspace , module = self . make_workspace ( <EOL> np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , int ) , <EOL> C . BY_TWO_MEASUREMENTS , <EOL> np . zeros ( ( <NUM_LIT:0> , ) , float ) , np . zeros ( ( <NUM_LIT:0> , ) , float ) ) <EOL> module . run ( workspace ) <EOL> for lh1 in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> for lh2 in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> m_name = ( "<STR_LIT>" % <EOL> ( lh1 , lh2 ) ) <EOL> m = workspace . measurements . get_current_measurement ( OBJECTS_NAME , <EOL> m_name ) <EOL> self . assertEqual ( len ( m ) , <NUM_LIT:0> ) <EOL> def test_03_02_two ( self ) : <EOL> np . random . seed ( <NUM_LIT:0> ) <EOL> labels = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:20> ) , int ) <EOL> index = <NUM_LIT:1> <EOL> for i_min , i_max in ( ( <NUM_LIT:1> , <NUM_LIT:4> ) , ( <NUM_LIT:6> , <NUM_LIT:9> ) ) : <EOL> for j_min , j_max in ( ( <NUM_LIT:2> , <NUM_LIT:6> ) , ( <NUM_LIT:8> , <NUM_LIT:11> ) , ( <NUM_LIT> , <NUM_LIT> ) ) : <EOL> labels [ i_min : i_max , j_min : j_max ] = index <EOL> index += <NUM_LIT:1> <EOL> num_labels = index - <NUM_LIT:1> <EOL> exps = np . exp ( np . arange ( np . max ( labels ) ) ) <EOL> m1 = np . random . permutation ( exps ) <EOL> m2 = np . random . permutation ( exps ) <EOL> for wants_custom_names in ( False , True ) : <EOL> for tm1 in ( C . TM_MEAN , C . TM_MEDIAN , C . TM_CUSTOM ) : <EOL> for tm2 in ( C . TM_MEAN , C . TM_MEDIAN , C . TM_CUSTOM ) : <EOL> workspace , module = self . make_workspace ( labels , <EOL> C . BY_TWO_MEASUREMENTS , <EOL> m1 , m2 ) <EOL> self . assertTrue ( isinstance ( module , C . ClassifyObjects ) ) <EOL> module . first_threshold_method . value = tm1 <EOL> module . first_threshold . value = <NUM_LIT:8> <EOL> module . second_threshold_method . value = tm2 <EOL> module . second_threshold . value = <NUM_LIT> <EOL> module . wants_image . value = True <EOL> def cutoff ( method , custom_cutoff ) : <EOL> if method == C . TM_MEAN : <EOL> return np . mean ( exps ) <EOL> elif method == C . TM_MEDIAN : <EOL> return np . median ( exps ) <EOL> else : <EOL> return custom_cutoff <EOL> c1 = cutoff ( tm1 , module . first_threshold . value ) <EOL> c2 = cutoff ( tm2 , module . second_threshold . value ) <EOL> m1_over = m1 >= c1 <EOL> m2_over = m2 >= c2 <EOL> if wants_custom_names : <EOL> f_names = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> module . wants_custom_names . value = True <EOL> module . low_low_custom_name . value = f_names [ <NUM_LIT:0> ] <EOL> module . low_high_custom_name . value = f_names [ <NUM_LIT:1> ] <EOL> module . high_low_custom_name . value = f_names [ <NUM_LIT:2> ] <EOL> module . high_high_custom_name . value = f_names [ <NUM_LIT:3> ] <EOL> else : <EOL> f_names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> m_names = [ "<STR_LIT:_>" . join ( ( C . M_CATEGORY , name ) ) <EOL> for name in f_names ] <EOL> module . run ( workspace ) <EOL> columns = module . get_measurement_columns ( None ) <EOL> for column in columns : <EOL> if column [ <NUM_LIT:0> ] != OBJECTS_NAME : <EOL> self . assertEqual ( column [ <NUM_LIT:0> ] , cpmeas . IMAGE ) <EOL> self . assertTrue ( column [ <NUM_LIT:2> ] == cpmeas . COLTYPE_INTEGER if column [ <NUM_LIT:1> ] . endswith ( <EOL> C . F_NUM_PER_BIN ) else cpmeas . COLTYPE_FLOAT ) <EOL> else : <EOL> self . assertEqual ( column [ <NUM_LIT:0> ] , OBJECTS_NAME ) <EOL> self . assertTrue ( column [ <NUM_LIT:2> ] == cpmeas . COLTYPE_INTEGER ) <EOL> self . assertEqual ( len ( columns ) , <NUM_LIT:12> ) <EOL> self . assertEqual ( len ( set ( [ column [ <NUM_LIT:1> ] for column in columns ] ) ) , <NUM_LIT:12> ) <EOL> categories = module . get_categories ( None , cpmeas . IMAGE ) <EOL> self . assertEqual ( len ( categories ) , <NUM_LIT:1> ) <EOL> categories = module . get_categories ( None , OBJECTS_NAME ) <EOL> self . assertEqual ( len ( categories ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( categories [ <NUM_LIT:0> ] , C . M_CATEGORY ) <EOL> names = module . get_measurements ( None , OBJECTS_NAME , "<STR_LIT:foo>" ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:0> ) <EOL> names = module . get_measurements ( None , "<STR_LIT:foo>" , C . M_CATEGORY ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:0> ) <EOL> names = module . get_measurements ( None , OBJECTS_NAME , C . M_CATEGORY ) <EOL> self . assertEqual ( len ( names ) , <NUM_LIT:4> ) <EOL> for m_name , expected in zip ( m_names , <EOL> ( ( ~ m1_over ) & ( ~ m2_over ) , <EOL> ( ~ m1_over ) & m2_over , <EOL> m1_over & ~ m2_over , <EOL> m1_over & m2_over ) ) : <EOL> m = workspace . measurements . get_current_measurement ( cpmeas . IMAGE , <EOL> '<STR_LIT:_>' . join ( ( m_name , C . F_NUM_PER_BIN ) ) ) <EOL> self . assertTrue ( m == expected . astype ( int ) . sum ( ) ) <EOL> m = workspace . measurements . get_current_measurement ( cpmeas . IMAGE , <EOL> '<STR_LIT:_>' . join ( ( m_name , C . F_PCT_PER_BIN ) ) ) <EOL> self . assertTrue ( m == <NUM_LIT> * float ( expected . astype ( int ) . sum ( ) ) / num_labels ) <EOL> m = workspace . measurements . get_current_measurement ( OBJECTS_NAME , <EOL> m_name ) <EOL> self . assertTrue ( np . all ( m == expected . astype ( int ) ) ) <EOL> self . assertTrue ( m_name in [ column [ <NUM_LIT:1> ] for column in columns ] ) <EOL> self . assertTrue ( m_name in [ "<STR_LIT:_>" . join ( ( C . M_CATEGORY , name ) ) <EOL> for name in names ] ) <EOL> image = workspace . image_set . get_image ( IMAGE_NAME ) . pixel_data <EOL> self . assertTrue ( np . all ( image [ labels == <NUM_LIT:0> , : ] == <NUM_LIT:0> ) ) <EOL> colors = image [ ( labels > <NUM_LIT:0> ) & ( m [ labels - <NUM_LIT:1> ] == <NUM_LIT:1> ) , : ] <EOL> if colors . shape [ <NUM_LIT:0> ] > <NUM_LIT:0> : <EOL> self . assertTrue ( all ( [ np . all ( colors [ : , i ] == colors [ <NUM_LIT:0> , i ] ) <EOL> for i in range ( <NUM_LIT:3> ) ] ) ) <EOL> def test_03_04_nans ( self ) : <EOL> labels = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:15> ) , int ) <EOL> labels [ <NUM_LIT:3> : <NUM_LIT:5> , <NUM_LIT:3> : <NUM_LIT:5> ] = <NUM_LIT:1> <EOL> labels [ <NUM_LIT:6> : <NUM_LIT:8> , <NUM_LIT:3> : <NUM_LIT:5> ] = <NUM_LIT:3> <EOL> labels [ <NUM_LIT:3> : <NUM_LIT:5> , <NUM_LIT:6> : <NUM_LIT:8> ] = <NUM_LIT:4> <EOL> labels [ <NUM_LIT:6> : <NUM_LIT:8> , <NUM_LIT:6> : <NUM_LIT:8> ] = <NUM_LIT:5> <EOL> labels [ <NUM_LIT:3> : <NUM_LIT:5> , <NUM_LIT:10> : <NUM_LIT:12> ] = <NUM_LIT:2> <EOL> m1 = np . array ( ( <NUM_LIT:1> , <NUM_LIT:2> , np . NaN , <NUM_LIT:1> , np . NaN ) ) <EOL> m2 = np . array ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> , np . NaN , np . NaN ) ) <EOL> for leave_last_out in ( False , True ) : <EOL> end = np . max ( labels ) - <NUM_LIT:1> if leave_last_out else np . max ( labels ) <EOL> workspace , module = self . make_workspace ( <EOL> labels , <EOL> C . BY_TWO_MEASUREMENTS , <EOL> m1 [ : end ] , m2 [ : end ] ) <EOL> self . assertTrue ( isinstance ( module , C . ClassifyObjects ) ) <EOL> module . first_threshold_method . value = C . TM_MEAN <EOL> module . first_threshold . value = <NUM_LIT:2> <EOL> module . second_threshold_method . value = C . TM_MEAN <EOL> module . second_threshold . value = <NUM_LIT:2> <EOL> module . wants_image . value = True <EOL> module . wants_custom_names . value = False <EOL> module . run ( workspace ) <EOL> f_names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> m_names = [ "<STR_LIT:_>" . join ( ( C . M_CATEGORY , name ) ) <EOL> for name in f_names ] <EOL> m = workspace . measurements <EOL> for m_name , expected in zip ( <EOL> m_names , <EOL> [ np . array ( ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) , <EOL> np . array ( ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) , <EOL> np . array ( ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) , <EOL> np . array ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) ] ) : <EOL> values = m [ OBJECTS_NAME , m_name ] <EOL> np . testing . assert_array_equal ( values , expected ) <EOL> def test_03_05_nan_offset_by_1 ( self ) : <EOL> labels = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:15> ) , int ) <EOL> labels [ <NUM_LIT:3> : <NUM_LIT:5> , <NUM_LIT:3> : <NUM_LIT:5> ] = <NUM_LIT:1> <EOL> labels [ <NUM_LIT:6> : <NUM_LIT:8> , <NUM_LIT:3> : <NUM_LIT:5> ] = <NUM_LIT:2> <EOL> m1 = np . array ( ( <NUM_LIT:4> , np . NaN ) ) <EOL> m2 = np . array ( ( <NUM_LIT:4> , <NUM_LIT:4> ) ) <EOL> workspace , module = self . make_workspace ( <EOL> labels , <EOL> C . BY_TWO_MEASUREMENTS , <EOL> m1 , m2 ) <EOL> self . assertTrue ( isinstance ( module , C . ClassifyObjects ) ) <EOL> module . first_threshold_method . value = C . TM_MEAN <EOL> module . first_threshold . value = <NUM_LIT:2> <EOL> module . second_threshold_method . value = C . TM_MEAN <EOL> module . second_threshold . value = <NUM_LIT:2> <EOL> module . wants_image . value = True <EOL> module . wants_custom_names . value = False <EOL> module . run ( workspace ) <EOL> image = workspace . image_set . get_image ( IMAGE_NAME ) . pixel_data <EOL> colors = module . get_colors ( <NUM_LIT:4> ) <EOL> reverse = np . zeros ( image . shape [ : <NUM_LIT:2> ] , int ) <EOL> for idx , color in enumerate ( colors ) : <EOL> reverse [ <EOL> np . all ( image == color [ np . newaxis , np . newaxis , : <NUM_LIT:3> ] , <NUM_LIT:2> ) ] = idx <EOL> self . assertTrue ( np . all ( reverse [ labels == <NUM_LIT:1> ] == <NUM_LIT:4> ) ) </s>
