Skip to content

Commit

Permalink
adds test files for butler policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Pease authored and n8pease committed Dec 14, 2015
1 parent 7778dc6 commit e01b1dc
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 10 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
138 changes: 138 additions & 0 deletions policy/testMapper.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
calibrations:
bias: {level: Ccd, persistable: ExposureF, python: lsst.afw.image.ExposureF, storage: FitsStorage,
template: bias/bias.fits.gz}
dark: {level: Ccd, persistable: ExposureF, python: lsst.afw.image.ExposureF, storage: FitsStorage,
template: dark/dark.fits.gz}
flat: {columns: filter, level: Ccd, persistable: ExposureF, python: lsst.afw.image.ExposureF,
reference: raw, storage: FitsStorage, template: flat/flat_f%(filter)s.fits.gz}
fringe: {columns: filter, level: Ccd, persistable: ExposureF, python: lsst.afw.image.ExposureF,
reference: raw, storage: FitsStorage, template: fringe/fringe_f%(filter)s.fits.gz}
datasets:
Mosaic_config: {persistable: Config, python: lsst.meas.mosaic.mosaicTask.MosaicConfig,
storage: ConfigStorage, tables: raw_skyTile, template: config/mosaic.py}
Mosaic_metadata: {persistable: PropertySet, python: lsst.daf.base.PropertySet, storage: BoostStorage,
tables: raw_skyTile, template: metadata/Mosaic.boost}
ampExposureId: {persistable: ignored, python: lsst.daf.base.PropertySet, storage: 'ignored:ampExposureId',
tables: raw, template: ignored}
ampExposureId_bits: {persistable: ignored, python: lsst.daf.base.PropertySet, storage: 'ignored:ampExposureId_bits',
tables: raw, template: ignored}
apCorr: {persistable: ApertureCorrection, python: lsst.meas.algorithms.ApertureCorrection,
storage: PickleStorage, tables: raw_skyTile, template: apCorr/v%(visit)d_f%(filter)s.pickle}
badSource: {persistable: ignored, python: lsst.afw.table.SourceCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: results/st%(skyTile)d/badSource.fits}
badSourceHist: {persistable: DecoratedImageU, python: lsst.afw.image.DecoratedImageU,
storage: FitsStorage, tables: raw_skyTile, template: results/st%(skyTile)d/badSourceHist.fits}
badSource_schema: {persistable: ignored, python: lsst.afw.table.SourceCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: schema/badSource.fits}
calexpBackground: {persistable: PurePythonClass, python: lsst.afw.math.BackgroundList,
storage: FitsCatalogStorage, tables: raw_skyTile, template: calexp/v%(visit)d/bkgd.fits}
ccdExposureId: {persistable: ignored, python: lsst.daf.base.PropertySet, storage: 'ignored:ccdExposureId',
tables: raw, template: ignored}
ccdExposureId_bits: {persistable: ignored, python: lsst.daf.base.PropertySet, storage: 'ignored:ccdExposureId_bits',
tables: raw, template: ignored}
chiSquaredCoaddId: {persistable: ignored, python: lsst.daf.base.PropertySet, storage: ignored,
tables: raw, template: ignored}
chiSquaredCoaddId_bits: {persistable: ignored, python: lsst.daf.base.PropertySet,
storage: ignored, tables: raw, template: ignored}
crDiffimSrc: {persistable: SourceCatalog, python: lsst.afw.table.SourceCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: crDiffimSrc/v%(visit)d_f%(filter)s.fits}
crDiffimSrc_schema: {persistable: SourceCatalog, python: lsst.afw.table.SourceCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: schema/crDiffSrc.fits}
deepCoaddId: {persistable: ignored, python: lsst.daf.base.PropertySet, storage: ignored,
tables: raw, template: ignored}
deepCoaddId_bits: {persistable: ignored, python: lsst.daf.base.PropertySet, storage: ignored,
tables: raw, template: ignored}
deepCoadd_modelfits: {persistable: ModelFitCatalog, python: lsst.meas.multifit.ModelFitCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: deepCoadd_results/%(filter)s_t%(tract)d_p%(patch)s/modelfits_%(filter)s_%(tract)d_%(patch)s.fits}
deepCoadd_modelfits_schema: {persistable: ModelFitCatalog, python: lsst.meas.multifit.ModelFitCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: schema/deepCoadd_modelfits.fits}
deepCoadd_multiModelfits: {persistable: ModelFitCatalog, python: lsst.meas.multifit.ModelFitCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: deepCoadd_results/%(filter)s_t%(tract)d_p%(patch)s/multiModelfits_%(filter)s_%(tract)d_%(patch)s.fits}
deepCoadd_multiModelfits_schema: {persistable: ModelFitCatalog, python: lsst.meas.multifit.ModelFitCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: schema/deepCoadd_multiModelfits.fits}
forced_config: {persistable: Config, python: lsst.meas.base.forcedCcd.ForcedCcdMeasurementConfig,
storage: ConfigStorage, tables: raw_skyTile, template: config/forced.py}
forced_metadata: {persistable: PropertySet, python: lsst.daf.base.PropertySet, storage: BoostStorage,
tables: raw_skyTile, template: forced_metadata/v%(visit)d_f%(filter)s.boost}
forced_schema: {persistable: ignored, python: lsst.afw.table.SourceCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: schema/forced.fits}
forced_src: {persistable: SourceCatalog, python: lsst.afw.table.SourceCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: forced/%(tract)d/v%(visit)d_f%(filter)s.fits}
goodSeeingCoaddId: {persistable: ignored, python: lsst.daf.base.PropertySet, storage: ignored,
tables: raw, template: ignored}
goodSeeingCoaddId_bits: {persistable: ignored, python: lsst.daf.base.PropertySet,
storage: ignored, tables: raw, template: ignored}
icMatch: {persistable: BaseCatalog, python: lsst.afw.table.BaseCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: icMatch/v%(visit)d_f%(filter)s.fits}
icSrc: {persistable: SourceCatalog, python: lsst.afw.table.SourceCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: icSrc/v%(visit)d_f%(filter)s.fits}
icSrc_schema: {persistable: SourceCatalog, python: lsst.afw.table.SourceCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: schema/icSrc.fits}
invalidSource: {persistable: ignored, python: lsst.afw.table.SourceCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: results/st%(skyTile)d/invalidSource.fits}
invalidSource_schema: {persistable: ignored, python: lsst.afw.table.SourceCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: schema/invalidSource.fits}
measureCcd_config: {persistable: Config, python: lsst.meas.multifit.measureCcd.MeasureCcdConfig,
storage: ConfigStorage, tables: raw_skyTile, template: config/measureCcd.py}
measureCcd_metadata: {persistable: PropertySet, python: lsst.daf.base.PropertySet,
storage: BoostStorage, tables: raw_skyTile, template: measureCcd_metadata/v%(visit)d_f%(filter)s.boost}
modelfits: {persistable: ModelFitCatalog, python: lsst.meas.multifit.ModelFitCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: modelfits/v%(visit)d_f%(filter)s.fits}
modelfits_schema: {persistable: ModelFitCatalog, python: lsst.meas.multifit.ModelFitCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: schema/modelfits.fits}
object: {persistable: ignored, python: lsst.ap.cluster.SourceClusterCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: results/st%(skyTile)d/object.fits}
object_schema: {persistable: ignored, python: lsst.ap.cluster.SourceClusterCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: schema/object.fits}
processCcd_config: {persistable: Config, python: lsst.pipe.tasks.processCcd.ProcessCcdConfig,
storage: ConfigStorage, tables: raw_skyTile, template: config/processCcd.py}
processCcd_metadata: {persistable: PropertySet, python: lsst.daf.base.PropertySet,
storage: BoostStorage, tables: raw_skyTile, template: processCcd_metadata/v%(visit)d_f%(filter)s.boost}
refcat: {persistable: SimpleCatalog, python: lsst.afw.table.SimpleCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: refcat.fits}
source: {persistable: ignored, python: lsst.afw.table.SourceCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: results/st%(skyTile)d/source.fits}
sourceAssoc_config: {persistable: Config, python: lsst.ap.tasks.sourceAssoc.SourceAssocConfig,
storage: ConfigStorage, tables: raw_skyTile, template: config/sourceAssoc.py}
sourceAssoc_metadata: {persistable: PropertySet, python: lsst.daf.base.PropertySet,
storage: BoostStorage, tables: raw_skyTile, template: sourceAssoc_metadata/st%(skyTile)d/metadata.boost}
sourceHist: {persistable: DecoratedImageU, python: lsst.afw.image.DecoratedImageU,
storage: FitsStorage, tables: raw_skyTile, template: results/st%(skyTile)d/sourceHist.fits}
source_schema: {persistable: ignored, python: lsst.afw.table.SourceCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: schema/source.fits}
src: {persistable: SourceCatalog, python: lsst.afw.table.SourceCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: src/v%(visit)d_f%(filter)s.fits}
src_schema: {persistable: SourceCatalog, python: lsst.afw.table.SourceCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: schema/src.fits}
test_config: {persistable: Config, python: lsst.obs.test.TestConfig, storage: ConfigStorage,
tables: raw_skyTile, template: config/test.py}
test_metadata: {persistable: PropertySet, python: lsst.daf.base.PropertySet, storage: BoostStorage,
tables: raw_skyTile, template: test/v%(visit)d_f%(filter)s.boost}
transformSrcMeasurement_config: {persistable: Config, python: lsst.pipe.tasks.transformMeasurement.RunTransformConfig,
storage: ConfigStorage, tables: raw_skyTile, template: config/transformSrcMeasurement.py}
transformSrcMeasurement_metadata: {persistable: PropertySet, python: lsst.daf.base.PropertySet,
storage: BoostStorage, tables: raw_skyTile, template: transformSrcMeasurement_metadata/v%(visit)d_f%(filter)s.boost}
transformed_src: {persistable: ignored, python: lsst.afw.table.BaseCatalog, storage: FitsCatalogStorage,
tables: raw_skyTile, template: transformed_src/v%(visit)d_f%(filter)s.fits}
transformed_src_schema: {persistable: ignored, python: lsst.afw.table.BaseCatalog,
storage: FitsCatalogStorage, tables: raw_skyTile, template: schema/transformed_src.fits}
defaultLevel: visit
defaultSubLevels: {}
defects: ../description/defects
exposures:
calexp: {level: Ccd, persistable: ExposureF, python: lsst.afw.image.ExposureF, storage: FitsStorage,
tables: raw_skyTile, template: calexp/calexp_v%(visit)d_f%(filter)s.fits}
crDiffim: {level: Ccd, persistable: ExposureF, python: lsst.afw.image.ExposureF,
storage: FitsStorage, tables: raw_skyTile, template: crDiffim/crDiffim_v%(visit)d_f%(filter)s.fits}
fcr: {level: Ccd, persistable: ExposureI, python: lsst.afw.image.ExposureI, storage: FitsStorage,
tables: raw_skyTile, template: fcr/v%(visit)d_f%(filter)s.fcr.fits}
postISRCCD: {level: Ccd, persistable: ExposureF, python: lsst.afw.image.ExposureF,
storage: FitsStorage, tables: raw_skyTile, template: postISRCCD/postISRCCD_v%(visit)d_f%(filter)s.fits}
raw: {level: Ccd, persistable: DecoratedImageU, python: lsst.afw.image.DecoratedImageU,
storage: FitsStorage, tables: raw_skyTile, template: raw/raw_v%(visit)d_f%(filter)s.fits.gz}
visitim: {level: Ccd, persistable: ExposureF, python: lsst.afw.image.ExposureF,
storage: FitsStorage, tables: raw_skyTile, template: visitim/visitim_v%(visit)d_f%(filter)s.fits}
wcs: {level: Ccd, persistable: ExposureI, python: lsst.afw.image.ExposureI, storage: FitsStorage,
tables: raw_skyTile, template: wcs/v%(visit)d_f%(filter)s.wcs.fits}
levels: {skyTile: visit, tract: patch}
needCalibRegistry: false
124 changes: 124 additions & 0 deletions tests/pexPolicyToButlerPolicy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/env python

#
# LSST Data Management System
# Copyright 2015 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# 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 LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#

import collections
import os
import unittest

from lsst.daf.persistence import Policy as dafPolicy
import lsst.pex.policy as pex_policy
import lsst.utils.tests as utilsTests


class PolicyTestCase(unittest.TestCase):
"""A test case for the butler policy to verify that it can load a pex policy properly."""

def loadPolicy(self):
pafPolicyPath = os.path.join(os.environ['OBS_TEST_DIR'], 'policy', 'testMapper.paf')
self.assertTrue(os.path.exists(pafPolicyPath))
pexPolicy = pex_policy.Policy.createPolicy(pafPolicyPath)
policy = dafPolicy(filePath=pafPolicyPath)
return (policy, pexPolicy)

def test(self):
policy, pexPolicy = self.loadPolicy()

# go back through the newly created Butler Policy, and verify that values match the paf Policy
for name in policy.names():
if pexPolicy.isArray(name):
pexVal = pexPolicy.getArray(name)
else:
pexVal = pexPolicy.get(name)
val = policy[name]
if isinstance(val, dafPolicy):
self.assertTrue(pexPolicy.getValueType(name) == pexPolicy.POLICY)
else:
self.assertEqual(val, pexVal)

for name in pexPolicy.names():
if pexPolicy.getValueType(name) == pexPolicy.POLICY:
self.assertTrue(isinstance(policy.get(name), dafPolicy))
else:
if pexPolicy.isArray(name):
pexVal = pexPolicy.getArray(name)
else:
pexVal = pexPolicy.get(name)
self.assertEqual(pexVal, policy.get(name))

#verify a known value, just for sanity:
self.assertEqual(policy.get('exposures.raw.template'), 'raw/raw_v%(visit)d_f%(filter)s.fits.gz')

def testGetStringArray(self):
policy, pexPolicy = self.loadPolicy()
s = policy.asArray('exposures.raw.tables')
self.assertEqual(s, ['raw', 'raw_skyTile'])

def testDumpAndLoad(self):
pafPolicyPath = os.path.join(os.environ['OBS_TEST_DIR'], 'policy', 'testMapper.paf')
self.assertTrue(os.path.exists(pafPolicyPath))
pexPolicy = pex_policy.Policy.createPolicy(pafPolicyPath)

policy = dafPolicy(filePath=pafPolicyPath)
policyPath = os.path.join(os.environ['OBS_TEST_DIR'], 'policy', 'tempTestMapper.yaml')
if os.path.exists(policyPath):
os.remove(policyPath)
policyFile = open(policyPath, 'w')
policy.dump(policyFile)
self.assertTrue(os.path.exists(policyPath))

pexPolicy = pex_policy.Policy.createPolicy(pafPolicyPath)

# test that the data went through the entire wringer correctly - verify the
# original pex data matches the dafPolicy data
yamlPolicy = dafPolicy(filePath=policyPath)
yamlNames = yamlPolicy.names()
yamlNames.sort()
pexNames = pexPolicy.names()
pexNames.sort()
self.assertEqual(yamlNames, pexNames)
for name in yamlNames:
if not isinstance(yamlPolicy[name], dafPolicy):
yamlPolicyVal = yamlPolicy[name]
if isinstance(yamlPolicyVal, collections.Iterable) and \
not isinstance(yamlPolicyVal, basestring):
self.assertEqual(yamlPolicyVal, pexPolicy.getArray(name))
else:
self.assertEqual(yamlPolicyVal, pexPolicy.get(name))
if os.path.exists(policyPath):
os.remove(policyPath)


def suite():
utilsTests.init()

suites = []
suites += unittest.makeSuite(PolicyTestCase)
suites += unittest.makeSuite(utilsTests.MemoryTestCase)
return unittest.TestSuite(suites)

def run(shouldExit = False):
utilsTests.run(suite(), shouldExit)

if __name__ == '__main__':
run(True)
17 changes: 7 additions & 10 deletions tests/policyInRepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,19 @@ def testInRepoPolicyOverrides(self):
_policy file.
"""

testData = ((os.path.join('data', 'policyInRepo'),
os.path.join('data', 'policyInRepo', '_policy.paf')),
(os.path.join('data', 'policyInRepo1/a'),
os.path.join('data', 'policyInRepo1', 'a', '_parent', '_policy.paf')),
(os.path.join('data', 'policyInRepo2/a'),
os.path.join('data', 'policyInRepo2', 'a', '_parent', '_parent', '_policy.paf'))
)
testData = (
# (os.path.join('data', 'policyInRepo'), os.path.join('data', 'policyInRepo', '_policy.paf')),
(os.path.join('data', 'policyInRepo1/a'), os.path.join('data', 'policyInRepo1', 'a', '_parent', '_policy.paf')),
(os.path.join('data', 'policyInRepo2/a'), os.path.join('data', 'policyInRepo2', 'a', '_parent', '_parent', '_policy.paf'))
)

for mapperRoot, actualPolicyPath in testData:
mapper = TestMapper(root=mapperRoot)
repoPolicyPath = os.path.join('data', 'policyInRepo', '_policy.paf')
self.assertTrue(os.path.exists(repoPolicyPath))
repoPolicy = pexPolicy.Policy_createPolicy(actualPolicyPath)
template = repoPolicy.get('exposures.raw.template')
mapperTemplate = mapper.mappings['raw'].template
self.assertEqual(template, mapperTemplate)
try: self.assertEqual(template, mapperTemplate)
except: import pdb; pdb.set_trace()

# Run a simple test case to verify that although the package's policy was overloaded with some
# values, other values specified in the policy file in the package are loaded.
Expand Down

0 comments on commit e01b1dc

Please sign in to comment.