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 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 _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))
def _configWepController(self, isrDir): """Configure the WEP controller. WEP: wavefront estimation pipeline. Parameters ---------- isrDir : str ISR directory. This directory path will have the input and output that the data butler needs. Returns ------- WepController Configured WEP controller. """ dataCollector = CamDataCollector(isrDir) isrWrapper = CamIsrWrapper(isrDir) sourSelc = self._configSourceSelector() sourProc = self._configSourceProcessor() wfsEsti = self._configWfEstimator() wepCntlr = WepController(dataCollector, isrWrapper, sourSelc, sourProc, wfsEsti) return wepCntlr
def setUp(self): self.modulePath = getModulePath() testDir = os.path.join(self.modulePath, "tests") self.dataDir = tempfile.TemporaryDirectory(dir=testDir) self.butlerInput = tempfile.TemporaryDirectory(dir=self.dataDir.name) self.opdDir = os.path.join( self.modulePath, "tests", "testData", "opdOutput", "9005000" ) # Configurate the WEP components dataCollector = CamDataCollector(self.butlerInput.name) sourSelc = self._configSourceSelector() sourProc = SourceProcessor() wfEsti = self._configWfEstimator() # Instantiate the WEP controller self.wepCntlr = WepController(dataCollector, None, sourSelc, sourProc, wfEsti) # Intemediate data used in the test self.filter = FilterType.REF self.neighborStarMap = dict() self.starMap = dict() self.wavefrontSensors = dict() self.wfsImgMap = dict() self.donutMap = dict() self.masterDonutMap = dict()
def setUp(self): self.modulePath = getModulePath() self.dataDir = os.path.join(self.modulePath, "tests", "tmp") self.isrDir = os.path.join(self.dataDir, "input") self.opdDir = os.path.join(self.modulePath, "tests", "testData", "opdOutput", "9005000") self._makeDir(self.isrDir) # Configurate the WEP components dataCollector = CamDataCollector(self.isrDir) isrWrapper = CamIsrWrapper(self.isrDir) sourSelc = self._configSourceSelector() sourProc = self._configSourceProcessor() wfsEsti = self._configWfEstimator() # Instantiate the WEP controller self.wepCntlr = WepController(dataCollector, isrWrapper, sourSelc, sourProc, wfsEsti) # Intemediate data used in the test self.filter = FilterType.REF self.neighborStarMap = dict() self.starMap = dict() self.wavefrontSensors = dict() self.wfsImgMap = dict() self.donutMap = dict() self.masterDonutMap = dict()
def _configWepController(self, camType, settingFileName): """Configure the WEP controller. WEP: wavefront estimation pipeline. Parameters ---------- camType : enum 'CamType' Camera type. settingFileName : str Setting file name. Returns ------- WepController Configured WEP controller. """ dataCollector = CamDataCollector(self.isrDir) isrWrapper = CamIsrWrapper(self.isrDir) bscDbType = self._getBscDbType() sourSelc = self._configSourceSelector(camType, bscDbType, settingFileName) sourProc = SourceProcessor(settingFileName=settingFileName) wfsEsti = self._configWfEstimator(camType) wepCntlr = WepController(dataCollector, isrWrapper, sourSelc, sourProc, wfsEsti) return wepCntlr
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")