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-16650: Update to new nJy PhotoCalib definition #48

Merged
merged 2 commits into from
Dec 27, 2018
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
6 changes: 4 additions & 2 deletions python/lsst/meas/mosaic/mosaicTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,14 @@ def writeFcr(self, dataRefList):
print("failed to read Wcs for PhotoCalib: %s" % (e))
continue
instFluxMag0, instFluxMag0Err = calib.getFluxMag0()
# TODO: need to scale these until DM-10153 is completed and PhotoCalib has replaced Calib
referenceFlux = 1e23 * 10**(48.6 / -2.5) * 1e9
bf = measMosaic.FluxFitBoundedField(bbox, newP, wcs,
zeroPoint=instFluxMag0,
nQuarter=nQuarter)
photoCalib = afwImage.PhotoCalib(
1.0/instFluxMag0,
instFluxMag0Err/instFluxMag0**2,
referenceFlux / instFluxMag0,
referenceFlux * instFluxMag0Err/instFluxMag0**2,
bf,
isConstant=False
)
Expand Down
3 changes: 2 additions & 1 deletion src/FluxFitBoundedField.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "lsst/afw/table/io/InputArchive.h"
#include "lsst/afw/table/io/CatalogVector.h"
#include "lsst/afw/table/io/Persistable.cc"
#include "lsst/utils/Magnitude.h"

namespace lsst {
namespace afw {
Expand Down Expand Up @@ -89,7 +90,7 @@ FluxFitBoundedField::FluxFitBoundedField(
}

double FluxFitBoundedField::evaluate(afw::geom::Point2D const & position) const {
double r = 1.0/_zeroPoint;
double r = utils::referenceFlux/_zeroPoint;
if (_ffp) {
auto xy = _transform(position);
if (xy.getX() < -1E-8 || xy.getY() < -1E-8) {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

801 changes: 801 additions & 0 deletions tests/data/8766/jointcal_photoCalib-0011506-049.fits

Large diffs are not rendered by default.

801 changes: 801 additions & 0 deletions tests/data/8766/jointcal_photoCalib-0011506-050.fits

Large diffs are not rendered by default.

819 changes: 819 additions & 0 deletions tests/data/8766/jointcal_photoCalib-0011506-101.fits

Large diffs are not rendered by default.

818 changes: 818 additions & 0 deletions tests/data/8766/jointcal_photoCalib-0011506-102.fits

Large diffs are not rendered by default.

798 changes: 798 additions & 0 deletions tests/data/8766/jointcal_wcs-0011506-049.fits

Large diffs are not rendered by default.

800 changes: 800 additions & 0 deletions tests/data/8766/jointcal_wcs-0011506-050.fits

Large diffs are not rendered by default.

818 changes: 818 additions & 0 deletions tests/data/8766/jointcal_wcs-0011506-101.fits

Large diffs are not rendered by default.

818 changes: 818 additions & 0 deletions tests/data/8766/jointcal_wcs-0011506-102.fits

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions tests/data/8766/photoCalib-0007358-049.fits

This file was deleted.

5 changes: 0 additions & 5 deletions tests/data/8766/photoCalib-0007358-050.fits

This file was deleted.

14 changes: 0 additions & 14 deletions tests/data/8766/photoCalib-0007358-101.fits

This file was deleted.

10 changes: 0 additions & 10 deletions tests/data/8766/photoCalib-0007358-102.fits

This file was deleted.

6 changes: 0 additions & 6 deletions tests/data/8766/wcs-0007358-049.fits

This file was deleted.

5 changes: 0 additions & 5 deletions tests/data/8766/wcs-0007358-050.fits

This file was deleted.

10 changes: 0 additions & 10 deletions tests/data/8766/wcs-0007358-101.fits

This file was deleted.

9 changes: 0 additions & 9 deletions tests/data/8766/wcs-0007358-102.fits

This file was deleted.

24 changes: 13 additions & 11 deletions tests/test_fluxFitBoundedField.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@

DATA_DIR = os.path.join(os.path.split(__file__)[0], "data")

# Note: mosaic's internal ffp object is magnitude-based.
# Instead, for these tests, we just divide this out when comparing.
referenceFlux = 1e23 * 10**(48.6 / -2.5) * 1e9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a #TODO or is this just for the internal tests and meas_mosaic won't be changed even when Calib is retired?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No TODO here: mosaic's internal format will not change.



def displayImageDifferences(image1, image2, rtol=1E-8, atol=1E-8, pause=False):
import lsst.afw.display
Expand Down Expand Up @@ -119,7 +123,7 @@ class FluxFitBoundedFieldTestCase(lsst.utils.tests.TestCase):
def setUp(self):
np.random.seed(100)
self.tract = 8766
self.visit = 7358
self.visit = 11506
self.ccds = {0: 49, 2: 50, 3: 101, 1: 102}
# Box is the same for all CCDs, since it's defined in CCD coordinates,
# which are rotated w.r.t. focal plane coordinates.
Expand All @@ -142,21 +146,18 @@ def setUp(self):
self.ffp[ccd] = lsst.meas.mosaic.FluxFitParams(fcrMetadata)
wcsFilename = os.path.join(
DATA_DIR,
"%d/wcs-%07d-%03d.fits" % (self.tract, self.visit, ccd)
"%d/jointcal_wcs-%07d-%03d.fits" % (self.tract, self.visit, ccd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably not something done on this ticket, but...we renamed "wcs" to "jointcal_wcs"...for meas_mosaic, too? I wasn't paying attention, but I thought the point of the rename must have been to let meas_mosaic and jointcal outputs exist in the same data repo so they could be selected via config (rather than input rerun) in the coaddition tasks.

Copy link
Contributor Author

@parejkoj parejkoj Dec 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was renamed: see mosaicTask.py:646.

The goal of the rename was to make it more obvious what the object was. jointcal and meas_mosaic have identical output so that the input to calibration/validation can be swapped between them.

)
# WCS is saved as an empty exposure with WCS
# (rather than as a WCS fits file)
wcsExposure = lsst.afw.image.ExposureF(wcsFilename)
self.wcs[ccd] = wcsExposure.getWcs()
self.wcs[ccd] = lsst.afw.geom.SkyWcs.readFits(wcsFilename)
photoCalibFilename = os.path.join(
DATA_DIR,
"%d/photoCalib-%07d-%03d.fits" % (self.tract, self.visit, ccd)
"%d/jointcal_photoCalib-%07d-%03d.fits" % (self.tract, self.visit, ccd)
)
self.photoCalib[ccd] = lsst.afw.image.PhotoCalib.readFits(photoCalibFilename)
camera[ccd] = MockDetector(MockOrientation(nQuarter))
self.dataRefs[ccd] = MockDataRef(visit=self.visit, tract=self.tract, ccd=ccd)
self.dataRefs[ccd].put(fcrMetadata, "fcr_md", )
self.dataRefs[ccd].put(wcsExposure, "wcs")
self.dataRefs[ccd].put(self.wcs[ccd], "jointcal_wcs")
self.dataRefs[ccd].put(calexpMetadata, "calexp_md")
self.dataRefs[ccd].put(camera, "camera")
self.dataRefs[ccd].put(self.bbox, "calexp_bbox")
Expand Down Expand Up @@ -189,6 +190,7 @@ def checkFillImage(self, nQuarter, ffp=True, wcs=True, display=False):
bf, ffp, wcs = self.makeBoundedField(nQuarter, ffp, wcs)
image1 = lsst.afw.image.ImageF(self.bbox)
bf.fillImage(image1, xStep=100, yStep=16)
image1 /= referenceFlux # turn nJy into Maggy: ffp outputs Maggy
if nQuarter%2:
width, height = self.bbox.getHeight(), self.bbox.getWidth()
else:
Expand Down Expand Up @@ -265,9 +267,9 @@ def checkPhotoCalibCatalog(self, nQuarter):
mag2 = catalog2["example_mag"]
# Check that the non-spatially varying part of the correction is the same.
fluxMag0 = results2.ffp.calib.getFluxMag0()
self.assertFloatsAlmostEqual(photoCalib.getInstFluxMag0(), fluxMag0[0],
self.assertFloatsAlmostEqual(photoCalib.getInstFluxAtZeroMagnitude(), fluxMag0[0],
rtol=1E-14)
self.assertFloatsAlmostEqual(photoCalib.getCalibrationErr(), fluxMag0[1]/fluxMag0[0]**2,
self.assertFloatsAlmostEqual(photoCalib.getCalibrationErr(), referenceFlux*fluxMag0[1]/fluxMag0[0]**2,
rtol=1E-14)
# Compute partially-calibrated magnitudes that don't account for the spatially-varying part.
mag0, magErr0 = results2.ffp.calib.getMagnitude(catalog.get("example_instFlux"),
Expand All @@ -279,7 +281,7 @@ def checkPhotoCalibCatalog(self, nQuarter):
# round-off error).
magDiff2 = mag2 - mag0
magDiff1 = mag1 - mag0
self.assertFloatsAlmostEqual(magDiff1, magDiff2, rtol=rtol*2E3)
self.assertFloatsAlmostEqual(magDiff1, magDiff2, rtol=rtol*3E3)

def checkPhotoCalibExposure(self, nQuarter):
ccd = self.ccds[nQuarter]
Expand Down