def setUp(self): from cellprofiler.preferences import set_headless, set_temporary_directory set_headless() set_temporary_directory(tempfile.gettempdir()) self.old_import = __builtin__.__import__ __builtin__.__import__ = import_all_but_wx
def aw_parse_args(): '''Parse the application arguments into setup parameters''' from cellprofiler.preferences import set_headless, set_plugin_directory from cellprofiler.preferences import set_ij_plugin_directory import optparse global work_announce_address set_headless() parser = optparse.OptionParser() parser.add_option("--work-announce", dest="work_announce_address", help="ZMQ port where work announcements are published", default=None) parser.add_option( "--log-level", dest="log_level", help="Logging level for logger: DEBUG, INFO, WARNING, ERROR", default=os.environ.get(AW_LOG_LEVEL, logging.INFO)) parser.add_option( "--plugins-directory", dest="plugins_directory", help= "Folder containing the CellProfiler plugin modules needed by client pipelines", default=None) parser.add_option( "--ij-plugins-directory", dest="ij_plugins_directory", help= "Folder containing the ImageJ plugin .jar and .class files needed bby client pipelines", default=None) parser.add_option( "--jvm-heap-size", dest="jvm_heap_size", default="512m", help=("This is the amount of memory reserved for the " "Java Virtual Machine (similar to the java -Xmx switch)." "Example formats: 512000k, 512m, 1g")) options, args = parser.parse_args() logging.root.setLevel(options.log_level) if len(logging.root.handlers) == 0: logging.root.addHandler(logging.StreamHandler()) if not options.work_announce_address: parser.print_help() sys.exit(1) work_announce_address = options.work_announce_address # # Set up the headless plugins and ij plugins directories before doing # anything so loading will get them # if options.plugins_directory is not None: set_plugin_directory(options.plugins_directory) else: logger.warning("Plugins directory not set") if options.ij_plugins_directory is not None: logger.debug("Using %s as IJ plugins directory" % options.ij_plugins_directory) set_ij_plugin_directory(options.ij_plugins_directory) else: logger.debug("IJ plugins directory not set")
def setUp(self): from cellprofiler.preferences import set_headless, set_temporary_directory set_headless() set_temporary_directory(tempfile.gettempdir()) self.old_import = builtins.__import__ builtins.__import__ = import_all_but_wx
def aw_parse_args(): '''Parse the application arguments into setup parameters''' from cellprofiler.preferences import \ set_headless, set_awt_headless, \ set_plugin_directory, set_ij_plugin_directory import optparse global work_announce_address set_headless() set_awt_headless(False) parser = optparse.OptionParser() parser.add_option("--work-announce", dest="work_announce_address", help="ZMQ port where work announcements are published", default=None) parser.add_option("--log-level", dest="log_level", help="Logging level for logger: DEBUG, INFO, WARNING, ERROR", default=os.environ.get(AW_LOG_LEVEL, logging.INFO)) parser.add_option("--plugins-directory", dest="plugins_directory", help="Folder containing the CellProfiler plugin modules needed by client pipelines", default=None) parser.add_option("--ij-plugins-directory", dest="ij_plugins_directory", help="Folder containing the ImageJ plugin .jar and .class files needed bby client pipelines", default=None) parser.add_option("--jvm-heap-size", dest="jvm_heap_size", default=None, help=("This is the amount of memory reserved for the " "Java Virtual Machine (similar to the java -Xmx switch)." "Example formats: 512000k, 512m, 1g")) options, args = parser.parse_args() if options.jvm_heap_size is not None: from cellprofiler.preferences import set_jvm_heap_mb set_jvm_heap_mb(options.jvm_heap_size, False) logging.root.setLevel(options.log_level) if len(logging.root.handlers) == 0: logging.root.addHandler(logging.StreamHandler()) if not options.work_announce_address: parser.print_help() sys.exit(1) work_announce_address = options.work_announce_address # # Set up the headless plugins and ij plugins directories before doing # anything so loading will get them # if options.plugins_directory is not None: set_plugin_directory(options.plugins_directory) else: logger.warning("Plugins directory not set") if options.ij_plugins_directory is not None: logger.debug("Using %s as IJ plugins directory" % options.ij_plugins_directory) set_ij_plugin_directory(options.ij_plugins_directory) else: logger.debug("IJ plugins directory not set")
def setUp(self): # # Make a temporary directory structure # cpprefs.set_headless() directory = self.directory = tempfile.mkdtemp() for i in range(3): os.mkdir(os.path.join(directory, str(i))) for j in range(3): os.mkdir(os.path.join(directory, str(i), str(j))) for k in range(3): os.mkdir(os.path.join(directory, str(i), str(j), str(k))) cpprefs.set_default_image_directory(os.path.join(self.directory, "1"))
def aw_parse_args(): '''Parse the application arguments into setup parameters''' from cellprofiler.preferences import set_headless, set_plugin_directory from cellprofiler.preferences import set_ij_plugin_directory import optparse global work_announce_address set_headless() parser = optparse.OptionParser() parser.add_option("--work-announce", dest="work_announce_address", help="ZMQ port where work announcements are published", default=None) parser.add_option( "--log-level", dest="log_level", help="Logging level for logger: DEBUG, INFO, WARNING, ERROR", default=os.environ.get(AW_LOG_LEVEL, logging.INFO)) parser.add_option( "--plugins-directory", dest="plugins_directory", help= "Folder containing the CellProfiler plugin modules needed by client pipelines", default=None) parser.add_option( "--ij-plugins-directory", dest="ij_plugins_directory", help= "Folder containing the ImageJ plugin .jar and .class files needed bby client pipelines", default=None) options, args = parser.parse_args() logging.root.setLevel(options.log_level) if not options.work_announce_address: parser.print_help() sys.exit(1) work_announce_address = options.work_announce_address # # Set up the headless plugins and ij plugins directories before doing # anything so loading will get them # if options.plugins_directory is not None: set_plugin_directory(options.plugins_directory) else: logger.warning("Plugins directory not set") if options.ij_plugins_directory is not None: logger.debug("Using %s as IJ plugins directory" % options.ij_plugins_directory) set_ij_plugin_directory(options.ij_plugins_directory) else: logger.debug("IJ plugins directory not set")
def setUp(self): # # Make three temporary directory structures # cpprefs.set_headless() self.directories = [tempfile.mkdtemp() for i in range(3)] for directory in self.directories: for i in range(3): os.mkdir(os.path.join(directory, str(i))) for j in range(3): os.mkdir(os.path.join(directory, str(i), str(j))) for k in range(3): os.mkdir(os.path.join(directory, str(i), str(j), str(k))) cpprefs.set_default_image_directory(os.path.join(self.directories[0], "1")) cpprefs.set_default_output_directory(os.path.join(self.directories[1], "1")) self.root_directory = os.path.join(self.directories[2], "1")
def aw_parse_args(): '''Parse the application arguments into setup parameters''' from cellprofiler.preferences import set_headless, set_plugin_directory from cellprofiler.preferences import set_ij_plugin_directory import optparse global work_announce_address set_headless() parser = optparse.OptionParser() parser.add_option("--work-announce", dest="work_announce_address", help="ZMQ port where work announcements are published", default=None) parser.add_option("--log-level", dest="log_level", help="Logging level for logger: DEBUG, INFO, WARNING, ERROR", default=os.environ.get(AW_LOG_LEVEL, logging.INFO)) parser.add_option("--plugins-directory", dest="plugins_directory", help="Folder containing the CellProfiler plugin modules needed by client pipelines", default=None) parser.add_option("--ij-plugins-directory", dest="ij_plugins_directory", help="Folder containing the ImageJ plugin .jar and .class files needed bby client pipelines", default=None) options, args = parser.parse_args() logging.root.setLevel(options.log_level) if len(logging.root.handlers) == 0: logging.root.addHandler(logging.StreamHandler()) if not options.work_announce_address: parser.print_help() sys.exit(1) work_announce_address = options.work_announce_address # # Set up the headless plugins and ij plugins directories before doing # anything so loading will get them # if options.plugins_directory is not None: set_plugin_directory(options.plugins_directory) else: logger.warning("Plugins directory not set") if options.ij_plugins_directory is not None: logger.debug("Using %s as IJ plugins directory" % options.ij_plugins_directory) set_ij_plugin_directory(options.ij_plugins_directory) else: logger.debug("IJ plugins directory not set")
def test_02_01_compare_to_matlab(self): expected = { 'EC50_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':3.982812, 'EC50_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':4.139827, 'EC50_DistCytoplasm_Intensity_MedianIntensity_CorrGreen':4.178600, 'EC50_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen':4.059770, 'EC50_DistCytoplasm_Intensity_MinIntensity_CorrGreen':4.066357, 'EC50_DistCytoplasm_Math_Ratio1':4.491367, 'EC50_DistCytoplasm_Math_Ratio2':3.848722, 'EC50_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':4.948056, 'EC50_DistCytoplasm_Texture_Entropy_CorrGreen_1':4.687104, 'EC50_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1':5.0285, 'EC50_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1':4.319017, 'EC50_DistCytoplasm_Texture_SumAverage_CorrGreen_1':4.548876, 'EC50_DistCytoplasm_Texture_SumEntropy_CorrGreen_1':4.779139, 'EC50_DistCytoplasm_Texture_Variance_CorrGreen_1':4.218379, 'EC50_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue':3.708711, 'EC50_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen':4.135146, 'EC50_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen':4.5372, 'EC50_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen':4.1371, 'EC50_DistanceCells_Intensity_MinIntensityEdge_CorrGreen':4.033999, 'EC50_DistanceCells_Intensity_MinIntensity_CorrGreen':4.079470, 'EC50_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1':5.118689, 'EC50_DistanceCells_Texture_Correlation_CorrGreen_1':4.002074, 'EC50_DistanceCells_Texture_Entropy_CorrGreen_1':5.008000, 'EC50_DistanceCells_Texture_InfoMeas1_CorrGreen_1':3.883586, 'EC50_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1':3.977216, 'EC50_DistanceCells_Texture_SumAverage_CorrGreen_1':4.9741, 'EC50_DistanceCells_Texture_SumEntropy_CorrGreen_1':5.1455, 'EC50_DistanceCells_Texture_SumVariance_CorrGreen_1':4.593041, 'EC50_DistanceCells_Texture_Variance_CorrGreen_1':4.619517, 'EC50_Nuclei_Correlation_Correlation_CorrGreenCorrBlue':3.751133, 'EC50_Nuclei_Math_Ratio1':4.491367, 'EC50_Nuclei_Math_Ratio2':3.848722, 'EC50_Nuclei_Texture_SumAverage_CorrGreen_1':3.765297, 'EC50_PropCells_AreaShape_Area':4.740853, 'EC50_PropCells_AreaShape_MajorAxisLength':5.064460, 'EC50_PropCells_AreaShape_MinorAxisLength':4.751471, 'EC50_PropCells_AreaShape_Perimeter':4.949292, 'EC50_PropCells_Correlation_Correlation_CorrGreenCorrBlue':3.772565, 'EC50_PropCells_Texture_GaborX_CorrGreen_1':5.007167, 'EC50_PropCells_Texture_InfoMeas2_CorrBlue_1':4.341353, 'EC50_PropCells_Texture_SumVariance_CorrBlue_1':4.298359, 'EC50_PropCells_Texture_SumVariance_CorrGreen_1':4.610826, 'EC50_PropCells_Texture_Variance_CorrBlue_1':4.396352, 'EC50_PropCells_Texture_Variance_CorrGreen_1':4.632468, 'EC50_PropCytoplasm_AreaShape_Area':4.669679, 'EC50_PropCytoplasm_AreaShape_MinorAxisLength':4.754476, 'EC50_PropCytoplasm_AreaShape_Perimeter':4.949292, 'EC50_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':4.072830, 'EC50_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen':4.0934, 'EC50_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':3.925800, 'EC50_PropCytoplasm_Intensity_MedianIntensity_CorrGreen':3.9252, 'EC50_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':4.777481, 'EC50_PropCytoplasm_Texture_Entropy_CorrGreen_1':4.4432, 'EC50_PropCytoplasm_Texture_GaborX_CorrGreen_1':5.163371, 'EC50_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1':4.701046, 'EC50_PropCytoplasm_Texture_SumEntropy_CorrGreen_1':4.510543, 'EC50_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1':4.560315, 'EC50_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1':4.966674, 'EC50_ThresholdedCells_Texture_Entropy_CorrBlue_1':4.457866, 'EC50_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1':4.624049, 'EC50_ThresholdedCells_Texture_SumAverage_CorrBlue_1':4.686706, 'EC50_ThresholdedCells_Texture_SumEntropy_CorrBlue_1':4.537378, 'EC50_ThresholdedCells_Texture_SumVariance_CorrBlue_1':4.322820, 'EC50_ThresholdedCells_Texture_SumVariance_CorrGreen_1':4.742158, 'EC50_ThresholdedCells_Texture_Variance_CorrBlue_1':4.265549, 'EC50_ThresholdedCells_Texture_Variance_CorrGreen_1':4.860020, 'OneTailedZfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen':-4.322503, 'OneTailedZfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen':-4.322503, 'OneTailedZfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen':-4.322503, 'OneTailedZfactor_DistCytoplasm_Math_Ratio1':0.622059, 'OneTailedZfactor_DistCytoplasm_Math_Ratio2':-4.508284, 'OneTailedZfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1':-4.645887, 'OneTailedZfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1':-4.279118, 'OneTailedZfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1':-4.765570, 'OneTailedZfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1':-4.682335, 'OneTailedZfactor_DistCytoplasm_Texture_Variance_CorrGreen_1':-4.415607, 'OneTailedZfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen':-4.200105, 'OneTailedZfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen':-4.316452, 'OneTailedZfactor_DistanceCells_Intensity_MinIntensity_CorrGreen':-4.316452, 'OneTailedZfactor_DistanceCells_Texture_Correlation_CorrGreen_1':0.202500, 'OneTailedZfactor_DistanceCells_Texture_Entropy_CorrGreen_1':-4.404815, 'OneTailedZfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1':-4.508513, 'OneTailedZfactor_DistanceCells_Texture_SumAverage_CorrGreen_1':-4.225356, 'OneTailedZfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1':-4.382768, 'OneTailedZfactor_DistanceCells_Texture_SumVariance_CorrGreen_1':0.492125, 'OneTailedZfactor_DistanceCells_Texture_Variance_CorrGreen_1':0.477360, 'OneTailedZfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue':0.563780, 'OneTailedZfactor_Nuclei_Math_Ratio1':0.622059, 'OneTailedZfactor_Nuclei_Math_Ratio2':-4.508284, 'OneTailedZfactor_Nuclei_Texture_SumAverage_CorrGreen_1':0.426178, 'OneTailedZfactor_PropCells_AreaShape_Area':-4.216674, 'OneTailedZfactor_PropCells_AreaShape_MajorAxisLength':-4.119131, 'OneTailedZfactor_PropCells_AreaShape_MinorAxisLength':-4.109793, 'OneTailedZfactor_PropCells_AreaShape_Perimeter':-4.068050, 'OneTailedZfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue':0.765440, 'OneTailedZfactor_PropCells_Texture_GaborX_CorrGreen_1':0.114982, 'OneTailedZfactor_PropCells_Texture_InfoMeas2_CorrBlue_1':0.108409, 'OneTailedZfactor_PropCells_Texture_SumVariance_CorrBlue_1':0.191251, 'OneTailedZfactor_PropCells_Texture_SumVariance_CorrGreen_1':0.559865, 'OneTailedZfactor_PropCells_Texture_Variance_CorrBlue_1':0.254078, 'OneTailedZfactor_PropCells_Texture_Variance_CorrGreen_1':0.556108, 'OneTailedZfactor_PropCytoplasm_AreaShape_Area':-4.223021, 'OneTailedZfactor_PropCytoplasm_AreaShape_MinorAxisLength':-4.095632, 'OneTailedZfactor_PropCytoplasm_AreaShape_Perimeter':-4.068050, 'OneTailedZfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen':-4.194663, 'OneTailedZfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1':-4.443338, 'OneTailedZfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1':0.207265, 'OneTailedZfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1':-4.297250, 'OneTailedZfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1':-4.525324, 'OneTailedZfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1':0.167795, 'OneTailedZfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1':0.067560, 'OneTailedZfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1':0.478527, 'OneTailedZfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1':0.155119, 'OneTailedZfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1':0.535907, 'OneTailedZfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1':0.572801, 'OneTailedZfactor_ThresholdedCells_Texture_Variance_CorrBlue_1':0.423454, 'OneTailedZfactor_ThresholdedCells_Texture_Variance_CorrGreen_1':0.440500, 'Vfactor_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':0.500429, 'Vfactor_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':0.325675, 'Vfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen':0.323524, 'Vfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen':0.138487, 'Vfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen':0.128157, 'Vfactor_DistCytoplasm_Math_Ratio1':0.503610, 'Vfactor_DistCytoplasm_Math_Ratio2':0.319610, 'Vfactor_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':0.522880, 'Vfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1':0.504303, 'Vfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1':0.289432, 'Vfactor_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1':0.234123, 'Vfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1':0.591687, 'Vfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1':0.520356, 'Vfactor_DistCytoplasm_Texture_Variance_CorrGreen_1':-0.007649, 'Vfactor_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue':0.761198, 'Vfactor_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen':0.234655, 'Vfactor_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen':0.252240, 'Vfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen':0.195125, 'Vfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen':0.138299, 'Vfactor_DistanceCells_Intensity_MinIntensity_CorrGreen':0.126784, 'Vfactor_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1':0.342691, 'Vfactor_DistanceCells_Texture_Correlation_CorrGreen_1':0.314396, 'Vfactor_DistanceCells_Texture_Entropy_CorrGreen_1':0.311771, 'Vfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1':0.410631, 'Vfactor_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1':0.170576, 'Vfactor_DistanceCells_Texture_SumAverage_CorrGreen_1':0.223147, 'Vfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1':0.269519, 'Vfactor_DistanceCells_Texture_SumVariance_CorrGreen_1':0.571528, 'Vfactor_DistanceCells_Texture_Variance_CorrGreen_1':0.566272, 'Vfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue':0.705051, 'Vfactor_Nuclei_Math_Ratio1':0.503610, 'Vfactor_Nuclei_Math_Ratio2':0.319610, 'Vfactor_Nuclei_Texture_SumAverage_CorrGreen_1':0.553708, 'Vfactor_PropCells_AreaShape_Area':0.340093, 'Vfactor_PropCells_AreaShape_MajorAxisLength':0.243838, 'Vfactor_PropCells_AreaShape_MinorAxisLength':0.320691, 'Vfactor_PropCells_AreaShape_Perimeter':0.238915, 'Vfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue':0.723520, 'Vfactor_PropCells_Texture_GaborX_CorrGreen_1':0.213161, 'Vfactor_PropCells_Texture_InfoMeas2_CorrBlue_1':0.199791, 'Vfactor_PropCells_Texture_SumVariance_CorrBlue_1':0.078959, 'Vfactor_PropCells_Texture_SumVariance_CorrGreen_1':0.642844, 'Vfactor_PropCells_Texture_Variance_CorrBlue_1':0.199105, 'Vfactor_PropCells_Texture_Variance_CorrGreen_1':0.640818, 'Vfactor_PropCytoplasm_AreaShape_Area':0.325845, 'Vfactor_PropCytoplasm_AreaShape_MinorAxisLength':0.312258, 'Vfactor_PropCytoplasm_AreaShape_Perimeter':0.238915, 'Vfactor_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':0.337565, 'Vfactor_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen':0.292900, 'Vfactor_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':0.175528, 'Vfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen':0.193308, 'Vfactor_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':0.276152, 'Vfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1':0.239567, 'Vfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1':0.332380, 'Vfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1':0.379141, 'Vfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1':0.337740, 'Vfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1':0.334520, 'Vfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1':0.192882, 'Vfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1':0.276245, 'Vfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1':0.139166, 'Vfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1':0.465237, 'Vfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1':0.355399, 'Vfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1':0.453937, 'Vfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1':0.564371, 'Vfactor_ThresholdedCells_Texture_Variance_CorrBlue_1':0.360566, 'Vfactor_ThresholdedCells_Texture_Variance_CorrGreen_1':0.548770, 'Zfactor_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':0.531914, 'Zfactor_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':0.265558, 'Zfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen':0.178586, 'Zfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen':0.084566, 'Zfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen':0.086476, 'Zfactor_DistCytoplasm_Math_Ratio1':0.623284, 'Zfactor_DistCytoplasm_Math_Ratio2':0.358916, 'Zfactor_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':0.429510, 'Zfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1':0.508275, 'Zfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1':0.068695, 'Zfactor_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1':0.347949, 'Zfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1':0.646576, 'Zfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1':0.494276, 'Zfactor_DistCytoplasm_Texture_Variance_CorrGreen_1':0.179011, 'Zfactor_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue':0.824686, 'Zfactor_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen':0.027644, 'Zfactor_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen':0.088491, 'Zfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen':0.065056, 'Zfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen':0.089658, 'Zfactor_DistanceCells_Intensity_MinIntensity_CorrGreen':0.078017, 'Zfactor_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1':0.238131, 'Zfactor_DistanceCells_Texture_Correlation_CorrGreen_1':0.301107, 'Zfactor_DistanceCells_Texture_Entropy_CorrGreen_1':0.251143, 'Zfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1':0.564957, 'Zfactor_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1':0.302767, 'Zfactor_DistanceCells_Texture_SumAverage_CorrGreen_1':0.036459, 'Zfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1':0.159798, 'Zfactor_DistanceCells_Texture_SumVariance_CorrGreen_1':0.516938, 'Zfactor_DistanceCells_Texture_Variance_CorrGreen_1':0.501186, 'Zfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue':0.691408, 'Zfactor_Nuclei_Math_Ratio1':0.623284, 'Zfactor_Nuclei_Math_Ratio2':0.358916, 'Zfactor_Nuclei_Texture_SumAverage_CorrGreen_1':0.587347, 'Zfactor_PropCells_AreaShape_Area':0.132425, 'Zfactor_PropCells_AreaShape_MajorAxisLength':0.034809, 'Zfactor_PropCells_AreaShape_MinorAxisLength':0.113864, 'Zfactor_PropCells_AreaShape_Perimeter':0.005984, 'Zfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue':0.717632, 'Zfactor_PropCells_Texture_GaborX_CorrGreen_1':0.251023, 'Zfactor_PropCells_Texture_InfoMeas2_CorrBlue_1':0.149719, 'Zfactor_PropCells_Texture_SumVariance_CorrBlue_1':0.102050, 'Zfactor_PropCells_Texture_SumVariance_CorrGreen_1':0.611960, 'Zfactor_PropCells_Texture_Variance_CorrBlue_1':0.197090, 'Zfactor_PropCells_Texture_Variance_CorrGreen_1':0.614879, 'Zfactor_PropCytoplasm_AreaShape_Area':0.205042, 'Zfactor_PropCytoplasm_AreaShape_MinorAxisLength':0.072682, 'Zfactor_PropCytoplasm_AreaShape_Perimeter':0.005984, 'Zfactor_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':0.272017, 'Zfactor_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen':0.115327, 'Zfactor_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':0.141850, 'Zfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen':0.105803, 'Zfactor_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':0.107640, 'Zfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1':0.067896, 'Zfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1':0.136688, 'Zfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1':0.334749, 'Zfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1':0.208829, 'Zfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1':0.263467, 'Zfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1':0.124355, 'Zfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1':0.236433, 'Zfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1':0.125845, 'Zfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1':0.449333, 'Zfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1':0.323243, 'Zfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1':0.507477, 'Zfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1':0.599000, 'Zfactor_ThresholdedCells_Texture_Variance_CorrBlue_1':0.361424, 'Zfactor_ThresholdedCells_Texture_Variance_CorrGreen_1':0.481393 } temp_dir = tempfile.mkdtemp() m = None try: cpprefs.set_headless() cpprefs.set_default_output_directory(temp_dir) print "Writing output to %s"%temp_dir path = os.path.split(__file__)[0] matfile_path = os.path.join(path,'calculatestatistics.mat') if not os.path.isfile(matfile_path): # Download from GIT URL matfile_path = os.path.join(temp_dir, 'calculatestatistics.mat') url = github_url + ( "/cellprofiler/modules/tests/" "calculatestatistics.mat") urllib.urlretrieve(url, matfile_path) measurements = loadmat(matfile_path, struct_as_record = True) measurements = measurements['m'] image_set_list = cpi.ImageSetList() image_set = image_set_list.get_image_set(0) m = cpmeas.Measurements() doses = [0 ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10, 0 ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10, 0 ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10, 0 ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10, 10,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0, 10,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0, 10,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0, 10,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0] for i,dose in enumerate(doses): m.add_image_measurement("Dose",dose) for object_name in measurements.dtype.fields: omeasurements = measurements[object_name][0,0] for feature_name in omeasurements.dtype.fields: data = omeasurements[feature_name][0,0][0,i].flatten() m.add_measurement(object_name, feature_name, data) if i < len(doses)-1: m.next_image_set() pipeline = cpp.Pipeline() module = C.CalculateStatistics() module.grouping_values.value = "Dose" module.dose_values[0].log_transform.value = False module.dose_values[0].measurement.value = "Dose" module.dose_values[0].wants_save_figure.value = True module.dose_values[0].figure_name.value = "EC49_" module.module_num = 1 pipeline.add_module(module) def callback(caller, event): self.assertFalse(isinstance(event, cpp.RunExceptionEvent)) workspace = cpw.Workspace(pipeline, module, image_set, cpo.ObjectSet(), m, image_set_list) module.post_run(workspace) for feature_name in m.get_feature_names(cpmeas.EXPERIMENT): if not expected.has_key(feature_name): print "Missing measurement: %s"%feature_name continue value = m.get_experiment_measurement(feature_name) e_value = expected[feature_name] diff = abs(value-e_value) *2 /abs(value+e_value) self.assertTrue(diff < .05, "%s: Matlab: %f, Python: %f diff: %f" % (feature_name, e_value, value, diff)) if diff > .01: print ("Warning: > 1%% difference for %s: Matlab: %f, Python: %f diff: %f" % (feature_name, e_value, value, diff)) if feature_name.startswith("EC50"): filename = "EC49_"+feature_name[5:]+".pdf" self.assertTrue(os.path.isfile(os.path.join(temp_dir, filename))) finally: try: if m is not None: m.close() except: pass for filename in os.listdir(temp_dir): path = os.path.join(temp_dir, filename) os.remove(path) os.rmdir(temp_dir)
def main(*args): '''Run the CellProfiler nose tests''' args = list(args) if '--noguitests' in args: args.remove('--noguitests') import cellprofiler.preferences as cpprefs cpprefs.set_headless() sys.modules['wx'] = MockModule() sys.modules['wx.html'] = MockModule() import matplotlib matplotlib.use('agg') with_guitests = False else: with_guitests = True def mock_start_vm(*args, **kwargs): raise SkipTest if '--nojavatests' in args: args.remove('--nojavatests') javabridge.start_vm = mock_start_vm elif not with_guitests: javabridge.activate_awt = mock_start_vm javabridge.execute_future_in_main_thread = mock_start_vm javabridge.execute_runnable_in_main_thread = mock_start_vm addplugins = [CPShutdownPlugin()] if not "--with-cpshutdown" in args: args.append("--with-cpshutdown") if '--with-kill-vm' in args: args[args.index('--with-kill-vm')] = '--with-javabridge' if '--with-javabridge' in args: class_path = get_jars() args.append('--classpath=%s' % os.pathsep.join(class_path)) if hasattr(sys, "frozen"): from javabridge.noseplugin import JavabridgePlugin javabridge_plugin_class = JavabridgePlugin addplugins.append(JavabridgePlugin()) else: javabridge_plugin_class = load_entry_point( 'javabridge', 'nose.plugins.0.10', 'javabridge') javabridge_plugin_class.extra_jvm_args += get_patcher_args(class_path) if "CP_JDWP_PORT" in os.environ: javabridge_plugin_class.extra_jvm_args.append( ("-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:%s" ",server=y,suspend=n") % os.environ["CP_JDWP_PORT"]) addplugins.append(javabridge_plugin_class()) # # Run the shutdown plugin before the javabridge plugin when exiting # CPShutdownPlugin.score = javabridge_plugin_class.score + 1 addplugins.append(LoadTestsFromXML()) if len(args) == 0: args = ['--testmatch=(?:^)test_.*'] args += ['--exe'] if hasattr(sys, "frozen"): # # Patch nose.core.TestProgram.usage # it will attempt to get usage.txt and it's not worth # the effort to make that work. # from nose.core import TestProgram TestProgram.usage = lambda cls: "" nose.main(argv=args, addplugins=addplugins)
def main(*args): '''Run the CellProfiler nose tests''' args = list(args) import cellprofiler.preferences as cpprefs cpprefs.set_headless() cpprefs.set_awt_headless(True) if '--noguitests' in args: args.remove('--noguitests') sys.modules['wx'] = MockModule() sys.modules['wx.html'] = MockModule() import matplotlib matplotlib.use('agg') with_guitests = False wxapp = None else: with_guitests = True import wx wxapp = wx.App(False) def mock_start_vm(*args, **kwargs): raise SkipTest if '--nojavatests' in args: args.remove('--nojavatests') javabridge.start_vm = mock_start_vm addplugins = [CPShutdownPlugin()] if not "--with-cpshutdown" in args: args.append("--with-cpshutdown") if '--with-kill-vm' in args: args[args.index('--with-kill-vm')] = '--with-javabridge' if '--with-javabridge' in args: class_path = get_jars() args.append('--classpath=%s' % os.pathsep.join(class_path)) if hasattr(sys, "frozen"): from javabridge.noseplugin import JavabridgePlugin javabridge_plugin_class = JavabridgePlugin addplugins.append(JavabridgePlugin()) else: javabridge_plugin_class = load_entry_point('javabridge', 'nose.plugins.0.10', 'javabridge') javabridge_plugin_class.extra_jvm_args += get_patcher_args(class_path) if "CP_JDWP_PORT" in os.environ: javabridge_plugin_class.extra_jvm_args.append( ("-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:%s" ",server=y,suspend=n") % os.environ["CP_JDWP_PORT"]) addplugins.append(javabridge_plugin_class()) # # Run the shutdown plugin before the javabridge plugin when exiting # CPShutdownPlugin.score = javabridge_plugin_class.score + 1 addplugins.append(LoadTestsFromXML()) if len(args) == 0: args = ['--testmatch=(?:^)test_.*'] args += ['--exe'] if hasattr(sys, "frozen"): # # Patch nose.core.TestProgram.usage # it will attempt to get usage.txt and it's not worth # the effort to make that work. # from nose.core import TestProgram TestProgram.usage = lambda cls: "" nose.main(argv=args, addplugins=addplugins)
import logging import logging.config logging.root.setLevel(logging.INFO) if len(logging.root.handlers) == 0: logging.root.addHandler(logging.StreamHandler()) import os import uuid import csv import matplotlib matplotlib.use('Agg') import Image import cellprofiler.preferences as cpprefs cpprefs.set_headless() # ASAP cpprefs.set_allow_schema_write(False) from cellprofiler.pipeline import Pipeline from cellprofiler.utilities.cpjvm import cp_start_vm, cp_stop_vm import pydoop.mapreduce.api as api import pydoop.mapreduce.pipes as pp from pydoop.avrolib import AvroContext from pyfeatures.bioimg import BioImgPlane # basename of the pipeline file, to be uploaded via distributed cache PIPELINE_BN = 'it.crs4.features.cppipe' # --- FIXME: the following info should be extracted from the pipeline file CHANNEL_TAGS = ['D.TIF', 'F.TIF', 'R.TIF']
Website: http://www.cellprofiler.org ''' import base64 from matplotlib.image import pil_to_array import numpy as np import os import PIL.Image as PILImage import scipy.ndimage from StringIO import StringIO import unittest import zlib from cellprofiler.preferences import set_headless set_headless() import cellprofiler.pipeline as cpp import cellprofiler.cpmodule as cpm import cellprofiler.cpimage as cpi import cellprofiler.measurements as cpmeas import cellprofiler.objects as cpo import cellprofiler.workspace as cpw import cellprofiler.cpmath.cpmorphology as morph from cellprofiler.cpmath.outline import outline import cellprofiler.modules.expandorshrinkobjects as E INPUT_NAME = "input" OUTPUT_NAME = "output"
from getpass import getpass # Import OMERO Python BlitzGateway from omero.gateway import BlitzGateway from omero.grid import DoubleColumn, ImageColumn, LongColumn, WellColumn from omero.constants.namespaces import NSBULKANNOTATIONS from omero.gateway import FileAnnotationWrapper from omero.model import OriginalFileI # Import Cell Profiler Dependencies import cellprofiler.preferences as cpprefs import cellprofiler.pipeline as cpp # Important to set when running headless cpprefs.set_headless() # noqa # module used to inject OMERO image planes into Cell Profiler Pipeline from cellprofiler.modules.injectimage import InjectImage # Connect to the server def connect(hostname, username, password): conn = BlitzGateway(username, password, host=hostname, secure=True) conn.connect() return conn # Load-plate def load_plate(conn, plate_id):
def main(args): '''Run CellProfiler args - command-line arguments, e.g. sys.argv ''' if any([arg.startswith('--work-announce') for arg in args]): # # Go headless ASAP # import cellprofiler.preferences as cpprefs cpprefs.set_headless() import cellprofiler.analysis_worker cellprofiler.analysis_worker.main() sys.exit(0) options, args = parse_args(args) set_log_level(options) if not hasattr(sys, "frozen") and options.code_statistics: print_code_statistics() return if options.print_groups_file is not None: print_groups(options.print_groups_file) return if options.batch_commands_file is not None: get_batch_commands(options.batch_commands_file) return if options.run_ilastik: run_ilastik() return # necessary to prevent matplotlib trying to use Tkinter as its backend. # has to be done before CellProfilerApp is imported from matplotlib import use as mpluse mpluse('WXAgg') if (not hasattr(sys, 'frozen')) and options.fetch_external_dependencies: import external_dependencies external_dependencies.fetch_external_dependencies(options.overwrite_external_dependencies) if (not hasattr(sys, 'frozen')) and options.build_extensions: build_extensions() if options.build_and_exit: return if options.output_html: from cellprofiler.gui.html.manual import generate_html webpage_path = options.output_directory if options.output_directory else None generate_html(webpage_path) return if options.print_measurements: print_measurements(options) return try: if options.show_gui: import wx wx.Log.EnableLogging(False) from cellprofiler.cellprofilerapp import CellProfilerApp show_splashbox = (options.pipeline_filename is None and options.workspace_filename is None and (not options.new_workspace) and options.show_splashbox) if options.workspace_filename: workspace_path = os.path.expanduser(options.workspace_filename) elif options.new_workspace: workspace_path = False else: workspace_path = None App = CellProfilerApp( 0, check_for_new_version = (options.pipeline_filename is None), show_splashbox = show_splashbox, workspace_path = workspace_path) # # Important to go headless ASAP # # cellprofiler.preferences can't be imported before we have a chance # to initialize the wx app. # import cellprofiler.preferences as cpprefs if not options.show_gui: cpprefs.set_headless() # What's there to do but run if you're running headless? # Might want to change later if there's some headless setup options.run_pipeline = True if options.plugins_directory is not None: cpprefs.set_plugin_directory(options.plugins_directory) if options.ij_plugins_directory is not None: cpprefs.set_ij_plugin_directory(options.ij_plugins_directory) if options.temp_dir is not None: cpprefs.set_temporary_directory(options.temp_dir) if options.data_file is not None: cpprefs.set_data_file(os.path.abspath(options.data_file)) if options.image_set_file is not None: cpprefs.set_image_set_file(options.image_set_file, False) from cellprofiler.utilities.version import version_string, version_number logging.root.info("Version: %s / %d" % (version_string, version_number)) if options.run_pipeline and not options.pipeline_filename: raise ValueError("You must specify a pipeline filename to run") if options.output_directory: cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: import cellprofiler.gui.cpframe as cpgframe if options.pipeline_filename: pipeline_path = os.path.expanduser(options.pipeline_filename) try: App.frame.pipeline.load(pipeline_path) if options.run_pipeline: App.frame.Command(cpgframe.ID_FILE_ANALYZE_IMAGES) except: import wx wx.MessageBox( 'CellProfiler was unable to load the pipeline file, "%s"' % options.pipeline_filename, "Error loading pipeline", style = wx.OK | wx.ICON_ERROR) logging.root.error("Unable to load pipeline", exc_info=True) App.MainLoop() return elif options.run_pipeline: run_pipeline_headless(options, args) except Exception, e: logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True) raise
def main(args): '''Run CellProfiler args - command-line arguments, e.g. sys.argv ''' if any([arg.startswith('--work-announce') for arg in args]): # # Go headless ASAP # import cellprofiler.preferences as cpprefs cpprefs.set_headless() import cellprofiler.analysis_worker cellprofiler.analysis_worker.main() sys.exit(0) options, args = parse_args(args) set_log_level(options) if not hasattr(sys, "frozen") and options.code_statistics: print_code_statistics() return if options.print_groups_file is not None: print_groups(options.print_groups_file) return if options.batch_commands_file is not None: get_batch_commands(options.batch_commands_file) return if options.run_ilastik: run_ilastik() return # necessary to prevent matplotlib trying to use Tkinter as its backend. # has to be done before CellProfilerApp is imported from matplotlib import use as mpluse mpluse('WXAgg') if (not hasattr(sys, 'frozen')) and options.fetch_external_dependencies: import external_dependencies external_dependencies.fetch_external_dependencies( options.overwrite_external_dependencies) if (not hasattr(sys, 'frozen')) and options.build_extensions: build_extensions() if options.build_and_exit: return if options.output_html: from cellprofiler.gui.html.manual import generate_html webpage_path = options.output_directory if options.output_directory else None generate_html(webpage_path) return if options.print_measurements: print_measurements(options) return try: if options.show_gui: import wx wx.Log.EnableLogging(False) from cellprofiler.cellprofilerapp import CellProfilerApp show_splashbox = (options.pipeline_filename is None and options.workspace_filename is None and (not options.new_workspace) and options.show_splashbox) if options.workspace_filename: workspace_path = os.path.expanduser(options.workspace_filename) elif options.new_workspace: workspace_path = False else: workspace_path = None App = CellProfilerApp( 0, check_for_new_version=(options.pipeline_filename is None), show_splashbox=show_splashbox, workspace_path=workspace_path) # # Important to go headless ASAP # # cellprofiler.preferences can't be imported before we have a chance # to initialize the wx app. # import cellprofiler.preferences as cpprefs if not options.show_gui: cpprefs.set_headless() # What's there to do but run if you're running headless? # Might want to change later if there's some headless setup options.run_pipeline = True if options.plugins_directory is not None: cpprefs.set_plugin_directory(options.plugins_directory) if options.ij_plugins_directory is not None: cpprefs.set_ij_plugin_directory(options.ij_plugins_directory) if options.temp_dir is not None: cpprefs.set_temporary_directory(options.temp_dir) if options.data_file is not None: cpprefs.set_data_file(os.path.abspath(options.data_file)) if options.image_set_file is not None: cpprefs.set_image_set_file(options.image_set_file, False) from cellprofiler.utilities.version import version_string, version_number logging.root.info("Version: %s / %d" % (version_string, version_number)) if options.run_pipeline and not options.pipeline_filename: raise ValueError("You must specify a pipeline filename to run") if options.output_directory: cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: import cellprofiler.gui.cpframe as cpgframe if options.pipeline_filename: pipeline_path = os.path.expanduser(options.pipeline_filename) try: App.frame.pipeline.load(pipeline_path) if options.run_pipeline: App.frame.Command(cpgframe.ID_FILE_ANALYZE_IMAGES) except: import wx wx.MessageBox( 'CellProfiler was unable to load the pipeline file, "%s"' % options.pipeline_filename, "Error loading pipeline", style=wx.OK | wx.ICON_ERROR) logging.root.error("Unable to load pipeline", exc_info=True) App.MainLoop() return elif options.run_pipeline: run_pipeline_headless(options, args) except Exception, e: logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True) raise
def setUp(self): from cellprofiler.preferences import set_headless set_headless() self.old_import = __builtin__.__import__ __builtin__.__import__ = import_all_but_wx
def main(args=None): '''Run CellProfiler args - command-line arguments, e.g. sys.argv ''' if args is None: args = sys.argv import cellprofiler.preferences as cpprefs cpprefs.set_awt_headless(True) exit_code = 0 switches = ('--work-announce', '--knime-bridge-address') if any([any([arg.startswith(switch) for switch in switches]) for arg in args]): # # Go headless ASAP # cpprefs.set_headless() for i, arg in enumerate(args): if arg == "--ij-plugins-directory" and len(args) > i + 1: cpprefs.set_ij_plugin_directory(args[i + 1]) break import cellprofiler.analysis_worker cellprofiler.analysis_worker.aw_parse_args() cellprofiler.analysis_worker.main() sys.exit(exit_code) options, args = parse_args(args) if options.print_version: from cellprofiler.utilities.version import \ dotted_version, version_string, git_hash, version_number print "CellProfiler %s" % dotted_version print "Git %s" % git_hash print "Version %s" % version_number print "Built %s" % version_string.split(" ")[0] sys.exit(exit_code) # # Important to go headless ASAP # if (not options.show_gui) or options.write_schema_and_exit: import cellprofiler.preferences as cpprefs cpprefs.set_headless() # What's there to do but run if you're running headless? # Might want to change later if there's some headless setup options.run_pipeline = True if options.jvm_heap_size is not None: from cellprofiler.preferences import set_jvm_heap_mb set_jvm_heap_mb(options.jvm_heap_size, False) set_log_level(options) if options.print_groups_file is not None: print_groups(options.print_groups_file) return if options.batch_commands_file is not None: get_batch_commands(options.batch_commands_file) return if options.run_ilastik: run_ilastik() return if options.add_message_for_user: if len(args) != 3: sys.stderr.write("Usage: (for add_message-for-user)\n") sys.stderr.write("CellProfiler --add-message-for-user <caption> <message> <pipeline-or-project>\n") sys.stderr.write("where:\n") sys.stderr.write(" <caption> - the message box caption\n") sys.stderr.write(" <message> - the message displayed inside the message box\n") sys.stderr.write(" <pipeline-or-project> - the path to the pipeline or project file to modify\n") return caption = args[0] message = args[1] path = args[2] import h5py using_hdf5 = h5py.is_hdf5(path) if using_hdf5: import cellprofiler.measurements as cpmeas m = cpmeas.Measurements( filename=path, mode="r+") pipeline_text = m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] else: with open(path, "r") as fd: pipeline_text = fd.read() header, body = pipeline_text.split("\n\n", 1) pipeline_text = header + \ ("\nMessageForUser:%s|%s\n\n" % (caption, message)) + body if using_hdf5: m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] = pipeline_text m.close() else: with open(path, "w") as fd: fd.write(pipeline_text) print "Message added to %s" % path return # necessary to prevent matplotlib trying to use Tkinter as its backend. # has to be done before CellProfilerApp is imported from matplotlib import use as mpluse mpluse('WXAgg') if options.omero_credentials is not None: set_omero_credentials_from_string(options.omero_credentials) if options.plugins_directory is not None: cpprefs.set_plugin_directory(options.plugins_directory, globally=False) if options.ij_plugins_directory is not None: cpprefs.set_ij_plugin_directory(options.ij_plugins_directory, globally=False) if options.temp_dir is not None: if not os.path.exists(options.temp_dir): os.makedirs(options.temp_dir) cpprefs.set_temporary_directory(options.temp_dir, globally=False) if not options.allow_schema_write: cpprefs.set_allow_schema_write(False) # # After the crucial preferences are established, we can start the VM # from cellprofiler.utilities.cpjvm import cp_start_vm cp_start_vm() # # Not so crucial preferences... # if options.image_set_file is not None: cpprefs.set_image_set_file(options.image_set_file) try: # --------------------------------------- # # Handle command-line tasks that that need to load the modules to run # if options.output_html: from cellprofiler.gui.html.manual import generate_html webpage_path = options.output_directory if options.output_directory else None generate_html(webpage_path) return if options.print_measurements: print_measurements(options) return if not hasattr(sys, "frozen") and options.code_statistics: print_code_statistics() return if options.write_schema_and_exit: write_schema(options.pipeline_filename) return # # ------------------------------------------ if options.show_gui: import wx wx.Log.EnableLogging(False) from cellprofiler.gui.app import App from cellprofiler.workspace import is_workspace_file if options.pipeline_filename: if is_workspace_file(options.pipeline_filename): workspace_path = os.path.expanduser(options.pipeline_filename) pipeline_path = None else: pipeline_path = os.path.expanduser(options.pipeline_filename) workspace_path = None elif options.new_project: workspace_path = False pipeline_path = None else: workspace_path = None pipeline_path = None app = App(0, workspace_path=workspace_path, pipeline_path=pipeline_path) if options.data_file is not None: cpprefs.set_data_file(os.path.abspath(options.data_file)) from cellprofiler.utilities.version import version_string, version_number logging.root.info("Version: %s / %d" % (version_string, version_number)) if options.run_pipeline and not options.pipeline_filename: raise ValueError("You must specify a pipeline filename to run") if options.output_directory: if not os.path.exists(options.output_directory): os.makedirs(options.output_directory) cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: if options.run_pipeline: app.frame.pipeline_controller.do_analyze_images() app.MainLoop() return elif options.run_pipeline: run_pipeline_headless(options, args) except Exception, e: logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True) exit_code = -1
Please see the AUTHORS file for credits. Website: http://www.cellprofiler.org """ import nose import sys import numpy as np np.seterr(all='ignore') if '--noguitests' in sys.argv: sys.argv.remove('--noguitests') import cellprofiler.preferences as cpprefs cpprefs.set_headless() sys.modules['wx'] = None import matplotlib matplotlib.use('agg') if '--nojavatests' in sys.argv: sys.argv.remove('--nojavatests') import cellprofiler.utilities.jutil as jutil jutil.start_vm = None if len(sys.argv) == 0: args = ['--testmatch=(?:^)test_.*'] else: args = sys.argv nose.main(argv=args + ['-w', 'cpa/tests'])
def test_02_01_compare_to_matlab(self): expected = { 'EC50_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 3.982812, 'EC50_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 4.139827, 'EC50_DistCytoplasm_Intensity_MedianIntensity_CorrGreen': 4.178600, 'EC50_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen': 4.059770, 'EC50_DistCytoplasm_Intensity_MinIntensity_CorrGreen': 4.066357, 'EC50_DistCytoplasm_Math_Ratio1': 4.491367, 'EC50_DistCytoplasm_Math_Ratio2': 3.848722, 'EC50_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 4.948056, 'EC50_DistCytoplasm_Texture_Entropy_CorrGreen_1': 4.687104, 'EC50_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1': 5.0285, 'EC50_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1': 4.319017, 'EC50_DistCytoplasm_Texture_SumAverage_CorrGreen_1': 4.548876, 'EC50_DistCytoplasm_Texture_SumEntropy_CorrGreen_1': 4.779139, 'EC50_DistCytoplasm_Texture_Variance_CorrGreen_1': 4.218379, 'EC50_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue': 3.708711, 'EC50_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen': 4.135146, 'EC50_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen': 4.5372, 'EC50_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen': 4.1371, 'EC50_DistanceCells_Intensity_MinIntensityEdge_CorrGreen': 4.033999, 'EC50_DistanceCells_Intensity_MinIntensity_CorrGreen': 4.079470, 'EC50_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1': 5.118689, 'EC50_DistanceCells_Texture_Correlation_CorrGreen_1': 4.002074, 'EC50_DistanceCells_Texture_Entropy_CorrGreen_1': 5.008000, 'EC50_DistanceCells_Texture_InfoMeas1_CorrGreen_1': 3.883586, 'EC50_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1': 3.977216, 'EC50_DistanceCells_Texture_SumAverage_CorrGreen_1': 4.9741, 'EC50_DistanceCells_Texture_SumEntropy_CorrGreen_1': 5.1455, 'EC50_DistanceCells_Texture_SumVariance_CorrGreen_1': 4.593041, 'EC50_DistanceCells_Texture_Variance_CorrGreen_1': 4.619517, 'EC50_Nuclei_Correlation_Correlation_CorrGreenCorrBlue': 3.751133, 'EC50_Nuclei_Math_Ratio1': 4.491367, 'EC50_Nuclei_Math_Ratio2': 3.848722, 'EC50_Nuclei_Texture_SumAverage_CorrGreen_1': 3.765297, 'EC50_PropCells_AreaShape_Area': 4.740853, 'EC50_PropCells_AreaShape_MajorAxisLength': 5.064460, 'EC50_PropCells_AreaShape_MinorAxisLength': 4.751471, 'EC50_PropCells_AreaShape_Perimeter': 4.949292, 'EC50_PropCells_Correlation_Correlation_CorrGreenCorrBlue': 3.772565, 'EC50_PropCells_Texture_GaborX_CorrGreen_1': 5.007167, 'EC50_PropCells_Texture_InfoMeas2_CorrBlue_1': 4.341353, 'EC50_PropCells_Texture_SumVariance_CorrBlue_1': 4.298359, 'EC50_PropCells_Texture_SumVariance_CorrGreen_1': 4.610826, 'EC50_PropCells_Texture_Variance_CorrBlue_1': 4.396352, 'EC50_PropCells_Texture_Variance_CorrGreen_1': 4.632468, 'EC50_PropCytoplasm_AreaShape_Area': 4.669679, 'EC50_PropCytoplasm_AreaShape_MinorAxisLength': 4.754476, 'EC50_PropCytoplasm_AreaShape_Perimeter': 4.949292, 'EC50_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 4.072830, 'EC50_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen': 4.0934, 'EC50_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 3.925800, 'EC50_PropCytoplasm_Intensity_MedianIntensity_CorrGreen': 3.9252, 'EC50_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 4.777481, 'EC50_PropCytoplasm_Texture_Entropy_CorrGreen_1': 4.4432, 'EC50_PropCytoplasm_Texture_GaborX_CorrGreen_1': 5.163371, 'EC50_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1': 4.701046, 'EC50_PropCytoplasm_Texture_SumEntropy_CorrGreen_1': 4.510543, 'EC50_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1': 4.560315, 'EC50_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1': 4.966674, 'EC50_ThresholdedCells_Texture_Entropy_CorrBlue_1': 4.457866, 'EC50_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1': 4.624049, 'EC50_ThresholdedCells_Texture_SumAverage_CorrBlue_1': 4.686706, 'EC50_ThresholdedCells_Texture_SumEntropy_CorrBlue_1': 4.537378, 'EC50_ThresholdedCells_Texture_SumVariance_CorrBlue_1': 4.322820, 'EC50_ThresholdedCells_Texture_SumVariance_CorrGreen_1': 4.742158, 'EC50_ThresholdedCells_Texture_Variance_CorrBlue_1': 4.265549, 'EC50_ThresholdedCells_Texture_Variance_CorrGreen_1': 4.860020, 'OneTailedZfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen': -4.322503, 'OneTailedZfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen': -4.322503, 'OneTailedZfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen': -4.322503, 'OneTailedZfactor_DistCytoplasm_Math_Ratio1': 0.622059, 'OneTailedZfactor_DistCytoplasm_Math_Ratio2': -4.508284, 'OneTailedZfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1': -4.645887, 'OneTailedZfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1': -4.279118, 'OneTailedZfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1': -4.765570, 'OneTailedZfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1': -4.682335, 'OneTailedZfactor_DistCytoplasm_Texture_Variance_CorrGreen_1': -4.415607, 'OneTailedZfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen': -4.200105, 'OneTailedZfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen': -4.316452, 'OneTailedZfactor_DistanceCells_Intensity_MinIntensity_CorrGreen': -4.316452, 'OneTailedZfactor_DistanceCells_Texture_Correlation_CorrGreen_1': 0.202500, 'OneTailedZfactor_DistanceCells_Texture_Entropy_CorrGreen_1': -4.404815, 'OneTailedZfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1': -4.508513, 'OneTailedZfactor_DistanceCells_Texture_SumAverage_CorrGreen_1': -4.225356, 'OneTailedZfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1': -4.382768, 'OneTailedZfactor_DistanceCells_Texture_SumVariance_CorrGreen_1': 0.492125, 'OneTailedZfactor_DistanceCells_Texture_Variance_CorrGreen_1': 0.477360, 'OneTailedZfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue': 0.563780, 'OneTailedZfactor_Nuclei_Math_Ratio1': 0.622059, 'OneTailedZfactor_Nuclei_Math_Ratio2': -4.508284, 'OneTailedZfactor_Nuclei_Texture_SumAverage_CorrGreen_1': 0.426178, 'OneTailedZfactor_PropCells_AreaShape_Area': -4.216674, 'OneTailedZfactor_PropCells_AreaShape_MajorAxisLength': -4.119131, 'OneTailedZfactor_PropCells_AreaShape_MinorAxisLength': -4.109793, 'OneTailedZfactor_PropCells_AreaShape_Perimeter': -4.068050, 'OneTailedZfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue': 0.765440, 'OneTailedZfactor_PropCells_Texture_GaborX_CorrGreen_1': 0.114982, 'OneTailedZfactor_PropCells_Texture_InfoMeas2_CorrBlue_1': 0.108409, 'OneTailedZfactor_PropCells_Texture_SumVariance_CorrBlue_1': 0.191251, 'OneTailedZfactor_PropCells_Texture_SumVariance_CorrGreen_1': 0.559865, 'OneTailedZfactor_PropCells_Texture_Variance_CorrBlue_1': 0.254078, 'OneTailedZfactor_PropCells_Texture_Variance_CorrGreen_1': 0.556108, 'OneTailedZfactor_PropCytoplasm_AreaShape_Area': -4.223021, 'OneTailedZfactor_PropCytoplasm_AreaShape_MinorAxisLength': -4.095632, 'OneTailedZfactor_PropCytoplasm_AreaShape_Perimeter': -4.068050, 'OneTailedZfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen': -4.194663, 'OneTailedZfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1': -4.443338, 'OneTailedZfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1': 0.207265, 'OneTailedZfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1': -4.297250, 'OneTailedZfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1': -4.525324, 'OneTailedZfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1': 0.167795, 'OneTailedZfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1': 0.067560, 'OneTailedZfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1': 0.478527, 'OneTailedZfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1': 0.155119, 'OneTailedZfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1': 0.535907, 'OneTailedZfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1': 0.572801, 'OneTailedZfactor_ThresholdedCells_Texture_Variance_CorrBlue_1': 0.423454, 'OneTailedZfactor_ThresholdedCells_Texture_Variance_CorrGreen_1': 0.440500, 'Vfactor_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 0.500429, 'Vfactor_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 0.325675, 'Vfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen': 0.323524, 'Vfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen': 0.138487, 'Vfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen': 0.128157, 'Vfactor_DistCytoplasm_Math_Ratio1': 0.503610, 'Vfactor_DistCytoplasm_Math_Ratio2': 0.319610, 'Vfactor_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 0.522880, 'Vfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1': 0.504303, 'Vfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1': 0.289432, 'Vfactor_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1': 0.234123, 'Vfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1': 0.591687, 'Vfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1': 0.520356, 'Vfactor_DistCytoplasm_Texture_Variance_CorrGreen_1': -0.007649, 'Vfactor_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue': 0.761198, 'Vfactor_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen': 0.234655, 'Vfactor_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen': 0.252240, 'Vfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen': 0.195125, 'Vfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen': 0.138299, 'Vfactor_DistanceCells_Intensity_MinIntensity_CorrGreen': 0.126784, 'Vfactor_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1': 0.342691, 'Vfactor_DistanceCells_Texture_Correlation_CorrGreen_1': 0.314396, 'Vfactor_DistanceCells_Texture_Entropy_CorrGreen_1': 0.311771, 'Vfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1': 0.410631, 'Vfactor_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1': 0.170576, 'Vfactor_DistanceCells_Texture_SumAverage_CorrGreen_1': 0.223147, 'Vfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1': 0.269519, 'Vfactor_DistanceCells_Texture_SumVariance_CorrGreen_1': 0.571528, 'Vfactor_DistanceCells_Texture_Variance_CorrGreen_1': 0.566272, 'Vfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue': 0.705051, 'Vfactor_Nuclei_Math_Ratio1': 0.503610, 'Vfactor_Nuclei_Math_Ratio2': 0.319610, 'Vfactor_Nuclei_Texture_SumAverage_CorrGreen_1': 0.553708, 'Vfactor_PropCells_AreaShape_Area': 0.340093, 'Vfactor_PropCells_AreaShape_MajorAxisLength': 0.243838, 'Vfactor_PropCells_AreaShape_MinorAxisLength': 0.320691, 'Vfactor_PropCells_AreaShape_Perimeter': 0.238915, 'Vfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue': 0.723520, 'Vfactor_PropCells_Texture_GaborX_CorrGreen_1': 0.213161, 'Vfactor_PropCells_Texture_InfoMeas2_CorrBlue_1': 0.199791, 'Vfactor_PropCells_Texture_SumVariance_CorrBlue_1': 0.078959, 'Vfactor_PropCells_Texture_SumVariance_CorrGreen_1': 0.642844, 'Vfactor_PropCells_Texture_Variance_CorrBlue_1': 0.199105, 'Vfactor_PropCells_Texture_Variance_CorrGreen_1': 0.640818, 'Vfactor_PropCytoplasm_AreaShape_Area': 0.325845, 'Vfactor_PropCytoplasm_AreaShape_MinorAxisLength': 0.312258, 'Vfactor_PropCytoplasm_AreaShape_Perimeter': 0.238915, 'Vfactor_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 0.337565, 'Vfactor_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen': 0.292900, 'Vfactor_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 0.175528, 'Vfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen': 0.193308, 'Vfactor_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 0.276152, 'Vfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1': 0.239567, 'Vfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1': 0.332380, 'Vfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1': 0.379141, 'Vfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1': 0.337740, 'Vfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1': 0.334520, 'Vfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1': 0.192882, 'Vfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1': 0.276245, 'Vfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1': 0.139166, 'Vfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1': 0.465237, 'Vfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1': 0.355399, 'Vfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1': 0.453937, 'Vfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1': 0.564371, 'Vfactor_ThresholdedCells_Texture_Variance_CorrBlue_1': 0.360566, 'Vfactor_ThresholdedCells_Texture_Variance_CorrGreen_1': 0.548770, 'Zfactor_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 0.531914, 'Zfactor_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 0.265558, 'Zfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen': 0.178586, 'Zfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen': 0.084566, 'Zfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen': 0.086476, 'Zfactor_DistCytoplasm_Math_Ratio1': 0.623284, 'Zfactor_DistCytoplasm_Math_Ratio2': 0.358916, 'Zfactor_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 0.429510, 'Zfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1': 0.508275, 'Zfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1': 0.068695, 'Zfactor_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1': 0.347949, 'Zfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1': 0.646576, 'Zfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1': 0.494276, 'Zfactor_DistCytoplasm_Texture_Variance_CorrGreen_1': 0.179011, 'Zfactor_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue': 0.824686, 'Zfactor_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen': 0.027644, 'Zfactor_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen': 0.088491, 'Zfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen': 0.065056, 'Zfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen': 0.089658, 'Zfactor_DistanceCells_Intensity_MinIntensity_CorrGreen': 0.078017, 'Zfactor_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1': 0.238131, 'Zfactor_DistanceCells_Texture_Correlation_CorrGreen_1': 0.301107, 'Zfactor_DistanceCells_Texture_Entropy_CorrGreen_1': 0.251143, 'Zfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1': 0.564957, 'Zfactor_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1': 0.302767, 'Zfactor_DistanceCells_Texture_SumAverage_CorrGreen_1': 0.036459, 'Zfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1': 0.159798, 'Zfactor_DistanceCells_Texture_SumVariance_CorrGreen_1': 0.516938, 'Zfactor_DistanceCells_Texture_Variance_CorrGreen_1': 0.501186, 'Zfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue': 0.691408, 'Zfactor_Nuclei_Math_Ratio1': 0.623284, 'Zfactor_Nuclei_Math_Ratio2': 0.358916, 'Zfactor_Nuclei_Texture_SumAverage_CorrGreen_1': 0.587347, 'Zfactor_PropCells_AreaShape_Area': 0.132425, 'Zfactor_PropCells_AreaShape_MajorAxisLength': 0.034809, 'Zfactor_PropCells_AreaShape_MinorAxisLength': 0.113864, 'Zfactor_PropCells_AreaShape_Perimeter': 0.005984, 'Zfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue': 0.717632, 'Zfactor_PropCells_Texture_GaborX_CorrGreen_1': 0.251023, 'Zfactor_PropCells_Texture_InfoMeas2_CorrBlue_1': 0.149719, 'Zfactor_PropCells_Texture_SumVariance_CorrBlue_1': 0.102050, 'Zfactor_PropCells_Texture_SumVariance_CorrGreen_1': 0.611960, 'Zfactor_PropCells_Texture_Variance_CorrBlue_1': 0.197090, 'Zfactor_PropCells_Texture_Variance_CorrGreen_1': 0.614879, 'Zfactor_PropCytoplasm_AreaShape_Area': 0.205042, 'Zfactor_PropCytoplasm_AreaShape_MinorAxisLength': 0.072682, 'Zfactor_PropCytoplasm_AreaShape_Perimeter': 0.005984, 'Zfactor_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 0.272017, 'Zfactor_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen': 0.115327, 'Zfactor_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 0.141850, 'Zfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen': 0.105803, 'Zfactor_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 0.107640, 'Zfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1': 0.067896, 'Zfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1': 0.136688, 'Zfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1': 0.334749, 'Zfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1': 0.208829, 'Zfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1': 0.263467, 'Zfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1': 0.124355, 'Zfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1': 0.236433, 'Zfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1': 0.125845, 'Zfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1': 0.449333, 'Zfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1': 0.323243, 'Zfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1': 0.507477, 'Zfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1': 0.599000, 'Zfactor_ThresholdedCells_Texture_Variance_CorrBlue_1': 0.361424, 'Zfactor_ThresholdedCells_Texture_Variance_CorrGreen_1': 0.481393 } temp_dir = tempfile.mkdtemp() try: cpprefs.set_headless() cpprefs.set_default_output_directory(temp_dir) print "Writing output to %s" % temp_dir path = os.path.split(__file__)[0] measurements = loadmat(os.path.join(path, 'calculatestatistics.mat'), struct_as_record=True) measurements = measurements['m'] image_set_list = cpi.ImageSetList() image_set = image_set_list.get_image_set(0) m = cpmeas.Measurements() doses = [ 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 ] for i, dose in enumerate(doses): m.add_image_measurement("Dose", dose) for object_name in measurements.dtype.fields: omeasurements = measurements[object_name][0, 0] for feature_name in omeasurements.dtype.fields: data = omeasurements[feature_name][0, 0][0, i] m.add_measurement(object_name, feature_name, data) if i < len(doses) - 1: m.next_image_set() pipeline = cpp.Pipeline() module = C.CalculateStatistics() module.grouping_values.value = "Dose" module.dose_values[0].log_transform.value = False module.dose_values[0].measurement.value = "Dose" module.dose_values[0].wants_save_figure.value = True module.dose_values[0].figure_name.value = "EC49_" module.module_num = 1 pipeline.add_module(module) def callback(caller, event): self.assertFalse(isinstance(event, cpp.RunExceptionEvent)) workspace = cpw.Workspace(pipeline, module, image_set, cpo.ObjectSet(), m, image_set_list) module.post_run(workspace) for feature_name in m.get_feature_names(cpmeas.EXPERIMENT): if not expected.has_key(feature_name): print "Missing measurement: %s" % feature_name continue value = m.get_experiment_measurement(feature_name) e_value = expected[feature_name] diff = abs(value - e_value) * 2 / abs(value + e_value) self.assertTrue( diff < .05, "%s: Matlab: %f, Python: %f diff: %f" % (feature_name, e_value, value, diff)) if diff > .01: print( "Warning: > 1%% difference for %s: Matlab: %f, Python: %f diff: %f" % (feature_name, e_value, value, diff)) if feature_name.startswith("EC50"): filename = "EC49_" + feature_name[5:] + ".pdf" self.assertTrue( os.path.isfile(os.path.join(temp_dir, filename))) finally: try: workspace.measurements.hdf5_dict.hdf5_file.close() except: pass for filename in os.listdir(temp_dir): path = os.path.join(temp_dir, filename) os.remove(path) os.rmdir(temp_dir)
import os from bioformats.formatwriter import write_image from bioformats import PT_UINT8 import shutil from StringIO import StringIO import tempfile import unittest from urllib import URLopener from urllib2 import urlopen import xml.dom.minidom as DOM import zipfile import zlib import cellprofiler.preferences as cpprefs cpprefs.set_headless() import cellprofiler.workspace as cpw import cellprofiler.grid as cpg import cellprofiler.image as cpi import cellprofiler.module as cpm import cellprofiler.object as cpo import cellprofiler.measurement as cpmeas import cellprofiler.pipeline as cpp import cellprofiler.modules.createwebpage as C from cellprofiler.modules.loadimages import C_FILE_NAME, C_PATH_NAME, C_URL from cellprofiler.modules.loadimages import pathname2url, url2pathname IMAGE_NAME = "image" THUMB_NAME = "thumb" DEFAULT_HTML_FILE = "default.html"
def main(args=None): '''Run CellProfiler args - command-line arguments, e.g. sys.argv ''' if args is None: args = sys.argv import cellprofiler.preferences as cpprefs cpprefs.set_awt_headless(True) exit_code = 0 switches = ('--work-announce', '--knime-bridge-address') if any( [any([arg.startswith(switch) for switch in switches]) for arg in args]): # # Go headless ASAP # cpprefs.set_headless() for i, arg in enumerate(args): if arg == "--ij-plugins-directory" and len(args) > i + 1: cpprefs.set_ij_plugin_directory(args[i + 1]) break import cellprofiler.worker cellprofiler.worker.aw_parse_args() cellprofiler.worker.main() sys.exit(exit_code) options, args = parse_args(args) if options.print_version: from cellprofiler.utilities.version import \ dotted_version, version_string, git_hash, version_number print "CellProfiler %s" % dotted_version print "Git %s" % git_hash print "Version %s" % version_number print "Built %s" % version_string.split(" ")[0] sys.exit(exit_code) # # Important to go headless ASAP # if (not options.show_gui) or options.write_schema_and_exit: import cellprofiler.preferences as cpprefs cpprefs.set_headless() # What's there to do but run if you're running headless? # Might want to change later if there's some headless setup options.run_pipeline = True if options.jvm_heap_size is not None: from cellprofiler.preferences import set_jvm_heap_mb set_jvm_heap_mb(options.jvm_heap_size, False) set_log_level(options) if options.print_groups_file is not None: print_groups(options.print_groups_file) return if options.batch_commands_file is not None: get_batch_commands(options.batch_commands_file) return if options.add_message_for_user: if len(args) != 3: sys.stderr.write("Usage: (for add_message-for-user)\n") sys.stderr.write( "CellProfiler --add-message-for-user <caption> <message> <pipeline-or-project>\n" ) sys.stderr.write("where:\n") sys.stderr.write(" <caption> - the message box caption\n") sys.stderr.write( " <message> - the message displayed inside the message box\n" ) sys.stderr.write( " <pipeline-or-project> - the path to the pipeline or project file to modify\n" ) return caption = args[0] message = args[1] path = args[2] import h5py using_hdf5 = h5py.is_hdf5(path) if using_hdf5: import cellprofiler.measurement as cpmeas m = cpmeas.Measurements(filename=path, mode="r+") pipeline_text = m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] else: with open(path, "r") as fd: pipeline_text = fd.read() header, body = pipeline_text.split("\n\n", 1) pipeline_text = header + \ ("\nMessageForUser:%s|%s\n\n" % (caption, message)) + body if using_hdf5: m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] = pipeline_text m.close() else: with open(path, "w") as fd: fd.write(pipeline_text) print "Message added to %s" % path return # necessary to prevent matplotlib trying to use Tkinter as its backend. # has to be done before CellProfilerApp is imported from matplotlib import use as mpluse mpluse('WXAgg') if options.omero_credentials is not None: set_omero_credentials_from_string(options.omero_credentials) if options.plugins_directory is not None: cpprefs.set_plugin_directory(options.plugins_directory, globally=False) if options.ij_plugins_directory is not None: cpprefs.set_ij_plugin_directory(options.ij_plugins_directory, globally=False) if options.temp_dir is not None: if not os.path.exists(options.temp_dir): os.makedirs(options.temp_dir) cpprefs.set_temporary_directory(options.temp_dir, globally=False) if not options.allow_schema_write: cpprefs.set_allow_schema_write(False) # # After the crucial preferences are established, we can start the VM # from cellprofiler.utilities.cpjvm import cp_start_vm cp_start_vm() # # Not so crucial preferences... # if options.image_set_file is not None: cpprefs.set_image_set_file(options.image_set_file) try: # --------------------------------------- # # Handle command-line tasks that that need to load the modules to run # if options.output_html: from cellprofiler.gui.html.manual import generate_html webpage_path = options.output_directory if options.output_directory else None generate_html(webpage_path) return if options.print_measurements: print_measurements(options) return if not hasattr(sys, "frozen") and options.code_statistics: print_code_statistics() return if options.write_schema_and_exit: write_schema(options.pipeline_filename) return # # ------------------------------------------ if options.show_gui: import wx wx.Log.EnableLogging(False) from cellprofiler.gui.app import App from cellprofiler.workspace import is_workspace_file if options.pipeline_filename: if is_workspace_file(options.pipeline_filename): workspace_path = os.path.expanduser( options.pipeline_filename) pipeline_path = None else: pipeline_path = os.path.expanduser( options.pipeline_filename) workspace_path = None elif options.new_project: workspace_path = False pipeline_path = None else: workspace_path = None pipeline_path = None app = App(0, workspace_path=workspace_path, pipeline_path=pipeline_path) if options.data_file is not None: cpprefs.set_data_file(os.path.abspath(options.data_file)) from cellprofiler.utilities.version import version_string, version_number logging.root.info("Version: %s / %d" % (version_string, version_number)) if options.run_pipeline and not options.pipeline_filename: raise ValueError("You must specify a pipeline filename to run") if options.output_directory: if not os.path.exists(options.output_directory): os.makedirs(options.output_directory) cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: if options.run_pipeline: app.frame.pipeline_controller.do_analyze_images() app.MainLoop() return elif options.run_pipeline: run_pipeline_headless(options, args) except Exception, e: logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True) exit_code = -1
def main(args): '''Run CellProfiler args - command-line arguments, e.g. sys.argv ''' if any([arg.startswith('--work-announce') for arg in args]): # # Go headless ASAP # import cellprofiler.preferences as cpprefs cpprefs.set_headless() for i, arg in enumerate(args): if arg == "--ij-plugins-directory" and len(args) > i+1: cpprefs.set_ij_plugin_directory(args[i+1]) break import cellprofiler.analysis_worker cellprofiler.analysis_worker.aw_parse_args() cellprofiler.analysis_worker.main() sys.exit(0) options, args = parse_args(args) if options.jvm_heap_size != None: from cellprofiler.preferences import set_jvm_heap_mb set_jvm_heap_mb(options.jvm_heap_size, False) set_log_level(options) if not hasattr(sys, "frozen") and options.code_statistics: print_code_statistics() return if options.print_groups_file is not None: print_groups(options.print_groups_file) return if options.batch_commands_file is not None: get_batch_commands(options.batch_commands_file) return if options.run_ilastik: run_ilastik() return if options.add_message_for_user: if len(args) != 3: sys.stderr.write("Usage: (for add_message-for-user)\n") sys.stderr.write("CellProfiler --add-message-for-user <caption> <message> <pipeline-or-project>\n") sys.stderr.write("where:\n") sys.stderr.write(" <caption> - the message box caption\n") sys.stderr.write(" <message> - the message displayed inside the message box\n") sys.stderr.write(" <pipeline-or-project> - the path to the pipeline or project file to modify\n") return caption = args[0] message = args[1] path = args[2] import h5py using_hdf5 = h5py.is_hdf5(path) if using_hdf5: import cellprofiler.measurements as cpmeas m = cpmeas.Measurements( filename = path, mode="r+") pipeline_text = m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] else: with open(path, "r") as fd: pipeline_text = fd.read() header, body = pipeline_text.split("\n\n", 1) pipeline_text = header + \ ("\nMessageForUser:%s|%s\n\n" % (caption, message)) + body if using_hdf5: m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] = pipeline_text m.close() else: with open(path, "w") as fd: fd.write(pipeline_text) print "Message added to %s" % path return # necessary to prevent matplotlib trying to use Tkinter as its backend. # has to be done before CellProfilerApp is imported from matplotlib import use as mpluse mpluse('WXAgg') if (not hasattr(sys, 'frozen')) and options.fetch_external_dependencies: import external_dependencies external_dependencies.fetch_external_dependencies(options.overwrite_external_dependencies) if (not hasattr(sys, 'frozen')) and options.build_extensions: build_extensions() if options.build_and_exit: return if options.output_html: from cellprofiler.gui.html.manual import generate_html webpage_path = options.output_directory if options.output_directory else None generate_html(webpage_path) return if options.print_measurements: print_measurements(options) return if options.omero_credentials is not None: set_omero_credentials_from_string(options.omero_credentials) try: if options.show_gui: import wx wx.Log.EnableLogging(False) from cellprofiler.cellprofilerapp import CellProfilerApp from cellprofiler.workspace import is_workspace_file show_splashbox = (options.pipeline_filename is None and (not options.new_project) and options.show_splashbox) if options.pipeline_filename: if is_workspace_file(options.pipeline_filename): workspace_path = os.path.expanduser(options.pipeline_filename) pipeline_path = None else: pipeline_path = os.path.expanduser(options.pipeline_filename) workspace_path = None elif options.new_project: workspace_path = False pipeline_path = None else: workspace_path = None pipeline_path = None App = CellProfilerApp( 0, check_for_new_version = (options.pipeline_filename is None), show_splashbox = show_splashbox, workspace_path = workspace_path, pipeline_path = pipeline_path) # # Important to go headless ASAP # # cellprofiler.preferences can't be imported before we have a chance # to initialize the wx app. # import cellprofiler.preferences as cpprefs if not options.show_gui: cpprefs.set_headless() # What's there to do but run if you're running headless? # Might want to change later if there's some headless setup options.run_pipeline = True if options.plugins_directory is not None: cpprefs.set_plugin_directory(options.plugins_directory) if options.ij_plugins_directory is not None: cpprefs.set_ij_plugin_directory(options.ij_plugins_directory) if options.temp_dir is not None: if not os.path.exists(options.temp_dir): os.makedirs(options.temp_dir) cpprefs.set_temporary_directory(options.temp_dir) if options.data_file is not None: cpprefs.set_data_file(os.path.abspath(options.data_file)) if options.image_set_file is not None: cpprefs.set_image_set_file(options.image_set_file, False) from cellprofiler.utilities.version import version_string, version_number logging.root.info("Version: %s / %d" % (version_string, version_number)) if options.run_pipeline and not options.pipeline_filename: raise ValueError("You must specify a pipeline filename to run") if options.output_directory: if not os.path.exists(options.output_directory): os.makedirs(options.output_directory) cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: if options.run_pipeline: App.frame.pipeline_controller.do_analyze_images() App.MainLoop() return elif options.run_pipeline: run_pipeline_headless(options, args) except Exception, e: logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True) raise
Website: http://www.cellprofiler.org ''' __version__ = "$Revision$" import base64 from matplotlib.image import pil_to_array import numpy as np import os import PIL.Image as PILImage import scipy.ndimage from StringIO import StringIO import unittest import zlib from cellprofiler.preferences import set_headless set_headless() import cellprofiler.pipeline as cpp import cellprofiler.cpmodule as cpm import cellprofiler.cpimage as cpi import cellprofiler.measurements as cpmeas import cellprofiler.objects as cpo import cellprofiler.workspace as cpw import cellprofiler.modules.calculatemath as C OUTPUT_MEASUREMENTS = "outputmeasurements" MATH_OUTPUT_MEASUREMENTS = "_".join(("Math", OUTPUT_MEASUREMENTS)) OBJECT = ["object%d" % i for i in range(2)]