Skip to content

Commit

Permalink
flux->instFlux
Browse files Browse the repository at this point in the history
The correct field to use is the CalibFlux field (not GaussianFlux nee
InstFlux), but I'd also been calling it the instFluxKeyName;
it was really the name of the fluxField, not the key.
  • Loading branch information
parejkoj committed Sep 18, 2018
1 parent 8e16a51 commit cb7cf42
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 40 deletions.
57 changes: 30 additions & 27 deletions python/lsst/jointcal/testUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ def createTwoFakeCcdImages(num1=4, num2=4, seed=100, fakeCcdId=12,
- `ccdImageList` : CcdImages containing the metadata and fake sources
(`list` of `lsst.jointcal.CcdImage`).
- `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`).
- 'instFluxKeyName' : name of the instFlux field in the catalogs ('str').
- 'fluxFieldName' : name of the instFlux field in the catalogs ('str').
"""
np.random.seed(seed)

visit1 = 849375
visit2 = 850587
instFluxKeyName = "SomeFlux"
fluxFieldName = "SomeFlux"

# Load or fake the necessary metadata for each CcdImage
dataDir = lsst.utils.getPackageDir('jointcal')
Expand All @@ -85,19 +85,19 @@ def createTwoFakeCcdImages(num1=4, num2=4, seed=100, fakeCcdId=12,
# so we can access parts of the camera later (e.g. focal plane)
camera = butler.get('camera', visit=visit1)

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

return lsst.pipe.base.Struct(camera=camera,
catalogs=[struct1.catalog, struct2.catalog],
ccdImageList=[struct1.ccdImage, struct2.ccdImage],
bbox=struct1.bbox,
instFluxKeyName=instFluxKeyName)
fluxFieldName=fluxFieldName)


def createFakeCcdImage(butler, visit, num, instFluxKeyName,
def createFakeCcdImage(butler, visit, num, fluxFieldName,
photoCalibMean=100.0, photoCalibErr=1.0, fakeCcdId=12):
"""Create a fake CcdImage by making a fake catalog.
Expand All @@ -110,8 +110,9 @@ def createFakeCcdImage(butler, visit, num, instFluxKeyName,
num : `int`
Number of sources to put in the catalogs. Should be
a square, to have sqrt(num) centroids on a grid.
instFluxKeyName : `str`
Name of the instFluxKey to populate in the catalog.
fluxFieldName : `str`
Name of the flux field to populate in the catalog, without `_instFlux`
(e.g. "slot_CalibFlux").
photoCalibMean : `float`, optional
Value to set for calibrationMean in the created PhotoCalib.
photoCalibErr : `float`, optional
Expand Down Expand Up @@ -140,14 +141,14 @@ def createFakeCcdImage(butler, visit, num, instFluxKeyName,
filt = butler.get("calexp_filter", dataId=dataId).getName()
photoCalib = lsst.afw.image.PhotoCalib(photoCalibMean, photoCalibErr)

catalog = createFakeCatalog(num, bbox, instFluxKeyName, skyWcs=skyWcs)
catalog = createFakeCatalog(num, bbox, fluxFieldName, skyWcs=skyWcs)
ccdImage = lsst.jointcal.ccdImage.CcdImage(catalog, skyWcs, visitInfo, bbox, filt, photoCalib,
detector, visit, fakeCcdId, instFluxKeyName)
detector, visit, fakeCcdId, fluxFieldName)

return lsst.pipe.base.Struct(catalog=catalog, ccdImage=ccdImage, bbox=bbox)


def createFakeCatalog(num, bbox, instFluxKeyName, skyWcs=None, refCat=False):
def createFakeCatalog(num, bbox, fluxFieldName, skyWcs=None, refCat=False):
"""Return a fake minimally-useful catalog for jointcal.
Parameters
Expand All @@ -157,8 +158,9 @@ def createFakeCatalog(num, bbox, instFluxKeyName, skyWcs=None, refCat=False):
a square, to have sqrt(num) centroids on a grid.
bbox : `lsst.afw.geom.Box2I`
Bounding Box of the detector to populate.
instFluxKeyName : `str`
Name of the instFluxKey to populate in the catalog.
fluxFieldName : `str`
Name of the flux field to populate in the catalog, without `_instFlux`
(e.g. "slot_CalibFlux").
skyWcs : `lsst.afw.geom.SkyWcs` or None, optional
If supplied, use this to fill in coordinates from centroids.
refCat : `bool`, optional
Expand All @@ -178,19 +180,19 @@ def createFakeCatalog(num, bbox, instFluxKeyName, skyWcs=None, refCat=False):
shapeKey = lsst.afw.table.QuadrupoleKey.addFields(schema, "shape", "",
lsst.afw.table.CoordinateType.PIXEL)
# Put the fake sources in the minimal catalog.
schema.addField(instFluxKeyName+"_flux", type="D", doc="post-ISR instFlux")
schema.addField(instFluxKeyName+"_fluxErr", type="D", doc="post-ISR instFlux stddev")
schema.addField(instFluxKeyName+"_calFlux", type="D", doc="maggies")
schema.addField(instFluxKeyName+"_calFluxErr", type="D", doc="maggies stddev")
schema.addField(instFluxKeyName+"_mag", type="D", doc="magnitude")
schema.addField(instFluxKeyName+"_magErr", type="D", doc="magnitude stddev")
schema.addField(fluxFieldName+"_instFlux", type="D", doc="post-ISR instFlux")
schema.addField(fluxFieldName+"_instFluxErr", type="D", doc="post-ISR instFlux stddev")
schema.addField(fluxFieldName+"_flux", type="D", doc="maggies")
schema.addField(fluxFieldName+"_fluxErr", type="D", doc="maggies stddev")
schema.addField(fluxFieldName+"_mag", type="D", doc="magnitude")
schema.addField(fluxFieldName+"_magErr", type="D", doc="magnitude stddev")
return fillCatalog(schema, num, bbox,
centroidKey, xErrKey, yErrKey, shapeKey, instFluxKeyName,
centroidKey, xErrKey, yErrKey, shapeKey, fluxFieldName,
skyWcs=skyWcs, refCat=refCat)


def fillCatalog(schema, num, bbox,
centroidKey, xErrKey, yErrKey, shapeKey, instFluxKeyName,
centroidKey, xErrKey, yErrKey, shapeKey, fluxFieldName,
skyWcs=None, fluxErrFraction=0.05, refCat=False):
"""Return a catalog populated with fake, but reasonable, sources.
Expand All @@ -212,8 +214,9 @@ def fillCatalog(schema, num, bbox,
Key for the yErr field to populate.
shapeKey : `lsst.afw.table.Key`
Key for the shape field to populate.
instFluxKeyName : `str`
Name of instFlux field to populate (i.e. instFluxKeyName+'_flux')
fluxFieldName : `str`
Name of the flux field to populate in the catalog, without `_instFlux`
(e.g. "slot_CalibFlux").
skyWcs : `lsst.afw.geom.SkyWcs` or None, optional
If supplied, use this to fill in coordinates from centroids.
fluxErrFraction : `float`, optional
Expand All @@ -229,7 +232,7 @@ def fillCatalog(schema, num, bbox,
table = lsst.afw.table.SourceTable.make(schema)
table.defineCentroid('centroid')
table.defineShape('shape')
table.defineInstFlux(instFluxKeyName)
table.defineCalibFlux(fluxFieldName)
if refCat:
catalog = lsst.afw.table.SimpleCatalog(table)
else:
Expand Down Expand Up @@ -259,8 +262,8 @@ def fillCatalog(schema, num, bbox,

catalog[xErrKey] = vx
catalog[yErrKey] = vy
catalog[instFluxKeyName + '_flux'] = instFlux
catalog[instFluxKeyName + '_fluxErr'] = instFluxErr
catalog[fluxFieldName + '_instFlux'] = instFlux
catalog[fluxFieldName + '_instFluxErr'] = instFluxErr

return catalog

Expand All @@ -286,7 +289,7 @@ def getMeasuredStarsFromCatalog(catalog, pixToFocal):
star = lsst.jointcal.star.MeasuredStar()
star.x = record.getX()
star.y = record.getY()
star.setInstFluxAndErr(record.getInstFlux(), record.getInstFluxErr())
star.setInstFluxAndErr(record.getCalibInstFlux(), record.getCalibInstFluxErr())
# TODO: cleanup after DM-4044
point = lsst.afw.geom.Point2D(star.x, star.y)
pointFocal = pixToFocal.applyForward(point)
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/jointcal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def rms(flux, ref_flux):
self.old_mag = np.fromiter((abMagFromFlux(r) for r in self.old_ref), dtype=float)
self.new_mag = np.fromiter((abMagFromFlux(r) for r in self.new_ref), dtype=float)

def signal_to_noise(sources, flux_key='slot_PsfFlux_flux', sigma_key='slot_PsfFlux_fluxErr'):
def signal_to_noise(sources, flux_key='slot_PsfFlux_instFlux', sigma_key='slot_PsfFlux_instFluxErr'):
"""Compute the mean signal/noise per source from a MatchDict of SourceRecords."""
result = np.empty(len(sources))
for i, src in enumerate(sources.values()):
Expand Down Expand Up @@ -322,7 +322,7 @@ def _make_match_dict(self, reference, visit_catalogs, photoCalibs, refcalib=None
fluxes = collections.defaultdict(list)
ref_fluxes = {}
sources = collections.defaultdict(list)
if 'slot_CalibFlux_flux' in reference.schema:
if 'slot_CalibFlux_instFlux' in reference.schema:
ref_flux_key = 'slot_CalibFlux'
else:
ref_flux_key = '{}_flux'
Expand All @@ -331,7 +331,7 @@ def get_fluxes(photoCalib, match):
"""Return (flux, ref_flux) or None if either is invalid."""
# NOTE: Protect against negative fluxes: ignore this match if we find one.
maggiesToJansky = 3631
flux = match[1]['slot_CalibFlux_flux']
flux = match[1]['slot_CalibFlux_instFlux']
if flux < 0:
return None
else:
Expand All @@ -354,7 +354,7 @@ def get_fluxes(photoCalib, match):
return Flux(flux, ref_flux)

for cat, photoCalib, filt in zip(visit_catalogs, photoCalibs, self.filters):
good = (cat.get('base_PsfFlux_flux')/cat.get('base_PsfFlux_fluxErr')) > self.flux_limit
good = (cat.get('base_PsfFlux_instFlux')/cat.get('base_PsfFlux_instFluxErr')) > self.flux_limit
# things the classifier called sources are not extended.
good &= (cat.get('base_ClassificationExtendedness_value') == 0)
matches = lsst.afw.table.matchRaDec(reference, cat[good], self.match_radius)
Expand Down
6 changes: 3 additions & 3 deletions src/CcdImage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ void CcdImage::loadCatalog(afw::table::SourceCatalog const &catalog, std::string
auto mxxKey = catalog.getSchema().find<double>("slot_Shape_xx").key;
auto myyKey = catalog.getSchema().find<double>("slot_Shape_yy").key;
auto mxyKey = catalog.getSchema().find<double>("slot_Shape_xy").key;
auto fluxKey = catalog.getSchema().find<double>(fluxField + "_flux").key;
auto fluxErrKey = catalog.getSchema().find<double>(fluxField + "_fluxErr").key;
auto instFluxKey = catalog.getSchema().find<double>(fluxField + "_instFlux").key;
auto instFluxErrKey = catalog.getSchema().find<double>(fluxField + "_instFluxErr").key;

auto transform = _detector->getTransform(afw::cameraGeom::PIXELS, afw::cameraGeom::FOCAL_PLANE);

Expand Down Expand Up @@ -67,7 +67,7 @@ void CcdImage::loadCatalog(afw::table::SourceCatalog const &catalog, std::string
<< " vxy^2: " << ms->vxy * ms->vxy << " vx*vy: " << ms->vx * ms->vy);
continue;
}
ms->setInstFluxAndErr(record.get(fluxKey), record.get(fluxErrKey));
ms->setInstFluxAndErr(record.get(instFluxKey), record.get(instFluxErrKey));
// TODO: the below lines will be less clumsy once DM-4044 is cleaned up and we can say:
// TODO: instFluxToMaggies(ms->getInstFlux(), ms) (because ms will be derived from afw::geom::Point).
afw::geom::Point<double, 2> point(ms->x, ms->y);
Expand Down
4 changes: 2 additions & 2 deletions src/MeasuredStar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ We can cook it up from the sdss shape:
'base_SdssShape_xy'
for fluxes, we might use :
'base_CircularApertureFlux_2_flux'
'base_CircularApertureFlux_2_fluxErr'
'base_CircularApertureFlux_2_instFlux'
'base_CircularApertureFlux_2_instFluxErr'
where the '2' should be read from the environment.
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ccdImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def checkCountStars(self, ccdImage, nStars):
skyWcs = ccdImage.readWCS().getSkyWcs()
self.refCat = testUtils.createFakeCatalog(nStars, self.bbox, "refFlux", skyWcs=skyWcs, refCat=True)
# associate the reference stars
self.associations.collectRefStars(self.refCat, matchCut, 'refFlux_flux')
self.associations.collectRefStars(self.refCat, matchCut, 'refFlux_instFlux')
measStars, refStars = ccdImage.countStars()
self.assertEqual(measStars, nStars)
self.assertEqual(refStars, nStars)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_photometryModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setUp(self):
self.ccdImageList = struct.ccdImageList
self.camera = struct.camera
self.catalogs = struct.catalogs
self.instFluxKeyName = struct.instFluxKeyName
self.fluxFieldName = struct.fluxFieldName

self.stars = []
for catalog, ccdImage in zip(self.catalogs, self.ccdImageList):
Expand All @@ -59,9 +59,9 @@ def _toPhotoCalib(self, ccdImage, catalog, stars):
"""Test converting this object to a PhotoCalib."""
photoCalib = self.model.toPhotoCalib(ccdImage)
if self.useMagnitude:
result = photoCalib.instFluxToMagnitude(catalog, self.instFluxKeyName)
result = photoCalib.instFluxToMagnitude(catalog, self.fluxFieldName)
else:
result = photoCalib.instFluxToMaggies(catalog, self.instFluxKeyName)
result = photoCalib.instFluxToMaggies(catalog, self.fluxFieldName)

expects = np.empty(len(stars))
for i, star in enumerate(stars):
Expand Down

0 comments on commit cb7cf42

Please sign in to comment.