Beispiel #1
0
    def _ingestImages(cls):

        # Generate the camera mapper
        camDataCollector = CamDataCollector(cls.dataDir.name)
        camDataCollector.genPhoSimMapper()

        # Ingest the E image
        imgFilesEimg = os.path.join(
            getModulePath(),
            "tests",
            "testData",
            "repackagedFiles",
            "lsst_e_9006001_f1_R22_S00_E000.fits.gz",
        )
        camDataCollector.ingestEimages(imgFilesEimg)

        # Ingest the amplifier image
        imgFilesRaw = os.path.join(
            getModulePath(),
            "tests",
            "testData",
            "repackagedFiles",
            "lsst_a_20_f5_R00_S22_E000.fits",
        )
        camDataCollector.ingestImages(imgFilesRaw)
    def testDoIsr(self):

        # Generate the camera mapper
        camDataCollector = CamDataCollector(self.isrDir)
        camDataCollector.genPhoSimMapper()

        # Generate the fake flat images
        fakeFlatDir = os.path.join(self.dataDir, "fake_flats")
        self._makeDir(fakeFlatDir)

        detector = "R00_S22"
        self._genFakeFlat(fakeFlatDir, detector)

        # Ingest the calibration images
        calibFiles = os.path.join(fakeFlatDir, "*")
        camDataCollector.ingestCalibs(calibFiles)

        # Ingest the raw images
        imgFiles = os.path.join(getModulePath(), "tests", "testData",
                                "repackagedFiles",
                                "lsst_a_20_f5_R00_S22_E000.fits")
        camDataCollector.ingestImages(imgFiles)

        # Do the ISR configuration
        self._doIsrConfig()

        # Do the ISR
        rerunName = "run1"
        self.camIsrWrapper.doISR(self.isrDir, rerunName=rerunName)

        # Check the condition
        postIsrCcdDir = os.path.join(self.isrDir, "rerun", rerunName,
                                     "postISRCCD")
        self.assertTrue(os.path.exists(postIsrCcdDir))
Beispiel #3
0
    def testDoIsr(self):

        # Generate the camera mapper
        camDataCollector = CamDataCollector(self.isrDir)
        camDataCollector.genPhoSimMapper()

        # Generate the fake flat images
        fakeFlatDir = os.path.join(self.dataDir, "fake_flats")
        self._makeDir(fakeFlatDir)

        detector = "R00_S22"
        self._genFakeFlat(fakeFlatDir, detector)

        # Ingest the calibration images
        calibFiles = os.path.join(fakeFlatDir, "*")
        camDataCollector.ingestCalibs(calibFiles)

        # Ingest the raw images
        imgFiles = os.path.join(getModulePath(), "tests", "testData",
                                "repackagedFiles",
                                "lsst_a_20_f5_R00_S22_E000.fits")
        camDataCollector.ingestImages(imgFiles)

        # Do the ISR configuration
        self._doIsrConfig()

        # Do the ISR
        rerunName = "run1"
        self.camIsrWrapper.doISR(self.isrDir, rerunName=rerunName)

        # Check the condition
        postIsrCcdDir = os.path.join(self.isrDir, "rerun", rerunName,
                                     "postISRCCD")
        self.assertTrue(os.path.exists(postIsrCcdDir))
Beispiel #4
0
    def _getCamDataCollectorAndIngestCalibs(self, detector):

        # Generate the camera mapper
        camDataCollector = CamDataCollector(self.isrDir.name)
        camDataCollector.genPhoSimMapper()

        # Generate the fake flat images
        fakeFlatDir = tempfile.TemporaryDirectory(dir=self.dataDir.name)

        self._genFakeFlat(fakeFlatDir.name, detector)

        # Ingest the calibration images
        calibFiles = os.path.join(fakeFlatDir.name, "*")
        camDataCollector.ingestCalibs(calibFiles)

        return camDataCollector
class TestCamDataCollector(unittest.TestCase):
    """Test the CamIsrWrapper class."""

    def setUp(self):

        self.dataDir = os.path.join(getModulePath(), "tests", "tmp")
        self.isrDir = os.path.join(self.dataDir, "input")
        self._makeDir(self.isrDir)

        self.camDataCollector = CamDataCollector(self.isrDir)

    def _makeDir(self, directory):

        if (not os.path.exists(directory)):
            os.makedirs(directory)

    def tearDown(self):

        shutil.rmtree(self.dataDir)

    def testGenCamMapper(self):

        self._genMapper()

        mapperFilePath = os.path.join(self.isrDir, "_mapper")
        self.assertTrue(os.path.isfile(mapperFilePath))

        numOfLine = self._getNumOfLineInFile(mapperFilePath)
        self.assertEqual(numOfLine, 1)

    def _genMapper(self):

        self.camDataCollector.genPhoSimMapper()

    def _getNumOfLineInFile(self, filePath):

        with open(filePath, "r") as file:
            return sum(1 for line in file.readlines())

    def testIngestCalibs(self):

        # Make fake gain images
        fakeFlatDir = os.path.join(self.dataDir, "fake_flats")
        self._makeDir(fakeFlatDir)

        detector = "R00_S22"
        self._genFakeFlat(fakeFlatDir, detector)

        # Generate the mapper
        self._genMapper()

        # Do the ingestion
        calibFiles = os.path.join(fakeFlatDir, "*")
        self.camDataCollector.ingestCalibs(calibFiles)

        # Check the ingested calibration products
        calibRegistryFilePath = os.path.join(self.isrDir,
                                             "calibRegistry.sqlite3")
        self.assertTrue(os.path.exists(calibRegistryFilePath))

        flatDir = os.path.join(self.isrDir, "flat")
        self.assertTrue(os.path.exists(flatDir))

    def _genFakeFlat(self, fakeFlatDir, detector):

        currWorkDir = self._getCurrWorkDir()

        self._changeWorkDir(fakeFlatDir)
        self._makeFakeFlat(detector)
        self._changeWorkDir(currWorkDir)

    def _getCurrWorkDir(self):

        return os.getcwd()

    def _changeWorkDir(self, dirPath):

        os.chdir(dirPath)

    def _makeFakeFlat(self, detector):

        command = "makeGainImages.py"
        argstring = "--detector_list %s" % detector
        runProgram(command, argstring=argstring)

    def testIngestImages(self):

        self._genMapper()

        imgFiles = os.path.join(getModulePath(), "tests", "testData",
                                "repackagedFiles",
                                "lsst_a_20_f5_R00_S22_E000.fits")
        self.camDataCollector.ingestImages(imgFiles)

        # Check the ingested calibration products
        registryFilePath = os.path.join(self.isrDir, "registry.sqlite3")
        self.assertTrue(os.path.exists(registryFilePath))

        rawDir = os.path.join(self.isrDir, "raw")
        self.assertTrue(os.path.exists(rawDir))
class TestCamDataCollector(unittest.TestCase):
    """Test the CamIsrWrapper class."""

    def setUp(self):

        testDir = os.path.join(getModulePath(), "tests")
        self.dataDir = tempfile.TemporaryDirectory(dir=testDir)

        self.isrDir = tempfile.TemporaryDirectory(dir=self.dataDir.name)

        self.camDataCollector = CamDataCollector(self.isrDir.name)

    def tearDown(self):

        self.dataDir.cleanup()

    def testGenCamMapper(self):

        self._genMapper()

        mapperFilePath = os.path.join(self.isrDir.name, "_mapper")
        self.assertTrue(os.path.isfile(mapperFilePath))

        numOfLine = self._getNumOfLineInFile(mapperFilePath)
        self.assertEqual(numOfLine, 1)

    def _genMapper(self):

        self.camDataCollector.genPhoSimMapper()

    def _getNumOfLineInFile(self, filePath):

        with open(filePath, "r") as file:
            return sum(1 for line in file.readlines())

    def testIngestCalibs(self):

        # Make fake gain images
        fakeFlatDir = tempfile.TemporaryDirectory(dir=self.dataDir.name)

        detector = "R00_S22"
        self._genFakeFlat(fakeFlatDir.name, detector)

        # Generate the mapper
        self._genMapper()

        # Do the ingestion
        calibFiles = os.path.join(fakeFlatDir.name, "*")
        self.camDataCollector.ingestCalibs(calibFiles)

        # Check the ingested calibration products
        calibRegistryFilePath = os.path.join(self.isrDir.name, "calibRegistry.sqlite3")
        self.assertTrue(os.path.exists(calibRegistryFilePath))

        flatDir = os.path.join(self.isrDir.name, "flat")
        self.assertTrue(os.path.exists(flatDir))

    def _genFakeFlat(self, fakeFlatDir, detector):

        currWorkDir = self._getCurrWorkDir()

        self._changeWorkDir(fakeFlatDir)
        self._makeFakeFlat(detector)
        self._changeWorkDir(currWorkDir)

    def _getCurrWorkDir(self):

        return os.getcwd()

    def _changeWorkDir(self, dirPath):

        os.chdir(dirPath)

    def _makeFakeFlat(self, detector):

        command = "makeGainImages.py"
        argstring = "--detector_list %s" % detector
        runProgram(command, argstring=argstring)

    def testIngestImages(self):

        self._genMapper()

        imgFiles = os.path.join(
            getModulePath(),
            "tests",
            "testData",
            "repackagedFiles",
            "lsst_a_20_f5_R00_S22_E000.fits",
        )
        self.camDataCollector.ingestImages(imgFiles)

        # Check the ingested files
        self._checkIngestion("raw")

    def _checkIngestion(self, imgType):

        registryFilePath = os.path.join(self.isrDir.name, "registry.sqlite3")
        self.assertTrue(os.path.exists(registryFilePath))

        rawDir = os.path.join(self.isrDir.name, imgType)
        self.assertTrue(os.path.exists(rawDir))

    def testIngestEimages(self):

        self._genMapper()

        imgFiles = os.path.join(
            getModulePath(),
            "tests",
            "testData",
            "repackagedFiles",
            "lsst_e_9006001_f1_R22_S00_E000.fits.gz",
        )
        self.camDataCollector.ingestEimages(imgFiles)

        # Check the ingested files
        self._checkIngestion("eimage")