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-5922: Rework camera geometry to use the replacement for XYTransform #60

Merged
merged 3 commits into from
Sep 2, 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
5 changes: 4 additions & 1 deletion python/lsst/obs/base/cameraMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ def _initMappings(self, policy, rootStorage=None, calibStorage=None, provided=No
subPolicy.merge(defPolicy)

if not hasattr(self, "map_" + datasetType) and 'composite' in subPolicy:
def compositeClosure(dataId, write=False, mapper=None, mapping=None, subPolicy=subPolicy):
def compositeClosure(dataId, write=False, mapper=None, mapping=None,
subPolicy=subPolicy):
components = subPolicy.get('composite')
assembler = subPolicy['assembler'] if 'assembler' in subPolicy else None
disassembler = subPolicy['disassembler'] if 'disassembler' in subPolicy else None
Expand Down Expand Up @@ -470,6 +471,7 @@ def mapSubClosure(dataId, write=False, mapper=weakref.proxy(self), mapping=mappi
loc.additionalData.set('imageOrigin',
dataId['imageOrigin'])
return loc

def querySubClosure(key, format, dataId, mapping=mapping):
subId = dataId.copy()
del subId['bbox']
Expand Down Expand Up @@ -1060,6 +1062,7 @@ def getRegistry(self):
"""
return self.registry


def exposureFromImage(image, dataId=None, mapper=None, logger=None, setVisitInfo=True):
"""Generate an Exposure from an image-like object

Expand Down
1 change: 1 addition & 0 deletions python/lsst/obs/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import re
import lsst.afw.geom as afwGeom


def bboxFromIraf(irafBBoxStr):
"""Return a Box2I corresponding to an IRAF-style BBOX

Expand Down
22 changes: 11 additions & 11 deletions python/lsst/obs/base/yamlCamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import range
import yaml

import numpy as np
Expand All @@ -28,20 +27,21 @@
from lsst.afw.table import AmpInfoCatalog, AmpInfoTable
from lsst.afw.cameraGeom.cameraFactory import makeDetector


class YamlCamera(cameraGeom.Camera):
"""The Commissioning Camera (comCam)
"""

def __init__(self, cameraYamlFile):
"""Construct a Camera
"""
with file(cameraYamlFile) as fd:
with open(cameraYamlFile) as fd:
cameraParams = yaml.load(fd, Loader=yaml.Loader)

plateScale = afwGeom.Angle(cameraParams["plateScale"], afwGeom.arcseconds)
radialCoeffs = np.array(cameraParams["radialCoeffs"])/plateScale.asRadians()
focalPlaneToPupil = afwGeom.RadialXYTransform(radialCoeffs)
pupilToFocalPlane = afwGeom.InvertedXYTransform(focalPlaneToPupil)
focalPlaneToPupil = afwGeom.makeRadialTransform(radialCoeffs)
pupilToFocalPlane = focalPlaneToPupil.getInverse()
cameraTransformMap = cameraGeom.CameraTransformMap(cameraGeom.FOCAL_PLANE,
{cameraGeom.PUPIL: pupilToFocalPlane})
detectorList = self._makeDetectorList(cameraParams["CCDs"], pupilToFocalPlane, plateScale)
Expand Down Expand Up @@ -89,15 +89,15 @@ def _makeDetectorConfigList(self, ccdParams):
detectorConfig.pitchDeg = ccd['pitch']
detectorConfig.yawDeg = ccd['yaw']
detectorConfig.rollDeg = ccd['roll']

return detectorConfigs

@staticmethod
def _makeBBoxFromList(ylist):
"""Given a list [(x0, y0), (xsize, ysize)], probably from a yaml file, return a BoxI
"""
(x0, y0), (xsize, ysize) = ylist
return afwGeom.BoxI(afwGeom.PointI(x0, y0), afwGeom.ExtentI(xsize, ysize))
return afwGeom.BoxI(afwGeom.PointI(x0, y0), afwGeom.ExtentI(xsize, ysize))

def _makeAmpInfoCatalog(self, ccd):
"""Construct an amplifier info catalog
Expand All @@ -106,9 +106,9 @@ def _makeAmpInfoCatalog(self, ccd):
assert len(ccd['amplifiers']) > 0
amp = ccd['amplifiers'].values()[0]

rawBBox = self._makeBBoxFromList(amp['rawBBox']) # total in file
rawBBox = self._makeBBoxFromList(amp['rawBBox']) # total in file
xRawExtent, yRawExtent = rawBBox.getDimensions()

from lsst.afw.table import LL, LR, UL, UR
readCorners = dict(LL = LL, LR = LR, UL = UL, UR = UR)

Expand All @@ -121,7 +121,7 @@ def _makeAmpInfoCatalog(self, ccd):
# end placeholder
self.ampInfoDict = {}
ampCatalog = AmpInfoCatalog(schema)
for name, amp in sorted(ccd['amplifiers'].items(), key=lambda x : x[1]['hdu']):
for name, amp in sorted(ccd['amplifiers'].items(), key=lambda x: x[1]['hdu']):
record = ampCatalog.addNew()
record.setName(name)
record.set(hduKey, amp['hdu'])
Expand All @@ -133,15 +133,15 @@ def _makeAmpInfoCatalog(self, ccd):
else:
x0, y0 = ix*xRawExtent, iy*yRawExtent

rawDataBBox = self._makeBBoxFromList(amp['rawDataBBox']) # Photosensitive area
rawDataBBox = self._makeBBoxFromList(amp['rawDataBBox']) # Photosensitive area
xDataExtent, yDataExtent = rawDataBBox.getDimensions()
record.setBBox(afwGeom.BoxI(
afwGeom.PointI(ix*xDataExtent, iy*yDataExtent), rawDataBBox.getDimensions()))

rawBBox = self._makeBBoxFromList(amp['rawBBox'])
rawBBox.shift(afwGeom.ExtentI(x0, y0))
record.setRawBBox(rawBBox)

rawDataBBox = self._makeBBoxFromList(amp['rawDataBBox'])
rawDataBBox.shift(afwGeom.ExtentI(x0, y0))
record.setRawDataBBox(rawDataBBox)
Expand Down
19 changes: 8 additions & 11 deletions tests/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
config.plateScale = 13.7
config.transformDict.nativeSys = 'FocalPlane'
config.transformDict.transforms = {}
config.transformDict.transforms['Pupil'] = lsst.afw.geom.transformConfig.TransformConfig()
config.transformDict.transforms['Pupil'].transform['multi'].transformDict = None
config.transformDict.transforms['Pupil'].transform['affine'].translation = [0.0, 0.0]
config.transformDict.transforms['Pupil'].transform['affine'].linear = [1.0, 0.0, 0.0, 1.0]
config.transformDict.transforms['Pupil'].transform['radial'].coeffs = None
import lsst.afw.geom.xyTransformFactory
config.transformDict.transforms['Pupil'].transform['inverted'].transform.retarget(
target=lsst.afw.geom.xyTransformFactory.makeRadialXYTransform, ConfigClass=lsst.afw.geom.xyTransformFactory.RadialXYTransformConfig)
config.transformDict.transforms['Pupil'].transform[
'inverted'].transform.coeffs = [0.0, 14805.4, 13619.3, 426637.0]
config.transformDict.transforms['Pupil'].transform.name = 'inverted'
config.transformDict.transforms['FieldAngle'] = lsst.afw.geom.transformConfig.TransformConfig()
config.transformDict.transforms['FieldAngle'].transform['multi'].transformDict = None
config.transformDict.transforms['FieldAngle'].transform['affine'].translation = [0.0, 0.0]
config.transformDict.transforms['FieldAngle'].transform['affine'].linear = [1.0, 0.0, 0.0, 1.0]
config.transformDict.transforms['FieldAngle'].transform['radial'].coeffs = None
config.transformDict.transforms['FieldAngle'].transform['inverted'].transform.retarget(target=lsst.afw.geom.transformRegistry['radial'])
config.transformDict.transforms['FieldAngle'].transform['inverted'].transform.coeffs = [0.0, 14805.4, 13619.3, 426637.0]
config.transformDict.transforms['FieldAngle'].transform.name = 'inverted'
config.detectorList = {}
config.detectorList[0] = lsst.afw.cameraGeom.cameraConfig.DetectorConfig()
config.detectorList[0].bbox_y0 = 0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

import filecmp
import os
import shutil
import unittest
import tempfile
import lsst.utils.tests
from lsst.utils import getPackageDir

import lsst.daf.persistence as dafPersist
import lsst.daf.persistence.test as dpTest

ROOT = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -63,13 +60,14 @@ def test(self):
f.write('lsst.obs.base.test.CompositeMapper')

# this should not raise an error, no error indicates that the mapper can not be found.
butler = dafPersist.Butler(root=self.childRepoDir)
dafPersist.Butler(root=self.childRepoDir)

def testNoMapper(self):
# Since in this case the _mapper file does not exist in the parent repo, this should raise an error
# indicating that the mapper can not be found.
with self.assertRaises(RuntimeError):
butler = dafPersist.Butler(self.childRepoDir, policyDir=self.testDir)
dafPersist.Butler(self.childRepoDir, policyDir=self.testDir)


class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions tests/testOutputRoot.py → tests/test_outputRoot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
Expand All @@ -22,7 +20,6 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#


from future import standard_library
standard_library.install_aliases()
import unittest
Expand Down
11 changes: 5 additions & 6 deletions tests/testPolicy.py → tests/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ def test(self):
"""

objA = dpTest.TestObject("abc")
objB = dpTest.TestObject("def")
dpTest.TestObject("def")

firstRepoPath = os.path.join(self.testData, 'repo1')
secondRepoPath = os.path.join(self.testData, 'repo2')
os.path.join(self.testData, 'repo2')

policy = dafPersist.Policy({'camera': 'lsst.afw.cameraGeom.Camera',
'datasets': {
'basicObject1': {
'python': 'lsst.daf.persistence.test.TestObject',
'template': 'basic/id%(id)s.pickle',
'storage': 'PickleStorage'},
}
}
})

firstRepoPath = os.path.join(self.testData, 'repo1')
Expand All @@ -71,19 +71,18 @@ def test(self):
with open(os.path.join(firstRepoPath, 'repositoryCfg.yaml')) as f:
cfg = yaml.load(f)
self.assertEqual(cfg.policy, policy)
butler.put(objA, 'basicObject1', {'id':1})
butler.put(objA, 'basicObject1', {'id': 1})

del butler
del repoArgs

# Test that a newly-initialized butler can find the policy in the repositoryCfg.
repoArgs = dafPersist.RepositoryArgs(root=firstRepoPath)
butler = dafPersist.Butler(inputs=repoArgs)
reloadedObjA = butler.get('basicObject1', {'id':1})
reloadedObjA = butler.get('basicObject1', {'id': 1})
self.assertEqual(reloadedObjA, objA)



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

Expand Down
3 changes: 1 addition & 2 deletions tests/testUtils.py → tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

from __future__ import absolute_import, division, print_function

import sys
import unittest

import lsst.utils.tests
Expand All @@ -42,7 +41,6 @@ def testValid(self):
for val, result in test_data.items():
self.assertEqual(obsBase.bboxFromIraf(val), result)


def testInvalid(self):
test_data = {
"1:1084,1:1024": RuntimeError,
Expand All @@ -60,6 +58,7 @@ class MemoryTester(lsst.utils.tests.MemoryTestCase):
def setup_module(module):
lsst.utils.tests.init()


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