Skip to content

Commit

Permalink
add ConstrainedPhotometryModel constructor test
Browse files Browse the repository at this point in the history
This tests for an error in construction that I introduced while cleaning up
duplicate code: the magnitude and flux versions are almost identical,
except for values of the chip transfos: one is just the photoCalib mean,
the other is the log() of that.
  • Loading branch information
parejkoj committed Aug 22, 2018
1 parent bd290b2 commit b240722
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
2 changes: 2 additions & 0 deletions python/lsst/jointcal/photometryMappings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ void declareChipVisitPhotometryMapping(py::module &mod) {

cls.def("getChipMapping", &ChipVisitPhotometryMapping::getChipMapping);
cls.def("getVisitMapping", &ChipVisitPhotometryMapping::getVisitMapping);
cls.def("getNParChip", &ChipVisitPhotometryMapping::getNParChip);
cls.def("getNParVisit", &ChipVisitPhotometryMapping::getNParVisit);
}

void declareChipVisitFluxMapping(py::module &mod) {
Expand Down
9 changes: 6 additions & 3 deletions python/lsst/jointcal/testUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
import lsst.jointcal.star


def createTwoFakeCcdImages(num1=4, num2=4, seed=100, fakeCcdId=12):
def createTwoFakeCcdImages(num1=4, num2=4, seed=100, fakeCcdId=12,
photoCalibMean1=100.0, photoCalibMean2=120.0):
"""Return two fake ccdImages built on CFHT Megacam metadata.
If ``num1 == num2``, the catalogs will align on-sky so each source will
Expand All @@ -53,6 +54,8 @@ def createTwoFakeCcdImages(num1=4, num2=4, seed=100, fakeCcdId=12):
Sensor identifier to use for both CcdImages. The wcs, bbox, calib, etc.
will still be drawn from the CFHT ccd=12 files, as that is the only
testdata that is included in this simple test dataset.
photoCalibMean1, photoCalibMean2: `float`, optional
The mean photometric calibration to pass to each ccdImage construction.
Returns
-------
Expand Down Expand Up @@ -83,9 +86,9 @@ def createTwoFakeCcdImages(num1=4, num2=4, seed=100, fakeCcdId=12):
camera = butler.get('camera', visit=visit1)

struct1 = createFakeCcdImage(butler, visit1, num1, instFluxKeyName,
photoCalibMean=100.0, photoCalibErr=1.0, fakeCcdId=fakeCcdId)
photoCalibMean=photoCalibMean1, photoCalibErr=1.0, fakeCcdId=fakeCcdId)
struct2 = createFakeCcdImage(butler, visit2, num2, instFluxKeyName,
photoCalibMean=120.0, photoCalibErr=5.0, fakeCcdId=fakeCcdId)
photoCalibMean=photoCalibMean2, photoCalibErr=5.0, fakeCcdId=fakeCcdId)

return lsst.pipe.base.Struct(camera=camera,
catalogs=[struct1.catalog, struct2.catalog],
Expand Down
57 changes: 52 additions & 5 deletions tests/test_photometryModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,17 @@ def _initModel2(self, Model):
# in `test_assignIndices()`.
# createTwoFakeCcdImages() always uses the same two visitIds,
# so there will be 2 visits total here.
struct1 = lsst.jointcal.testUtils.createTwoFakeCcdImages(100, 100, seed=100, fakeCcdId=12)
ccdImageList = struct1.ccdImageList
struct2 = lsst.jointcal.testUtils.createTwoFakeCcdImages(100, 100, seed=101, fakeCcdId=13)
ccdImageList.extend(struct2.ccdImageList)
struct1 = lsst.jointcal.testUtils.createTwoFakeCcdImages(100, 100, seed=100, fakeCcdId=12,
photoCalibMean1=100.0,
photoCalibMean2=120.0)
self.ccdImageList2 = struct1.ccdImageList
struct2 = lsst.jointcal.testUtils.createTwoFakeCcdImages(100, 100, seed=101, fakeCcdId=13,
photoCalibMean1=101.0,
photoCalibMean2=121.0)
self.ccdImageList2.extend(struct2.ccdImageList)
camera = struct1.camera # the camera is the same in both structs
focalPlaneBBox = camera.getFpBBox()
self.model2 = Model(ccdImageList, focalPlaneBBox, self.visitOrder)
self.model2 = Model(self.ccdImageList2, focalPlaneBBox, self.visitOrder)

def test_getNpar(self):
"""
Expand Down Expand Up @@ -233,6 +237,24 @@ def test_assignIndices(self):
index = self.model2.assignIndices("ModelChip", self.firstIndex)
self.assertEqual(index, expect)

def _testConstructor(self, expectVisit, expectChips):
"""Post-construction, the ChipTransfos should be the PhotoCalib mean of
the first visit's ccds, and the VisitTransfos should be the identity.
"""
# Identify to the model that we're fitting both components.
self.model2.assignIndices("Model", self.firstIndex)

# check the visitMappings
for ccdImage in self.ccdImageList2:
result = self.model2.getMapping(ccdImage).getVisitMapping().getTransfo().getParameters()
self.assertFloatsEqual(result, expectVisit, msg=ccdImage.getName())

# check the chipMappings
for ccdImage, expect in zip(self.ccdImageList2, expectChips):
result = self.model2.getMapping(ccdImage).getChipMapping().getTransfo().getParameters()
# almost equal because log() may have been involved in the math
self.assertFloatsAlmostEqual(result, expect, msg=ccdImage.getName())


class ConstrainedFluxModelTestCase(ConstrainedPhotometryModelTestCase,
FluxTestBase,
Expand All @@ -248,6 +270,17 @@ def setUp(self):

self._initModel2(lsst.jointcal.ConstrainedFluxModel)

def testConstructor(self):
expectVisit = np.zeros(int(getNParametersPolynomial(self.visitOrder)))
expectVisit[0] = 1
# chipMappings are fixed per-chip, and thus are
# shared between the first pair and second pair of fake ccdImages
expectChips = [self.ccdImageList2[0].getPhotoCalib().getCalibrationMean(),
self.ccdImageList2[0].getPhotoCalib().getCalibrationMean(),
self.ccdImageList2[2].getPhotoCalib().getCalibrationMean(),
self.ccdImageList2[2].getPhotoCalib().getCalibrationMean()]
self._testConstructor(expectVisit, expectChips)


class ConstrainedMagnitudeModelTestCase(ConstrainedPhotometryModelTestCase,
MagnitudeTestBase,
Expand All @@ -265,6 +298,20 @@ def setUp(self):

self.useMagnitude = True

def testConstructor(self):
expectVisit = np.zeros(int(getNParametersPolynomial(self.visitOrder)))

def fluxToMag(flux):
return -2.5*np.log10(flux)

# chipMappings are fixed per-chip, and thus are
# shared between the first pair and second pair of fake ccdImages
expectChips = [fluxToMag(self.ccdImageList2[0].getPhotoCalib().getCalibrationMean()),
fluxToMag(self.ccdImageList2[0].getPhotoCalib().getCalibrationMean()),
fluxToMag(self.ccdImageList2[2].getPhotoCalib().getCalibrationMean()),
fluxToMag(self.ccdImageList2[2].getPhotoCalib().getCalibrationMean())]
self._testConstructor(expectVisit, expectChips)


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

0 comments on commit b240722

Please sign in to comment.