<s> '''<STR_LIT>''' <EOL> import numpy as np <EOL> import cellprofiler . cpimage as cpi <EOL> import cellprofiler . cpmodule as cpm <EOL> import cellprofiler . measurements as cpmeas <EOL> import cellprofiler . settings as cps <EOL> from cellprofiler . gui . help import USING_METADATA_HELP_REF <EOL> AGG_AVG = '<STR_LIT>' <EOL> AGG_MEDIAN = '<STR_LIT>' <EOL> AGG_STDEV = '<STR_LIT>' <EOL> AGG_CV = '<STR_LIT>' <EOL> AGG_NAMES = [ AGG_AVG , AGG_STDEV , AGG_MEDIAN , AGG_CV ] <EOL> OI_OBJECTS = '<STR_LIT>' <EOL> OI_IMAGE = '<STR_LIT>' <EOL> WF_NAME = '<STR_LIT>' <EOL> WF_ROWCOL = '<STR_LIT>' <EOL> class DisplayPlatemap ( cpm . CPModule ) : <EOL> module_name = "<STR_LIT>" <EOL> category = "<STR_LIT>" <EOL> variable_revision_number = <NUM_LIT:2> <EOL> def get_object ( self ) : <EOL> if self . objects_or_image . value == OI_OBJECTS : <EOL> return self . object . value <EOL> else : <EOL> return cpmeas . IMAGE <EOL> def create_settings ( self ) : <EOL> self . objects_or_image = cps . Choice ( <EOL> "<STR_LIT>" , <EOL> [ OI_OBJECTS , OI_IMAGE ] , doc = """<STR_LIT>""" % globals ( ) ) <EOL> self . object = cps . ObjectNameSubscriber ( <EOL> '<STR_LIT>' , <EOL> cps . NONE , doc = '''<STR_LIT>''' ) <EOL> self . plot_measurement = cps . Measurement ( <EOL> '<STR_LIT>' , <EOL> self . get_object , cps . NONE , doc = '''<STR_LIT>''' ) <EOL> self . plate_name = cps . Measurement ( '<STR_LIT>' , <EOL> lambda : cpmeas . IMAGE , <EOL> '<STR_LIT>' , doc = '''<STR_LIT>''' % globals ( ) ) <EOL> self . plate_type = cps . Choice ( <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , doc = <EOL> '''<STR_LIT>''' ) <EOL> self . well_format = cps . Choice ( <EOL> "<STR_LIT>" , <EOL> [ WF_NAME , WF_ROWCOL ] , doc = """<STR_LIT>""" % globals ( ) ) <EOL> self . well_name = cps . Measurement ( <EOL> '<STR_LIT>' , <EOL> lambda : cpmeas . IMAGE , '<STR_LIT>' , doc = '''<STR_LIT>''' % globals ( ) ) <EOL> self . well_row = cps . Measurement ( '<STR_LIT>' , <EOL> lambda : cpmeas . IMAGE , '<STR_LIT>' , doc = '''<STR_LIT>''' % globals ( ) ) <EOL> self . well_col = cps . Measurement ( '<STR_LIT>' , <EOL> lambda : cpmeas . IMAGE , '<STR_LIT>' , doc = '''<STR_LIT>''' % globals ( ) ) <EOL> self . agg_method = cps . Choice ( <EOL> '<STR_LIT>' , <EOL> AGG_NAMES , AGG_NAMES [ <NUM_LIT:0> ] , doc = '''<STR_LIT>''' % globals ( ) ) <EOL> self . title = cps . Text ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> doc = '''<STR_LIT>''' ) <EOL> def settings ( self ) : <EOL> return [ self . objects_or_image , self . object , self . plot_measurement , <EOL> self . plate_name , self . plate_type , self . well_name , <EOL> self . well_row , self . well_col , self . agg_method , self . title , <EOL> self . well_format ] <EOL> def visible_settings ( self ) : <EOL> result = [ self . objects_or_image ] <EOL> if self . objects_or_image . value == OI_OBJECTS : <EOL> result += [ self . object ] <EOL> result += [ self . plot_measurement ] <EOL> result += [ self . plate_type ] <EOL> result += [ self . plate_name ] <EOL> result += [ self . well_format ] <EOL> if self . well_format == WF_NAME : <EOL> result += [ self . well_name ] <EOL> elif self . well_format == WF_ROWCOL : <EOL> result += [ self . well_row , self . well_col ] <EOL> result += [ self . agg_method , self . title ] <EOL> return result <EOL> def run ( self , workspace ) : <EOL> if self . show_window : <EOL> m = workspace . get_measurements ( ) <EOL> plates = map ( <EOL> unicode , <EOL> m . get_all_measurements ( cpmeas . IMAGE , self . plate_name . value ) ) <EOL> if self . well_format == WF_NAME : <EOL> wells = m . get_all_measurements ( cpmeas . IMAGE , self . well_name . value ) <EOL> elif self . well_format == WF_ROWCOL : <EOL> wells = [ '<STR_LIT>' % ( x , y ) for x , y in zip ( m . get_all_measurements ( cpmeas . IMAGE , self . well_row . value ) , <EOL> m . get_all_measurements ( cpmeas . IMAGE , self . well_col . value ) ) ] <EOL> data = m . get_all_measurements ( self . get_object ( ) , self . plot_measurement . value ) <EOL> pm_dict = { } <EOL> for plate , well , data in zip ( plates , wells , data ) : <EOL> if data is None : <EOL> continue <EOL> if plate in pm_dict : <EOL> if well in pm_dict [ plate ] : <EOL> pm_dict [ plate ] [ well ] += [ data ] <EOL> else : <EOL> pm_dict [ plate ] . update ( { well : [ data ] } ) <EOL> else : <EOL> pm_dict [ plate ] = { well : [ data ] } <EOL> for plate , sub_dict in pm_dict . items ( ) : <EOL> for well , vals in sub_dict . items ( ) : <EOL> vals = np . hstack ( vals ) <EOL> if self . agg_method == AGG_AVG : <EOL> pm_dict [ plate ] [ well ] = np . mean ( vals ) <EOL> elif self . agg_method == AGG_STDEV : <EOL> pm_dict [ plate ] [ well ] = np . std ( vals ) <EOL> elif self . agg_method == AGG_MEDIAN : <EOL> pm_dict [ plate ] [ well ] = np . median ( vals ) <EOL> elif self . agg_method == AGG_CV : <EOL> pm_dict [ plate ] [ well ] = np . std ( vals ) / np . mean ( vals ) <EOL> else : <EOL> raise NotImplemented <EOL> workspace . display_data . pm_dict = pm_dict <EOL> def display ( self , workspace , figure ) : <EOL> pm_dict = workspace . display_data . pm_dict <EOL> if not hasattr ( figure , "<STR_LIT>" ) : <EOL> figure . set_subplots ( ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> if self . title . value != '<STR_LIT>' : <EOL> title = '<STR_LIT>' % ( self . title . value , workspace . measurements . image_set_number ) <EOL> else : <EOL> title = '<STR_LIT>' % ( self . agg_method , self . plot_measurement . value ) <EOL> figure . subplot_platemap ( <NUM_LIT:0> , <NUM_LIT:0> , pm_dict , self . plate_type , <EOL> title = title ) <EOL> def run_as_data_tool ( self , workspace ) : <EOL> return self . run ( workspace ) <EOL> def backwards_compatibilize ( self , setting_values , variable_revision_number , <EOL> module_name , from_matlab ) : <EOL> if variable_revision_number == <NUM_LIT:1> : <EOL> setting_values += [ WF_NAME ] <EOL> variable_revision_number = <NUM_LIT:2> <EOL> return setting_values , variable_revision_number , from_matlab </s>
