Example #1
0
 def getSpectralAngleByBand(self, nbins=500, updater=None):
     """Calculate the spectral angle between every pixel in two cubes using
     bands
     
     Fast for BSQ cubes, slow for BIL, and extremely slow for BIP.
     """
     sam = HSI.createCube('bsq', self.lines, self.samples, 1, numpy.float32)
     data = sam.getBandRaw(0)
     
     top = numpy.zeros((self.lines, self.samples), dtype=numpy.float32)
     bot1 = numpy.zeros((self.lines, self.samples), dtype=numpy.float32)
     bot2 = numpy.zeros((self.lines, self.samples), dtype=numpy.float32)
     for i in range(self.bands):
         if updater:
             updater.updateStatus(i, self.bands, "Calculating Spectral Angle")
         if self.bbl[i]:
             band1 = self.cube1.getBand(i)
             band2 = self.cube2.getBand(i)
             top += band1 * band2
             bot1 += numpy.square(band1)
             bot2 += numpy.square(band2)
     
     bot = numpy.sqrt(bot1 + bot2)
     tot = top/bot
     data[:,:] = numpy.nan_to_num(numpy.arccos(tot) * (180.0 / math.pi))
     self.dprint(data)
     return sam
Example #2
0
    def getSpectralAngleByFocalPlane(self, iter, updater=None):
        """Calculate the spectral angle between every pixel in two cubes using
        focal planes
        
        Fast for BIP and BIL, slow for BSQ.
        """
        sam = HSI.createCube('bsq', self.lines, self.samples, 1, numpy.float32)
        data = sam.getBandRaw(0)
        bblmask = self.getFocalPlaneBadBandMask()

        for i, plane1, plane2 in iter:
            if updater:
                updater.updateStatus(i, self.lines,
                                     "Calculating Spectral Angle")
            p1 = numpy.cast[numpy.float32](plane1 * bblmask)
            p2 = numpy.cast[numpy.float32](plane2 * bblmask)
            zerotest = numpy.add.reduce(plane1 - plane2)

            top = numpy.add.reduce(p1 * p2)
            bot = numpy.sqrt(numpy.add.reduce(p1 * p1)) * numpy.sqrt(
                numpy.add.reduce(p2 * p2))
            # the arccos may not be zero if the spectra are exactly the same due
            # to round-off error in the squaring/sqrt.  So, we add this check
            # here to force the total to 1.0 if any pixel in plane1 is exactly
            # equal to the pixel in plane 2
            tot = numpy.where(zerotest == 0.0, 1.0, top / bot)
            line = numpy.nan_to_num(numpy.arccos(tot) * (180.0 / math.pi))

            self.dprint("%s %s" % (line.shape, line))
            data[i, :] = line
        self.dprint(data)
        return sam
Example #3
0
    def getSpectralAngleByFocalPlane(self, iter, updater=None):
        """Calculate the spectral angle between every pixel in two cubes using
        focal planes
        
        Fast for BIP and BIL, slow for BSQ.
        """
        sam = HSI.createCube('bsq', self.lines, self.samples, 1, numpy.float32)
        data = sam.getBandRaw(0)
        bblmask = self.getFocalPlaneBadBandMask()

        for i, plane1, plane2 in iter:
            if updater:
                updater.updateStatus(i, self.lines, "Calculating Spectral Angle")
            p1 = numpy.cast[numpy.float32](plane1 * bblmask)
            p2 = numpy.cast[numpy.float32](plane2 * bblmask)
            zerotest = numpy.add.reduce(plane1 - plane2)
            
            top = numpy.add.reduce(p1 * p2)
            bot = numpy.sqrt(numpy.add.reduce(p1 * p1)) * numpy.sqrt(numpy.add.reduce(p2 * p2))
            # the arccos may not be zero if the spectra are exactly the same due
            # to round-off error in the squaring/sqrt.  So, we add this check
            # here to force the total to 1.0 if any pixel in plane1 is exactly
            # equal to the pixel in plane 2
            tot = numpy.where(zerotest == 0.0, 1.0, top/bot)
            line = numpy.nan_to_num(numpy.arccos(tot) * (180.0 / math.pi))
            
            self.dprint("%s %s" % (line.shape, line))
            data[i,:] = line
        self.dprint(data)
        return sam
Example #4
0
    def getSpectralAngleByBand(self, nbins=500, updater=None):
        """Calculate the spectral angle between every pixel in two cubes using
        bands
        
        Fast for BSQ cubes, slow for BIL, and extremely slow for BIP.
        """
        sam = HSI.createCube('bsq', self.lines, self.samples, 1, numpy.float32)
        data = sam.getBandRaw(0)

        top = numpy.zeros((self.lines, self.samples), dtype=numpy.float32)
        bot1 = numpy.zeros((self.lines, self.samples), dtype=numpy.float32)
        bot2 = numpy.zeros((self.lines, self.samples), dtype=numpy.float32)
        for i in range(self.bands):
            if updater:
                updater.updateStatus(i, self.bands,
                                     "Calculating Spectral Angle")
            if self.bbl[i]:
                band1 = self.cube1.getBand(i)
                band2 = self.cube2.getBand(i)
                top += band1 * band2
                bot1 += numpy.square(band1)
                bot2 += numpy.square(band2)

        bot = numpy.sqrt(bot1 + bot2)
        tot = top / bot
        data[:, :] = numpy.nan_to_num(numpy.arccos(tot) * (180.0 / math.pi))
        self.dprint(data)
        return sam
Example #5
0
    def getHeatMapByFocalPlane(self, iter):
        """Generate a heat map using focal planes
        
        Fast for BIP and BIL, slow for BSQ.  This is a slightly more
        complicated algorithm that uses focal planes to create the histogram.
        Because there's an extra python loop inside this method, the
        theoretical speed of this method is slower than L{getHistogramByBand}.
        However, because BIL and BIP cubes are structured to read focal
        plane images very quickly, this method is many times faster than
        L{getHistogramByBand} when both cubes are BIL or BIP.  If one cube is
        BSQ, it's probably faster to use L{getHistogramByBand} because more
        work is done by numpy.
        """
        self.heatmap = HSI.createCube('bsq', self.lines, self.samples, 1, self.dtype)
        data = self.heatmap.getBandRaw(0)
        bblmask = self.getFocalPlaneBadBandMask()

        for i, plane1, plane2 in iter:
            p1 = plane1 * bblmask
            p2 = plane2 * bblmask
            line = numpy.add.reduce(abs(p1 - p2), axis=0)
            self.dprint("%s %s" % (line.shape, line))
            data[i,:] = line
        self.dprint(data)
        return self.heatmap
Example #6
0
    def getHeatMapByFocalPlane(self, iter):
        """Generate a heat map using focal planes
        
        Fast for BIP and BIL, slow for BSQ.  This is a slightly more
        complicated algorithm that uses focal planes to create the histogram.
        Because there's an extra python loop inside this method, the
        theoretical speed of this method is slower than L{getHistogramByBand}.
        However, because BIL and BIP cubes are structured to read focal
        plane images very quickly, this method is many times faster than
        L{getHistogramByBand} when both cubes are BIL or BIP.  If one cube is
        BSQ, it's probably faster to use L{getHistogramByBand} because more
        work is done by numpy.
        """
        self.heatmap = HSI.createCube('bsq', self.lines, self.samples, 1,
                                      self.dtype)
        data = self.heatmap.getBandRaw(0)
        bblmask = self.getFocalPlaneBadBandMask()

        for i, plane1, plane2 in iter:
            p1 = plane1 * bblmask
            p2 = plane2 * bblmask
            line = numpy.add.reduce(abs(p1 - p2), axis=0)
            self.dprint("%s %s" % (line.shape, line))
            data[i, :] = line
        self.dprint(data)
        return self.heatmap
Example #7
0
    def getDifferenceByFocalPlane(self, iter):
        """Difference the cubes using focal planes
        
        Fast for BIP and BIL, slow for BSQ.
        """
        self.difference = HSI.createCube('bil', self.lines, self.samples, self.bands, self.dtype)
        bblmask = self.getFocalPlaneBadBandMask()

        for i, plane1, plane2 in iter:
            p1 = plane1 * bblmask
            p2 = plane2 * bblmask
            diff = p1 - p2
            plane = self.difference.getFocalPlaneRaw(i)
            plane[:,:] = diff
            self.dprint("%s %s" % (plane.shape, plane))
        return self.difference
Example #8
0
    def getDifferenceByFocalPlane(self, iter):
        """Difference the cubes using focal planes
        
        Fast for BIP and BIL, slow for BSQ.
        """
        self.difference = HSI.createCube('bil', self.lines, self.samples,
                                         self.bands, self.dtype)
        bblmask = self.getFocalPlaneBadBandMask()

        for i, plane1, plane2 in iter:
            p1 = plane1 * bblmask
            p2 = plane2 * bblmask
            diff = p1 - p2
            plane = self.difference.getFocalPlaneRaw(i)
            plane[:, :] = diff
            self.dprint("%s %s" % (plane.shape, plane))
        return self.difference
Example #9
0
    def getDifferenceByBand(self,nbins=500):
        """Difference two cubes using bands
        
        Fast for BSQ cubes, slow for BIL, and extremely slow for BIP.  The most
        straight-forward algorithm, but is slow unless the cubes are in BSQ
        format.  Differences two cubes on a band-by-band basis and puts the
        results in a new cube.
        """
        self.difference = HSI.createCube('bsq', self.lines, self.samples, self.bands, self.dtype)

        for i in range(self.cube1.bands):
            if self.bbl[i]:
                band = self.difference.getBandRaw(i)
                band1 = self.cube1.getBand(i)
                band2 = self.cube2.getBand(i)
                band[:,:] = band1 - band2
                self.dprint(band)
        return self.difference
Example #10
0
    def getHeatMapByBand(self,nbins=500):
        """Generate a heat map using bands
        
        Fast for BSQ cubes, slow for BIL, and extremely slow for BIP.  The
        most straight-forward algorithm, but is slow unless the cubes are in
        BSQ format.  Differences the corresponding bands, runs a histogram on
        them, and puts the results into the instance histogram.
        """
        self.heatmap = HSI.createCube('bsq', self.lines, self.samples, 1, self.dtype)
        data = self.heatmap.getBandRaw(0)

        for i in range(self.bands):
            if self.bbl[i]:
                band1 = self.cube1.getBand(i)
                band2 = self.cube2.getBand(i)
                band = abs(band1-band2)
                data += band
        self.dprint(data)
        return self.heatmap
Example #11
0
    def getDifferenceByBand(self, nbins=500):
        """Difference two cubes using bands
        
        Fast for BSQ cubes, slow for BIL, and extremely slow for BIP.  The most
        straight-forward algorithm, but is slow unless the cubes are in BSQ
        format.  Differences two cubes on a band-by-band basis and puts the
        results in a new cube.
        """
        self.difference = HSI.createCube('bsq', self.lines, self.samples,
                                         self.bands, self.dtype)

        for i in range(self.cube1.bands):
            if self.bbl[i]:
                band = self.difference.getBandRaw(i)
                band1 = self.cube1.getBand(i)
                band2 = self.cube2.getBand(i)
                band[:, :] = band1 - band2
                self.dprint(band)
        return self.difference
Example #12
0
    def getHeatMapByBand(self, nbins=500):
        """Generate a heat map using bands
        
        Fast for BSQ cubes, slow for BIL, and extremely slow for BIP.  The
        most straight-forward algorithm, but is slow unless the cubes are in
        BSQ format.  Differences the corresponding bands, runs a histogram on
        them, and puts the results into the instance histogram.
        """
        self.heatmap = HSI.createCube('bsq', self.lines, self.samples, 1,
                                      self.dtype)
        data = self.heatmap.getBandRaw(0)

        for i in range(self.bands):
            if self.bbl[i]:
                band1 = self.cube1.getBand(i)
                band2 = self.cube2.getBand(i)
                band = abs(band1 - band2)
                data += band
        self.dprint(data)
        return self.heatmap
Example #13
0
    def getEuclideanDistanceByFocalPlane(self, iter, updater=None):
        """Calculate the euclidean distance for every pixel in two cubes using
        focal planes
        
        Fast for BIP and BIL, slow for BSQ.
        """
        euclidean = HSI.createCube('bsq', self.lines, self.samples, 1, numpy.float32)
        data = euclidean.getBandRaw(0)
        bblmask = self.getFocalPlaneBadBandMask()

        for i, plane1, plane2 in iter:
            if updater:
                updater.updateStatus(i, self.lines, "Calculating Euclidean Distance")
            p1 = plane1 * bblmask
            p2 = plane2 * bblmask
            plane = p1 - p2
            line = numpy.sqrt(numpy.add.reduce(plane * plane, axis=0))
            self.dprint("%s %s" % (line.shape, line))
            data[i,:] = line
        self.dprint(data)
        return euclidean
Example #14
0
 def getEuclideanDistanceByBand(self, nbins=500, updater=None):
     """Calculate the euclidean distance for every pixel in two cubes using
     bands
     
     Fast for BSQ cubes, slow for BIL, and extremely slow for BIP.
     """
     euclidean = HSI.createCube('bsq', self.lines, self.samples, 1, numpy.float32)
     data = euclidean.getBandRaw(0)
     
     working = numpy.zeros((self.lines, self.samples), dtype=numpy.float32)
     for i in range(self.bands):
         if updater:
             updater.updateStatus(i, self.bands, "Calculating Euclidean Distance")
         if self.bbl[i]:
             band1 = self.cube1.getBand(i)
             band2 = self.cube2.getBand(i)
             band = band1 - band2
             working += numpy.square(band)
     
     data = numpy.sqrt(working)
     self.dprint(data)
     return euclidean
Example #15
0
    def getEuclideanDistanceByFocalPlane(self, iter, updater=None):
        """Calculate the euclidean distance for every pixel in two cubes using
        focal planes
        
        Fast for BIP and BIL, slow for BSQ.
        """
        euclidean = HSI.createCube('bsq', self.lines, self.samples, 1,
                                   numpy.float32)
        data = euclidean.getBandRaw(0)
        bblmask = self.getFocalPlaneBadBandMask()

        for i, plane1, plane2 in iter:
            if updater:
                updater.updateStatus(i, self.lines,
                                     "Calculating Euclidean Distance")
            p1 = plane1 * bblmask
            p2 = plane2 * bblmask
            plane = p1 - p2
            line = numpy.sqrt(numpy.add.reduce(plane * plane, axis=0))
            self.dprint("%s %s" % (line.shape, line))
            data[i, :] = line
        self.dprint(data)
        return euclidean
Example #16
0
    def getEuclideanDistanceByBand(self, nbins=500, updater=None):
        """Calculate the euclidean distance for every pixel in two cubes using
        bands
        
        Fast for BSQ cubes, slow for BIL, and extremely slow for BIP.
        """
        euclidean = HSI.createCube('bsq', self.lines, self.samples, 1,
                                   numpy.float32)
        data = euclidean.getBandRaw(0)

        working = numpy.zeros((self.lines, self.samples), dtype=numpy.float32)
        for i in range(self.bands):
            if updater:
                updater.updateStatus(i, self.bands,
                                     "Calculating Euclidean Distance")
            if self.bbl[i]:
                band1 = self.cube1.getBand(i)
                band2 = self.cube2.getBand(i)
                band = band1 - band2
                working += numpy.square(band)

        data = numpy.sqrt(working)
        self.dprint(data)
        return euclidean
Example #17
0
        self.fovy = 30
        self.n = 1
        self.f = 10000

    def onResize(self, w=None, h=None):
        super(PerspectiveView, self).onResize(w, h)
        self.aspect = float(self.w) / float(self.h)

    def onMotion(self, x, y):
        self.head += (x - self.x)
        self.pitch += (y - self.y)
        self.x = x
        self.y = y
        return True

    def updateProjection(self):
        gluPerspective(self.fovy, self.aspect, self.n, self.f)

    def updateView(self):
        glTranslate(0, 0, -self.distance)
        glRotate(self.head, 0, 1, 0)
        glRotate(self.pitch, 1, 0, 0)


if __name__ == '__main__':
    import cube
    glut_ui.run(
        glbase.BaseController(
            PerspectiveView(80),
            cube.createCube(10)))
Example #18
0
    def onMotion(self, x, y):
        self.head += (x - self.x)
        self.pitch += (y - self.y)
        self.x = x
        self.y = y
        # return True for redrawing
        return True

    def updateProjection(self):
        l = -self.w / 2
        r = -l
        b = -self.h / 2
        t = -b
        n = 0
        f = 1000
        glOrtho(l, r, b, t, n, f)

    def updateView(self):
        glTranslate(0, 0, -self.distance)
        glRotate(self.head, 0, 1, 0)
        glRotate(self.pitch, 1, 0, 0)


if __name__ == '__main__':
    import cube
    glut_ui.run(
        glbase.BaseController(
            OrthogonalView(200),
            cube.createCube(100)))