Exemple #1
0
class TestImage(unittest.TestCase):
    """Test the Image class."""

    def setUp(self):

        self.testDataDir = os.path.join(getModulePath(), "tests", "testData")
        self.imgFile = os.path.join(
            self.testDataDir, "testImages", "LSST_NE_SN25", "z11_0.25_intra.txt"
        )

        self.img = Image()
        self.img.setImg(imageFile=self.imgFile)

    def testGetCentroidFind(self):

        centroidFind = self.img.getCentroidFind()
        self.assertTrue(isinstance(centroidFind, CentroidRandomWalk))

    def testGetImg(self):

        img = self.img.getImg()
        self.assertEqual(img.shape, (120, 120))

    def testGetImgFilePath(self):

        imgFilePath = self.img.getImgFilePath()
        self.assertEqual(imgFilePath, self.imgFile)

    def testSetImgByImageArray(self):

        newImg = np.random.rand(5, 5)
        self.img.setImg(image=newImg)

        self.assertTrue(np.all(self.img.getImg() == newImg))
        self.assertEqual(self.img.getImgFilePath(), "")

    def testSetImgByFitsFile(self):

        opdFitsFile = os.path.join(
            self.testDataDir, "opdOutput", "9006000", "opd_9006000_0.fits.gz"
        )
        self.img.setImg(imageFile=opdFitsFile)

        img = self.img.getImg()
        self.assertEqual(img.shape, (255, 255))

        imgFilePath = self.img.getImgFilePath()
        self.assertEqual(imgFilePath, opdFitsFile)

    def testUpdateImage(self):

        newImg = np.random.rand(5, 5)
        self.img.updateImage(newImg)

        self.assertTrue(np.all(self.img.getImg() == newImg))

    def testUpdateImageWithNoHoldImage(self):

        img = Image()

        newImg = np.random.rand(5, 5)
        self.assertWarns(UserWarning, img.updateImage, newImg)

    def testGetCenterAndR_ef(self):

        realcx, realcy, realR = self.img.getCenterAndR()
        self.assertEqual(int(realcx), 61)
        self.assertEqual(int(realcy), 61)
        self.assertGreater(int(realR), 35)

    def testGetSNR(self):

        # Add the noise to the image
        image = self.img.getImg()
        noisedImg = image + np.random.random(image.shape) * 0.1

        self.img.setImg(image=noisedImg)
        snr = self.img.getSNR()

        self.assertGreater(snr, 15)
Exemple #2
0
class TestImage(unittest.TestCase):
    """Test the Image class."""

    def setUp(self):

        self.testDataDir = os.path.join(getModulePath(), "tests", "testData")
        self.imgFile = os.path.join(self.testDataDir, "testImages",
                                    "LSST_NE_SN25", "z11_0.25_intra.txt")

        self.img = Image()
        self.img.setImg(imageFile=self.imgFile)

    def testGetImg(self):

        img = self.img.getImg()
        self.assertEqual(img.shape, (120, 120))

    def testGetImgFilePath(self):

        imgFilePath = self.img.getImgFilePath()
        self.assertEqual(imgFilePath, self.imgFile)

    def testSetImgByImageArray(self):

        newImg = np.random.rand(5, 5)
        self.img.setImg(image=newImg)

        self.assertTrue(np.all(self.img.getImg() == newImg))
        self.assertEqual(self.img.getImgFilePath(), "")

    def testSetImgByFitsFile(self):

        opdFitsFile = os.path.join(self.testDataDir, "opdOutput", "9005000",
                                   "opd_9005000_0.fits.gz")
        self.img.setImg(imageFile=opdFitsFile)

        img = self.img.getImg()
        self.assertEqual(img.shape, (255, 255))

        imgFilePath = self.img.getImgFilePath()
        self.assertEqual(imgFilePath, opdFitsFile)

    def testUpdateImage(self):

        newImg = np.random.rand(5, 5)
        self.img.updateImage(newImg)

        self.assertTrue(np.all(self.img.getImg() == newImg))

    def testUpdateImageWithNoHoldImage(self):

        img = Image()

        newImg = np.random.rand(5, 5)
        self.assertWarns(UserWarning, img.updateImage, newImg)

    def testGetCenterAndR_ef(self):

        realcx, realcy, realR, imgBinary = \
            self.img.getCenterAndR_ef(checkEntropy=True)
        self.assertEqual(int(realcx), 61)
        self.assertEqual(int(realcy), 61)
        self.assertGreater(int(realR), 35)

    def testGetCenterAndR_ef_withEntropyCheck(self):

        # Creat a zero image
        zeroImg = Image()
        zeroImg.setImg(image=np.ones([4, 4]))

        realcx, realcy, realR, imgBinary = \
            zeroImg.getCenterAndR_ef(checkEntropy=True)

        self.assertEqual(realcx, [])

        # update to the random image
        zeroImg.updateImage(np.random.rand(100, 100))
        realcx, realcy, realR, imgBinary = \
            zeroImg.getCenterAndR_ef(checkEntropy=True)
        self.assertEqual(realcx, [])

    def testGetSNR(self):

        # Add the noise to the image
        image = self.img.getImg()
        noisedImg = image + np.random.random(image.shape) * 0.1

        self.img.setImg(image=noisedImg)
        snr = self.img.getSNR()

        self.assertGreater(snr, 15)
Exemple #3
0
class TestImage(unittest.TestCase):
    """Test the Image class."""
    def setUp(self):

        # Get the path of module
        modulePath = getModulePath()

        # Define the algorithm folder
        algoFolderPath = os.path.join(modulePath, "configData", "cwfs", "algo")

        # Define the image folder and image names
        # Image data -- Don't know the final image format.
        # It is noted that image.readFile inuts is based on the txt file
        imageFolderPath = os.path.join(modulePath, "tests", "testData",
                                       "testImages", "LSST_NE_SN25")
        imgName = "z11_0.25_intra.txt"

        # Image files Path
        imgFile = os.path.join(imageFolderPath, imgName)

        # There is the difference between intra and extra images
        self.img = Image()
        self.img.setImg(imageFile=imgFile)

    def testZeroImg(self):

        # Creat a zero image
        zeroImg = Image()
        zeroImg.setImg(image=np.zeros([4, 4]))
        self.assertEqual(np.sum(zeroImg.image), 0)

        # Update Image
        zeroImg.updateImage(np.ones([4, 4]))
        self.assertEqual(np.sum(zeroImg.image), 16)

        realcx, realcy, realR, imgBinary = zeroImg.getCenterAndR_ef(
            randNumFilePath=None, checkEntropy=True)

        self.assertEqual(realcx, [])

        # update to the random image
        zeroImg.updateImage(np.random.rand(100, 100))
        realcx, realcy, realR, imgBinary = zeroImg.getCenterAndR_ef(
            randNumFilePath=None, checkEntropy=True)
        self.assertEqual(realcx, [])

    def testImg(self):

        realcx, realcy, realR, imgBinary = self.img.getCenterAndR_ef(
            randNumFilePath=None, checkEntropy=True)
        self.assertEqual(int(realcx), 61)
        self.assertEqual(int(realcy), 61)
        self.assertGreater(int(realR), 35)

        # Calculate the S/N
        # Add the noise to the image
        noisedImg = self.img.image + np.random.random(
            self.img.image.shape) * 0.1
        self.img.setImg(image=noisedImg)
        snr = self.img.getSNR()

        self.assertGreater(snr, 15)