Skip to content

Commit

Permalink
Use only stars in internal jointcal fitting
Browse files Browse the repository at this point in the history
and limit to isolated stars with SNR > 10.
This config shows improvement in the photometric repeatability
and match to the reference catalog.
* Revert to astrometry source selector in unit tests
  that check equality in metrics when jointcal run on testdata.
* Remove some now-redundant config overrides in those
  affected unit tests.
  • Loading branch information
yalsayyad committed May 4, 2019
1 parent 2557255 commit 4e16c15
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 26 deletions.
28 changes: 22 additions & 6 deletions python/lsst/jointcal/jointcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,28 @@ def validate(self):
raise pexConfig.FieldValidationError(JointcalConfig.colorterms, self, msg)

def setDefaults(self):
sourceSelector = self.sourceSelector["astrometry"]
sourceSelector.setDefaults()
# don't want to lose existing flags, just add to them.
sourceSelector.badFlags.extend(["slot_Shape_flag"])
# This should be used to set the FluxField value in jointcal::JointcalControl
sourceSelector.sourceFluxType = self.sourceFluxType
# Use science source selector which can filter on extendedness, SNR, and whether blended
self.sourceSelector.name = 'science'
# Use only stars because aperture fluxes of galaxies are biased and depend on seeing
self.sourceSelector['science'].doUnresolved = True
# with dependable signal to noise ratio.
self.sourceSelector['science'].doSignalToNoise = True
# Min SNR must be > 0 because jointcal cannot handle negative fluxes,
# and S/N > 10 to use sources that are not too faint, and thus better measured.
self.sourceSelector['science'].signalToNoise.minimum = 10.
# Base SNR on CalibFlux because that is the flux jointcal that fits and must be positive
fluxField = f"slot_{self.sourceFluxType}Flux_instFlux"
self.sourceSelector['science'].signalToNoise.fluxField = fluxField
self.sourceSelector['science'].signalToNoise.errField = fluxField + "Err"
# Do not trust blended sources' aperture fluxes which also depend on seeing
self.sourceSelector['science'].doIsolated = True
# Do not trust either flux or centroid measurements with flags,
# chosen from the usual QA flags for stars)
self.sourceSelector['science'].doFlags = True
badFlags = ['base_PixelFlags_flag_edge', 'base_PixelFlags_flag_saturated',
'base_PixelFlags_flag_interpolatedCenter', 'base_SdssCentroid_flag',
'base_PsfFlux_flag', 'base_PixelFlags_flag_suspectCenter']
self.sourceSelector['science'].flags.bad = badFlags


class JointcalTask(pipeBase.CmdLineTask):
Expand Down
5 changes: 5 additions & 0 deletions tests/config/cfht-flagged-config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
config.sourceSelector.name = "flagged"
# Calib flag names changed with RFC-498 (DM-14997). The following sets the config to use the
# old names associated with the current data in testdata_jointcal that was processed pre-RFC-498.
# Remove line if the data in testdata_jointcal are ever reprocessed post-RFC-498 (e.g. DM-17597)
config.sourceSelector.active.field = "calib_psfUsed"
8 changes: 8 additions & 0 deletions tests/config/config.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
config.astrometryRefObjLoader.ref_dataset_name = "sdss-dr9-fink-v5b"
config.photometryRefObjLoader.ref_dataset_name = "sdss-dr9-fink-v5b"
# TODO DM-17597: Use the astrometrySourceSelector until we redo the refcats and metrics.
# Once we do that, we can try using the sourceSelector defaults and recompute all
# the metrics to match, though it may result in problems due to not having enough sources
# because the testdata is generally fainter than the HSC/LSST data that the defaults
# are now designed for.
config.sourceSelector.name = "astrometry"
config.sourceSelector["astrometry"].sourceFluxType = "Calib"
config.sourceSelector["astrometry"].badFlags.extend(["slot_Shape_flag", "base_PixelFlags_flag_interpolated"])
12 changes: 3 additions & 9 deletions tests/test_jointcal_cfht.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ def test_jointcalTask_2_visits(self):
self.config.astrometryModel = "simple"
self.config.photometryModel = "simpleFlux"

self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")

# to test whether we got the expected chi2 contribution files.
self.other_args.extend(['--config', 'writeChi2FilesInitialFinal=True'])

Expand Down Expand Up @@ -115,7 +113,6 @@ def setup_jointcalTask_2_visits_constrainedAstrometry(self):
self.config = lsst.jointcal.jointcal.JointcalConfig()
self.config.astrometryModel = "constrained"
self.config.doPhotometry = False
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
self.jointcalStatistics.do_photometry = False

# See Readme for an explanation of these empirical values.
Expand Down Expand Up @@ -161,7 +158,6 @@ def setup_jointcalTask_2_visits_constrainedPhotometry(self):
self.config = lsst.jointcal.jointcal.JointcalConfig()
self.config.photometryModel = "constrainedFlux"
self.config.doAstrometry = False
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
self.jointcalStatistics.do_astrometry = False

# See Readme for an explanation of these empirical values.
Expand Down Expand Up @@ -211,11 +207,9 @@ def test_jointcalTask_2_visits_constrainedPhotometry_lineSearch(self):
def test_jointcalTask_2_visits_constrainedPhotometry_flagged(self):
"""Test the use of the FlaggedSourceSelector."""
pa1, metrics = self.setup_jointcalTask_2_visits_constrainedPhotometry()
self.config.sourceSelector.name = "flagged"
# Calib flag names changed with RFC-498 (DM-14997). The following sets the config to use the
# old names associated with the current data in testdata_jointcal that was processed pre-RFC-498.
# Remove line if the data in testdata_jointcal are ever reprocessed post-RFC-498.
self.config.sourceSelector.active.field = "calib_psfUsed"
test_config = os.path.join(lsst.utils.getPackageDir('jointcal'),
'tests/config/cfht-flagged-config.py')
self.configfiles.append(test_config)
# Reduce warnings due to flaggedSourceSelector having fewer sources than astrometrySourceSelector.
self.config.minMeasuredStarsPerCcd = 30
self.config.minRefStarsPerCcd = 20
Expand Down
3 changes: 0 additions & 3 deletions tests/test_jointcal_decam.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def test_jointcalTask_2_visits(self):
self.config = lsst.jointcal.jointcal.JointcalConfig()
self.config.astrometryModel = "simple"
self.config.photometryModel = "simpleFlux"
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")

# See Readme for an explanation of these empirical values.
# NOTE: the photometry and astrometry refstars numbers are different
Expand Down Expand Up @@ -108,7 +107,6 @@ def setup_jointcalTask_2_visits_constrainedAstrometry_no_photometry(self):
self.config = lsst.jointcal.jointcal.JointcalConfig()
self.config.astrometryModel = "constrained"
self.config.doPhotometry = False
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
self.jointcalStatistics.do_photometry = False

# See Readme for an explanation of these empirical values.
Expand Down Expand Up @@ -159,7 +157,6 @@ def setup_jointcalTask_2_visits_constrainedPhotometry_no_astrometry(self):
"""
self.config = lsst.jointcal.jointcal.JointcalConfig()
self.config.photometryModel = "constrainedFlux"
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
self.config.doAstrometry = False
self.jointcalStatistics.do_astrometry = False

Expand Down
8 changes: 0 additions & 8 deletions tests/test_jointcal_hsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def test_jointcalTask_2_visits_simple(self):
self.config = lsst.jointcal.jointcal.JointcalConfig()
self.config.astrometryModel = "simple"
self.config.photometryModel = "simpleFlux"
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")

# See Readme for an explanation of these empirical values.
dist_rms_relative = 17e-3*u.arcsecond
Expand Down Expand Up @@ -101,7 +100,6 @@ def test_jointcalTask_11_visits_simple_astrometry_no_photometry(self):
self.config = lsst.jointcal.jointcal.JointcalConfig()
self.config.astrometryModel = "simple"
self.config.doPhotometry = False
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
self.jointcalStatistics.do_photometry = False

# See Readme for an explanation of these empirical values.
Expand All @@ -124,7 +122,6 @@ def setup_jointcalTask_2_visits_simplePhotometry(self):
self.config = lsst.jointcal.jointcal.JointcalConfig()
self.config.photometryModel = "simpleFlux"
self.config.doAstrometry = False
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
self.jointcalStatistics.do_astrometry = False

# See Readme for an explanation of these empirical values.
Expand Down Expand Up @@ -191,7 +188,6 @@ def testJointcalTask_2_visits_simple_astrometry_no_photometry(self):
self.config = lsst.jointcal.jointcal.JointcalConfig()
self.config.astrometryModel = "simple"
self.config.doPhotometry = False
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
self.jointcalStatistics.do_photometry = False

data_refs = self._testJointcalTask(2, dist_rms_relative, self.dist_rms_absolute,
Expand All @@ -206,7 +202,6 @@ def test_jointcalTask_2_visits_simple_astrometry_gaia_refcat(self):
self.config.astrometryModel = "simple"
self.config.photometryModel = "simpleFlux"
# use the a.net refcat for photometry, gaia for astrometry
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
test_config = os.path.join(lsst.utils.getPackageDir('jointcal'), 'tests/config/hsc-gaia-config.py')
self.configfiles.append(test_config)
dist_rms_relative = 17e-3*u.arcsecond
Expand Down Expand Up @@ -243,7 +238,6 @@ def test_jointcalTask_2_visits_simple_astrometry_no_photometry_match_cut_10(self
self.config.astrometryModel = "simple"
self.config.matchCut = 10.0 # TODO: once DM-6885 is fixed, we need to put `*lsst.afw.geom.arcseconds`
self.config.doPhotometry = False
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
self.jointcalStatistics.do_photometry = False

# See Readme for an explanation of these empirical values.
Expand All @@ -265,7 +259,6 @@ def test_jointcalTask_3_visits_simple_astrometry_no_photometry(self):
self.config.astrometryModel = "simple"
self.config.minMeasurements = 2
self.config.doPhotometry = False
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
self.jointcalStatistics.do_photometry = False

# See Readme for an explanation of these empirical values.
Expand All @@ -289,7 +282,6 @@ def test_jointcalTask_3_visits_simple_astrometry_no_photometry_min_measurements_
self.config.minMeasurements = 3
self.config.astrometryModel = "simple"
self.config.doPhotometry = False
self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated")
self.jointcalStatistics.do_photometry = False

# See Readme for an explanation of these empirical values.
Expand Down

0 comments on commit 4e16c15

Please sign in to comment.