예제 #1
0
    def Generate(self, settings):
        mdh = MetaDataHandler.NestedClassMDHandler()
        copy_sample_metadata(self.pipeline.mdh, mdh)
        mdh['Rendering.Method'] = self.name
        if 'imageID' in self.pipeline.mdh.getEntryNames():
            mdh['Rendering.SourceImageID'] = self.pipeline.mdh['imageID']
        mdh['Rendering.SourceFilename'] = getattr(self.pipeline, 'filename',
                                                  '')
        mdh['Rendering.NEventsRendered'] = len(
            self.pipeline[self.pipeline.keys(
            )[0]])  # in future good to use colourfilter for per channel info?
        mdh.Source = MetaDataHandler.NestedClassMDHandler(self.pipeline.mdh)

        for cb in renderMetadataProviders:
            cb(mdh)

        pixelSize = settings['pixelSize']
        sliceThickness = settings['zSliceThickness']

        status = statusLog.StatusLogger('Generating %s Image ...' % self.name)

        # get image bounds at integer multiple of pixel size
        imb = self._get_image_bounds(pixelSize, sliceThickness,
                                     *settings.get('zBounds', [None, None]))

        #record the pixel origin in nm from the corner of the camera for futrue overlays
        ox, oy, oz = MetaDataHandler.origin_nm(mdh)
        if not imb.z0 == 0:
            # single plane in z stack
            # FIXME - what is z for 3D fitting at a single focal plane? Check for pipeline['focus']==0 instead?
            oz = 0

        mdh['Origin.x'] = ox + imb.x0
        mdh['Origin.y'] = oy + imb.y0
        mdh['Origin.z'] = oz + imb.z0

        colours = settings['colours']
        oldC = self.colourFilter.currentColour

        ims = []

        for c in colours:
            self.colourFilter.setColour(c)
            ims.append(np.atleast_3d(self.genIm(settings, imb, mdh)))

        self.colourFilter.setColour(oldC)

        return GeneratedImage(ims,
                              imb,
                              pixelSize,
                              sliceThickness,
                              colours,
                              mdh=mdh)
예제 #2
0
    def execute(self, namespace):
        from PYME.Analysis.points import ripleys
        from PYME.IO import MetaDataHandler

        points_real = namespace[self.inputPositions]
        mask = namespace.get(self.inputMask, None)

        three_d = np.count_nonzero(points_real['z']) > 0

        try:
            origin_coords = MetaDataHandler.origin_nm(points_real.mdh)
        except:
            origin_coords = (0, 0, 0)

        if three_d:
            bb, K = ripleys.ripleys_k(x=points_real['x'],
                                      y=points_real['y'],
                                      z=points_real['z'],
                                      mask=mask,
                                      n_bins=self.nbins,
                                      bin_size=self.binSize,
                                      sampling=self.sampling,
                                      threaded=self.threaded,
                                      coord_origin=origin_coords)
        else:
            bb, K = ripleys.ripleys_k(x=points_real['x'],
                                      y=points_real['y'],
                                      mask=mask,
                                      n_bins=self.nbins,
                                      bin_size=self.binSize,
                                      sampling=self.sampling,
                                      threaded=self.threaded,
                                      coord_origin=origin_coords)

        if self.normalization == 'L':
            d = 3 if three_d else 2
            bb, L = ripleys.ripleys_l(bb, K, d)
            res = tabular.DictSource({'bins': bb, 'vals': L})
        else:
            res = tabular.DictSource({'bins': bb, 'vals': K})

        # propagate metadata, if present
        try:
            res.mdh = points_real.mdh
        except AttributeError:
            pass

        namespace[self.outputName] = res
예제 #3
0
    def execute(self, namespace):
        from PYME.Analysis.points import ripleys
        from PYME.IO import MetaDataHandler

        points_real = namespace[self.inputPositions]
        mask = namespace.get(self.inputMask, None)

        # three_d = np.count_nonzero(points_real['z']) > 0
        if self.three_d:
            if np.count_nonzero(points_real['z']) == 0:
                raise RuntimeError('Need a 3D dataset')
            if mask and mask.data.shape[2] < 2:
                raise RuntimeError(
                    'Need a 3D mask to run in 3D. Generate a 3D mask or select 2D.'
                )
        else:
            if mask and mask.data.shape[2] > 1:
                raise RuntimeError('Need a 2D mask.')

        if self.statistics and mask is None:
            raise RuntimeError('Mask is needed to calculate statistics.')

        if self.statistics and 1.0 / self.nsim > self.significance:
            raise RuntimeError(
                'Need at least {} simulations to achieve a significance of {}'.
                format(int(np.ceil(1.0 / self.significance)),
                       self.significance))

        try:
            ox, oy, _ = MetaDataHandler.origin_nm(points_real.mdh)
            origin_coords = (ox, oy, 0)  # see origin_nm docs
        except:
            origin_coords = (0, 0, 0)

        if self.three_d:
            bb, K = ripleys.ripleys_k(x=points_real['x'],
                                      y=points_real['y'],
                                      z=points_real['z'],
                                      mask=mask,
                                      n_bins=self.nbins,
                                      bin_size=self.binSize,
                                      sampling=self.sampling,
                                      threaded=self.threaded,
                                      coord_origin=origin_coords)
        else:
            bb, K = ripleys.ripleys_k(x=points_real['x'],
                                      y=points_real['y'],
                                      mask=mask,
                                      n_bins=self.nbins,
                                      bin_size=self.binSize,
                                      sampling=self.sampling,
                                      threaded=self.threaded,
                                      coord_origin=origin_coords)

        # Run MC simulations
        if self.statistics:
            K_min, K_max, p_clustered, p_dispersed = ripleys.mc_sampling_statistics(
                K,
                mask=mask,
                n_points=len(points_real['x']),
                n_bins=self.nbins,
                three_d=self.three_d,
                bin_size=self.binSize,
                significance=self.significance,
                n_sim=self.nsim,
                sampling=self.sampling,
                threaded=self.threaded,
                coord_origin=origin_coords)

        # Check for alternate Ripley's normalization
        norm_func = None
        if self.normalization == 'L':
            norm_func = ripleys.ripleys_l
        elif self.normalization == 'dL':
            # Results will be of length 2 less than other results
            norm_func = ripleys.ripleys_dl
        elif self.normalization == 'H':
            norm_func = ripleys.ripleys_h
        elif self.normalization == 'dH':
            # Results will be of length 2 less than other results
            norm_func = ripleys.ripleys_dh

        # Apply normalization if present
        if norm_func is not None:
            d = 3 if self.three_d else 2
            bb0, K = norm_func(bb, K, d)  # bb0 in case we use dL/dH
            if self.statistics:
                _, K_min = norm_func(bb, K_min, d)
                _, K_max = norm_func(bb, K_max, d)
                if self.normalization == 'dL' or self.normalization == 'dH':
                    # Truncate p_clustered for dL and dH to match size
                    p_clustered = p_clustered[1:-1]
                    p_dispersed = p_dispersed[1:-1]
            bb = bb0

        if self.statistics:
            res = tabular.DictSource({
                'bins': bb,
                'vals': K,
                'min': K_min,
                'max': K_max,
                'pc': p_clustered,
                'pd': p_dispersed
            })
        else:
            res = tabular.DictSource({'bins': bb, 'vals': K})

        # propagate metadata, if present
        try:
            res.mdh = points_real.mdh
        except AttributeError:
            pass

        namespace[self.outputName] = res
예제 #4
0
    def origin(self):
        #the origin, in nm from the camera - used for overlaying with different ROIs

        return MetaDataHandler.origin_nm(self.mdh, self.pixelSize)