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-13053: allow refcat selection improve fitting #128

Merged
merged 3 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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