Skip to content

Commit

Permalink
Merge pull request #743 from lsst/tickets/DM-44352
Browse files Browse the repository at this point in the history
DM-44352: Prevent overwriting existing detector mapping
  • Loading branch information
cmsaunders committed Sep 13, 2024
2 parents 569e0e2 + bb76bc6 commit 2160c40
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
26 changes: 19 additions & 7 deletions src/cameraGeom/Camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,25 @@ std::shared_ptr<Camera const> Camera::Builder::finish() const {
// from PIXELS to other things.
for (auto const & pair : getIdMap()) {
auto const & detectorBuilder = *pair.second;
connections.push_back(
TransformMap::Connection{
detectorBuilder.getOrientation().makeFpPixelTransform(detectorBuilder.getPixelSize()),
getNativeCameraSys(),
detectorBuilder.getNativeCoordSys()
}
);
std::vector<TransformMap::Connection> detectorConnections = getDetectorBuilderConnections(detectorBuilder);
std::vector<std::vector<CameraSys>> allDetConnections;
for (auto const &connection : detectorConnections) {
std::vector<CameraSys> tmpConnection = {connection.fromSys, connection.toSys};
allDetConnections.push_back(tmpConnection);
}
std::vector<CameraSys> connection = {detectorBuilder.getNativeCoordSys(), getNativeCameraSys()};
std::vector<CameraSys> invConnection = {getNativeCameraSys(), detectorBuilder.getNativeCoordSys()};
if ((std::find(allDetConnections.begin(), allDetConnections.end(), connection) == allDetConnections.end())
&& (std::find(allDetConnections.begin(), allDetConnections.end(), invConnection) == allDetConnections.end()) ) {

connections.push_back(
TransformMap::Connection{
detectorBuilder.getOrientation().makeFpPixelTransform(detectorBuilder.getPixelSize()),
getNativeCameraSys(),
detectorBuilder.getNativeCoordSys()
}
);
}
connections.insert(connections.end(),
getDetectorBuilderConnections(detectorBuilder).begin(),
getDetectorBuilderConnections(detectorBuilder).end());
Expand Down
2 changes: 1 addition & 1 deletion src/cameraGeom/Detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ void Detector::InCameraBuilder::setTransformFromPixelsTo(
CameraSys const & toSys,
std::shared_ptr<afw::geom::TransformPoint2ToPoint2 const> transform
) {
if (toSys.getDetectorName() != getName()) {
if ((toSys.hasDetectorName()) && (toSys.getDetectorName() != getName())) {
throw LSST_EXCEPT(
pex::exceptions::InvalidParameterError,
(boost::format("Cannot add coordinate system for detector '%s' to detector '%s'.") %
Expand Down
33 changes: 33 additions & 0 deletions tests/test_cameraGeom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import unittest
import os

import astshim as ast
import numpy as np

import lsst.utils.tests
Expand All @@ -41,10 +42,12 @@
FIELD_ANGLE,
FOCAL_PLANE,
makeUpdatedDetector,
Orientation,
PIXELS,
)
import lsst.afw.cameraGeom.testUtils as testUtils
import lsst.afw.cameraGeom.utils as cameraGeomUtils
from lsst.afw.geom import TransformPoint2ToPoint2

try:
type(display)
Expand Down Expand Up @@ -218,6 +221,36 @@ def testTransformDet(self):
self.assertPairsAlmostEqual(pixOffDet, pixOffDetRoundTrip)
self.assertEqual(numOffUsable, 5)

def testAACustomDetectorTransform(self):
"""Test that user-set detector to focal plane transforms are not
overriden.
"""
cameraBuilder = Camera.Builder("CameraWithCustomTransforms")

pixelSize = lsst.geom.Extent2D((0.02, 0.02))
# Detector with custom map:
detectorBuilder = cameraBuilder.add("Det0", 0)
detectorBuilder.setPixelSize(pixelSize)
detectorBuilder.setOrientation(Orientation())

customMap = ast.ZoomMap(2, 1.5)
transform = TransformPoint2ToPoint2(customMap)
detectorBuilder.setTransformFromPixelsTo(FOCAL_PLANE, transform)

# Detector with default map:
detectorBuilder = cameraBuilder.add("Det1", 1)
detectorBuilder.setPixelSize(pixelSize)
detectorBuilder.setOrientation(Orientation())

camera = cameraBuilder.finish()

testPoint = lsst.geom.Point2D(1, 1)
testPointFPDet0 = camera[0].getTransform(PIXELS, FOCAL_PLANE).applyForward(testPoint)
testPointFPDet1 = camera[1].getTransform(PIXELS, FOCAL_PLANE).applyForward(testPoint)

self.assertEqual(testPointFPDet0.x, 1.5)
self.assertNotEqual(testPointFPDet0.x, testPointFPDet1.x)

def testFindDetectors(self):
for cw in self.cameraList:
detCtrFocalPlaneList = []
Expand Down

0 comments on commit 2160c40

Please sign in to comment.