<s> '''<STR_LIT>''' <EOL> import gc <EOL> import numpy as np <EOL> import cellprofiler . cpmodule as cpm <EOL> import cellprofiler . settings as cps <EOL> C_REMOVE_OLD = "<STR_LIT>" <EOL> C_REMOVE = "<STR_LIT>" <EOL> C_KEEP_OLD = "<STR_LIT>" <EOL> C_KEEP = "<STR_LIT>" <EOL> '''<STR_LIT>''' <EOL> S_NUMBER_OF_PER_MODULE_SETTINGS = <NUM_LIT:1> <EOL> '''<STR_LIT>''' <EOL> S_NUMBER_OF_SETTINGS_PER_IMAGE = <NUM_LIT:1> <EOL> class ConserveMemory ( cpm . CPModule ) : <EOL> module_name = "<STR_LIT>" <EOL> category = '<STR_LIT>' <EOL> variable_revision_number = <NUM_LIT:1> <EOL> def create_settings ( self ) : <EOL> self . how_to_remove = cps . Choice ( <EOL> "<STR_LIT>" , <EOL> [ C_REMOVE , C_KEEP ] , doc = """<STR_LIT>""" % globals ( ) ) <EOL> self . spacer_top = cps . Divider ( line = False ) <EOL> self . image_names = [ ] <EOL> self . add_image ( can_remove = False ) <EOL> self . spacer_bottom = cps . Divider ( line = False ) <EOL> self . add_image_button = cps . DoSomething ( "<STR_LIT>" , "<STR_LIT>" , <EOL> self . add_image ) <EOL> def query ( self ) : <EOL> if self . how_to_remove == C_REMOVE : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> def add_image ( self , can_remove = True ) : <EOL> '''<STR_LIT>''' <EOL> group = cps . SettingsGroup ( ) <EOL> if can_remove : <EOL> group . append ( "<STR_LIT>" , cps . Divider ( line = False ) ) <EOL> group . append ( "<STR_LIT>" , cps . ImageNameSubscriber ( self . query ( ) , cps . NONE ) ) <EOL> if can_remove : <EOL> group . append ( "<STR_LIT>" , cps . RemoveSettingButton ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> self . image_names , <EOL> group ) ) <EOL> self . image_names . append ( group ) <EOL> def settings ( self ) : <EOL> return [ self . how_to_remove ] + [ im . image_name for im in self . image_names ] <EOL> def prepare_settings ( self , setting_values ) : <EOL> image_count = ( ( len ( setting_values ) - S_NUMBER_OF_PER_MODULE_SETTINGS ) / <EOL> S_NUMBER_OF_SETTINGS_PER_IMAGE ) <EOL> del self . image_names [ image_count : ] <EOL> while image_count > len ( self . image_names ) : <EOL> self . add_image ( ) <EOL> def visible_settings ( self ) : <EOL> for image_setting in self . image_names : <EOL> image_setting . image_name . text = self . query ( ) <EOL> result = [ self . how_to_remove , self . spacer_top ] <EOL> for image_setting in self . image_names : <EOL> result += image_setting . visible_settings ( ) <EOL> result += [ self . add_image_button ] <EOL> return result <EOL> def run ( self , workspace ) : <EOL> image_set = workspace . image_set <EOL> image_names = [ x . image_name . value for x in self . image_names ] <EOL> workspace . display_data . statistics = [ ] <EOL> if self . how_to_remove == C_KEEP : <EOL> all_names = [ x . name for x in image_set . providers ] <EOL> for name in set ( all_names ) - set ( image_names ) : <EOL> image_set . clear_image ( name ) <EOL> for name in image_names : <EOL> workspace . display_data . statistics . append ( [ "<STR_LIT>" % name ] ) <EOL> else : <EOL> for name in image_names : <EOL> image_set . clear_image ( name ) <EOL> workspace . display_data . statistics . append ( [ "<STR_LIT>" % name ] ) <EOL> gc . collect ( ) <EOL> def display ( self , workspace , figure ) : <EOL> figure . set_subplots ( ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> figure . subplot_table ( <NUM_LIT:0> , <NUM_LIT:0> , workspace . display_data . statistics ) <EOL> def upgrade_settings ( self , setting_values , variable_revision_number , <EOL> module_name , from_matlab ) : <EOL> if from_matlab and variable_revision_number == <NUM_LIT:5> : <EOL> new_setting_values = [ C_REMOVE ] <EOL> for image_name in setting_values [ <NUM_LIT:2> : ] : <EOL> if image_name . lower ( ) != cps . DO_NOT_USE . lower ( ) : <EOL> new_setting_values . append ( image_name ) <EOL> setting_values = new_setting_values <EOL> variable_revision_number = <NUM_LIT:1> <EOL> from_matlab = False <EOL> if ( not from_matlab ) and variable_revision_number == <NUM_LIT:1> : <EOL> remap = { '<STR_LIT>' : C_REMOVE , <EOL> C_REMOVE_OLD : C_REMOVE , <EOL> '<STR_LIT>' : C_KEEP , <EOL> C_KEEP_OLD : C_KEEP <EOL> } <EOL> if setting_values [ <NUM_LIT:0> ] in remap : <EOL> setting_values [ <NUM_LIT:0> ] = remap [ setting_values [ <NUM_LIT:0> ] ] <EOL> return setting_values , variable_revision_number , from_matlab <EOL> SpeedUpCellProfiler = ConserveMemory </s>
