Coverage for tests/test_datastoreFits.py : 25%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is part of daf_butler. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
DummyRegistry)
except ImportError: lsst.afw = None
def setUpClass(cls): if lsst.afw is None: raise unittest.SkipTest("afw not available.")
# Base classes need to know where the test directory is cls.testDir = TESTDIR
# Storage Classes are fixed for all datastores in these tests scConfigFile = os.path.join(TESTDIR, "config/basic/storageClasses.yaml") cls.storageClassFactory = StorageClassFactory() cls.storageClassFactory.addFromConfig(scConfigFile)
# Read the Datastore config so we can get the class # information (since we should not assume the constructor # name here, but rely on the configuration file itself) datastoreConfig = DatastoreConfig(cls.configFile) cls.datastoreType = doImport(datastoreConfig["cls"])
self.setUpDatastoreTests(DummyRegistry, DatastoreConfig)
if self.root is not None and os.path.exists(self.root): shutil.rmtree(self.root, ignore_errors=True)
datastore = self.makeDatastore() self.assertIsNotNone(datastore)
catalog = self.makeExampleCatalog() datastore = self.makeDatastore()
# Put dimensions = self.registry.dimensions.extract(("visit", "physical_filter")) dataId = {"visit": 123456, "physical_filter": "blue", "instrument": "dummy"} storageClass = self.storageClassFactory.getStorageClass("SourceCatalog")
ref = self.makeDatasetRef("calexp", dimensions, storageClass, dataId)
datastore.put(catalog, ref)
# Does it exist? self.assertTrue(datastore.exists(ref))
uri = datastore.getUri(ref) if self.fileExt is not None: self.assertTrue(uri.endswith(self.fileExt)) self.assertTrue(uri.startswith(self.uriScheme))
# Get catalogOut = datastore.get(ref, parameters=None) self.assertCatalogEqual(catalog, catalogOut)
# These should raise ref = self.makeDatasetRef("calexp2", dimensions, storageClass, dataId) with self.assertRaises(FileNotFoundError): # non-existing file datastore.get(ref, parameters=None)
catalog = self.makeExampleCatalog() datastore = self.makeDatastore()
# Put storageClass = self.storageClassFactory.getStorageClass("SourceCatalog") dimensions = self.registry.dimensions.extract(("visit", "physical_filter")) dataId = {"visit": 1234567, "physical_filter": "blue", "instrument": "dummy"}
ref = self.makeDatasetRef("calexp", dimensions, storageClass, dataId) datastore.put(catalog, ref)
# Does it exist? self.assertTrue(datastore.exists(ref))
# Get catalogOut = datastore.get(ref) self.assertCatalogEqual(catalog, catalogOut)
# Remove datastore.remove(ref)
# Does it exist? self.assertFalse(datastore.exists(ref))
# Get should now fail with self.assertRaises(FileNotFoundError): datastore.get(ref) # Can only delete once with self.assertRaises(FileNotFoundError): datastore.remove(ref)
catalog = self.makeExampleCatalog() dimensions = self.registry.dimensions.extract(("visit", "physical_filter")) dataId = {"visit": 12345, "physical_filter": "red", "instrument": "dummy"}
storageClass = self.storageClassFactory.getStorageClass("SourceCatalog") ref = self.makeDatasetRef("calexp", dimensions, storageClass, dataId)
inputDatastore = self.makeDatastore("test_input_datastore") outputDatastore = self.makeDatastore("test_output_datastore")
inputDatastore.put(catalog, ref) outputDatastore.transfer(inputDatastore, ref)
catalogOut = outputDatastore.get(ref) self.assertCatalogEqual(catalog, catalogOut)
example = os.path.join(self.testDir, "data", "basic", "small.fits") exposure = lsst.afw.image.ExposureF(example) datastore = self.makeDatastore() # Put dimensions = self.registry.dimensions.extract(("visit", "physical_filter")) dataId = {"visit": 231, "physical_filter": "Fc", "instrument": "dummy"} storageClass = datastore.storageClassFactory.getStorageClass("ExposureF") ref = self.makeDatasetRef("calexp", dimensions, storageClass, dataId)
datastore.put(exposure, ref)
# Does it exist? self.assertTrue(datastore.exists(ref))
# Get exposureOut = datastore.get(ref) self.assertEqual(type(exposure), type(exposureOut))
# Get some components for compName in ("wcs", "image", "mask", "coaddInputs", "psf"): compRef = self.makeDatasetRef(ref.datasetType.componentTypeName(compName), dimensions, storageClass.components[compName], dataId, id=ref.id) component = datastore.get(compRef) self.assertIsInstance(component, compRef.datasetType.storageClass.pytype)
# Get the WCS component to check it wcsRef = self.makeDatasetRef(ref.datasetType.componentTypeName("wcs"), dimensions, storageClass.components["wcs"], dataId, id=ref.id) wcs = datastore.get(wcsRef)
# Simple check of WCS bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(9, 9)) self.assertWcsAlmostEqualOverBBox(wcs, exposure.getWcs(), bbox)
example = os.path.join(self.testDir, "data", "basic", "small.fits") exposure = lsst.afw.image.ExposureF(example) datastore = self.makeDatastore() # Put dimensions = self.registry.dimensions.extract(("visit", "physical_filter")) dataId = {"visit": 23, "physical_filter": "F", "instrument": "dummy"} storageClass = datastore.storageClassFactory.getStorageClass("ExposureCompositeF") ref = self.makeDatasetRef("calexp", dimensions, storageClass, dataId)
# Get the predicted URI self.assertFalse(datastore.exists(ref)) uri = datastore.getUri(ref, predict=True) self.assertTrue(uri.endswith("#predicted"))
components = storageClass.assembler().disassemble(exposure) self.assertTrue(components)
# Get a component compsRead = {} for compName in ("wcs", "image", "mask", "coaddInputs", "psf"): compRef = self.makeDatasetRef(ref.datasetType.componentTypeName(compName), dimensions, components[compName].storageClass, dataId)
datastore.put(components[compName].component, compRef)
# Does it exist? self.assertTrue(datastore.exists(compRef))
component = datastore.get(compRef) self.assertIsInstance(component, compRef.datasetType.storageClass.pytype) compsRead[compName] = component
# Simple check of WCS bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(9, 9)) self.assertWcsAlmostEqualOverBBox(compsRead["wcs"], exposure.getWcs(), bbox)
# Try to reassemble the exposure retrievedExposure = storageClass.assembler().assemble(compsRead) self.assertIsInstance(retrievedExposure, type(exposure))
"""PosixDatastore specialization"""
# Override the working directory before calling the base class self.root = tempfile.mkdtemp(dir=TESTDIR) super().setUp()
"""PosixDatastore specialization"""
"""PosixDatastore specialization"""
unittest.main() |