Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for butler metadata object access #26

Merged
merged 3 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file not shown.
7 changes: 7 additions & 0 deletions data/calexpMetadataObjectsTest/repositoryCfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
!RepositoryCfg_v1
_isLegacyRepository: false
_mapper: lsst.obs.test.MapperForTestCalexpMetadataObjects
_mapperArgs: null
_parents: []
_policy: null
_root: null
3 changes: 3 additions & 0 deletions policy/testCalexpMetadataObjects.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exposures:
calexp:
template: 'example-calexp.fits'
40 changes: 39 additions & 1 deletion python/lsst/obs/test/testMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .testCamera import TestCamera
from .makeTestRawVisitInfo import MakeTestRawVisitInfo

__all__ = ["TestMapper"]
__all__ = ["TestMapper", "MapperForTestCalexpMetadataObjects"]


class TestMapper(CameraMapper):
Expand Down Expand Up @@ -101,3 +101,41 @@ def _makeCamera(self, policy, repositoryDir):
"""Make a camera (instance of lsst.afw.cameraGeom.Camera) describing the camera geometry
"""
return TestCamera()


class MapperForTestCalexpMetadataObjects(lsst.obs.base.CameraMapper):
packageName = "obs_test"

def __init__(self, root):
policyFilePath = dafPersist.Policy.defaultPolicyFile(
self.packageName, "testCalexpMetadataObjects.yaml", "policy")
policy = dafPersist.Policy(policyFilePath)
super(MapperForTestCalexpMetadataObjects, self).__init__(
policy, repositoryDir=root, root=root)
self.filterIdMap = {
'u': 0, 'g': 1, 'r': 2, 'i': 3, 'z': 4, 'y': 5, 'i2': 5}
# The LSST Filters from L. Jones 04/07/10
afwImageUtils.defineFilter('u', 364.59)
afwImageUtils.defineFilter('g', 476.31)
afwImageUtils.defineFilter('r', 619.42)
afwImageUtils.defineFilter('i', 752.06)
afwImageUtils.defineFilter('z', 866.85)
afwImageUtils.defineFilter('y', 971.68, alias=['y4']) # official y filter

def _makeCamera(self, policy, repositoryDir):
"""Normally this makes a camera. For composite testing, we don't need a camera.
"""
return TestCamera()

def _extractDetectorName(self, dataId):
"""Normally this extracts the detector (CCD) name from the dataset
identifier. The name in question is the detector name used by
lsst.afw.cameraGeom.

We don't need anything meaninful here, so just override so as not to
throw (in the base class impl)
"""
return "0"



119 changes: 119 additions & 0 deletions tests/testMetadataObjectAccess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env python

#
# LSST Data Management System
# Copyright 2017 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 lsst.afw.image
import lsst.daf.persistence as dafPersist
import lsst.utils.tests
from lsst.utils import getPackageDir
import lsst.afw.image.basicUtils as imageBasicUtils
import math
import os
import unittest

obsTestDir = getPackageDir('obs_test')

class TestCalexpMetadataObjects(unittest.TestCase):
"""A test case for getting metadata objects from a Calexp"""

def setUp(self):
self.input = os.path.join(obsTestDir,
'data',
'calexpMetadataObjectsTest')

def nanSafeAssertEqual(self, val1, val2):
try:
self.assertEqual(val1, val2)
except AssertionError as err:
if math.isnan(val1) and math.isnan(val2):
pass
else:
raise err

def testNanSafeAssertEqual(self):
val1 = float('nan')
val2 = float(123.45)
with self.assertRaises(AssertionError):
self.nanSafeAssertEqual(val1, val2)
val1 = float(123.44)
val2 = float(123.45)
with self.assertRaises(AssertionError):
self.nanSafeAssertEqual(val1, val2)
# should not raise:
val1 = float('nan')
val2 = float('nan')
self.nanSafeAssertEqual(val1, val2)
val1 = float(123.45)
val2 = float(123.45)
self.nanSafeAssertEqual(val1, val2)

def test(self):
"""Get the wcs, calib, and visitInfo from a calexp dataset."""
butler = dafPersist.Butler(inputs=self.input)
wcs = butler.get('calexp_wcs', filter='r', immediate=True)
calib = butler.get('calexp_calib', filter='r', immediate=True)
visitInfo = butler.get('calexp_visitInfo', filter='r', immediate=True)
calexp = butler.get('calexp', filter='r', immediate=True)
self.assertIsInstance(calexp, lsst.afw.image.ExposureF)

self.assertIsInstance(wcs, lsst.afw.image.Wcs)
self.assertTrue(imageBasicUtils.wcsNearlyEqualOverBBox(wcs, calexp.getWcs(), calexp.getBBox()))

self.assertIsInstance(calib, lsst.afw.image.Calib)
self.assertEqual(calib, calexp.getCalib())

self.assertIsInstance(visitInfo, lsst.afw.image.VisitInfo)

self.assertEqual(visitInfo.getExposureId(), calexp.getInfo().getVisitInfo().getExposureId())
self.assertEqual(visitInfo.getExposureTime(), calexp.getInfo().getVisitInfo().getExposureTime())
self.nanSafeAssertEqual(visitInfo.getDarkTime(), calexp.getInfo().getVisitInfo().getDarkTime())
self.assertEqual(visitInfo.getDate(), calexp.getInfo().getVisitInfo().getDate())
self.nanSafeAssertEqual(visitInfo.getUt1(), calexp.getInfo().getVisitInfo().getUt1())
self.nanSafeAssertEqual(visitInfo.getEra(), calexp.getInfo().getVisitInfo().getEra())
self.assertEqual(visitInfo.getBoresightRaDec(), calexp.getInfo().getVisitInfo().getBoresightRaDec())
self.assertEqual(visitInfo.getBoresightAzAlt(), calexp.getInfo().getVisitInfo().getBoresightAzAlt())
self.assertEqual(visitInfo.getBoresightAirmass(), calexp.getInfo().getVisitInfo().getBoresightAirmass())
self.nanSafeAssertEqual(visitInfo.getBoresightRotAngle(),
calexp.getInfo().getVisitInfo().getBoresightRotAngle())
self.assertEqual(visitInfo.getRotType(), calexp.getInfo().getVisitInfo().getRotType())
self.assertEqual(visitInfo.getObservatory(), calexp.getInfo().getVisitInfo().getObservatory())
self.assertEqual(visitInfo.getWeather(), calexp.getInfo().getVisitInfo().getWeather())
self.nanSafeAssertEqual(visitInfo.getLocalEra(), calexp.getInfo().getVisitInfo().getLocalEra())
self.nanSafeAssertEqual(visitInfo.getBoresightHourAngle(),
calexp.getInfo().getVisitInfo().getBoresightHourAngle())





class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass


def setup_module(module):
lsst.utils.tests.init()


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()