Exemple #1
0
 def test_01_01_load_matlab(self):
     data = ('eJzzdQzxcXRSMNUzUPB1DNFNy8xJ1VEIyEksScsvyrVSCHAO9/TTUXAuSk0s'
             'SU1RyM+zUgjJKFXwKs1RMDQDIitDCytjMwUjAwNLBZIBA6OnLz8DA0MWEwND'
             'xZy3EXfzLhuIlG1aIr0i5HaehJD4zidt9RN25EQ4dh+5lTVbTbHwsVleumbn'
             '4iMro+Z1HH9QWMHzZtKWzqkm9ryKHDGRFwvPfa+1O26/8TYzQ48804XE88ph'
             'qR9Wr1ioe1Rr+3rBpTdm/tYKOBB549/cq9EvEi02XtDdwvSk2bfzFm+6W17Y'
             'u2dXVQ2ZuXkXypanpUrcEH7yc3EkC098/0ehyOs/tJlOCu2MXcj6zbDQqeaE'
             '/ra8Ek7Rkuo1u/i3VU5osdFYM+/YrZ318jl/p07ZI3v8T//hquZpX162q84J'
             'OttWUnW8Mu7JBxmVCr4DCSuazR5NYfFjZK7NebN4+vT71U51O2v3LTqydUF+'
             '+9vST1t070fuKLe0CO2YfvvXFN3XXYV1Mr1cL8tYYvOkzzFVbpm1Lm9Wawk/'
             'a2zefOHqJtkrL/5MELIRqrgZNGfG8++/Qhf/rdmaXrO/+t910eevbb/+stzx'
             '22nOHTmBs4oh3H8+ON9K2ZP/b2PFfbM14SV2na9/G1tzix48yTmHpy3Ffm8d'
             '37p1H3O894hb7hBWjMtLPn6EO4ftwqUNvM9nB2dP/FPKape32bjJbvGJ3S1f'
             '1mn4+z94uO2gtXDyqsnLX+1w+dhxftPrF5Fs/hdrls4VfyYX8zM4Y6HIvk1/'
             'z86KD/356tzyG/bPLe+c/O57t/Z91/nHRo8nbKtfI37xjnLj7bh5276t1py3'
             'pfrzNPfkaKWi/8d2nOqrv7Z53R/Rq7/X/0//fdNsHrdm9f5pDp/qF6x6/Ui4'
             'cZmg9YeQv+/WWS467Odd+ej+ZT8/u9S0uWW77+56J+r6JSRy2tHqUjk/ztv7'
             'beq2/Cv8wx+Qd8/m5kP5qdt+/WfJeirzEgCAxWF+')
     pipeline = cpp.Pipeline()
     def callback(caller,event):
         self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))
     pipeline.add_listener(callback)
     pipeline.load(StringIO(zlib.decompress(base64.b64decode(data))))
     #
     # There are 3 ImageMath modules:
     # 1)
     #   image_name[0] = DNA, factor[0] = 1, operation = invert, truncation
     #   output_image_name = DNAAfterMath
     # 2)
     #   image_name[0] = DNA, factor[0] = 1
     #   image_name[1] = Cytoplasm, factor[1] = 2
     #   operation = add, exponent = 4, multiply = 5, no truncation
     #   output_image_name = ImageAfterMath
     # 3)  DNA, Cytoplasm, Actin
     self.assertEqual(len(pipeline.modules()), 4)
     module = pipeline.modules()[1]
     self.assertTrue(isinstance(module, I.ImageMath))
     self.assertEqual(len(module.images), 2)
     self.assertEqual(module.images[0].image_name.value, 'DNA')
     self.assertEqual(module.output_image_name.value, 'DNAAfterMath')
     self.assertEqual(module.operation.value, I.O_INVERT)
     self.assertTrue(module.truncate_low.value)
     self.assertTrue(module.truncate_high.value)
     
     module = pipeline.modules()[2]
     self.assertTrue(isinstance(module, I.ImageMath))
     self.assertEqual(len(module.images), 2)
     self.assertEqual(module.images[0].image_name.value, 'DNA')
     self.assertEqual(module.images[0].factor.value, 1)
     self.assertEqual(module.images[1].image_name.value, 'Cytoplasm')
     self.assertEqual(module.images[1].factor.value, 2)
     self.assertEqual(module.output_image_name.value, 'ImageAfterMath')
     self.assertEqual(module.operation.value, I.O_ADD)
     self.assertEqual(module.exponent.value, 4)
     self.assertEqual(module.after_factor.value, 5)
     self.assertFalse(module.truncate_low.value)
     self.assertFalse(module.truncate_high.value)
     
     module = pipeline.modules()[3]
     self.assertTrue(isinstance(module, I.ImageMath))
     self.assertEqual(len(module.images), 3)
     self.assertEqual(module.images[0].image_name.value, 'DNA')
     self.assertEqual(module.images[1].image_name.value, 'Cytoplasm')
     self.assertEqual(module.images[2].image_name.value, 'Actin')
     self.assertEqual(module.output_image_name.value, 'ImageAfterMath')
     self.assertEqual(module.operation.value, I.O_ADD)
    def do_job(self, job):
        '''Handle a work request to its completion
        
        job - WorkRequest
        '''
        import cellprofiler.pipeline as cpp
        job_measurements = []
        try:
            send_dictionary = job.wants_dictionary
    
            logger.info("Starting job")
            # Fetch the pipeline and preferences for this analysis if we don't have it
            current_pipeline, current_preferences = \
                self.pipelines_and_preferences.get(
                    self.current_analysis_id, (None, None))
            if not current_pipeline:
                logger.debug("Fetching pipeline and preferences")
                rep = self.send(PipelinePreferencesRequest(
                    self.current_analysis_id))
                logger.debug("Received pipeline and preferences response")
                preferences_dict = rep.preferences
                # update preferences to match remote values
                cpprefs.set_preferences_from_dict(preferences_dict)
 
                logger.debug("Loading pipeline")
                pipeline_blob = rep.pipeline_blob.tostring()
                current_pipeline = cpp.Pipeline()
                current_pipeline.loadtxt(StringIO.StringIO(pipeline_blob), 
                                         raise_on_error=True)
                logger.debug("Pipeline loaded")
                current_pipeline.add_listener(
                    self.pipeline_listener.handle_event)
                current_preferences = rep.preferences
                self.pipelines_and_preferences[self.current_analysis_id] = (
                    current_pipeline, current_preferences)
            else:
                # update preferences to match remote values
                cpprefs.set_preferences_from_dict(current_preferences)
            
            # Reset the listener's state
            self.pipeline_listener.reset()
            logger.debug("Getting initial measurements")
            # Fetch the path to the intial measurements if needed.
            current_measurements = self.initial_measurements.get(
                self.current_analysis_id)
            if current_measurements is None:
                logger.debug("Sending initial measurements request")
                rep = self.send(InitialMeasurementsRequest(
                    self.current_analysis_id))
                logger.debug("Got initial measurements")
                current_measurements = \
                    self.initial_measurements[self.current_analysis_id] = \
                    cpmeas.load_measurements_from_buffer(rep.buf)
            else:
                logger.debug("Has initial measurements")
            # Make a copy of the measurements for writing during this job
            current_measurements = cpmeas.Measurements(copy=current_measurements)
            all_measurements.add(current_measurements)
            job_measurements.append(current_measurements)
        
            successful_image_set_numbers = []
            image_set_numbers = job.image_set_numbers
            worker_runs_post_group = job.worker_runs_post_group
            logger.info("Doing job: " + ",".join(map(str, image_set_numbers)))
        
            self.pipeline_listener.image_set_number = image_set_numbers[0]
        
            if not worker_runs_post_group:
                # Get the shared state from the first imageset in this run.
                shared_dicts = self.send(
                    SharedDictionaryRequest(self.current_analysis_id)).dictionaries
                assert len(shared_dicts) == len(current_pipeline.modules())
                for module, new_dict in zip(current_pipeline.modules(), 
                                            shared_dicts):
                    module.set_dictionary_for_worker(new_dict)
        
            # Run prepare group if this is the first image in the group.  We do
            # this here (even if there's no grouping in the pipeline) to ensure
            # that any changes to the modules' shared state dictionaries get
            # propagated correctly.
            should_process = True
            if current_measurements[cpmeas.IMAGE, 
                                    cpmeas.GROUP_INDEX, 
                                    image_set_numbers[0]] == 1:
                workspace = cpw.Workspace(current_pipeline, None, None, None,
                                          current_measurements, None, None)
                if not current_pipeline.prepare_group(
                    workspace, 
                    current_measurements.get_grouping_keys(), 
                    image_set_numbers):
                    # exception handled elsewhere, possibly cancelling this run.
                    should_process = False
                del workspace
        
            # process the images
            if should_process:
                abort = False
                for image_set_number in image_set_numbers:
                    gc.collect()
                    try:
                        self.pipeline_listener.image_set_number = image_set_number
                        last_workspace = current_pipeline.run_image_set(
                            current_measurements,
                            image_set_number,
                            self.interaction_handler,
                            self.display_handler,
                            self.cancel_handler)
                        if self.pipeline_listener.should_abort:
                            abort = True
                            break
                        elif self.pipeline_listener.should_skip:
                            # Report skipped image sets as successful so that
                            # analysis can complete.
                            # Report their measurements because some modules
                            # may have provided measurements before skipping.
                            pass
                        successful_image_set_numbers.append(image_set_number)
                        # Send an indication that the image set finished successfully.
                        if send_dictionary:
                            # The jobserver would like a copy of our modules' 
                            # run_state dictionaries.
                            dicts = [m.get_dictionary_for_worker() 
                                     for m in current_pipeline.modules()]
                            req = ImageSetSuccessWithDictionary(
                                self.current_analysis_id,
                                image_set_number=image_set_number,
                                shared_dicts = dicts)
                        else:
                            req = ImageSetSuccess(
                                self.current_analysis_id,
                                image_set_number = image_set_number)
                        rep = self.send(req)
                    except cpp.CancelledException:
                        logging.info("Aborting job after cancellation")
                        abort = True
                    except Exception:
                        try:
                            logging.error("Error in pipeline", exc_info=True)
                            if self.handle_exception(
                                image_set_number=image_set_number) == ED_STOP:
                                abort = True
                                break
                        except:
                            logging.error("Error in handling of pipeline exception", exc_info=True)
                            # this is bad.  We can't handle nested exceptions
                            # remotely so we just fail on this run.
                            abort = True
        
                if abort:
                    current_measurements.close()
                    job_measurements.remove(current_measurements)
                    return
        
                if worker_runs_post_group:
                    last_workspace.interaction_handler =\
                        self.interaction_handler
                    last_workspace.cancel_handler = self.cancel_handler
                    last_workspace.post_group_display_handler = \
                        self.post_group_display_handler
                    # There might be an exception in this call, but it will be
                    # handled elsewhere, and there's nothing we can do for it
                    # here.
                    current_pipeline.post_group(
                        last_workspace, 
                        current_measurements.get_grouping_keys())
                    del last_workspace
        
            # send measurements back to server
            req = MeasurementsReport(self.current_analysis_id,
                                     buf=current_measurements.file_contents(),
                                     image_set_numbers=image_set_numbers)
            rep = self.send(req)
        
        except cpp.CancelledException:
            # Main thread received shutdown signal
            raise
        
        except Exception:
            logging.error("Error in worker", exc_info=True)
            if self.handle_exception() == ED_STOP:
                raise cpp.CancelledException("Cancelling after user-requested stop")
        finally:
            # Clean up any measurements owned by us
            for m in job_measurements:
                m.close()
Exemple #3
0
    def test_01_03_load_v2(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:10016

Morph:[module_num:1|svn_version:\'9935\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D]
    Select the input image:InputImage
    Name the output image:MorphImage
    Select the operation to perform:bothat
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:branchpoints
    Repeat operation:Forever
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:bridge
    Repeat operation:Custom
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:clean
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:close
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:convex hull
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:diag
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:dilate
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:distance
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:endpoints
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:erode
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:fill
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:fill small holes
    Repeat operation:Once
    Maximum hole area:2
    Scale\x3A:3
    Select the operation to perform:hbreak
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:invert
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:majority
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:open
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:remove
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:shrink
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:skel
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:skelpe
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:spur
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:thicken
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:thin
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:tophat
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:vbreak
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO.StringIO(data))
        ops = [
            morph.F_BOTHAT, morph.F_BRANCHPOINTS, morph.F_BRIDGE,
            morph.F_CLEAN, morph.F_CLOSE, morph.F_CONVEX_HULL, morph.F_DIAG,
            morph.F_DILATE, morph.F_DISTANCE, morph.F_ENDPOINTS, morph.F_ERODE,
            morph.F_FILL, morph.F_FILL_SMALL, morph.F_HBREAK, morph.F_INVERT,
            morph.F_MAJORITY, morph.F_OPEN, morph.F_REMOVE, morph.F_SHRINK,
            morph.F_SKEL, morph.F_SKELPE, morph.F_SPUR, morph.F_THICKEN,
            morph.F_THIN, morph.F_TOPHAT, morph.F_VBREAK
        ]
        self.assertEqual(len(pipeline.modules()), 1)
        module = pipeline.modules()[0]
        self.assertTrue(isinstance(module, morph.Morph))
        self.assertEqual(module.image_name, "InputImage")
        self.assertEqual(module.output_image_name, "MorphImage")
        self.assertEqual(len(module.functions), len(ops))
        for op, function in zip(ops, module.functions):
            self.assertEqual(function.function, op)
            if op == morph.F_BRANCHPOINTS:
                self.assertEqual(function.repeats_choice, morph.R_FOREVER)
            elif op == morph.F_BRIDGE:
                self.assertEqual(function.repeats_choice, morph.R_CUSTOM)
            else:
                self.assertEqual(function.repeats_choice, morph.R_ONCE)
            self.assertEqual(function.custom_repeats, 2)
            self.assertEqual(function.scale, 3)
        fn0 = module.functions[0]
        self.assertEqual(fn0.structuring_element, morph.SE_DISK)
        self.assertEqual(fn0.x_offset, 1)
        self.assertEqual(fn0.y_offset, 1)
        self.assertEqual(fn0.angle, 0)
        self.assertEqual(fn0.width, 3)
        self.assertEqual(fn0.height, 3)
        strel = np.array(fn0.strel.get_matrix())
        self.assertEqual(strel.shape[0], 3)
        self.assertEqual(strel.shape[1], 3)
        self.assertTrue(np.all(strel))
Exemple #4
0
    def test_01_02_load_v2(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:3
DateRevision:20120112154631
ModuleCount:1
HasImagePlaneDetails:False

Metadata:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)]
    Extract metadata?:Yes
    Extraction method count:2
    Extraction method:Manual
    Source:From file name
    Regular expression:^Channel(?P<ChannelNumber>\x5B12\x5D)-(?P<Index>\x5B0-9\x5D+)-(?P<WellRow>\x5BA-H\x5D)-(?P<WellColumn>\x5B0-9\x5D{2}).tif$
    Regular expression:(?P<Date>\x5B0-9\x5D{4}_\x5B0-9\x5D{2}_\x5B0-9\x5D{2})$
    Filter images:All images
    :or (file does contain "Channel2")
    Metadata file location\x3A:
    Match file and image metadata:\x5B\x5D
    Case insensitive matching:No
    Extraction method:Import metadata
    Source:From folder name
    Regular expression:^(?P<Plate>.*)_(?P<Well>\x5BA-P\x5D\x5B0-9\x5D{2})_s(?P<Site>\x5B0-9\x5D)_w(?P<ChannelNumber>\x5B0-9\x5D)
    Regular expression:Example(?P<Project>\x5B^\\\\\\\\\x5D+)Images
    Filter images:Images selected using a filter
    :or (file does contain "")
    Metadata file location\x3A:/imaging/analysis/metadata.csv
    Match file and image metadata:\x5B{\'Image Metadata\'\x3A u\'ChannelNumber\', \'CSV Metadata\'\x3A u\'Wavelength\'}\x5D
    Case insensitive matching:Yes
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO(data))
        self.assertEqual(len(pipeline.modules()), 1)
        module = pipeline.modules()[0]
        self.assertTrue(isinstance(module, M.Metadata))
        self.assertTrue(module.wants_metadata)
        self.assertEqual(len(module.extraction_methods), 2)
        em0, em1 = module.extraction_methods
        self.assertEqual(em0.extraction_method, M.X_MANUAL_EXTRACTION)
        self.assertEqual(em0.source, M.XM_FILE_NAME)
        self.assertEqual(
            em0.file_regexp.value,
            r"^Channel(?P<ChannelNumber>[12])-(?P<Index>[0-9]+)-(?P<WellRow>[A-H])-(?P<WellColumn>[0-9]{2}).tif$"
        )
        self.assertEqual(em0.folder_regexp.value,
                         r"(?P<Date>[0-9]{4}_[0-9]{2}_[0-9]{2})$")
        self.assertEqual(em0.filter_choice, M.F_ALL_IMAGES)
        self.assertEqual(em0.filter, 'or (file does contain "Channel2")')
        self.assertFalse(em0.wants_case_insensitive)

        self.assertEqual(em1.extraction_method, M.X_IMPORTED_EXTRACTION)
        self.assertEqual(em1.source, M.XM_FOLDER_NAME)
        self.assertEqual(em1.filter_choice, M.F_FILTERED_IMAGES)
        self.assertEqual(em1.csv_location, "/imaging/analysis/metadata.csv")
        self.assertEqual(
            em1.csv_joiner.value,
            "[{'Image Metadata': u'ChannelNumber', 'CSV Metadata': u'Wavelength'}]"
        )
        self.assertTrue(em1.wants_case_insensitive)
 def test_01_03_load_v1(self):
     data = ('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')
     pipeline = cpp.Pipeline()
     def callback(caller,event):
         self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))
     pipeline.add_listener(callback)
     pipeline.load(StringIO(zlib.decompress(base64.b64decode(data))))
     self.assertEqual(len(pipeline.modules()),5)
     module = pipeline.modules()[-2]
     self.assertTrue(isinstance(module, C.ClassifyObjects))
     self.assertEqual(module.contrast_choice.value, C.BY_SINGLE_MEASUREMENT)
     self.assertEqual(len(module.single_measurements), 2)
     
     group = module.single_measurements[0]
     self.assertEqual(group.object_name, "Nuclei")
     self.assertEqual(group.measurement.value, "Intensity_IntegratedIntensity_OrigBlue")
     self.assertEqual(group.bin_choice, C.BC_EVEN)
     self.assertEqual(group.bin_count, 3)
     self.assertAlmostEqual(group.low_threshold.value, 0.2)
     self.assertTrue(group.wants_low_bin)
     self.assertAlmostEqual(group.high_threshold.value, 0.8)
     self.assertTrue(group.wants_high_bin)
     self.assertTrue(group.wants_custom_names)
     for name, expected in zip(group.bin_names.value.split(','),
                               ('First','Second','Third','Fourth','Fifth')):
         self.assertEqual(name, expected)
     self.assertTrue(group.wants_images)
     self.assertEqual(group.image_name, "ClassifiedNuclei")
     
     group = module.single_measurements[1]
     self.assertEqual(group.object_name, "Nuclei")
     self.assertEqual(group.measurement.value, "Intensity_MaxIntensity_OrigBlue")
     self.assertEqual(group.bin_choice, C.BC_CUSTOM)
     self.assertEqual(group.custom_thresholds, ".2,.5,.8")
     self.assertFalse(group.wants_custom_names)
     self.assertFalse(group.wants_images)
 
     module = pipeline.modules()[-1]
     self.assertTrue(isinstance(module, C.ClassifyObjects))
     self.assertEqual(module.contrast_choice, C.BY_TWO_MEASUREMENTS)
     self.assertEqual(module.object_name, "Nuclei")
     self.assertEqual(module.first_measurement, "Location_Center_X")
     self.assertEqual(module.first_threshold_method, C.TM_MEDIAN)
     self.assertEqual(module.second_measurement, "Location_Center_Y")
     self.assertEqual(module.second_threshold_method, C.TM_MEDIAN)
    def test_04_03_load_v3(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:9207

MeasureImageQuality:[module_num:1|svn_version:\'9143\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D]
    Select an image to measure:Alpha
    Check for blur?:Yes
    Window size for blur measurements:25
    Check for saturation?:Yes
    Calculate threshold?:Yes
    Select a thresholding method:Otsu Global
    Typical fraction of the image covered by objects:0.2
    Calculate quartiles and sum of radial power spectrum?:Yes
    Two-class or three-class thresholding?:Three classes
    Minimize the weighted variance or the entropy?:Weighted variance
    Assign pixels in the middle intensity class to the foreground or the background?:Foreground
    Select an image to measure:Beta
    Check for blur?:No
    Window size for blur measurements:15
    Check for saturation?:No
    Calculate threshold?:No
    Select a thresholding method:MoG Global
    Typical fraction of the image covered by objects:0.3
    Calculate quartiles and sum of radial power spectrum?:No
    Two-class or three-class thresholding?:Two classes
    Minimize the weighted variance or the entropy?:Entropy
    Assign pixels in the middle intensity class to the foreground or the background?:Background
"""
        pipeline = cpp.Pipeline()
        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))
        pipeline.add_listener(callback)
        pipeline.load(StringIO.StringIO(data))
        self.assertEqual(len(pipeline.modules()), 1)
        module = pipeline.modules()[0]
        self.assertTrue(isinstance(module, miq.MeasureImageQuality))
        self.assertEqual(len(module.image_groups),2)
        
        group = module.image_groups[0]
        thr = group.threshold_groups[0]
        self.assertEqual(group.image_names, "Alpha")
        self.assertTrue(group.check_blur)
        self.assertEqual(group.scale_groups[0].scale, 25)
        self.assertTrue(group.check_saturation)
        self.assertTrue(group.calculate_threshold)
        self.assertEqual(thr.threshold_method, miq.cpthresh.TM_OTSU)
        self.assertAlmostEqual(thr.object_fraction.value, 0.2)
        self.assertEqual(thr.two_class_otsu, miq.O_THREE_CLASS)
        self.assertEqual(thr.use_weighted_variance, miq.O_WEIGHTED_VARIANCE)
        self.assertEqual(thr.assign_middle_to_foreground, miq.O_FOREGROUND)
        
        group = module.image_groups[1]
        thr = group.threshold_groups[0]
        self.assertEqual(group.image_names, "Beta")
        self.assertFalse(group.check_blur)
        self.assertEqual(group.scale_groups[0].scale, 15)
        self.assertFalse(group.check_saturation)
        self.assertFalse(group.calculate_threshold)
        self.assertEqual(thr.threshold_method, miq.cpthresh.TM_MOG)
        self.assertAlmostEqual(thr.object_fraction.value, 0.3)
        self.assertEqual(thr.two_class_otsu, miq.O_TWO_CLASS)
        self.assertEqual(thr.use_weighted_variance, miq.O_ENTROPY)
        self.assertEqual(thr.assign_middle_to_foreground, miq.O_BACKGROUND)
Exemple #7
0
 def test_01_05_load_v3_batch_data(self):
     '''Test loading a version 3 pipeline with batch data in it'''
     data = ('eJztnX9vG0d6xynHzsVO2kuCAtf+EYAHFHDSRvLO71m3yEm2klio5egi937g'
             'fPXR0lpiQZECSSVWiwPuz76k/tnX0lfQl9CdHe5wnglHpKhHEimNAFneJZ/5'
             'Pt9nd4ef3VnObm+8fL7xpCnWsub2xsvVt+1O0dzptIZve/2jx83u8Mvm037R'
             'Ghb7zV73cfPl4UlztzhuUt4k7LGgj7ls0izLG/P9rGxt/3X5578PVhrvl38/'
             'KH/vjF66N1pe8X7N8m4xHLa7B4N7jbuNvx2t/5/y9zetfrv1plP8ptU5KQZj'
             'iXr9Vvdt7+XpsXtpu7d/0iletI78N5c/L06O3hT9wXdv68DRyzvtd0Vnt/0f'
             'RWChftv3xQ/tQbvXHcWP2g/XOt3eMNA1dTj834arw0pQh0/L38+89eb9zxrj'
             '99+dULdPvPd/PFpud/fbP7T3T1qdZvuodeCymKW9vwnaM8ubxdvWSWdoG2u+'
             '7XX2i37dnp7S3vtBe2a53/rx2292LhS/+WJjtvgPgniz/LTX7z8pdyETvz4l'
             '/n4Qf38U/22/KLpeXefx8eJkr1O0ceKn+firIN4sb7YHw1Z3r3hadDqDxmzt'
             'TKrHTr93XLdR1yOb0s4KaGelQZHqOE/+k7bnefMnF8j/+9aw3SMXjKezxd8L'
             '4s3y9unur5/P6Ps9EP9e4/dl7zJL3T8OdM3vy+LdcPXrd629YfOoNdw7nKfu'
             'aw3c7X7R/uSy99+JdTzsF4ND0y3vV4ch5nE8rZ1Z+5Xr7h/Pu1/JGf3Puj0u'
             'ul/Nm/88dds09FDgxM/DG8+L4nXZLRwdd4rdJ7tbDmFMe7+b0t7nQXtm+ZEB'
             'lxIoH7W6rc7poD14tFP0ysYflUKPjk/fmL6nZLXhPHVmjfk57elhq9stOmTr'
             '+fN/3V4ru8DR6/PuL1udzslRSVYXii/JapY63AXxdxv6S6rn3V/Yl3n5M9vx'
             '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'
             'QnILZS255RW5SVmTm0QcvZMSkltuEMpBs5TaN45YbwXJLZBVltxyS27KkRvi'
             '6J1UkNxyg1AOmqXyyQ1xFhapILmFshW5DXYf7rSGh93WUeHmI5flad3uw1fl'
             'T7u33+4W5V+bx+s6j1evbCKvXpWZvHoFUnGLIBczKz6QsvOxS03wpcwE8/Vz'
             'eKY9p+sXwXN+zHL9HPmqyeZmu1/sDXv904s9j3Dzp88rfT+Ir3/q+PuR5wnN'
             'G3cVzx88bxxZy9DirqKe1/G8PKznq87zXNRZn/d1ndv9PPvn8ZS4fwr8muUL'
             'dMOuztd53F9F3Hrj7LpOej7ndu9b/7F7cx9f263uiWlj3v45W8vol+WONe9z'
             'Hcv46se0Uf0g1POytsOs/cJlPcdx1uejXpWPq+6XVkDcSmNtxjx/8hzzjHCs'
             'z+lF7lfOvx3opW6/cDuUxz7BiluE/mHW4/Oq9TGeU4/1HOZFeC77zpS4vwt0'
             'zbI7yQrPsbztc9P7kzn5gF8FH8yy/UmGF7cI/c085xeX3d/Mc7512f3WeZ+X'
             'Pu089Cqfe/6T86fR61jP2V7k/ua8/Wk2I78gcojAiluE/mTW43lZ877u56Jf'
             'tP15nnPfPjrYf5ORaz9+FzluvXF2XSedL7ttdA3tTLoetNlrdnvD5smgwG9n'
             '0bbHrJ/zi/Z5FV6/IDPGYV9nmYd/9o7LXaJ/9ceZG/jz2kn9ynztnJ+n5tvP'
             'JsUt8nZa9H6Czxi3EP3EzsmAXbCfmEfXjopf//a8zP1AzBg373WP8DzlRa9b'
             'YMUty3ZYlrh5z/cxx6M+asDj0CyP7v/YfLK2/+ay/c7CU8u8PUN/6pLjsPef'
             'ZdwOyxK3COOxl7ndb/rnzFXcT7Y+Je5DEGeXX/7Ya+6V59AD7/4brHaWcTst'
             'S9xN7A/+MkXvXxpwvzPL//b5r3b+eafTGhZfrf3jF6/N0m+LTuf73o9f/WFj'
             'deePX9RrnvY6J0fdr/6QreZ//E/yJf2zffNuu4ysVn4xsc6LvD+sT6nXVV83'
             'fDalnUnjXb8t2geHw2K/+UOr3zY3HDQur71l2a4p7vLOh86jdzhFTzfg/meW'
             'TZ/y+6LVH3U0/M9frJpV273u8HC0jo7WbbZOx2uuu56LwDXznpdO6p++6fWL'
             'g37vpLs/zhurnWXcTinu+uLWG2fvd2eMg9BlHAe5rOsOy34/XYq7nXFzjm9s'
             'vthYLp9Xfb1jGeuS4m5n3CzX7ekC5HmZx/us9xdMuH+SXbe/FJfiLno83PTx'
             'jHQ/QYq7TXF/aZy9X6fxiuu9n2UZ65Libk/cYePs/TqNL6TrCCkuxd2muNmu'
             'Iwi0uGWpS4pLcTclbt2LS/cpprgUd7vjnnlx6b7BFJfiUtx5eCHd/5fiUtzt'
             'jEvXB1Ncirs9cZjzJswStyx1SXG3J+6DH8dxK0Hcp+XvZ976ZeF1M+1lBdrH'
             'qZ1J1y171TzI44ZucjtXeV15Hh+zbudl6U9uetx64+zt+XEDbk/zO96ezXZ3'
             'vzjGbOfZlHYmXZ/09lPbkOfvtrU3bTuk/ir1V8sct97A2Z5Y7SxL3eaNW/b+'
             '7qq5c1m2602PW2+cvT1n5ZFl8XtT+tNp/cOnQTtmuXcy7LS7xU86iMto76rq'
             'tWjnp8vqa1mOwxSX4hbx/Cgdr4sRt944u76JZ25H3HpjsY7XRWtnWbZjiktx'
             'y9RfXLf+dftIcSnuJsatN673uMLSv24fKS7F3cS49cb1HldY+je1nWXZj1Lc'
             '7Yxbbyznfr6seae45Y571jh7v7vu8c90HKa4FJfiUlyKS+OW1x+33ji7vul+'
             '2BSX4lJciktxKS7FpbgUl+Lw4p55cel6XYpLcSkuxaW4FJfiUlyKu+1x615c'
             'uv6f4lJciktxKS7FpbhljFv34tJ4e4pLcSkuxaW4FJfiUlyKS3EpLsWluBSX'
             '4lJciktxKS7FpbgUl+JSXIpLcSkuxaW4FJfiUlyKu+y4ww/GcStBnFn2v09m'
             '3v8nT2fSfSn/4L3/49HyXtHpHPd7b9udor921Ns/6RSDtU6vtV/dsDJYe17+'
             'd6v6r5fXFB0e6PCzdAbt7kGnqNQqsd1quZKs9d5N0XsW6D2L6e31+v1ib9ju'
             'dE6O2t3WsN3rvm4dH3dO157aV7b8VzbMK4ugfzxFfz3QX4/pt/eL7rD99vS4'
             'X9b7ZNg7KoX21rZGa3fKtRv12uvUnbZ/6UBXT9MdFHu97n6rf+o0d+s116GH'
             'tj/VesOiP2yXjQ9O3vSLg3LfcbovR6/s1q8sgv60/epxoP84pn9UtAYn5XFj'
             'Dp5OddCsbdtVT8erbDuz+H4S6D6Zomvnqmv1y6XD1nFRa39Xrd4oV++a1Zet'
             '3+4Oi+6gPTyF+lv16rH+tP2cBvp0iv6weDcs/9S6L+3iWO9PU/SyQC+L6e21'
             'Onsn5dYsyi7icO1pvbRdLl2lzrT6yUBHxnSKd8e9/nDY228NW29ag2Lt62rF'
             'y97maMVs22tmvb1yXxwWb1rDvUPzwmDtabXiiVnxjVlh9Z55evcn6Pm8cWe0'
             '/Iv379377LNPPrl378Of3f/o5z//+P54+8e4p+G1c7/hc9D//WrePO6urKzc'
             'vXvnTvlnxfzzwXvjPH7ntffhlPZMnf++MfuPaf+/3jsfp33eiL+/MVqX3p/e'
             'n95//vf/P0+1wjU=')
     pipeline = cpp.Pipeline()
     def callback(caller,event):
         self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))
     pipeline.add_listener(callback)
     pipeline.load(StringIO(zlib.decompress(base64.b64decode(data))))
     module = pipeline.modules()[-1]
     self.assertTrue(isinstance(module, C.CreateBatchFiles))
     batch_data = zlib.decompress(module.batch_state)
     image_set_list = cpi.ImageSetList()
     image_set_list.load_state(batch_data)
     self.assertEqual(image_set_list.count(), 96)
     self.assertEqual(image_set_list.legacy_fields['PathnamerawDNA'],
                      '\\\\iodine\\imaging_analysis\\People\\Lee\\ExampleImages\\ExampleSBSImages')
    def test_03_09_flag_image_abort(self):
        #
        # Regression test of issue #1210
        # Make a pipeline that aborts during FlagImage
        #
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:3
DateRevision:20140918122611
GitHash:ded6939
ModuleCount:6
HasImagePlaneDetails:False

Images:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:2|show_window:False|notes:\x5B\'To begin creating your project, use the Images module to compile a list of files and/or folders that you want to analyze. You can also specify a set of rules to include only the desired files in your selected folders.\'\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    :
    Filter images?:Images only
    Select the rule criteria:and (extension does isimage) (directory doesnot containregexp "\x5B\\\\\\\\\\\\\\\\/\x5D\\\\\\\\.")

Metadata:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:4|show_window:False|notes:\x5B\'The Metadata module optionally allows you to extract information describing your images (i.e, metadata) which will be stored along with your measurements. This information can be contained in the file name and/or location, or in an external file.\'\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Extract metadata?:No
    Metadata data type:Text
    Metadata types:{}
    Extraction method count:1
    Metadata extraction method:Extract from file/folder names
    Metadata source:File name
    Regular expression:^(?P<Plate>.*)_(?P<Well>\x5BA-P\x5D\x5B0-9\x5D{2})_s(?P<Site>\x5B0-9\x5D)_w(?P<ChannelNumber>\x5B0-9\x5D)
    Regular expression:(?P<Date>\x5B0-9\x5D{4}_\x5B0-9\x5D{2}_\x5B0-9\x5D{2})$
    Extract metadata from:All images
    Select the filtering criteria:and (file does contain "")
    Metadata file location:
    Match file and image metadata:\x5B\x5D
    Use case insensitive matching?:No

NamesAndTypes:[module_num:3|svn_version:\'Unknown\'|variable_revision_number:5|show_window:False|notes:\x5B\'The NamesAndTypes module allows you to assign a meaningful name to each image by which other modules will refer to it.\'\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Assign a name to:All images
    Select the image type:Grayscale image
    Name to assign these images:DNA
    Match metadata:\x5B\x5D
    Image set matching method:Order
    Set intensity range from:Image metadata
    Assignments count:1
    Single images count:0
    Select the rule criteria:and (file does contain "")
    Name to assign these images:DNA
    Name to assign these objects:Cell
    Select the image type:Grayscale image
    Set intensity range from:Image metadata
    Retain outlines of loaded objects?:No
    Name the outline image:LoadedOutlines

Groups:[module_num:4|svn_version:\'Unknown\'|variable_revision_number:2|show_window:False|notes:\x5B\'The Groups module optionally allows you to split your list of images into image subsets (groups) which will be processed independently of each other. Examples of groupings include screening batches, microtiter plates, time-lapse movies, etc.\'\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Do you want to group your images?:No
    grouping metadata count:1
    Metadata category:None

FlagImage:[module_num:5|svn_version:\'Unknown\'|variable_revision_number:4|show_window:False|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Hidden:1
    Hidden:1
    Name the flag\'s category:Metadata
    Name the flag:QCFlag
    Flag if any, or all, measurement(s) fails to meet the criteria?:Flag if any fail
    Skip image set if flagged?:Yes
    Flag is based on:Whole-image measurement
    Select the object to be used for flagging:None
    Which measurement?:Height_DNA
    Flag images based on low values?:No
    Minimum value:0.0
    Flag images based on high values?:Yes
    Maximum value:100.0
    Rules file location:Elsewhere...\x7C
    Rules file name:rules.txt
    Class number:

MeasureImageIntensity:[module_num:6|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Select the image to measure:DNA
    Measure the intensity only from areas enclosed by objects?:No
    Select the input objects:None
"""
        self.awthread = self.AWThread(self.announce_addr)
        self.awthread.start()
        self.set_work_socket()
        self.awthread.ex(self.awthread.aw.do_job, 
                         cpanalysis.WorkReply(
                             image_set_numbers = [1],
                             worker_runs_post_group = False,
                             wants_dictionary = True))
        #
        # The worker should ask for the pipeline and preferences next.
        #
        req = self.awthread.recv(self.work_socket)
        self.assertIsInstance(req, cpanalysis.PipelinePreferencesRequest)
        self.assertEqual(req.analysis_id, self.analysis_id)
        
        input_dir = os.path.join(example_images_directory(), "ExampleSBSImages")
        cpprefs.set_default_image_directory(input_dir)
        preferences = {cpprefs.DEFAULT_IMAGE_DIRECTORY: 
                       cpprefs.config_read(cpprefs.DEFAULT_IMAGE_DIRECTORY) }
        
        rep = cpanalysis.Reply(
            pipeline_blob = np.array(data),
            preferences = preferences)
        req.reply(rep)
        #
        # The worker asks for the initial measurements.
        #
        req = self.awthread.recv(self.work_socket)
        self.assertIsInstance(req, cpanalysis.InitialMeasurementsRequest)
        self.assertEqual(req.analysis_id, self.analysis_id)
        m = get_measurements_for_good_pipeline()
        pipeline = cpp.Pipeline()
        pipeline.loadtxt(StringIO(data))
        pipeline.write_pipeline_measurement(m)
        
        try:
            req.reply(cpanalysis.Reply(buf = m.file_contents()))
        finally:
            m.close()
        #
        # Next, the worker asks for the shared dictionary
        #
        req = self.awthread.recv(self.work_socket)
        self.assertIsInstance(req, cpanalysis.SharedDictionaryRequest)
        shared_dictionaries = [{ ("foo%d" % i):"bar%d" % i} for i in range(1,7)]
        rep = cpanalysis.SharedDictionaryReply(
            dictionaries = shared_dictionaries)
        req.reply(rep)
        #
        # MeasureImageIntensity follows FlagImage and it is poised to ask
        # for a display. So if we get that, we know the module has been run
        # and we fail the test.
        #
        req = self.awthread.recv(self.work_socket)
        self.assertFalse(isinstance(req, cpanalysis.DisplayRequest))
        self.assertFalse(isinstance(req, cpanalysis.ExceptionReport))
    def test_01_03_load_v3(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:10252

MeasureGranularity:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D]
    Image count:2
    Object count:2
    Select an image to measure:DNA
    Subsampling factor for granularity measurements:0.25
    Subsampling factor for background reduction:0.25
    Radius of structuring element:10
    Range of the granular spectrum:16
    Object name:Nuclei
    Object name:Cells
    Object count:3
    Select an image to measure:Actin
    Subsampling factor for granularity measurements:0.33
    Subsampling factor for background reduction:0.5
    Radius of structuring element:12
    Range of the granular spectrum:20
    Object name:Nuclei
    Object name:Cells
    Object name:Cytoplasm
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO(data))
        self.assertEqual(len(pipeline.modules()), 1)
        module = pipeline.modules()[0]
        self.assertTrue(isinstance(module, M.MeasureGranularity))
        self.assertEqual(len(module.images), 2)
        for image_setting, image_name, subsample_size, bsize, elsize, glen, objs in (
            (module.images[0], "DNA", 0.25, 0.25, 10, 16, ("Nuclei", "Cells")),
            (
                module.images[1],
                "Actin",
                0.33,
                0.50,
                12,
                20,
                ("Nuclei", "Cells", "Cytoplasm"),
            ),
        ):
            # self.assertTrue(isinstance(image_setting, M.MeasureGranularity))
            self.assertEqual(image_setting.image_name, image_name)
            self.assertAlmostEqual(image_setting.subsample_size.value,
                                   subsample_size)
            self.assertAlmostEqual(image_setting.image_sample_size.value,
                                   bsize)
            self.assertEqual(image_setting.element_size.value, elsize)
            self.assertEqual(image_setting.granular_spectrum_length.value,
                             glen)
            self.assertEqual(len(image_setting.objects), len(objs))
            self.assertEqual(image_setting.object_count.value, len(objs))
            self.assertTrue(
                all([
                    ob.objects_name.value in objs
                    for ob in image_setting.objects
                ]))
Exemple #10
0
    def test_01_03_load_v3(self):
        data = """CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:10865

MeasureTexture:[module_num:1|svn_version:\'1\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D]
    Hidden:2
    Hidden:2
    Hidden:2
    Select an image to measure:rawDNA
    Select an image to measure:rawGFP
    Select objects to measure:Cells
    Select objects to measure:Nuclei
    Texture scale to measure:3
    Angles to measure:Horizontal,Vertical
    Texture scale to measure:5
    Angles to measure:Diagonal,Anti-diagonal
    Measure Gabor features?:Yes
    Number of angles to compute for Gabor:6

MeasureTexture:[module_num:2|svn_version:\'1\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D]
    Hidden:2
    Hidden:2
    Hidden:2
    Select an image to measure:rawDNA
    Select an image to measure:rawGFP
    Select objects to measure:Cells
    Select objects to measure:Nuclei
    Texture scale to measure:3
    Angles to measure:Horizontal,Vertical
    Texture scale to measure:5
    Angles to measure:Diagonal,Anti-diagonal
    Measure Gabor features?:No
    Number of angles to compute for Gabor:6
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO(data))
        self.assertEqual(len(pipeline.modules()), 2)
        for i, wants_gabor in enumerate((True, False)):
            module = pipeline.modules()[i]
            self.assertTrue(isinstance(module, M.MeasureTexture))
            self.assertEqual(len(module.image_groups), 2)
            self.assertEqual(module.image_groups[0].image_name, "rawDNA")
            self.assertEqual(module.image_groups[1].image_name, "rawGFP")
            self.assertEqual(len(module.object_groups), 2)
            self.assertEqual(module.object_groups[0].object_name, "Cells")
            self.assertEqual(module.object_groups[1].object_name, "Nuclei")
            self.assertEqual(len(module.scale_groups), 2)
            self.assertEqual(module.scale_groups[0].scale, 3)
            angles = module.scale_groups[0].angles.get_selections()
            self.assertEqual(len(angles), 2)
            self.assertTrue(M.H_HORIZONTAL in angles)
            self.assertTrue(M.H_VERTICAL in angles)

            angles = module.scale_groups[1].angles.get_selections()
            self.assertEqual(len(angles), 2)
            self.assertTrue(M.H_DIAGONAL in angles)
            self.assertTrue(M.H_ANTIDIAGONAL in angles)

            self.assertEqual(module.scale_groups[1].scale, 5)
            self.assertEqual(module.wants_gabor, wants_gabor)
            self.assertEqual(module.gabor_angles, 6)
            self.assertEqual(module.images_or_objects, M.IO_BOTH)
Exemple #11
0
    def test_01_04_load_v4(self):
        data = """CellProfiler Pipeline: http://www.cellprofiler.org
Version:3
DateRevision:20141017202435
GitHash:b261e94
ModuleCount:3
HasImagePlaneDetails:False

MeasureTexture:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Hidden:2
    Hidden:2
    Hidden:2
    Select an image to measure:rawDNA
    Select an image to measure:rawGFP
    Select objects to measure:Cells
    Select objects to measure:Nuclei
    Texture scale to measure:3
    Angles to measure:Horizontal,Vertical
    Texture scale to measure:5
    Angles to measure:Diagonal,Anti-diagonal
    Measure Gabor features?:Yes
    Number of angles to compute for Gabor:6
    Measure images or objects?:Images

MeasureTexture:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Hidden:2
    Hidden:2
    Hidden:2
    Select an image to measure:rawDNA
    Select an image to measure:rawGFP
    Select objects to measure:Cells
    Select objects to measure:Nuclei
    Texture scale to measure:3
    Angles to measure:Horizontal,Vertical
    Texture scale to measure:5
    Angles to measure:Diagonal,Anti-diagonal
    Measure Gabor features?:No
    Number of angles to compute for Gabor:6
    Measure images or objects?:Objects

MeasureTexture:[module_num:3|svn_version:\'Unknown\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Hidden:2
    Hidden:2
    Hidden:2
    Select an image to measure:rawDNA
    Select an image to measure:rawGFP
    Select objects to measure:Cells
    Select objects to measure:Nuclei
    Texture scale to measure:3
    Angles to measure:Horizontal,Vertical
    Texture scale to measure:5
    Angles to measure:Diagonal,Anti-diagonal
    Measure Gabor features?:No
    Number of angles to compute for Gabor:6
    Measure images or objects?:Both
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO(data))
        self.assertEqual(len(pipeline.modules()), 3)
        for i, (wants_gabor, io_choice) in enumerate(
                ((True, M.IO_IMAGES),
                 (False, M.IO_OBJECTS),
                 (False, M.IO_BOTH))):
            module = pipeline.modules()[i]
            self.assertTrue(isinstance(module, M.MeasureTexture))
            self.assertEqual(len(module.image_groups), 2)
            self.assertEqual(module.image_groups[0].image_name, "rawDNA")
            self.assertEqual(module.image_groups[1].image_name, "rawGFP")
            self.assertEqual(len(module.object_groups), 2)
            self.assertEqual(module.object_groups[0].object_name, "Cells")
            self.assertEqual(module.object_groups[1].object_name, "Nuclei")
            self.assertEqual(len(module.scale_groups), 2)
            self.assertEqual(module.scale_groups[0].scale, 3)
            angles = module.scale_groups[0].angles.get_selections()
            self.assertEqual(len(angles), 2)
            self.assertTrue(M.H_HORIZONTAL in angles)
            self.assertTrue(M.H_VERTICAL in angles)

            angles = module.scale_groups[1].angles.get_selections()
            self.assertEqual(len(angles), 2)
            self.assertTrue(M.H_DIAGONAL in angles)
            self.assertTrue(M.H_ANTIDIAGONAL in angles)

            self.assertEqual(module.scale_groups[1].scale, 5)
            self.assertEqual(module.wants_gabor, wants_gabor)
            self.assertEqual(module.gabor_angles, 6)
Exemple #12
0
    def test_01_10_img_787(self):
        data = ('eJyVk/s7E4oDxkeJU5xJhJPLcr91rEMuyxR6ODqZ+yS5Lmm5bC5z35Rrclml'
                'EqYdB5PIDuUyxhzRYpg7oWJhmNvcRmM7Pef7F3zfH97f3ud5n8/zvg5Wbtes'
                'rEEXfgWDHKzczt1GhgQagJxC/KNuoyJCISAnGw97mAHIJiLQPyrwFggVBgG5'
                'YQJBDv4RILA5CHwech4MAZuAfgOfB4P+bwFE7B2AAABgWRwAiCXMeXo5ToFl'
                'o0vAE2K13N+44Hnxd6WjxiaryGxMNfDdA1AZtLm7pB69+jH8eotvI7Ge3mW8'
                '1HU8QqLEvvF3OMaFuL6XyA7Q/mQlcbh09p2iICwNIeVQk/N7Ta+U5hRI0x+b'
                'dMR9kLMoWEffDLBC4zs0SSJ7d+K7eFMrD32zW5d8K6aldKI20LiIWEyyPzD1'
                'a+tDuVIa86PEKwecyA0qC8lG2yR2eJapznJiKqIpIytrOmeIty3cjFV80hGo'
                'tbZCoWLfgsep2KniItqZnBMK3fHBqcpIqdqoY8fZpSLszPTSuRoQFnXP9Q3C'
                'a/hr7rbjUUBLxiVDYyVNYsq63/GwSx09efnVOGypiDxwO7gHL+rlTNDA5Yrx'
                'tpuSTGeoQ+inSnRssxZXyLogGTsqRtWDHLuaNXDRaLF18AC+iZyI+RwGar08'
                'hl005TSm+YibtPfezxSSBPUls3qfdnUe63xtQ9ygk360gM04gZyFpovrwd/5'
                'MZtb8CdV3dTAjS23YY+IoiE/M4/FAr6YPKuNf8UZqx3sfetTUiiQEHw8bYSW'
                'KSxL3Os596Fcbg/8jZGaJ0s3yWtPVKPrQGGTOxbbSrdYkVirJOXaIwQ9IG/g'
                'L2/NRmuV1AsaK34P7OBAHWHBJL4sHtVGxt4pmzNapWjrq2rx7bkHycWcthmR'
                'yKDdtzMaO28ydjHDkGhjrOaUy+VYyfpfns/BjYhNX0xV+iZbbnKqQsy0LPVO'
                'mMmNGFSqkqgTP6BYmDO/hf+iMnZ6e3zAWd/L8lCCGOfRjYIKwpUDa4PFobod'
                'FQxjwaXh7WeJvRT0T++5CSlqLHgUlZGex9uvDREEruLxz/KbfTLIJFpGThQH'
                'V/PGq1s5LHNKVq1alXzxBKyIMpfeJEKKIowJqd/+C26RCXYqVblrk/isL/nP'
                'R01ZB/jV2/Eqry6cQcYxitb/+uZmQqijJelChG93WzrX5YeA1eryCU+m2x/u'
                'kem0NO2v5QEtjBph4BZxWykqK9I6DjisC9QiuK/+sDIe2k70b2i7z1HXq7SF'
                'rTXDH/cQCleufwpjgWWllJsN7/ItZVTvDZVldaobWYeyxWypfYjj8GW9Tp0/'
                'ygWhl8qj25Ovcye4opVXNDgRzv1cyvj4H9PRp5mWYXZN9Wh+7bs5SqdP4ikz'
                '+b3GjKl/Nlv1blalBsutM2YmBIm8hvYdsaY8mbBZoJO2rae24z+spGcCJBUq'
                'svZRl+d4QEP/rKaQciJolPaA/Wj2rCCFjQl/Wxhzmo1SiGnsNH+y1yqDYyqq'
                'QVuxIrCGtmvckRzEqwel3KzlzXuDDonMnQTvryHTeluIp+1oSZILpF/Bgpvx'
                'Kq9fusfHX8lFeWTM23BNjl0Zoqxi9D1znfKSHQNtbCR5hVusL8bWxf2569me'
                '0LchkyQ5ZC99f8lV9PKBwrzOYya5Mg42Lv/s4Ml3vXfjHw3JMDY5gh/UkorK'
                'O78b+gHbvwj1xRdlF9gKcPOKhWKKhOp5/GTzFifanFZYmKSSm+NlgvsCseJi'
                'RXBFfCnsGD9/1NvdLokl2anba2nQSY5oU9/Zvthz3155ZPK6/NLbPu6j+VnP'
                'UaoT9Y6wOWD7pOoH172fK+KkMTMGElbfVbEkVmO5axnKFXMX4kuKjYXHFI/1'
                '5cEI7nzyaniVl10Dy7jr/dsGTnJXy/OtwKtAZuEQ8mFGUCiR8Xo7zX7DOVEX'
                'uRjAZAg3fvVzxSOLX5u5KzdvucIdfdsRHIHLU1UviAN3o7rn8MM9Qm579O68'
                'qy2QaxdnW5OhDXqYzZn1fNy/btGGoDao+6IEQ3wcnEkaM/IRWkw9xYw99fn8'
                'fWyV3tDGJOrjemz2yYTNmOI16jlL0fdH57cWNo3dx3OD6Oot+NJ8U3A3/IrD'
                'nH+o3Lr8/wb4wtkxBSxNZxyL7LkZlaVl+WJvsRR3JL9rUSbHljdTVFmtRyot'
                '0+/eXS1PNx+7PHlWFqyODBNfGRd644cCRACT/kYd0dKe0ocLfcUdwG0r+xki'
                '5cvR/c8b06ETNwaFvYsCM7bTDJpIxZ7N6Lo8uBOW3Ppkwx0j8IB92WcWaWcN'
                'n47dhZDrlD43u3GsRjyMfT98PtWUEDwd1fr6oHnM0YdQF+v+hl59OIo5wIS7'
                'ERHe8cvwpB/gPGDOVGqoz/cGwl10w1a3cE62S5+xIJeRXZqg2oIkBHIYdwPj'
                '69byo+arQrDNW82VffowxSCPGXSSqGJ2mmt3+MfXLTpeUZYN4SGhxdUrfBSw'
                'evwkz779b06XfiXkMF+OSalfjul25Oe+3DnE2M3c6iTOFkC0kVgzjRcD5ykl'
                '6JJe+0LHlwO99xVyLNKpBYzTevuXZMymVR0e0ad5XeqYipR7j3Vv1bgOWkCv'
                'mlWIsrczbJBNIFV/pWvehpK5sWSbB8UAm3RZirYoTyPt4gaWCqhqMtS4GZkT'
                'nHxWs2B8ELJsFYPFiKnw1k8SxGRzBglptg7jte3mPuEquIZgmicj0/RPCcsk'
                'a9XKLorhRpPQq5T3CKu3oJ8ZCeX9FIiIgMZIwxTocFFtS18TNVrQ1OHLVhRm'
                'BUdrHbaczqmpGqGIsJol0fviys/9ow0QFciCYljpYMiFAEjdxtDP/QnIsF0f'
                'c/ElniF+fh/131K+Ifz8BgABJqAFQIDtMQm/tE1/gJbla5zbIdoFCLCjWXv/'
                'Cz7DUEw=')
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(
            StringIO.StringIO(zlib.decompress(base64.b64decode(data))))
        module = pipeline.modules()[2]
        self.assertTrue(isinstance(module, R.RescaleIntensity))
        self.assertEqual(module.image_name, "OrigGreen")
        self.assertEqual(module.rescaled_image_name, "Rescaledgreen")
        self.assertEqual(module.rescale_method, R.M_MANUAL_INPUT_RANGE)
        self.assertEqual(module.wants_automatic_low, R.LOW_EACH_IMAGE)
        self.assertEqual(module.wants_automatic_high, R.HIGH_EACH_IMAGE)
Exemple #13
0
    def test_01_09_load_v1(self):
        data = ('eJztWl9P2zAQd2lhMKSNaRKbtBc/7AE2GqXlj6CaoB3dtG6UVYA2IcSYaV3w'
                '5MRV4rB2ExIfa498pH2ExW3SpKYlbSm0aIlkNXfx737ns++SOM1n9rYyb+Gy'
                'osJ8Zi9eJhTDAkW8zAwtBXW+ADcNjDguQaan4HuDwI8WhQkVJpKpxZWUugyT'
                'qroG+jsiufwj8fsSgAn7Z9JuY86lcUeO+JqQdzHnRD8xx0EMPHf0l3b7ggyC'
                'jin+gqiFTY/C1ef0MturVZqX8qxkUbyNNH9n+9i2tGNsmJ/LLtC5XCBVTHfJ'
                'LywNwe22g8+ISZju4B37srbJy7jEK+JwOePFISLFIWq3WZ9e9P8AvP6xNnF7'
                '4us/48hEL5EzUrIQhURDJ00vhD01wF60xV4UZLczN8KlA3Azkv+i7eEqj7+r'
                'oiKHGuLF0274x1rsjIFtBrrin5b4hbyDzSKiuCTG0G3cIi12ImCxS1ysBRez'
                '/daxwJ0G4JYkv4W8ecqYiaFZwUVSJkV4Vs8TyBk8xtDAJubiHMGiZXKmQQPp'
                'J9gdX1CcHkp8Qs4yqDMOLdNJGHm8E5Id93DtTIH2uF7mdxC4u/AzKI+fgdb4'
                'CjmLy8iiHOZEEsMsMXCRM6N2q/7LeayoiYHxDdJPOW9UZW2tn/Ht29XxJn6u'
                'BvA9AK3zKmRVSSzY/vY1H8PxN2n7uzqUfAvKm6eSv0LebRQ6p8zVq2DT3uiv'
                'Y3V5UPfpUYlzN/fLRBvcLdeLruLc6f7cr5/pAL4p0BpnIW/WOKtQZGo+OxcB'
                'dj5JdoT8bW6j8EY8+ON15fX8kZC+Ykp32M/1g0y8cDjvajYZtTR9/UCNrx3+'
                'Tiwkzxudd4mNrCvn28Z9kPMlr4+kgwt6LlqVxi1k4fs+RoYzoKXz+bhQ5ZnO'
                'Tx1d0tFlUc3T3GR8hQA/X0h+Cjmnc6ybhNeO8hjpntTpOfSu69cw1vmo1etO'
                '63LU/Bx03eoXdxHg532qU73g7kud6hc3+bi3fYzbqiPt3kvrmx4nBrMqg7cz'
                'anW03f6J5zckeglXbpO/3f4JO/5hv6l6gRt2fQxxIS7Ehbj/EZf24YZx/whx'
                'dzufo/ocE+JGA5cG16+fsB6EuBDXO64a6fw+LGT/fr3o/x1cn4evQGseCrmI'
                'Ka0YTPx/w1C0+p8MTIUyVGp85Ve27NOc74O/4KkE8KQlnnQnHg0j0zJwnYq4'
                'W5NKvqGtszY3LLvZ/1iReFc68RqNj/EepfN1vsl2dd6m2vD54z9mS7PRmWvn'
                'W55nb/7/bvTDF41Ernx/mw7AxXw+iUPg/4De1tncNf3dMd5V/38aZ6rY')
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(
            StringIO.StringIO(zlib.decompress(base64.b64decode(data))))
        self.assertEqual(len(pipeline.modules()), 3)
        module = pipeline.modules()[2]
        self.assertTrue(isinstance(module, R.RescaleIntensity))
        #
        # image_name = DNA
        # rescaled_image_name = RescaledDNA
        # rescaling_method = M_MANUAL_IO_RANGE
        # manual intensities
        # source_low = .01
        # source_high = .99
        # src_scale = .1 to .9
        # dest_scale = .2 to .8
        # low_truncation_choice = R_SET_TO_CUSTOM
        # custom_low_truncation = .05
        # high_truncation_choice = R_SET_TO_CUSTOM
        # custom_high_truncation = .95
        # matching_image_name = Cytoplasm
        # divisor_value = 2
        # divisor_measurement = Intensity_MeanIntensity_DNA
        self.assertEqual(module.image_name.value, "DNA")
        self.assertEqual(module.rescaled_image_name.value, "RescaledDNA")
        self.assertEqual(module.rescale_method.value, R.M_MANUAL_IO_RANGE)
        self.assertEqual(module.wants_automatic_high.value, R.CUSTOM_VALUE)
        self.assertEqual(module.wants_automatic_low.value, R.CUSTOM_VALUE)
        self.assertAlmostEqual(module.source_low.value, .01)
        self.assertAlmostEqual(module.source_high.value, .99)
        self.assertAlmostEqual(module.source_scale.min, .1)
        self.assertAlmostEqual(module.source_scale.max, .9)
        self.assertEqual(module.low_truncation_choice.value, R.R_SET_TO_CUSTOM)
        self.assertEqual(module.high_truncation_choice.value,
                         R.R_SET_TO_CUSTOM)
        self.assertAlmostEqual(module.custom_low_truncation.value, .05)
        self.assertAlmostEqual(module.custom_high_truncation.value, .95)
        self.assertEqual(module.matching_image_name.value, "Cytoplasm")
        self.assertAlmostEqual(module.divisor_value.value, 2)
        self.assertEqual(module.divisor_measurement.value,
                         "Intensity_MeanIntensity_DNA")
    def test_01_02_load_v2(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:3
DateRevision:20130220214757
ModuleCount:5
HasImagePlaneDetails:False

SendEmail:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True]
    Hidden:2
    Hidden:6
    Sender address:[email protected]
    Subject line:Hello, world
    Server name:smtp.cellprofiler.org
    Port:587
    Select connection security:STARTTLS
    Username and password required to login?:Yes
    Username:[email protected]
    Password:rumplestiltskin
    Recipient address:[email protected]
    Recipient address:[email protected]
    When should the email be sent?:After first cycle
    Image cycle number:1
    Image cycle count:1
    Message text:First cycle
    When should the email be sent?:After last cycle
    Image cycle number:1
    Image cycle count:1
    Message text:Last cycle
    When should the email be sent?:After group start
    Image cycle number:1
    Image cycle count:1
    Message text:Group start
    When should the email be sent?:After group end
    Image cycle number:1
    Image cycle count:1
    Message text:Group end
    When should the email be sent?:Every # of cycles
    Image cycle number:1
    Image cycle count:5
    Message text:Every fifth cycle
    When should the email be sent?:After cycle #
    Image cycle number:17
    Image cycle count:1
    Message text:Cycle 17
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO(data))
        self.assertEqual(len(pipeline.modules()), 1)
        module = pipeline.modules()[0]
        assert isinstance(module, SE.SendEmail)
        self.assertEqual(module.from_address, "*****@*****.**")
        self.assertEqual(module.subject, "Hello, world")
        self.assertEqual(module.smtp_server, "smtp.cellprofiler.org")
        self.assertEqual(module.port, 587)
        self.assertEqual(module.connection_security, SE.C_STARTTLS)
        self.assertTrue(module.use_authentication)
        self.assertEqual(module.username, "*****@*****.**")
        self.assertEqual(module.password, "rumplestiltskin")
        self.assertEqual(len(module.recipients), 2)
        self.assertEqual(module.recipients[0].recipient,
                         "*****@*****.**")
        self.assertEqual(module.recipients[1].recipient,
                         "*****@*****.**")
        self.assertEqual(len(module.when), 6)
        self.assertEqual(module.when[0].choice, SE.S_FIRST)
        self.assertEqual(module.when[0].message, "First cycle")
        self.assertEqual(module.when[1].choice, SE.S_LAST)
        self.assertEqual(module.when[2].choice, SE.S_GROUP_START)
        self.assertEqual(module.when[3].choice, SE.S_GROUP_END)
        self.assertEqual(module.when[4].choice, SE.S_EVERY_N)
        self.assertEqual(module.when[4].image_set_count, 5)
        self.assertEqual(module.when[5].choice, SE.S_CYCLE_N)
        self.assertEqual(module.when[5].image_set_number, 17)
Exemple #15
0
    def make_workspace(
        self, control_points, lengths, radii, image, mask=None, auximage=None
    ):
        """Create a workspace containing the control point measurements

        control_points - an n x 2 x m array where n is the # of control points,
                         and m is the number of objects.
        lengths - the length of each object
        radii - the radii_from_training defining the radius at each control pt
        image - the image to be straightened
        mask - the mask associated with the image (default = no mask)
        auximage - a second image to be straightnened (default = no second image)
        """
        module = S.StraightenWorms()
        module.objects_name.value = OBJECTS_NAME
        module.straightened_objects_name.value = STRAIGHTENED_OBJECTS_NAME
        module.images[0].image_name.value = IMAGE_NAME
        module.images[0].straightened_image_name.value = STRAIGHTENED_IMAGE_NAME
        module.flip_image.value = IMAGE_NAME
        module.module_num = 1

        # Trick the module into thinking it's read the data file

        class P:
            def __init__(self):
                self.radii_from_training = radii

        module.training_set_directory.dir_choice = cps.URL_FOLDER_NAME
        module.training_set_directory.custom_path = "http://www.cellprofiler.org"
        module.training_set_file_name.value = "TrainingSet.xml"
        module.training_params = {"TrainingSet.xml": (P(), "URL")}

        pipeline = cpp.Pipeline()
        pipeline.add_module(module)

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.RunExceptionEvent))

        pipeline.add_listener(callback)

        m = cpmeas.Measurements()
        for i, (y, x) in enumerate(control_points):
            for v, f in ((x, S.F_CONTROL_POINT_X), (y, S.F_CONTROL_POINT_Y)):
                feature = "_".join((S.C_WORM, f, str(i + 1)))
                m.add_measurement(OBJECTS_NAME, feature, v)
        feature = "_".join((S.C_WORM, S.F_LENGTH))
        m.add_measurement(OBJECTS_NAME, feature, lengths)

        image_set_list = cpi.ImageSetList()
        image_set = image_set_list.get_image_set(0)
        image_set.add(IMAGE_NAME, cpi.Image(image, mask))

        if auximage is not None:
            image_set.add(AUX_IMAGE_NAME, cpi.Image(auximage))
            module.add_image()
            module.images[1].image_name.value = AUX_IMAGE_NAME
            module.images[1].straightened_image_name.value = AUX_STRAIGHTENED_IMAGE_NAME

        object_set = cpo.ObjectSet()
        objects = cpo.Objects()
        labels = np.zeros(image.shape, int)
        for i in range(control_points.shape[2]):
            if lengths[i] == 0:
                continue
            self.rebuild_worm_from_control_points_approx(
                control_points[:, :, i], radii, labels, i + 1
            )
        objects.segmented = labels

        object_set.add_objects(objects, OBJECTS_NAME)

        workspace = cpw.Workspace(
            pipeline, module, image_set, object_set, m, image_set_list
        )
        return workspace, module
Exemple #16
0
    def run_group_request(self, session_id, message_type, message):
        '''Handle a run-group request message'''
        pipeline = cpp.Pipeline()
        m = cpmeas.Measurements()
        image_group = m.hdf5_dict.hdf5_file.create_group("ImageData")
        if len(message) < 2:
            self.raise_cellprofiler_exception(session_id,
                                              "Missing run request sections")
            return
        pipeline_txt = message.pop(0).bytes
        image_metadata = message.pop(0).bytes
        n_image_sets = None
        try:
            image_metadata = json.loads(image_metadata)
            channel_names = []
            for channel_name, channel_metadata in image_metadata:
                channel_names.append(channel_name)
                if len(message) < 1:
                    self.raise_cellprofiler_exception(
                        session_id,
                        "Missing binary data for channel %s" % channel_name)
                    return None, None, None
                pixel_data = self.decode_image(channel_metadata,
                                               message.pop(0).bytes,
                                               grouping_allowed=True)
                if pixel_data.ndim < 3:
                    self.raise_cellprofiler_exception(
                        session_id,
                        "The image for channel %s does not have a Z or T dimension"
                    )
                    return
                if n_image_sets is None:
                    n_image_sets = pixel_data.shape[0]
                elif n_image_sets != pixel_data.shape[0]:
                    self.raise_cellprofiler_exception(
                        session_id,
                        "The images passed have different numbers of Z or T planes"
                    )
                    return
                image_group.create_dataset(channel_name, data=pixel_data)
        except Exception as e:
            self.raise_cellprofiler_exception(session_id, e.message)
            return None, None, None
        try:
            pipeline.loadtxt(StringIO(pipeline_txt))
        except Exception as e:
            logger.warning(
                "Failed to load pipeline: sending pipeline exception",
                exc_info=1)
            self.raise_pipeline_exception(session_id, str(e))
            return

        image_numbers = np.arange(1, n_image_sets + 1)
        for image_number in image_numbers:
            m[cpmeas.IMAGE, cpmeas.GROUP_NUMBER, image_number] = 1
            m[cpmeas.IMAGE, cpmeas.GROUP_INDEX, image_number] = image_number
        input_modules, other_modules = self.split_pipeline(pipeline)
        workspace = cpw.Workspace(pipeline, None, m, None, m, None)
        logger.info("Preparing group")
        for module in other_modules:
            module.prepare_group(
                workspace, dict([("image_number", i) for i in image_numbers]),
                image_numbers)

        for image_index in range(n_image_sets):
            object_set = cpo.ObjectSet()
            m.next_image_set(image_index + 1)
            for channel_name in channel_names:
                dataset = image_group[channel_name]
                pixel_data = dataset[image_index]
                m.add(channel_name, cpi.Image(pixel_data))

            for module in other_modules:
                workspace = cpw.Workspace(pipeline, module, m, object_set, m,
                                          None)
                try:
                    logger.info("Running module # %d: %s" %
                                (module.module_num, module.module_name))
                    pipeline.run_module(module, workspace)
                    if workspace.disposition in \
                            (cpw.DISPOSITION_SKIP, cpw.DISPOSITION_CANCEL):
                        break
                except Exception as e:
                    msg = "Encountered error while running module, \"%s\": %s" % (
                        module.module_name, e.message)
                    logger.warning(msg, exc_info=1)
                    self.raise_cellprofiler_exception(session_id, msg)
                    return
            else:
                continue
            if workspace.disposition == cpw.DISPOSITION_CANCEL:
                break
        for module in other_modules:
            module.post_group(
                workspace, dict([("image_number", i) for i in image_numbers]))
        logger.info("Finished group")

        type_names, feature_dict = self.find_measurements(
            other_modules, pipeline)

        double_features = []
        double_data = []
        float_features = []
        float_data = []
        int_features = []
        int_data = []
        string_features = []
        string_data = []
        metadata = [
            double_features, float_features, int_features, string_features
        ]

        for object_name, features in feature_dict.items():
            df = []
            double_features.append((object_name, df))
            ff = []
            float_features.append((object_name, ff))
            intf = []
            int_features.append((object_name, intf))
            sf = []
            string_features.append((object_name, sf))
            if object_name == cpmeas.IMAGE:
                object_counts = [] * n_image_sets
            else:
                object_numbers = m[object_name, cpmeas.OBJECT_NUMBER,
                                   image_numbers]
                object_counts = [len(x) for x in object_numbers]
            for feature, data_type in features:
                if data_type == 'java.lang.String':
                    continue
                if not m.has_feature(object_name, feature):
                    data = np.zeros(np.sum(object_counts))
                else:
                    data = m[object_name, feature, image_numbers]
                temp = []
                for i, (di, count) in enumerate(zip(data, object_counts)):
                    if count == 0:
                        continue
                    di = np.atleast_1d(di)
                    if len(di) > count:
                        di = di[:count]
                    elif len(di) == count:
                        temp.append(di)
                    else:
                        temp += [di + np.zeros(len(di) - count)]
                if len(temp) > 0:
                    data = np.hstack(temp)

                if type_names[data_type] == 'java.lang.Double':
                    df.append((feature, len(data)))
                    if len(data) > 0:
                        double_data.append(data.astype("<f8"))
                elif type_names[data_type] == 'java.lang.Float':
                    ff.append((feature, len(data)))
                    if len(data) > 0:
                        float_data.append(data.astype('<f4'))
                elif type_names[data_type] == 'java.lang.Integer':
                    intf.append((feature, len(data)))
                    if len(data) > 0:
                        int_data.append(data.astype('<i4'))
        data = np.hstack([
            np.frombuffer(
                np.ascontiguousarray(np.hstack(ditem)).data, np.uint8)
            for ditem in (double_data, float_data, int_data) if len(ditem) > 0
        ])
        data = np.ascontiguousarray(data)
        self.socket.send_multipart([
            zmq.Frame(session_id),
            zmq.Frame(),
            zmq.Frame(RUN_REPLY_1),
            zmq.Frame(json.dumps(metadata)),
            zmq.Frame(data)
        ])
Exemple #17
0
    def test_01_02_load_v2(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:10891

StraightenWorms:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D]
    Select the input untangled worm objects:OverlappingWorms
    Name the output straightened worm objects:StraightenedWorms
    Worm width:20
    Training set file location:Default Input Folder\x7CNone
    Training set file name:TrainingSet.mat
    Image count:1
    Measure intensity distribution?:Yes
    Number of segments:4
    Align worms?:Top brightest
    Alignment image:Brightfield
    Select an input image to straighten:Brightfield
    Name the output straightened image:StraightenedImage

StraightenWorms:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D]
    Select the input untangled worm objects:OverlappingWorms
    Name the output straightened worm objects:StraightenedWorms
    Worm width:20
    Training set file location:Default Input Folder\x7CNone
    Training set file name:TrainingSet.mat
    Image count:1
    Measure intensity distribution?:Yes
    Number of segments:4
    Align worms?:Bottom brightest
    Alignment image:Brightfield
    Select an input image to straighten:Brightfield
    Name the output straightened image:StraightenedImage

StraightenWorms:[module_num:3|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D]
    Select the input untangled worm objects:OverlappingWorms
    Name the output straightened worm objects:StraightenedWorms
    Worm width:20
    Training set file location:Default Input Folder\x7CNone
    Training set file name:TrainingSet.mat
    Image count:1
    Measure intensity distribution?:Yes
    Number of segments:4
    Align worms?:Do not align
    Alignment image:Brightfield
    Select an input image to straighten:Brightfield
    Name the output straightened image:StraightenedImage
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO(data))
        self.assertEqual(len(pipeline.modules()), 3)
        for alignment, module in zip(
            (S.FLIP_TOP, S.FLIP_BOTTOM, S.FLIP_NONE), pipeline.modules()
        ):
            self.assertTrue(isinstance(module, S.StraightenWorms))
            self.assertEqual(module.objects_name, "OverlappingWorms")
            self.assertEqual(module.straightened_objects_name, "StraightenedWorms")
            self.assertEqual(module.width, 20)
            self.assertEqual(
                module.training_set_directory.dir_choice, cps.DEFAULT_INPUT_FOLDER_NAME
            )
            self.assertEqual(module.training_set_file_name, "TrainingSet.mat")
            self.assertEqual(len(module.images), 1)
            self.assertTrue(module.wants_measurements)
            self.assertEqual(module.number_of_segments, 4)
            self.assertEqual(module.number_of_stripes, 1)
            self.assertEqual(module.flip_worms, alignment)
            self.assertEqual(module.flip_image, "Brightfield")
            self.assertEqual(module.images[0].image_name, "Brightfield")
            self.assertEqual(
                module.images[0].straightened_image_name, "StraightenedImage"
            )
Exemple #18
0
    def test_01_02_load_v1(self):
        data = ('eJztnN1u2zYUgCnnB806tO52sWG90cUGNFtiyGmyNsGQ2km2xVudGk3Qoii6'
                'jLHpmIMkGhKVxhsK7HKPtUfYY+xyjzBRliyJUSJZlpXIoQDBOjQ/Hp6jQ1LU'
                'D5v1o+f1HXmjosjN+tFqF6tIbqmQdomhbck6XZF3DQQp6shE35KbRJd/slR5'
                'TZGVza319a2qYh8rmyDdJjWa9+yfv1oALNq/d+y95P614MpSYGfyIaIU66fm'
                'ApgHn7vpf9v7K2hgeKKiV1C1kOmr8NIbepccDfqjv5qkY6noAGrBzPZ2YGkn'
                'yDBfdD3Q/buFz5F6iH9HnAletpfoDJuY6C7vls+njvQSyullfvj3K98PEucH'
                'lv4wkM7y7wM//3yE3x4E8pddGesdfIY7FlRlrMHTUS1YeUpMeXOh8ubA3kF9'
                'Iu5pDLfI1X/ROT9tFeFhfWsxfJnj2d5gRjcRNC0DaUinaf344uQ31KaBggJ+'
                'TFOvI3ROV78/h20qa5C2e0n8WgqVUwIHBGTi13HP5xs7ipLovQPCepnctFSK'
                '++ogCz6u3lKIl8BjkMze+RA3b/tZR0nqu8DVl8lVZWVdidC7yPHe5vFL7m9a'
                'vU7cJ+Sj4mMY78ni+yOOZ/IekXVCZctEvh1p7U8bn9PSlzY+Jm2Hl7X/admZ'
                'tb5WjL4vOP8wuaFTpJuYDo6b8NwX2JAyKrcWU+49rlwm1+2rnMMe7KNjdpRs'
                'fP2MK4fJe6gL7S5JdtqbvIcNu9UQYzBT8c7rW6soqbhqBJe2nuNwtZh63gXh'
                '88rkF9S05B9VcgLVifWP66fHGfr3JsbPpHFw3eNh3v5Nc72qVBRnW6m6B4Hy'
                'xLiYrZ22r6vTHBeD88CyKwfGRQT1iwNjkrj5lCuXyf642EIG1hBFRqRfbkK/'
                'vcTVfynolwz0j9vO13Put6Pm47Ps340p+5efL1anbB/fb1WV67+eTzuejTMe'
                'TMs+/vw9ieCmGZ/fThiff8ZwP4Nwe2TyL4+etb5jN3DRduWb5WMmvUaq+pK8'
                '335bX229W/ZSdolqafr2W2V1890f1ZW1D8PMh9gmncTlSLtnad7yZMLz04vh'
                'noLw+WEy8/EbBA3X8esflldZUpPotOemrblpe3Dgp0yzX8/zfs2sc3nH+axz'
                'wp/ZcsKf2XJJ/Klc032uInJ5XzfOOpf3/ZFZ50T/mS2XrP/cuPZ63mSuBq72'
                'Z9TzjKP3RG6r0DTdN0CKZG/e3D642r9R99tfI3zaY69NnbEXhPQ2KqDdNy2O'
                'o+apPxADnRrE0jvFs7f3pc9JHMfS+fe98vSr83IYc2w//3Ki+iviPG/zCyrS'
                'ec6z3wn4ScZ6B/ULaHee4+BtjKtZ52ogmzjIqpyi+E1wghOc4AQnxqsi+E1w'
                't5OrgavjvAzCcc52fx46nBYVyV7BCU5wgpsVbj/ARfXfn4Bw/81kYlEV6+jC'
                'ja0i2S04wQlOcIIrBlcLcJM87yqKvYITnOAEJzjBCW72uH9KPidxnOSWJQXy'
                '/xrQE3X983Ugf9mV20hV+wZh64gZFc1Z7MqsqAR2hqtNVZ7bh43AwlNMTz9G'
                'T43TU7tMjzZcjslRhb0PUyvuIk2O1tHnqpnqxR2kU9wd9A1btUWJBiluVxpu'
                'astOrXupTO95jN4dTu9OjL3DZzjQsCX2pbZn8HCJgtEH3MnPq8LpVy7T34Zq'
                '22LfGtqm9Sq7ntS0pTz1BNcTWIrQE4zrkiuX5x6W7t+/uj0BEG5Hfvv671la'
                'vXPSnCRJF+cXd2N45r+PwcXNuZ8mjdeuH4HL83s239b8/wMM1XyW')
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO(zlib.decompress(base64.b64decode(data))))
        #
        # 2 CalculateMath modules: 4 & 5
        # 4: ImageMeasurement, multiply
        #    Image - Intensity_MaxIntensity_DNA, multiply by 2, raise to 3
        #    Image - Intensity_MeanIntensity_DNA, multiply by 4, raise to 5
        #    multiply by 6 raise to 7
        # 5: ObjectMeasurement, multiply
        #    Nuclei - AreaShape_Area
        #    Nuclei - AreaShape_Perimeter
        #
        self.assertEqual(len(pipeline.modules()), 6)
        module = pipeline.modules()[4]
        module.output_feature_name.value = "ImageMeasurement"
        self.assertEqual(module.operands[0].operand_choice, C.MC_IMAGE)
        self.assertEqual(module.operands[1].operand_choice, C.MC_IMAGE)
        self.assertEqual(module.operands[0].operand_measurement,
                         "Intensity_MaxIntensity_DNA")
        self.assertEqual(module.operands[1].operand_measurement,
                         "Intensity_MeanIntensity_DNA")
        self.assertEqual(module.operands[0].multiplicand, 2)
        self.assertEqual(module.operands[0].exponent, 3)
        self.assertEqual(module.operands[1].multiplicand, 4)
        self.assertEqual(module.operands[1].exponent, 5)
        self.assertEqual(module.final_multiplicand, 6)
        self.assertEqual(module.final_exponent, 7)
        module = pipeline.modules()[5]
        self.assertEqual(module.operands[0].operand_choice, C.MC_OBJECT)
        self.assertEqual(module.operands[1].operand_choice, C.MC_OBJECT)
        self.assertEqual(module.operands[0].object, "Nuclei")
        self.assertEqual(module.operands[1].object, "Nuclei")
        self.assertEqual(module.operands[0].operand_measurement,
                         "AreaShape_Area")
        self.assertEqual(module.operands[1].operand_measurement,
                         "AreaShape_Perimeter")
    def test_04_04_load_v4(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:10908

MeasureImageQuality:[module_num:1|svn_version:\'10368\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D]
    Calculate metrics for which images?:All loaded images
    Image count:1
    Scale count:1
    Threshold count:0
    Select the images to measure:Alpha
    Include the image rescaling value?:Yes
    Calculate blur metrics?:Yes
    Window size for blur measurements:20
    Calculate saturation metrics?:Yes
    Calculate intensity metrics?:Yes
    Calculate thresholds?:Yes
    Use all thresholding methods?:Yes

MeasureImageQuality:[module_num:2|svn_version:\'10368\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D]
    Calculate metrics for which images?:Select...
    Image count:1
    Scale count:1
    Threshold count:1
    Select the images to measure:Alpha
    Include the image rescaling value?:Yes
    Calculate blur metrics?:Yes
    Window size for blur measurements:20
    Calculate saturation metrics?:Yes
    Calculate intensity metrics?:Yes
    Calculate thresholds?:Yes
    Use all thresholding methods?:Yes
    Select a thresholding method:Otsu Global
    Typical fraction of the image covered by objects:0.1
    Two-class or three-class thresholding?:Two classes
    Minimize the weighted variance or the entropy?:Weighted variance
    Assign pixels in the middle intensity class to the foreground or the background?:Foreground

MeasureImageQuality:[module_num:3|svn_version:\'10368\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D]
    Calculate metrics for which images?:Select...
    Image count:1
    Scale count:1
    Threshold count:1
    Select the images to measure:Delta,Beta
    Include the image rescaling value?:Yes
    Calculate blur metrics?:Yes
    Window size for blur measurements:20
    Calculate saturation metrics?:Yes
    Calculate intensity metrics?:Yes
    Calculate thresholds?:Yes
    Use all thresholding methods?:Yes
    Select a thresholding method:Otsu Global
    Typical fraction of the image covered by objects:0.1
    Two-class or three-class thresholding?:Three classes
    Minimize the weighted variance or the entropy?:Weighted variance
    Assign pixels in the middle intensity class to the foreground or the background?:Foreground

MeasureImageQuality:[module_num:4|svn_version:\'10368\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D]
    Calculate metrics for which images?:Select...
    Image count:2
    Scale count:1
    Scale count:1
    Threshold count:1
    Threshold count:1
    Select the images to measure:Delta
    Include the image rescaling value?:Yes
    Calculate blur metrics?:Yes
    Window size for blur measurements:20
    Calculate saturation metrics?:Yes
    Calculate intensity metrics?:Yes
    Calculate thresholds?:Yes
    Use all thresholding methods?:No
    Select a thresholding method:Otsu Global
    Typical fraction of the image covered by objects:0.1
    Two-class or three-class thresholding?:Two classes
    Minimize the weighted variance or the entropy?:Weighted variance
    Assign pixels in the middle intensity class to the foreground or the background?:Foreground
    Select the images to measure:Epsilon
    Include the image rescaling value?:Yes
    Calculate blur metrics?:Yes
    Window size for blur measurements:20
    Calculate saturation metrics?:Yes
    Calculate intensity metrics?:Yes
    Calculate thresholds?:Yes
    Use all thresholding methods?:Yes
    Select a thresholding method:Otsu Global
    Typical fraction of the image covered by objects:0.1
    Two-class or three-class thresholding?:Two classes
    Minimize the weighted variance or the entropy?:Weighted variance
    Assign pixels in the middle intensity class to the foreground or the background?:Foreground

MeasureImageQuality:[module_num:5|svn_version:\'10368\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D]
    Calculate metrics for which images?:Select...
    Image count:1
    Scale count:2
    Threshold count:2
    Select the images to measure:Zeta
    Include the image rescaling value?:Yes
    Calculate blur metrics?:Yes
    Window size for blur measurements:20
    Window size for blur measurements:30
    Calculate saturation metrics?:Yes
    Calculate intensity metrics?:Yes
    Calculate thresholds?:Yes
    Use all thresholding methods?:No
    Select a thresholding method:Otsu Global
    Typical fraction of the image covered by objects:0.1
    Two-class or three-class thresholding?:Two classes
    Minimize the weighted variance or the entropy?:Weighted variance
    Assign pixels in the middle intensity class to the foreground or the background?:Foreground
    Select a thresholding method:Otsu Global
    Typical fraction of the image covered by objects:0.1
    Two-class or three-class thresholding?:Three classes
    Minimize the weighted variance or the entropy?:Weighted variance
    Assign pixels in the middle intensity class to the foreground or the background?:Foreground
"""
        pipeline = cpp.Pipeline()
        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))
        pipeline.add_listener(callback)
        pipeline.load(StringIO.StringIO(data))
        self.assertEqual(len(pipeline.modules()), 5)
        for module in pipeline.modules():
            self.assertTrue(isinstance(module, miq.MeasureImageQuality))
        
        module = pipeline.modules()[0]
        self.assertEqual(len(module.image_groups),1)
        group = module.image_groups[0]
        self.assertEqual(group.threshold_groups, [])
        self.assertEqual(module.images_choice, miq.O_ALL_LOADED)
        self.assertTrue(group.check_blur)
        self.assertEqual(group.scale_groups[0].scale, 20)
        self.assertTrue(group.check_saturation)
        self.assertTrue(group.check_intensity)
        self.assertTrue(group.calculate_threshold)
        self.assertTrue(group.use_all_threshold_methods)
        
        module = pipeline.modules()[1]
        self.assertEqual(len(module.image_groups),1)
        group = module.image_groups[0]
        self.assertEqual(module.images_choice, miq.O_SELECT)
        self.assertEqual(group.image_names, "Alpha")
        
        module = pipeline.modules()[2]
        self.assertEqual(len(module.image_groups),1)
        group = module.image_groups[0]
        self.assertEqual(module.images_choice, miq.O_SELECT)
        self.assertEqual(group.image_names, "Delta,Beta")
        
        module = pipeline.modules()[3]
        self.assertEqual(len(module.image_groups),2)
        group = module.image_groups[0]
        self.assertEqual(module.images_choice, miq.O_SELECT)
        self.assertEqual(group.image_names, "Delta")
        self.assertTrue(group.check_intensity)
        self.assertFalse(group.use_all_threshold_methods)
        thr = group.threshold_groups[0]
        self.assertEqual(thr.threshold_method, miq.cpthresh.TM_OTSU)
        self.assertEqual(thr.use_weighted_variance, miq.O_WEIGHTED_VARIANCE)
        self.assertEqual(thr.two_class_otsu, miq.O_TWO_CLASS)
        group = module.image_groups[1]
        self.assertEqual(group.image_names, "Epsilon")
        
        module = pipeline.modules()[4]
        self.assertEqual(len(module.image_groups),1)
        group = module.image_groups[0]
        self.assertEqual(module.images_choice, miq.O_SELECT)
        self.assertEqual(group.image_names, "Zeta")
        self.assertFalse(group.use_all_threshold_methods)
        thr = group.threshold_groups[0]
        self.assertEqual(thr.threshold_method, miq.cpthresh.TM_OTSU)
        self.assertEqual(thr.use_weighted_variance, miq.O_WEIGHTED_VARIANCE)
        self.assertEqual(thr.two_class_otsu, miq.O_TWO_CLASS)
        thr = group.threshold_groups[1]
        self.assertEqual(thr.threshold_method, miq.cpthresh.TM_OTSU)
        self.assertEqual(thr.use_weighted_variance, miq.O_WEIGHTED_VARIANCE)
        self.assertEqual(thr.two_class_otsu, miq.O_THREE_CLASS)
        self.assertEqual(thr.assign_middle_to_foreground, miq.O_FOREGROUND)
Exemple #20
0
    def test_01_01_load_matlab(self):
        data = ('eJwBTgSx+01BVExBQiA1LjAgTUFULWZpbGUsIFBsYXRmb3JtOiBQQ1dJTiwg'
                'Q3JlYXRlZCBvbjogRnJpIEp1bCAxNyAxNjoxNzoxNyAyMDA5ICAgICAgICAg'
                'ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAAAUlN'
                'DwAAAMYDAAB4nOxYT2/TMBR3t3ZsIFWDCYljDhw4bCUZTNqRwSbooS1i1SSO'
                'buplRm5cJc7U8sk48pH4CMRZ0iYmm/PHaVo0S9bTc/x+fv/sZ6cNADh9DcCO'
                'T3f9vgXuWivkG7HO+UvEGLYttwWa4FU4/tvvV9DBcETQFSQecsGiReNd+5oO'
                '59PFpx4dewT14SQ+2W99bzJCjju4jgTDz1/xDJFL/BOBZIumfUO32MXUDuVD'
                'fHF0sS5lwrptv/96ufRDQ/ADHz+IjfP5H8ByfjPFb/ux+fthH6IZO7qYQZNp'
                'E8jMG45zKsHZFXA4P3Cw9dF39SbItwR5zncn0EKhH2XyO4I85/ueSRDOFodn'
                'gjznP91A20bk+Eg3gnGOo0twGgmcRjBfhf5V278nyHO+azNku5jNw3GVOGXz'
                'KW8cjIzrpuWhoR++j+Ios/+pIM/5c6rZlGmei7L7sS3gcH5IGSQxZ/KxLxKc'
                'AwGH8xzCciBD42RkVNpXdJ/I5LYTctvgu39Gq9S77nNSlR0RlflzK4G3Bfq0'
                '3jwwSsqt2n9152PddTOvP2V4aXV4wFxP+0zoCJLMOKrO4VXXRVV2RbToPipj'
                'V1CnzhwEc+Ck3YN7cLZw0cXYquV8FPe3fmgk5OuuF3nj+y6n/c2EfBPoHd1Q'
                'kV/rcr7L8LLu26z+uK/eFpWT3f+eC/pzHttjfIvHHiQa5qUieuXW6RfVeVLU'
                'n2XsP/MY9R/s2NwA+0W5Dvg/7D8uob//Jpq7JiTR/yMV98Cq7RfzuHOiRl+Z'
                '//Kes0Xuoef8lEJq5Ks+D1T744mAx/nuxOohWPx9MRj9QCYLIBZ65M0T+y1U'
                'ui9ktGzcRPpm7+H/t/F6WTb+QXG1HOpNNxcn7T1GgzxaAqnEEWmR+00MV/Pv'
                'Omgaw6tKTxlu2vtmGY87NYvgFtW3qB2q8mHd8vwxPuuNsynxuY9WZV9W/FXv'
                't0daLZXVxRcgGSfOU48RbKN/CuND6/zxQf4CAAD//2NjYGDgAGJGBghgReKz'
                'IYnzAbEDVAwkz4JFPReSegEo3yc/McUzNzE9tRhhjgcBc0TRzAHxfVMTi0uL'
                'UsFGeeaVpOYVZ5ZUUmCeZ0pqXklmWmVAUWauY2lJfm5iSWYykeaJoZknhnCf'
                'f1JWanIJkgOJCTdeNPNAfOfEnOTSnMSSVN/Ekgwiw59YcyyQzGHDYg5yvDNB'
                '+UIswuyCghD9BgTcwciA7A5GBkMK7GVl4mFiY8P0PyH9IHfxAHGMzCYZfxlt'
                'mbfSb6UZoO7wYESYQ0y612DArR4GRqp6ALPX4U6p2wdz')
        pipeline = cpp.Pipeline()
        # def callback(caller,event):
        #    self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))
        # pipeline.add_listener(callback)
        pipeline.load(StringIO(zlib.decompress(base64.b64decode(data))))
        #
        # 6 modules: last two are CalculateMath
        #
        # 1) Image: Intensity_TotalIntensity_OrigBlue
        #    Image: Intensity_TotalArea_OrigBlue
        #    Divide
        #    ImgMeas
        # 2) Nuclei: Intensity_IntegratedIntensity_OrigBlue
        #    Nuclei: Intensity_MaxIntensity_OrigBlue
        #    Exponent = 2, multiplier = .5
        #    Divide
        #    ObjectMeas
        #
        self.assertEqual(len(pipeline.modules()), 6)
        module = pipeline.modules()[4]
        self.assertTrue(isinstance(module, C.CalculateMath))
        self.assertEqual(module.output_feature_name.value, "ImgMeas")
        self.assertEqual(module.operation.value, C.O_DIVIDE)
        self.assertEqual(module.operands[0].operand_choice, C.MC_IMAGE)
        self.assertEqual(module.operands[1].operand_choice, C.MC_IMAGE)
        self.assertEqual(module.operands[0].operand_measurement.value,
                         "Intensity_TotalIntensity_OrigBlue")
        self.assertEqual(module.operands[1].operand_measurement.value,
                         "Intensity_TotalArea_OrigBlue")

        module = pipeline.modules()[5]
        self.assertTrue(isinstance(module, C.CalculateMath))
        self.assertEqual(module.output_feature_name.value, "ObjectMeas")
        self.assertEqual(module.operation.value, C.O_DIVIDE)
        self.assertEqual(module.operands[0].operand_choice, C.MC_OBJECT)
        self.assertEqual(module.operands[1].operand_choice, C.MC_OBJECT)
        self.assertEqual(module.operands[0].operand_objects, "Nuclei")
        self.assertEqual(module.operands[1].operand_objects, "Nuclei")
        self.assertEqual(module.operands[0].operand_measurement.value,
                         "Intensity_IntegratedIntensity_OrigBlue")
        self.assertEqual(module.operands[1].operand_measurement.value,
                         "Intensity_MaxIntensityEdge_OrigBlue")
        self.assertEqual(module.final_exponent.value, 2)
        self.assertEqual(module.final_multiplicand.value, .5)
Exemple #21
0
 def test_03_01_save_and_load(self):
     '''Save a pipeline to batch data, open it to check and load it'''
     data = ('eJztWW1PGkEQXhC1WtPYTzb9tB+llROoGiWNgi9NSYUSIbZGbbvCApvu7ZJ7'
             'UWlj0o/9Wf1J/QndxTs4tsoBRS3JHbkcMzfPPDOzs8uxl8uU9jPbcFWLw1ym'
             'FKsSimGBIqvKDT0FmbUEdwyMLFyBnKVgycYwY9dgIgET8dTqRmolCZPx+AYY'
             '7ghlc0/EJf4cgClxfSTOsHNr0pFDnlPKRWxZhNXMSRABzxz9L3EeIoOgM4oP'
             'EbWx2aFw9VlW5aVmo30rxys2xXmke43Fkbf1M2yY76su0LldIJeYFsk3rKTg'
             'mh3gc2ISzhy841/Vtnm5pfDKOhTmOnUIKXWQdVnw6KX9W9Cxj9xQt6ce+3lH'
             'JqxCzknFRhQSHdXaUbTGwcffRJe/CXAk0BKX9sHNK3HIs4QvrdjeJSpbUEdW'
             'uS79rPv4mVb8SLmcOrGw3ugr/lAXPgRe9Zl3uAsXBnkO+sp7VolXyrscMm5B'
             '28T91/02/lHgphSce7i4GdCJ0y/fOSVfKe9RE1/UsYE1TXP91H38rCh+pCzG'
             'uYwpbRhcLlHGiWXY7OuJaCC9ISZ3q5NdqbhdzLZb+yH4hpmXy3I2ioVtGTFE'
             'myYZxbwcdpzvu68eku8+cGmf/GZAdz9IeaeOGMM0ERtx3P30z24+c6d86jqc'
             'uOP8Il18EdE/DP8L3w8fvnegezyl/Glxq/BaPljhTe1l9LOUPoj15YBfbB5n'
             'YoXTqKvZ4dTW2eZxPLZx+j2xlLy6Ni4SgWwpozfmPUj8fuvhuhK/lGUMRxgZ'
             'TmArV9GYVOU4s+qOLunodlGzo3mgeZMcxbwZir9p8QZFpj4C/kHnUfKO+YJ5'
             'NJ7z6OPsYP8rxuV3NcAFuAAX4P43XNqD63c/pLUZUzO43YCEVXBjnPINcOON'
             'S4OgXwPc8DipvO35Ut2/kfZfQO9+ewG6+03K3s04TW9topsa5ahyvYut7Yuv'
             'Wc+Gdj/P52sKz9ptPOXWK5AzuU8tb5ja9TuRbal4Q1rvCNT6zdzA561DWHwW'
             'pnvXXa13Zxx+bw3DFwn9zffYBxdxKidxP8Fg47zYw97NbVj7P/nFW+E=')
     def callback(caller,event):
         self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))
         self.assertFalse(isinstance(event, cpp.RunExceptionEvent))
     for windows_mode in ((False, True) if sys.platform.startswith("win")
                          else (False,)):
         pipeline = cpp.Pipeline()
         pipeline.add_listener(callback)
         pipeline.load(StringIO(zlib.decompress(base64.b64decode(data))))
         ipath = os.path.join(T.example_images_directory(),'ExampleSBSImages')
         bpath = tempfile.mkdtemp()
         bfile = os.path.join(bpath,C.F_BATCH_DATA)
         hfile = os.path.join(bpath, C.F_BATCH_DATA_H5)
         try:
             li = pipeline.modules()[0]
             self.assertTrue(isinstance(li, LI.LoadImages))
             module = pipeline.modules()[1]
             self.assertTrue(isinstance(module, C.CreateBatchFiles))
             li.location.dir_choice = LI.ABSOLUTE_FOLDER_NAME
             li.location.custom_path = ipath
             module.wants_default_output_directory.value = False
             module.custom_output_directory.value = bpath
             module.remote_host_is_windows.value = windows_mode
             self.assertEqual(len(module.mappings), 1)
             mapping = module.mappings[0]
             mapping.local_directory.value = ipath
             self.assertFalse(pipeline.in_batch_mode())
             measurements = cpmeas.Measurements()
             image_set_list = cpi.ImageSetList()
             result = pipeline.prepare_run(
                 cpw.Workspace(pipeline, None, None, None,
                               measurements, image_set_list))
             self.assertFalse(pipeline.in_batch_mode())
             self.assertFalse(result)
             self.assertFalse(module.batch_mode.value)
             pipeline = cpp.Pipeline()
             pipeline.add_listener(callback)
             fd = open(hfile,'rb')
             try:
                 pipeline.load(fd)
                 fd.seek(0)
             finally:
                 fd.close()
             
             measurements = cpmeas.load_measurements(hfile)
             image_set_list = cpi.ImageSetList()
             self.assertTrue(pipeline.in_batch_mode())
             module = pipeline.modules()[1]
             self.assertTrue(isinstance(module, C.CreateBatchFiles))
             self.assertTrue(module.batch_mode.value)
             image_numbers = measurements.get_image_numbers()
             self.assertTrue([x == i+1 for i, x in enumerate(image_numbers)])
             workspace = cpw.Workspace(pipeline, None, None, None,
                                       measurements, image_set_list)
             pipeline.prepare_run(workspace)
             pipeline.prepare_group(workspace, {}, range(1,97))
             for i in range(96):
                 image_set = image_set_list.get_image_set(i)
                 for image_name in ('DNA', 'Cytoplasm'):
                     pathname = measurements.get_measurement(
                         cpmeas.IMAGE, "PathName_"+image_name, i+1)
                     self.assertEqual(pathname, 
                                      '\\imaging\\analysis' if windows_mode
                                      else '/imaging/analysis')
             del measurements
         finally:
             if os.path.exists(bfile):
                 os.unlink(bfile)
             if os.path.exists(hfile):
                 os.unlink(hfile)
             os.rmdir(bpath)
Exemple #22
0
    def test_load_with_extracted_operations(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:3
DateRevision:20160418141927
GitHash:9969f42
ModuleCount:5
HasImagePlaneDetails:False

Images:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:2|show_window:False|notes:\x5B\'To begin creating your project, use the Images module to compile a list of files and/or folders that you want to analyze. You can also specify a set of rules to include only the desired files in your selected folders.\'\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    :
    Filter images?:Images only
    Select the rule criteria:and (extension does isimage) (directory doesnot containregexp "\x5B\\\\\\\\\\\\\\\\/\x5D\\\\\\\\.")

Metadata:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:4|show_window:False|notes:\x5B\'The Metadata module optionally allows you to extract information describing your images (i.e, metadata) which will be stored along with your measurements. This information can be contained in the file name and/or location, or in an external file.\'\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Extract metadata?:No
    Metadata data type:Text
    Metadata types:{}
    Extraction method count:1
    Metadata extraction method:Extract from file/folder names
    Metadata source:File name
    Regular expression:^(?P<Plate>.*)_(?P<Well>\x5BA-P\x5D\x5B0-9\x5D{2})_s(?P<Site>\x5B0-9\x5D)_w(?P<ChannelNumber>\x5B0-9\x5D)
    Regular expression:(?P<Date>\x5B0-9\x5D{4}_\x5B0-9\x5D{2}_\x5B0-9\x5D{2})$
    Extract metadata from:All images
    Select the filtering criteria:and (file does contain "")
    Metadata file location:
    Match file and image metadata:\x5B\x5D
    Use case insensitive matching?:No

NamesAndTypes:[module_num:3|svn_version:\'Unknown\'|variable_revision_number:6|show_window:False|notes:\x5B\'The NamesAndTypes module allows you to assign a meaningful name to each image by which other modules will refer to it.\'\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Assign a name to:All images
    Select the image type:Grayscale image
    Name to assign these images:DNA
    Match metadata:\x5B\x5D
    Image set matching method:Order
    Set intensity range from:Image metadata
    Assignments count:1
    Single images count:0
    Maximum intensity:255.0
    Select the rule criteria:and (file does contain "")
    Name to assign these images:DNA
    Name to assign these objects:Cell
    Select the image type:Grayscale image
    Set intensity range from:Image metadata
    Retain outlines of loaded objects?:No
    Name the outline image:LoadedOutlines
    Maximum intensity:255.0

Groups:[module_num:4|svn_version:\'Unknown\'|variable_revision_number:2|show_window:False|notes:\x5B\'The Groups module optionally allows you to split your list of images into image subsets (groups) which will be processed independently of each other. Examples of groupings include screening batches, microtiter plates, time-lapse movies, etc.\'\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Do you want to group your images?:No
    grouping metadata count:1
    Metadata category:None

Morph:[module_num:5|svn_version:\'Unknown\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False]
    Select the input image:DNA
    Name the output image:MorphBlue
    Select the operation to perform:bothat
    Number of times to repeat operation:Once
    Repetition number:2
    Diameter:3.0
    Structuring element:Disk
    X offset:1.0
    Y offset:1.0
    Angle:0.0
    Width:3.0
    Height:3.0
    Custom:5,5,1111111111111111111111111
    Rescale values from 0 to 1?:Yes
    Select the operation to perform:close
    Number of times to repeat operation:Once
    Repetition number:2
    Diameter:3.0
    Structuring element:Disk
    X offset:1.0
    Y offset:1.0
    Angle:0.0
    Width:3.0
    Height:3.0
    Custom:5,5,1111111111111111111111111
    Rescale values from 0 to 1?:Yes
    Select the operation to perform:dilate
    Number of times to repeat operation:Once
    Repetition number:2
    Diameter:3.0
    Structuring element:Disk
    X offset:1.0
    Y offset:1.0
    Angle:0.0
    Width:3.0
    Height:3.0
    Custom:5,5,1111111111111111111111111
    Rescale values from 0 to 1?:Yes
    Select the operation to perform:erode
    Number of times to repeat operation:Once
    Repetition number:2
    Diameter:3.0
    Structuring element:Disk
    X offset:1.0
    Y offset:1.0
    Angle:0.0
    Width:3.0
    Height:3.0
    Custom:5,5,1111111111111111111111111
    Rescale values from 0 to 1?:Yes
    Select the operation to perform:fill small holes
    Number of times to repeat operation:Once
    Maximum hole area:2
    Diameter:3.0
    Structuring element:Disk
    X offset:1.0
    Y offset:1.0
    Angle:0.0
    Width:3.0
    Height:3.0
    Custom:5,5,1111111111111111111111111
    Rescale values from 0 to 1?:Yes
    Select the operation to perform:invert
    Number of times to repeat operation:Once
    Repetition number:2
    Diameter:3.0
    Structuring element:Disk
    X offset:1.0
    Y offset:1.0
    Angle:0.0
    Width:3.0
    Height:3.0
    Custom:5,5,1111111111111111111111111
    Rescale values from 0 to 1?:Yes
    Select the operation to perform:open
    Number of times to repeat operation:Once
    Repetition number:2
    Diameter:3.0
    Structuring element:Disk
    X offset:1.0
    Y offset:1.0
    Angle:0.0
    Width:3.0
    Height:3.0
    Custom:5,5,1111111111111111111111111
    Rescale values from 0 to 1?:Yes
    Select the operation to perform:skel
    Number of times to repeat operation:Once
    Repetition number:2
    Diameter:3.0
    Structuring element:Disk
    X offset:1.0
    Y offset:1.0
    Angle:0.0
    Width:3.0
    Height:3.0
    Custom:5,5,1111111111111111111111111
    Rescale values from 0 to 1?:Yes
    Select the operation to perform:tophat
    Number of times to repeat operation:Once
    Repetition number:2
    Diameter:3.0
    Structuring element:Disk
    X offset:1.0
    Y offset:1.0
    Angle:0.0
    Width:3.0
    Height:3.0
    Custom:5,5,1111111111111111111111111
    Rescale values from 0 to 1?:Yes
"""

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline = cpp.Pipeline()
        pipeline.add_listener(callback)
        pipeline.load(io.StringIO(data))

        module = pipeline.modules()[-1]
        with pytest.raises(cps.ValidationError):
            module.test_valid(pipeline)
Exemple #23
0
    def test_01_01_load_v1(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:10268

UnmixColors:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D]
    Stain count:13
    Color image\x3A:Color
    Image name\x3A:Hematoxylin
    Stain:Hematoxylin
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:Eosin
    Stain:Eosin
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:DAB
    Stain:DAB
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:FastRed
    Stain:Fast red
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:FastBlue
    Stain:Fast blue
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:MethylGreen
    Stain:Methyl green
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:AEC
    Stain:AEC
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name:AnilineBlue
    Stain:Aniline blue
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:Azocarmine
    Stain:Azocarmine
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:AlicanBlue
    Stain:Alican blue
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:PAS
    Stain:PAS
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:HematoxylinAndPAS
    Stain:Hematoxylin and PAS
    Red absorbance\x3A:0.5
    Green absorbance\x3A:0.5
    Blue absorbance\x3A:0.5
    Image name\x3A:RedWine
    Stain:Custom
    Red absorbance\x3A:0.1
    Green absorbance\x3A:0.2
    Blue absorbance\x3A:0.3
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO(data))
        self.assertEqual(len(pipeline.modules()), 1)
        module = pipeline.modules()[0]
        self.assertTrue(isinstance(module, U.UnmixColors))
        self.assertEqual(module.input_image_name, "Color")
        self.assertEqual(module.stain_count.value, 13)
        self.assertEqual(module.outputs[0].image_name, "Hematoxylin")
        self.assertEqual(module.outputs[-1].image_name, "RedWine")
        for i, stain in enumerate((
                U.CHOICE_HEMATOXYLIN, U.CHOICE_EOSIN, U.CHOICE_DAB,
                U.CHOICE_FAST_RED, U.CHOICE_FAST_BLUE, U.CHOICE_METHYL_GREEN,
                U.CHOICE_AEC, U.CHOICE_ANILINE_BLUE, U.CHOICE_AZOCARMINE,
                U.CHOICE_ALICAN_BLUE, U.CHOICE_PAS)):
            self.assertEqual(module.outputs[i].stain_choice, stain)
        self.assertAlmostEqual(module.outputs[-1].red_absorbance.value, .1)
        self.assertAlmostEqual(module.outputs[-1].green_absorbance.value, .2)
        self.assertAlmostEqual(module.outputs[-1].blue_absorbance.value, .3)
Exemple #24
0
    def test_01_03_load_v2(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:10016

Morph:[module_num:1|svn_version:\'9935\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D]
    Select the input image:InputImage
    Name the output image:MorphImage
    Select the operation to perform:branchpoints
    Repeat operation:Forever
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:bridge
    Repeat operation:Custom
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:clean
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:convex hull
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:diag
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:distance
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:endpoints
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:fill
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:hbreak
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:majority
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:remove
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:shrink
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:skelpe
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:spur
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:thicken
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:thin
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
    Select the operation to perform:vbreak
    Repeat operation:Once
    Custom # of repeats:2
    Scale\x3A:3
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(io.StringIO(data))
        ops = [
            morph.F_BRANCHPOINTS,
            morph.F_BRIDGE,
            morph.F_CLEAN,
            morph.F_CONVEX_HULL,
            morph.F_DIAG,
            morph.F_DISTANCE,
            morph.F_ENDPOINTS,
            morph.F_FILL,
            morph.F_HBREAK,
            morph.F_MAJORITY,
            morph.F_REMOVE,
            morph.F_SHRINK,
            morph.F_SKELPE,
            morph.F_SPUR,
            morph.F_THICKEN,
            morph.F_THIN,
            morph.F_VBREAK,
        ]
        self.assertEqual(len(pipeline.modules()), 1)
        module = pipeline.modules()[0]
        self.assertTrue(isinstance(module, morph.Morph))
        self.assertEqual(module.image_name, "InputImage")
        self.assertEqual(module.output_image_name, "MorphImage")
        self.assertEqual(len(module.functions), len(ops))
    def test_01_04_load_v2(self):
        data = ('eJztne9z2jYYxwUhXdPe7dJtL/qmN7/a7XrEA5bs0rwZ+VEW7kLCDa5rX6WO'
                'LUA7I3G2nIT91fkTZoEdG8XExtgGU3EhIOHP80hfP5L1iBBax92L4xPpQK5I'
                'rePuXg/pUGrrCu0RY3gkYVqWTg2oUKhJBB9JLYKlM6hKtapUPTiq/XG0/0Gq'
                'VSofQLxbodn63n5o9wF4YT++tO9F56Vtp1zw3Vm5AylFuG9ugxJ469Q/2PdP'
                'ioGUGx1+UnQLmp4Lt76Je6Q7Hj2+1CKapcNLZeg/2L5dWsMbaJhXPRd0Xm6j'
                'e6h30H+Q64J72N/wFpmIYId37PO1j34J5fx2BuSuYdjN4eyfKFQddKh9Bmbr'
                'mW4PFU+3Aqcbe3zvq2fHnwPv+FKAzm98x+86ZYQ1dIs0S9ElNFT6j61m9g5D'
                '7L3k7LHylYH6J/YpYnwlhC/M8AVQjdiPHzi/rNyxg8YO7SFUTMuAQ4hpdF1+'
                '4uyxcltBhkR6foOma68eYm+Xs8fuXXhP9z7eKyqVhuyUR9H3BWeHlS8tVYdo'
                'Neen5vQ/7nldlPsdROvnNtdPVq5WyvuViPyyOofxYf0uzfAlcEkwjBJnrzi/'
                'rHxGJEyoZJnOfBLF/9aMnS3wxZ4FeO4Fx7k3l9sBnr/PIf5+4drNyk1MITYR'
                'HV+zZ32DXZK8Ojdql9MzjCvOcEWbi+YvCreIfnHmv4+3EOtjyRwpqn0tv0HY'
                'XJ29oPn0DPYUS6dSk11kpAbRNWi49rKOz7jzUFbzngyiXWdeczqz8hU1Lekv'
                'ndwoemB/k9SJPy8VuRarv+48ndb4jHJe0tQlKF6T5OLq8uT8lasZx8thquMq'
                'ri789aMiV6p5jZdF2lkP8bcz429afrxGz+lvqvETEK+LcHHWz6cDBWOo1/Ko'
                '17LzSdr5Bu+3WllOn3aIv5+59rJyAxkmLXegSrBW7g6QoZUbxDLooNxAPTpY'
                'av25bLwtOk8egHzFV1rr+qznyaD8/1RXTBP1ENSmmWGSdtLSLQq3iG55zcOz'
                'jq8485aXK7eU+4DEOe7+4AVRFYoIvj6FtlHj+rOvnaucV5LMp3/k+s3Kp5ZJ'
                'yXBPgz2E/Qlw3DhsQQ0pOF+6pbUuf5oHHGScd1RW4i+J8fdlTjuSvH6t276C'
                'G8dxxt10HKfb3qT3/xbVpxoQz9Hicn+j5qM016Npxos9/S3lL05eIdfK8kFZ'
                'PozCf8fxrKyTu2v7nvk81L0jksrWwNC7Hmc9ruPozfQaoP4gzXVM0PXjH2g7'
                'ZW/v37I3srEK5/Q/Sd2SzH+ZZizQ0oyzoPfRGsSAfYNYWEtfr3lxFtbuoP2l'
                'iV7s1xz/6zy/h/U3qXw46/k+6X2ZdciD4+qTNbfp/UtTlxZU8KrbuQ66JL1e'
                'yyMnxlEwJ8ZRMCfGUTCX9Xpknbk465gLcmf/5KufaekTlJef20v/iyXz8rxw'
                'cfSxtWES5aqfWe4LMXHOl9ynyCMn5mWPq4PndYmThy/U7t88rsBx7JH/3EOW'
                '+0KTD0mwjaHR8v7zwp2D53UK2nckN/9ClU6EkhDW4Mhnrx5iT+gef3/cp/va'
                '2smL/oITnOAEJzjBCU5wgnueq/u4qHmjt66fpgl56q/gvk2uDpKJ86TsrLof'
                'm5Lf5iX+BCc4wX07XN3Hif1SwQlOcIITnOAEt075XF64Onhep6TyTqG34AQn'
                'OMEJTnCCE5zgBCc4wW0mV/dxq8gHB0WPK3BcwXle8B3/NaS9/r+z33XKKtT1'
                'kUHY90gY8nDyZQemrBNFm357gHxhP236vkiA+RmF+Klzfurz/CANYop645Fh'
                'e7MoGSoUqXLTqW3btcduLfN7H+L3hPN7Ms+v8yUA0z0A5P5zNbk1rb6aVHP/'
                '2HNyPkL873P+9+f5V6cfrhhPG2DKzoctxlPP5qr8+T9ftBPgzx9vRaf85t3W'
                '+3fg+XEGwGx8e3H/8Gdcv6XSVrEIno7T1yE80/EVeHpjdt4WFhtvv4L5x7t9'
                '3qTj45ynAruB5fX1/JUe2+b62YTj/wfn4gog')
        pipeline = cpp.Pipeline()
        def callback(caller,event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))
        pipeline.add_listener(callback)
        pipeline.load(StringIO(zlib.decompress(base64.b64decode(data))))        
        self.assertEqual(len(pipeline.modules()),5)
        module = pipeline.modules()[-2]
        self.assertTrue(isinstance(module, C.ClassifyObjects))
        self.assertEqual(module.contrast_choice.value, C.BY_SINGLE_MEASUREMENT)
        self.assertEqual(len(module.single_measurements), 2)
        
        group = module.single_measurements[0]
        self.assertEqual(group.object_name, "Nuclei")
        self.assertEqual(group.measurement.value, "Intensity_IntegratedIntensity_OrigBlue")
        self.assertEqual(group.bin_choice, C.BC_EVEN)
        self.assertEqual(group.bin_count, 3)
        self.assertAlmostEqual(group.low_threshold.value, 0.2)
        self.assertTrue(group.wants_low_bin)
        self.assertAlmostEqual(group.high_threshold.value, 0.8)
        self.assertTrue(group.wants_high_bin)
        self.assertTrue(group.wants_custom_names)
        for name, expected in zip(group.bin_names.value.split(','),
                                  ('First','Second','Third','Fourth','Fifth')):
            self.assertEqual(name, expected)
        self.assertTrue(group.wants_images)
        self.assertEqual(group.image_name, "ClassifiedNuclei")
        
        group = module.single_measurements[1]
        self.assertEqual(group.object_name, "Nuclei")
        self.assertEqual(group.measurement.value, "Intensity_MaxIntensity_OrigBlue")
        self.assertEqual(group.bin_choice, C.BC_CUSTOM)
        self.assertEqual(group.custom_thresholds, ".2,.5,.8")
        self.assertFalse(group.wants_custom_names)
        self.assertFalse(group.wants_images)

        module = pipeline.modules()[-1]
        self.assertTrue(isinstance(module, C.ClassifyObjects))
        self.assertEqual(module.contrast_choice, C.BY_TWO_MEASUREMENTS)
        self.assertEqual(module.object_name, "Nuclei")
        self.assertEqual(module.first_measurement, "Location_Center_X")
        self.assertEqual(module.first_threshold_method, C.TM_MEDIAN)
        self.assertEqual(module.second_measurement, "Location_Center_Y")
        self.assertEqual(module.second_threshold_method, C.TM_CUSTOM)
        self.assertAlmostEqual(module.second_threshold.value, .4)
Exemple #26
0
    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)
    def test_2_5_load_v2(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:10308

ColorToGray:[module_num:1|svn_version:\'10300\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D]
    Select the input image:DNA
    Conversion method:Combine
    Image type\x3A:Channels
    Name the output image:OrigGrayw
    Relative weight of the red channel:1
    Relative weight of the green channel:3
    Relative weight of the blue channel:5
    Convert red to gray?:Yes
    Name the output image:OrigRedx
    Convert green to gray?:Yes
    Name the output image:OrigGreeny
    Convert blue to gray?:Yes
    Name the output image:OrigBluez
    Channel count:3
    Channel number\x3A:Red\x3A 1
    Relative weight of the channel:1
    Image name\x3A:RedChannel1
    Channel number\x3A:Blue\x3A 3
    Relative weight of the channel:2
    Image name\x3A:GreenChannel2
    Channel number\x3A:Green\x3A 2
    Relative weight of the channel:3
    Image name\x3A:BlueChannel3
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO(data))
        self.assertEqual(len(pipeline.modules()), 1)
        module = pipeline.modules()[0]
        self.assertTrue(isinstance(module, cpm_ctg.ColorToGray))
        self.assertEqual(module.image_name, "DNA")
        self.assertEqual(module.combine_or_split, cpm_ctg.COMBINE)
        self.assertEqual(module.rgb_or_channels, cpm_ctg.CH_CHANNELS)
        self.assertEqual(module.grayscale_name, "OrigGrayw")
        self.assertEqual(module.red_contribution, 1)
        self.assertEqual(module.green_contribution, 3)
        self.assertEqual(module.blue_contribution, 5)
        self.assertTrue(module.use_red)
        self.assertTrue(module.use_green)
        self.assertTrue(module.use_blue)
        self.assertEqual(module.red_name, "OrigRedx")
        self.assertEqual(module.green_name, "OrigGreeny")
        self.assertEqual(module.blue_name, "OrigBluez")
        self.assertEqual(module.channel_count.value, 3)
        self.assertEqual(module.channels[0].channel_choice,
                         module.channel_names[0])
        self.assertEqual(module.channels[1].channel_choice,
                         module.channel_names[2])
        self.assertEqual(module.channels[2].channel_choice,
                         module.channel_names[1])
        self.assertEqual(module.channels[0].contribution, 1)
        self.assertEqual(module.channels[1].contribution, 2)
        self.assertEqual(module.channels[2].contribution, 3)
        self.assertEqual(module.channels[0].image_name, "RedChannel1")
        self.assertEqual(module.channels[1].image_name, "GreenChannel2")
        self.assertEqual(module.channels[2].image_name, "BlueChannel3")
    def test_01_03_load_v2(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:8925

LoadImages:[module_num:1|svn_version:\'8913\'|variable_revision_number:4|show_window:False|notes:\x5B\x5D]
    What type of files are you loading?:individual images
    How do you want to load these files?:Text-Exact match
    How many images are there in each group?:3
    Type the text that the excluded images have in common:Do not use
    Analyze all subfolders within the selected folder?:No
    Image location:Default Image Folder
    Enter the full path to the images:
    Do you want to check image sets for missing or duplicate files?:Yes
    Do you want to group image sets by metadata?:No
    Do you want to exclude certain files?:No
    What metadata fields do you want to group by?:
    Type the text that these images have in common (case-sensitive):hoe
    What do you want to call this image in CellProfiler?:Cytoplasm
    What is the position of this image in each group?:1
    Do you want to extract metadata from the file name, the subfolder path or both?:None
    Type the regular expression that finds metadata in the file name\x3A:^(?P<Plate>.*)_(?P<Well>\x5BA-P\x5D\x5B0-9\x5D{2})_s(?P<Site>\x5B0-9\x5D)
    Type the regular expression that finds metadata in the subfolder path\x3A:.*\x5B\\\\/\x5D(?P<Date>.*)\x5B\\\\/\x5D(?P<Run>.*)$
    Type the text that these images have in common (case-sensitive):ax2
    What do you want to call this image in CellProfiler?:Speckles
    What is the position of this image in each group?:2
    Do you want to extract metadata from the file name, the subfolder path or both?:None
    Type the regular expression that finds metadata in the file name\x3A:^(?P<Plate>.*)_(?P<Well>\x5BA-P\x5D\x5B0-9\x5D{2})_s(?P<Site>\x5B0-9\x5D)
    Type the regular expression that finds metadata in the subfolder path\x3A:.*\x5B\\\\/\x5D(?P<Date>.*)\x5B\\\\/\x5D(?P<Run>.*)$

Smooth:[module_num:2|svn_version:\'8664\'|variable_revision_number:1|show_window:False|notes:\x5B\x5D]
    Select the input image:Cytoplasm
    Name the output image:SmoothedCytoplasm
    Select smoothing method\x3A:Smooth Keeping Edges
    Calculate object size automatically?:No
    Size of objects\x3A:100.0
    Edge intensity difference\x3A:0.1

Morph:[module_num:3|svn_version:\'8780\'|variable_revision_number:1|show_window:False|notes:\x5B\x5D]
    Select input image\x3A:SmoothedCytoplasm
    Name the output image\x3A:DNA
    Select operation to perform\x3A:erode
    Repeat operation\x3A:Custom
    Custom # of repeats:20

IdentifyPrimAutomatic:[module_num:4|svn_version:\'8826\'|variable_revision_number:4|show_window:False|notes:\x5B\x5D]
    Select the input image:DNA
    Name the identified primary objects:Nuclei
    Typical diameter of objects, in pixel units (Min,Max)\x3A:50,400
    Discard objects outside the diameter range?:Yes
    Try to merge too small objects with nearby larger objects?:Yes
    Discard objects touching the border of the image?:Yes
    Select the thresholding method:Otsu Global
    Threshold correction factor:1.0
    Lower and upper bounds on threshold\x3A:0.000000,1.000000
    Approximate fraction of image covered by objects?:0.01
    Method to distinguish clumped objects:Intensity
    Method to draw dividing lines between clumped objects:Intensity
    Size of smoothing filter\x3A:10
    Suppress local maxima within this distance\x3A:7
    Speed up by using lower-resolution image to find local maxima?:Yes
    Name the outline image:PrimaryOutlines
    Fill holes in identified objects?:Yes
    Automatically calculate size of smoothing filter?:Yes
    Automatically calculate minimum size of local maxima?:Yes
    Enter manual threshold\x3A:0.0
    Select binary image\x3A:None
    Save outlines of the identified objects?:No
    Calculate the Laplacian of Gaussian threshold automatically?:Yes
    Enter Laplacian of Gaussian threshold\x3A:0.5
    Two-class or three-class thresholding?:Three classes
    Minimize the weighted variance or the entropy?:Weighted variance
    Assign pixels in the middle intensity class to the foreground or the background?:Background
    Automatically calculate the size of objects for the Laplacian of Gaussian filter?:Yes
    Enter LoG filter diameter\x3A :5

IdentifySecondary:[module_num:5|svn_version:\'8826\'|variable_revision_number:3|show_window:False|notes:\x5B\x5D]
    Select the input objects:Nuclei
    Name the identified objects:Cells
    Select the method to identify the secondary objects:Propagation
    Select the input image:Cytoplasm
    Select the thresholding method:Otsu Global
    Threshold correction factor:1.0
    Lower and upper bounds on threshold\x3A:0.000000,1.000000
    Approximate fraction of image covered by objects?:0.01
    Number of pixels by which to expand the primary objects\x3A:10
    Regularization factor\x3A:0.05
    Name the outline image:SecondaryOutlines
    Enter manual threshold\x3A:0.0
    Select binary image\x3A:None
    Save outlines of the identified objects?:No
    Two-class or three-class thresholding?:Three classes
    Minimize the weighted variance or the entropy?:Weighted variance
    Assign pixels in the middle intensity class to the foreground or the background?:Background
    Do you want to discard objects that touch the edge of the image?:No
    Do you want to discard associated primary objects?:No
    New primary objects name\x3A:FilteredNuclei

IdentifyTertiarySubregion:[module_num:6|svn_version:\'8886\'|variable_revision_number:1|show_window:False|notes:\x5B\x5D]
    Select the larger identified objects:Cells
    Select the smaller identified objects:Nuclei
    Name the identified subregion objects:Cytoplasm
    Name the outline image:CytoplasmOutlines
    Retain the outlines for use later in the pipeline (for example, in SaveImages)?:No

IdentifyPrimAutomatic:[module_num:7|svn_version:\'8826\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D]
    Select the input image:Speckles
    Name the identified primary objects:Speckles
    Typical diameter of objects, in pixel units (Min,Max)\x3A:4,30
    Discard objects outside the diameter range?:Yes
    Try to merge too small objects with nearby larger objects?:No
    Discard objects touching the border of the image?:Yes
    Select the thresholding method:Otsu Global
    Threshold correction factor:1.0
    Lower and upper bounds on threshold\x3A:0.000000,1.000000
    Approximate fraction of image covered by objects?:0.01
    Method to distinguish clumped objects:Intensity
    Method to draw dividing lines between clumped objects:Intensity
    Size of smoothing filter\x3A:10
    Suppress local maxima within this distance\x3A:7
    Speed up by using lower-resolution image to find local maxima?:Yes
    Name the outline image:PrimaryOutlines
    Fill holes in identified objects?:Yes
    Automatically calculate size of smoothing filter?:Yes
    Automatically calculate minimum size of local maxima?:Yes
    Enter manual threshold\x3A:0.0
    Select binary image\x3A:None
    Save outlines of the identified objects?:No
    Calculate the Laplacian of Gaussian threshold automatically?:Yes
    Enter Laplacian of Gaussian threshold\x3A:0.5
    Two-class or three-class thresholding?:Three classes
    Minimize the weighted variance or the entropy?:Weighted variance
    Assign pixels in the middle intensity class to the foreground or the background?:Background
    Automatically calculate the size of objects for the Laplacian of Gaussian filter?:Yes
    Enter LoG filter diameter\x3A :5

Relate:[module_num:8|svn_version:\'8866\'|variable_revision_number:2|show_window:False|notes:\x5B\x5D]
    Select the input child objects:Speckles
    Select the input parent objects:Cells
    Find distances?:Both
    Calculate per-parent means for all child measurements?:No
    Find distances to other parents?:Yes
    Parent name\x3A:Cytoplasm
    Parent name\x3A:Nuclei
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO(data))
        self.assertEqual(len(pipeline.modules()), 8)
        module = pipeline.modules()[-1]
        self.assertTrue(isinstance(module, R.Relate))
        self.assertEqual(module.sub_object_name, "Speckles")
        self.assertEqual(module.parent_name, "Cells")
        self.assertEqual(module.find_parent_child_distances, R.D_BOTH)
        self.assertFalse(module.wants_per_parent_means)
        self.assertTrue(module.wants_step_parent_distances)
        self.assertEqual(len(module.step_parent_names), 2)
        for group, expected in zip(module.step_parent_names,
                                   ("Cytoplasm", "Nuclei")):
            self.assertEqual(group.step_parent_name, expected)
Exemple #29
0
    def test_01_04_load_v3(self):
        data = r"""CellProfiler Pipeline: http://www.cellprofiler.org
Version:3
DateRevision:20130402163959
ModuleCount:1
HasImagePlaneDetails:False

Morph:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True]
    Select the input image:Thresh
    Name the output image:MorphedThresh
    Select the operation to perform:dilate
    Number of times to repeat operation:Once
    Repetition number:2
    Scale:7.0
    Structuring element:Custom
    X offset:1
    Y offset:1
    Angle:45
    Width:3
    Height:3
    Custom:5,7,11111110000000011111000000001111111
    Select the operation to perform:close
    Number of times to repeat operation:Once
    Repetition number:2
    Scale:3
    Structuring element:Diamond
    X offset:1
    Y offset:1
    Angle:0
    Width:3
    Height:3
    Custom:5,5,1111111111111111111111111
    Select the operation to perform:open
    Number of times to repeat operation:Once
    Repetition number:2
    Scale:4.0
    Structuring element:Line
    X offset:1
    Y offset:1
    Angle:60.0
    Width:3
    Height:3
    Custom:5,5,1111111111111111111111111
    Select the operation to perform:erode
    Number of times to repeat operation:Once
    Repetition number:2
    Scale:3
    Structuring element:Octagon
    X offset:1
    Y offset:1
    Angle:0
    Width:3
    Height:3
    Custom:5,5,1111111111111111111111111
    Select the operation to perform:close
    Number of times to repeat operation:Once
    Repetition number:2
    Scale:3
    Structuring element:Pair
    X offset:4.0
    Y offset:2.0
    Angle:0
    Width:3
    Height:3
    Custom:5,5,1111111111111111111111111
    Select the operation to perform:dilate
    Number of times to repeat operation:Once
    Repetition number:2
    Scale:15.0
    Structuring element:Periodic line
    X offset:-1.0
    Y offset:-3.0
    Angle:0
    Width:3
    Height:3
    Custom:5,5,1111111111111111111111111
    Select the operation to perform:erode
    Number of times to repeat operation:Once
    Repetition number:2
    Scale:3
    Structuring element:Rectangle
    X offset:1
    Y offset:1
    Angle:0
    Width:5.0
    Height:8.0
    Custom:5,5,1111111111111111111111111
    Select the operation to perform:open
    Number of times to repeat operation:Once
    Repetition number:2
    Scale:9.0
    Structuring element:Square
    X offset:1
    Y offset:1
    Angle:0
    Width:3
    Height:3
    Custom:5,5,1111111111111111111111111
"""
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.LoadExceptionEvent))

        pipeline.add_listener(callback)
        pipeline.load(StringIO.StringIO(data))
        module = pipeline.modules()[0]
        assert isinstance(module, morph.Morph)
        self.assertEqual(module.image_name, "Thresh")
        self.assertEqual(module.output_image_name, "MorphedThresh")
        self.assertEqual(len(module.functions), 8)
        f0 = module.functions[0]
        matrix = f0.strel.get_matrix()
        self.assertEqual(len(matrix), 5)
        self.assertEqual(len(matrix[0]), 7)
        expected = [[1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0],
                    [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0],
                    [1, 1, 1, 1, 1, 1, 1]]
        np.testing.assert_array_equal(matrix, np.array(expected, bool))
        for f, se in zip(
                module.functions,
            (morph.SE_ARBITRARY, morph.SE_DIAMOND, morph.SE_LINE,
             morph.SE_OCTAGON, morph.SE_PAIR, morph.SE_PERIODIC_LINE,
             morph.SE_RECTANGLE, morph.SE_SQUARE)):
            self.assertEqual(f.structuring_element, se)
            if se == morph.SE_LINE:
                self.assertEqual(f.angle, 60)
                self.assertEqual(f.scale, 4.0)
            elif se == morph.SE_PERIODIC_LINE:
                self.assertEqual(f.x_offset, -1)
                self.assertEqual(f.y_offset, -3)
            elif se == morph.SE_RECTANGLE:
                self.assertEqual(f.width, 5)
                self.assertEqual(f.height, 8)
Exemple #30
0
    def test_03_03_run_missing_measurement(self):
        # Regression test of knime-bridge issue #6
        #
        # Missing measurement causes exception
        #
        pipeline = cpp.Pipeline()
        load_images = LoadImages()
        load_images.module_num = 1
        load_images.images[0].channels[0].image_name.value = "Foo"
        pipeline.add_module(load_images)
        identify = IdentifyPrimaryObjects()
        identify.module_num = 2
        identify.use_advanced.value = True
        identify.image_name.value = "Foo"
        identify.object_name.value = "dizzy"
        identify.threshold_scope.value = TS_GLOBAL
        identify.global_operation.value = TM_MANUAL
        identify.manual_threshold.value = .5
        identify.exclude_size.value = False
        pipeline.add_module(identify)

        flag_module = FlagImage()
        flag_module.module_num = 3
        flag = flag_module.flags[0]
        flag.wants_skip.value = True
        criterion = flag.measurement_settings[0]
        criterion.source_choice.value = S_IMAGE
        criterion.measurement.value = "Count_dizzy"
        criterion.wants_minimum.value = True
        criterion.minimum_value.value = 1000
        pipeline.add_module(flag_module)

        measureobjectsizeshape = MeasureObjectSizeShape()
        measureobjectsizeshape.module_num = 4
        measureobjectsizeshape.object_groups[0].name.value = "dizzy"
        pipeline.add_module(measureobjectsizeshape)

        pipeline_txt = StringIO()
        pipeline.savetxt(pipeline_txt)

        image = np.zeros((11, 17))
        image[2:-2, 2:-2] = 1

        image_metadata = [[
            "Foo",
            [["Y", image.shape[0], image.strides[0] / 8],
             ["X", image.shape[1], image.strides[1] / 8]]
        ]]
        message = [
            zmq.Frame(self.session_id),
            zmq.Frame(),
            zmq.Frame(RUN_REQ_1),
            zmq.Frame(pipeline_txt.getvalue()),
            zmq.Frame(json.dumps(image_metadata)),
            zmq.Frame(image)
        ]
        self.socket.send_multipart(message)
        response = self.socket.recv_multipart()
        self.assertEqual(response.pop(0), self.session_id)
        self.assertEqual(response.pop(0), "")
        self.assertEqual(response.pop(0), RUN_REPLY_1)
        metadata = json.loads(response.pop(0))
        data = response.pop(0)
        measurements = self.decode_measurements(metadata, data)
        self.assertEqual(measurements[cpmeas.IMAGE]["Count_dizzy"][0], 1)
        self.assertEqual(measurements["dizzy"]["Location_Center_Y"][0], 5)
        self.assertEqual(len(measurements["dizzy"]["AreaShape_Area"]), 0)