Ejemplo n.º 1
0
    def grid3D(self, z_min, z_max, drift_corrected=False):
        z_scale = float(self.z_bins) / (z_max - z_min)
        image = numpy.zeros(self.im_shape_3D, dtype=numpy.int32)
        for locs in self.locsInFrameRangeIterator(self.fmin, self.fmax,
                                                  ["x", "y", "z"]):

            # Create z value filter.
            #
            # We filter here rather than just relying on gridC.grid3D as application
            # of z drift correction could move out of z range peaks into the acceptable
            # range.
            #
            mask = (locs["z"] > z_min) & (locs["z"] < z_max)
            if (numpy.count_nonzero(mask) == 0):
                continue

            # Remove localizations that are out of range.
            locs["x"] = locs["x"][mask]
            locs["y"] = locs["y"][mask]
            locs["z"] = locs["z"][mask]

            # Apply drift correction if requested.
            if drift_corrected:
                locs["x"] += self.dx
                locs["y"] += self.dy
                locs["z"] += self.dz

            # Add to image.
            i_x = numpy.floor(locs["x"] * self.scale).astype(numpy.int32)
            i_y = numpy.floor(locs["y"] * self.scale).astype(numpy.int32)
            i_z = numpy.floor(
                (locs["z"] - z_min) * z_scale).astype(numpy.int32)
            gridC.grid3D(i_x, i_y, i_z, image)
        return image
Ejemplo n.º 2
0
    def grid3D(self, z_min, z_max, drift_corrected = False):
        z_scale = float(self.z_bins)/(z_max - z_min)
        image = numpy.zeros(self.im_shape_3D, dtype = numpy.int32)
        for locs in self.locsInFrameRangeIterator(self.fmin, self.fmax, ["x", "y", "z"]):

            # Create z value filter.
            #
            # We filter here rather than just relying on gridC.grid3D as application
            # of z drift correction could move out of z range peaks into the acceptable
            # range.
            #
            mask = (locs["z"] > z_min) & (locs["z"] < z_max)
            if (numpy.count_nonzero(mask) == 0):
                continue

            # Remove localizations that are out of range.
            locs["x"] = locs["x"][mask]
            locs["y"] = locs["y"][mask]
            locs["z"] = locs["z"][mask]
            
            # Apply drift correction if requested.
            if drift_corrected:
                locs["x"] += self.dx
                locs["y"] += self.dy
                locs["z"] += self.dz
                        
            # Add to image.
            i_x = numpy.floor(locs["x"]*self.scale).astype(numpy.int32)
            i_y = numpy.floor(locs["y"]*self.scale).astype(numpy.int32)
            i_z = numpy.floor((locs["z"] - z_min)*z_scale).astype(numpy.int32)
            gridC.grid3D(i_x, i_y, i_z, image)
        return image
Ejemplo n.º 3
0
    def gridTracks3D(self, z_min, z_max, dx = 0.0, dy = 0.0, verbose = False):
        z_scale = float(self.z_bins)/(z_max - z_min)
        image = numpy.zeros(self.im_shape_3D, dtype = numpy.int32)
        for locs in self.tracksIterator(fields = ["x", "y", "z"]):
            if verbose:
                sys.stdout.write(".")
                sys.stdout.flush()
                
            # Add to image.
            f_x = locs["x"] + dx
            f_y = locs["y"] + dy
            f_z = (locs["z"] - z_min)*z_scale
            
            i_x = numpy.floor(f_x*self.scale).astype(numpy.int32)
            i_y = numpy.floor(f_y*self.scale).astype(numpy.int32)
            i_z = numpy.floor(f_z.astype(numpy.int32))
            gridC.grid3D(i_x, i_y, i_z, image)

        if verbose:
            sys.stdout.write("\n")
            
        return image
Ejemplo n.º 4
0
    def i3To3DGrid(self, z_bins, fmin = 0, fmax = 500000, zmin = -1000.0, zmax = 1000.0, uncorrected = False, verbose = True):

        if uncorrected:
            [x, y, z] = [self.i3data['x'],
                         self.i3data['y'],
                         self.i3data['z']]
        else:
            [x, y, z] = [self.i3data['xc'],
                         self.i3data['yc'],
                         self.i3data['zc']]
            
        cat = self.i3data['c']
        f = self.i3data['fr']

        [image_x, image_y] = self.im_size
        xy_scale = int(self.scale)
        z_bins = int(z_bins)
        z_range = zmax - zmin

        max_max = 0.0
        max_counts = []
        image_data = []
        for channel in self.channels:
            mask = (cat == channel) & (f >= fmin) & (f < fmax) & (z > zmin) & (z < zmax)
            i_x = numpy.floor(x[mask] * xy_scale).astype(int)
            i_y = numpy.floor(y[mask] * xy_scale).astype(int)
            i_z = numpy.floor((z[mask] - zmin) * float(z_bins)/z_range).astype(int)
            if (i_x.shape[0] > 0):
                channel_data = grid_c.grid3D(i_x, i_y, i_z, (image_x*xy_scale, image_y*xy_scale, z_bins))
            else:
                channel_data = numpy.zeros((image_x*xy_scale, image_y*xy_scale, z_bins))
            image_data.append(channel_data.astype(numpy.float32))
            max_count = numpy.max(channel_data)
            if max_count > max_max:
                max_max = max_count
            max_counts.append(max_count)

        return [image_data, self.channels, max_counts, max_max]
Ejemplo n.º 5
0
    def i3To3DGrid(self, z_bins, fmin = 0, fmax = 500000, zmin = -1000.0, zmax = 1000.0, uncorrected = False, verbose = True):

        if uncorrected:
            [x, y, z] = [self.i3data['x'],
                         self.i3data['y'],
                         self.i3data['z']]
        else:
            [x, y, z] = [self.i3data['xc'],
                         self.i3data['yc'],
                         self.i3data['zc']]
            
        cat = self.i3data['c']
        f = self.i3data['fr']

        [image_x, image_y] = self.im_size
        xy_scale = int(self.scale)
        z_bins = int(z_bins)
        z_range = zmax - zmin

        max_max = 0.0
        max_counts = []
        image_data = []
        for channel in self.channels:
            mask = (cat == channel) & (f >= fmin) & (f < fmax) & (z > zmin) & (z < zmax)
            i_x = numpy.floor(x[mask] * xy_scale).astype(int)
            i_y = numpy.floor(y[mask] * xy_scale).astype(int)
            i_z = numpy.floor((z[mask] - zmin) * float(z_bins)/z_range).astype(int)
            if (i_x.shape[0] > 0):
                channel_data = grid_c.grid3D(i_x, i_y, i_z, (image_x*xy_scale, image_y*xy_scale, z_bins))
            else:
                channel_data = numpy.zeros((image_x*xy_scale, image_y*xy_scale, z_bins))
            image_data.append(channel_data.astype(numpy.float32))
            max_count = numpy.max(channel_data)
            if max_count > max_max:
                max_max = max_count
            max_counts.append(max_count)

        return [image_data, self.channels, max_counts, max_max]