Skip to content

Commit

Permalink
Add refcat selection config option and test
Browse files Browse the repository at this point in the history
This required modifying the basic catalog loading test, because the selector
might cause a catalog copy, even if it does no selection.
  • Loading branch information
parejkoj committed Feb 27, 2019
1 parent 7c26e80 commit 1992c2c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
14 changes: 10 additions & 4 deletions python/lsst/jointcal/jointcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from lsst.pipe.tasks.colorterms import ColortermLibrary
from lsst.verify import Job, Measurement

from lsst.meas.algorithms import LoadIndexedReferenceObjectsTask
from lsst.meas.algorithms import LoadIndexedReferenceObjectsTask, ReferenceSourceSelectorTask
from lsst.meas.algorithms.sourceSelector import sourceSelectorRegistry

from .dataIds import PerTractCcdDataIdContainer
Expand Down Expand Up @@ -281,6 +281,10 @@ class JointcalConfig(pexConfig.Config):
doc="How to select sources for cross-matching",
default="astrometry"
)
referenceSelector = pexConfig.ConfigurableField(
target=ReferenceSourceSelectorTask,
doc="How to down-select the loaded reference catalog.",
)
writeInitMatrix = pexConfig.Field(
dtype=bool,
doc="Write the pre/post-initialization Hessian and gradient to text files, for debugging."
Expand Down Expand Up @@ -337,6 +341,7 @@ def __init__(self, butler=None, profile_jointcal=False, **kwargs):
pipeBase.CmdLineTask.__init__(self, **kwargs)
self.profile_jointcal = profile_jointcal
self.makeSubtask("sourceSelector")
self.makeSubtask("referenceSelector")
if self.config.doAstrometry:
self.makeSubtask('astrometryRefObjLoader', butler=butler)
else:
Expand Down Expand Up @@ -638,11 +643,12 @@ def _load_reference_catalog(self, refObjLoader, center, radius, filterName,
afwGeom.Angle(radius, afwGeom.radians),
filterName)

selected = self.referenceSelector.run(skyCircle.refCat)
# Need memory contiguity to get reference filters as a vector.
if not skyCircle.refCat.isContiguous():
refCat = skyCircle.refCat.copy(deep=True)
if not selected.sourceCat.isContiguous():
refCat = selected.sourceCat.copy(deep=True)
else:
refCat = skyCircle.refCat
refCat = selected.sourceCat

if applyColorterms:
try:
Expand Down
24 changes: 23 additions & 1 deletion tests/test_jointcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,29 @@ def test_load_reference_catalog(self):
center,
radius,
filterName)
self.assertEqual(refCat, fakeRefCat)
# operator== isn't implemented for Catalogs, so we have to check like
# this, in case the records are copied during load.
self.assertEqual(len(refCat), len(fakeRefCat))
for r1, r2 in zip(refCat, fakeRefCat):
self.assertEqual(r1, r2)

def test_load_reference_catalog_subselect(self):
"""Test that we can select out the one source in the fake refcat
with a ridiculous S/N cut.
"""
refObjLoader, center, radius, filterName, fakeRefCat = self._make_fake_refcat()

config = lsst.jointcal.jointcal.JointcalConfig()
config.doAstrometry = False
config.doPhotometry = False
config.referenceSelector.doSignalToNoise = True
config.referenceSelector.signalToNoise.minimum = 1e10
config.referenceSelector.signalToNoise.fluxField = "fake_flux"
config.referenceSelector.signalToNoise.errField = "fake_fluxErr"
jointcal = lsst.jointcal.JointcalTask(config=config)

refCat, fluxField = jointcal._load_reference_catalog(refObjLoader, center, radius, filterName)
self.assertEqual(len(refCat), 0)


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

0 comments on commit 1992c2c

Please sign in to comment.