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

DM-4813: Skip obs_cfht butler mapper test if datadir isn't found. #9

Merged
merged 4 commits into from
Jan 18, 2016
Merged
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
68 changes: 31 additions & 37 deletions tests/testButler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# LSST Data Management System
# Copyright 2012 LSST Corporation.
# Copyright 2012-2016 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
Expand All @@ -22,14 +22,19 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from __future__ import print_function

import os
import sys

import unittest
import warnings
from lsst.utils import getPackageDir
import lsst.utils.tests as utilsTests
import lsst.daf.persistence as dafPersist
import lsst.afw.cameraGeom as cameraGeom
import lsst.afw.cameraGeom.utils as cameraGeomUtils
import lsst.pex.exceptions as pexExcept

try:
type(display)
Expand All @@ -38,32 +43,28 @@

frame = 0


class GetRawTestCase(unittest.TestCase):
"""Testing butler raw image retrieval"""

def setUp(self):
datadir = self.getTestDataDir()
if datadir:
self.butler = dafPersist.Butler(root=os.path.join(datadir, "DATA"),
calibRoot=os.path.join(datadir, "CALIB"))
self.size = (2112, 4644)
self.dataId = {'visit': 1038843}
self.filter = "i2"
self.runTests = True
else:
self.runTests = False
self.butler = dafPersist.Butler(root=os.path.join(datadir, "DATA"),
calibRoot=os.path.join(datadir, "CALIB"))
self.size = (2112, 4644)
self.dataId = {'visit': 1038843}
self.filter = "i2"

def tearDown(self):
if self.runTests:
del self.butler
del self.butler

def assertExposure(self, exp, ccd, checkFilter=True):
print "dataId: ", self.dataId
print "ccd: ", ccd
print "width: ", exp.getWidth()
print "height: ", exp.getHeight()
print "detector name: ", exp.getDetector().getName()
print "filter name: ", exp.getFilter().getFilterProperty().getName()
print("dataId: ", self.dataId)
print("ccd: ", ccd)
print("width: ", exp.getWidth())
print("height: ", exp.getHeight())
print("detector name: ", exp.getDetector().getName())
print("filter name: ", exp.getFilter().getFilterProperty().getName())

self.assertEqual(exp.getWidth(), self.size[0])
self.assertEqual(exp.getHeight(), self.size[1])
Expand All @@ -77,21 +78,20 @@ def assertExposure(self, exp, ccd, checkFilter=True):
ccd = cameraGeom.cast_Ccd(exp.getDetector())
for amp in ccd:
amp = cameraGeom.cast_Amp(amp)
print ccd.getId(), amp.getId(), amp.getDataSec().toString(), \
amp.getBiasSec().toString(), amp.getElectronicParams().getGain()
print(ccd.getId(), amp.getId(), amp.getDataSec().toString(),
amp.getBiasSec().toString(), amp.getElectronicParams().getGain())
cameraGeomUtils.showCcd(ccd, ccdImage=exp, frame=frame)

def getTestDataDir(self):
datadir = os.getenv("TESTDATA_CFHT_DIR")
if datadir:
return datadir
else:
print >> sys.stderr, "Skipping test as testdata_cfht is not setup"
try:
datadir = getPackageDir("testdata_cfht")
except pexExcept.NotFoundError as e:
warnings.warn(e.message)
raise unittest.SkipTest("Skipping test as testdata_cfht is not setup")
return datadir

def testRaw(self):
"""Test retrieval of raw image"""
if not self.runTests:
return
if display:
global frame
frame += 1
Expand All @@ -104,33 +104,26 @@ def testRaw(self):

def getDetrend(self, detrend):
"""Test retrieval of detrend image"""
if not self.runTests:
return
for ccd in range(36):
flat = self.butler.get(detrend, self.dataId, ccd=ccd)
flat = self.butler.get(detrend, self.dataId, ccd=ccd, immediate=True)

self.assertExposure(flat, ccd, checkFilter=False)

def testFlat(self):
if not self.runTests:
return
self.getDetrend("flat")

def testBias(self):
if not self.runTests:
return
self.getDetrend("bias")

def testFringe(self):
if not self.runTests:
return
self.getDetrend("fringe")

def testPackageName(self):
self.assertEqual(self.butler.mapper.packageName, "obs_cfht")

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


def suite():
"""Returns a suite containing all the test cases in this module."""

Expand All @@ -141,7 +134,8 @@ def suite():
suites += unittest.makeSuite(utilsTests.MemoryTestCase)
return unittest.TestSuite(suites)

def run(shouldExit = False):

def run(shouldExit=False):
"""Run the tests"""
utilsTests.run(suite(), shouldExit)

Expand Down