Skip to content

Commit

Permalink
Merge pull request #213 from lsst/tickets/DM-10302
Browse files Browse the repository at this point in the history
DM-10302 Change flux->instFlux
  • Loading branch information
parejkoj committed Sep 19, 2018
2 parents 7ce568d + 61ef4d8 commit ebdc737
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 38 deletions.
6 changes: 3 additions & 3 deletions examples/photoCalTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def loadData():
# Read sources
#
srcCat = afwTable.SourceCatalog.readFits(os.path.join(mypath, "tests", "v695833-e0-c000.xy.fits"))
srcCat.getPsfFluxErr()[:] = np.sqrt(srcCat.getPsfFlux())
srcCat.getPsfInstFluxErr()[:] = np.sqrt(srcCat.getPsfInstFlux())

return exposure, srcCat

Expand All @@ -88,7 +88,7 @@ def run():
config = PhotoCalTask.ConfigClass()
config.applyColorTerms = False # we don't have any available, so this suppresses a warning
# The associated data has been prepared on the basis that we use PsfFlux to perform photometry.
config.fluxField = "base_PsfFlux_flux"
config.fluxField = "base_PsfFlux_instFlux"
pTask = PhotoCalTask(config=config, schema=schema)
#
# The tasks may have added extra elements to the schema (e.g. AstrometryTask's centroidKey to
Expand All @@ -102,7 +102,7 @@ def run():
print("Adding columns to the source catalogue")
cat = afwTable.SourceCatalog(schema)
cat.table.defineCentroid(srcCat.table.getCentroidDefinition())
cat.table.definePsfFlux(srcCat.table.getPsfFluxDefinition())
cat.table.definePsfFlux(srcCat.table.schema.get("slot_psfFlux"))

This comment has been minimized.

Copy link
@laurenam

laurenam Sep 21, 2018

Contributor

I realize it's "too late" (and that this -- being an example -- is probably well bitrotted in other ways), I think the 'p' should be capitalized in slot_PsfFlux


scm = afwTable.SchemaMapper(srcCat.getSchema(), schema)
for schEl in srcCat.getSchema():
Expand Down
5 changes: 3 additions & 2 deletions python/lsst/pipe/tasks/imageDifference.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,9 @@ def runDataRef(self, sensorRef, templateIdList=None):
exposure, diaSources, subtractedExposure.getWcs())
self.forcedMeasurement.run(forcedSources, exposure, diaSources, subtractedExposure.getWcs())
mapper = afwTable.SchemaMapper(forcedSources.schema, diaSources.schema)
mapper.addMapping(forcedSources.schema.find("base_PsfFlux_flux")[0], "totFlux", True)
mapper.addMapping(forcedSources.schema.find("base_PsfFlux_fluxErr")[0], "totFluxErr", True)
mapper.addMapping(forcedSources.schema.find("base_PsfFlux_instFlux")[0], "totFlux", True)
mapper.addMapping(forcedSources.schema.find("base_PsfFlux_instFluxErr")[0],
"totFluxErr", True)
for diaSource, forcedSource in zip(diaSources, forcedSources):
diaSource.assign(forcedSource, mapper)

Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/mocks/mockObservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ def makeRandomBoundedField():
bbox = detector.getBBox()
apCorrMap = lsst.afw.image.ApCorrMap()
for name in getApCorrNameSet():
apCorrMap.set(name + "_flux", makeRandomBoundedField())
apCorrMap.set(name + "_fluxErr", makeRandomBoundedField())
apCorrMap.set(name + "_instFlux", makeRandomBoundedField())
apCorrMap.set(name + "_instFluxErr", makeRandomBoundedField())
return apCorrMap

def buildTransmissionCurve(self, detector):
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/pipe/tasks/multiBand.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,8 +1542,8 @@ def __init__(self, butler=None, schema=None, **kwargs):
inputSchema = self.getInputSchema(butler=butler, schema=schema)
self.schemaMapper = afwTable.SchemaMapper(inputSchema, True)
self.schemaMapper.addMinimalSchema(inputSchema, True)
self.fluxKey = inputSchema.find(self.config.snName + "_flux").getKey()
self.fluxErrKey = inputSchema.find(self.config.snName + "_fluxErr").getKey()
self.instFluxKey = inputSchema.find(self.config.snName + "_instFlux").getKey()
self.instFluxErrKey = inputSchema.find(self.config.snName + "_instFluxErr").getKey()
self.fluxFlagKey = inputSchema.find(self.config.snName + "_flag").getKey()

self.flagKeys = {}
Expand Down Expand Up @@ -1626,10 +1626,10 @@ def run(self, catalogs, patchRef):
break

isBad = any(inputRecord.get(flag) for flag in self.badFlags)
if isBad or inputRecord.get(self.fluxFlagKey) or inputRecord.get(self.fluxErrKey) == 0:
if isBad or inputRecord.get(self.fluxFlagKey) or inputRecord.get(self.instFluxErrKey) == 0:
sn = 0.
else:
sn = inputRecord.get(self.fluxKey)/inputRecord.get(self.fluxErrKey)
sn = inputRecord.get(self.instFluxKey)/inputRecord.get(self.instFluxErrKey)
if numpy.isnan(sn) or sn < 0.:
sn = 0.
if (parent or child) and priorityRecord is None:
Expand Down
54 changes: 34 additions & 20 deletions python/lsst/pipe/tasks/photoCal.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class PhotoCalConfig(pexConf.Config):
reserve = pexConf.ConfigurableField(target=ReserveSourcesTask, doc="Reserve sources from fitting")
fluxField = pexConf.Field(
dtype=str,
default="slot_CalibFlux_flux",
doc=("Name of the source flux field to use. The associated flag field\n"
default="slot_CalibFlux_instFlux",
doc=("Name of the source instFlux field to use. The associated flag field\n"
"('<name>_flags') will be implicitly included in badFlags."),
)
applyColorTerms = pexConf.Field(
Expand Down Expand Up @@ -259,15 +259,26 @@ def __init__(self, refObjLoader, schema=None, **kwds):
doc="set if source was reserved from photometric calibration")

def getSourceKeys(self, schema):
"""!Return a struct containing the source catalog keys for fields used by PhotoCalTask.
"""Return a struct containing the source catalog keys for fields used
by PhotoCalTask.
Returned fields include:
- flux
- fluxErr
Parameters
----------
schema : `lsst.afw.table.schema`
Schema of the catalog to get keys from.
Returns
-------
result : `lsst.pipe.base.Struct`
Result struct with components:
- ``instFlux``: Instrument flux key.
- ``instFluxErr``: Instrument flux error key.
"""
flux = schema.find(self.config.fluxField).key
fluxErr = schema.find(self.config.fluxField + "Err").key
return pipeBase.Struct(flux=flux, fluxErr=fluxErr)
instFlux = schema.find(self.config.fluxField).key
instFluxErr = schema.find(self.config.fluxField + "Err").key
return pipeBase.Struct(instFlux=instFlux, instFluxErr=instFluxErr)

@pipeBase.timeMethod
def extractMagArrays(self, matches, filterName, sourceKeys):
Expand All @@ -286,17 +297,17 @@ def extractMagArrays(self, matches, filterName, sourceKeys):
@note These magnitude arrays are the @em inputs to the photometric calibration, some may have been
discarded by clipping while estimating the calibration (https://jira.lsstcorp.org/browse/DM-813)
"""
srcFluxArr = np.array([m.second.get(sourceKeys.flux) for m in matches])
srcFluxErrArr = np.array([m.second.get(sourceKeys.fluxErr) for m in matches])
if not np.all(np.isfinite(srcFluxErrArr)):
srcInstFluxArr = np.array([m.second.get(sourceKeys.instFlux) for m in matches])
srcInstFluxErrArr = np.array([m.second.get(sourceKeys.instFluxErr) for m in matches])
if not np.all(np.isfinite(srcInstFluxErrArr)):
# this is an unpleasant hack; see DM-2308 requesting a better solution
self.log.warn("Source catalog does not have flux uncertainties; using sqrt(flux).")
srcFluxErrArr = np.sqrt(srcFluxArr)
srcInstFluxErrArr = np.sqrt(srcInstFluxArr)

# convert source flux from DN to an estimate of Jy
# convert source instFlux from DN to an estimate of Jy
JanskysPerABFlux = 3631.0
srcFluxArr = srcFluxArr * JanskysPerABFlux
srcFluxErrArr = srcFluxErrArr * JanskysPerABFlux
srcInstFluxArr = srcInstFluxArr * JanskysPerABFlux
srcInstFluxErrArr = srcInstFluxErrArr * JanskysPerABFlux

if not matches:
raise RuntimeError("No reference stars are available")
Expand Down Expand Up @@ -364,16 +375,19 @@ def extractMagArrays(self, matches, filterName, sourceKeys):
else:
refMagArr = np.array([abMagFromFlux(rf) for rf in refFluxArrList[0]])

srcMagArr = np.array([abMagFromFlux(sf) for sf in srcFluxArr])
srcMagArr = np.array([abMagFromFlux(sf) for sf in srcInstFluxArr])

# Fitting with error bars in both axes is hard
# for now ignore reference flux error, but ticket DM-2308 is a request for a better solution
magErrArr = np.array([abMagErrFromFluxErr(fe, sf) for fe, sf in zip(srcFluxErrArr, srcFluxArr)])
magErrArr = np.array([abMagErrFromFluxErr(fe, sf)
for fe, sf in zip(srcInstFluxErrArr, srcInstFluxArr)])
if self.config.magErrFloor != 0.0:
magErrArr = (magErrArr**2 + self.config.magErrFloor**2)**0.5

srcMagErrArr = np.array([abMagErrFromFluxErr(sfe, sf) for sfe, sf in zip(srcFluxErrArr, srcFluxArr)])
refMagErrArr = np.array([abMagErrFromFluxErr(rfe, rf) for rfe, rf in zip(refFluxErrArr, refFluxArr)])
srcMagErrArr = np.array([abMagErrFromFluxErr(sfe, sf)
for sfe, sf in zip(srcInstFluxErrArr, srcInstFluxArr)])
refMagErrArr = np.array([abMagErrFromFluxErr(rfe, rf)
for rfe, rf in zip(refFluxErrArr, refFluxArr)])

good = np.isfinite(srcMagArr) & np.isfinite(refMagArr)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_fakeProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def checkSourceCatalog(self, srcCat, thresh=5):
for fakePos, fakeIntensity in FakeSourcesTestTask.fakeSources:
distSq = (srcX - fakePos.x)**2 + (srcY - fakePos.y)**2
if distSq <= thresh**2:
fluxDiff = abs(source.getPsfFlux() - fakeIntensity)
fluxDiff = abs(source.getPsfInstFlux() - fakeIntensity)
self.assertLessEqual(fluxDiff, 5*np.sqrt(fakeIntensity))
fakeSourceCounter += 1
# Verify the correct number of fake sources were found
Expand Down
10 changes: 5 additions & 5 deletions tests/test_photoCal.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def setUp(self):
self.srcCat = afwTable.SourceCatalog.readFits(
os.path.join(testDir, "data", "v695833-e0-c000.xy.fits"))

self.srcCat["slot_ApFlux_fluxErr"] = 1
self.srcCat["slot_PsfFlux_fluxErr"] = 1
self.srcCat["slot_ApFlux_instFluxErr"] = 1
self.srcCat["slot_PsfFlux_instFluxErr"] = 1

# The .xy.fits file has sources in the range ~ [0,2000],[0,4500]
# which is bigger than the exposure
Expand Down Expand Up @@ -92,15 +92,15 @@ def setUp(self):
self.config.match.matchRadius = 0.5
self.config.match.referenceSelection.doMagLimit = True
self.config.match.referenceSelection.magLimit.maximum = 22.0
self.config.match.referenceSelection.magLimit.fluxField = "i_flux"
self.config.match.referenceSelection.magLimit.fluxField = "i_instFlux"
self.config.match.referenceSelection.doFlags = True
self.config.match.referenceSelection.flags.good = ['photometric']
self.config.match.referenceSelection.flags.bad = ['resolved']
self.config.match.sourceSelection.doUnresolved = False # Don't have star/galaxy in the srcCat

# The test and associated data have been prepared on the basis that we
# use the PsfFlux to perform photometry.
self.config.fluxField = "base_PsfFlux_flux"
self.config.fluxField = "base_PsfFlux_instFlux"

def tearDown(self):
del self.srcCat
Expand All @@ -123,7 +123,7 @@ def _runTask(self):
if refFlux <= 0:
continue
refMag = afwImage.abMagFromFlux(refFlux) # reference catalog mag
instFlux = m[1].getPsfFlux() # Instrumental Flux
instFlux = m[1].getPsfInstFlux() # Instrumental Flux
if instFlux <= 0:
continue
instMag = pCal.calib.getMagnitude(instFlux) # Instrumental mag
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def testInterface(self):
cfg.calibrate.measurement.slots.shape = None
cfg.calibrate.measurement.slots.psfFlux = None
cfg.calibrate.measurement.slots.apFlux = None
cfg.calibrate.measurement.slots.instFlux = None
cfg.calibrate.measurement.slots.gaussianFlux = None
cfg.calibrate.measurement.slots.modelFlux = None
cfg.calibrate.measurement.slots.calibFlux = None
# no reference catalog, so...
Expand Down

0 comments on commit ebdc737

Please sign in to comment.