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-23971: Undo TE1 "regression" #118

Merged
merged 2 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 13 additions & 14 deletions python/lsst/validate/drp/astromerrmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def fitAstromErrModel(snr, dist):
return params


def build_astrometric_error_model(matchedMultiVisitDataset, brightSnr=100,
def build_astrometric_error_model(matchedMultiVisitDataset, brightSnrMin=100,
medianRef=100, matchRef=500):
r"""Serializable model of astrometry errors across multiple visits.

Expand All @@ -112,7 +112,7 @@ def build_astrometric_error_model(matchedMultiVisitDataset, brightSnr=100,
matchedMultiVisitDataset : `MatchedMultiVisitDataset`
A dataset containing matched statistics for stars across multiple
visits.
brightSnr : `float` or `astropy.unit.Quantity`, optional
brightSnrMin : `float` or `astropy.unit.Quantity`, optional
Minimum SNR for a star to be considered "bright" (dimensionless).
medianRef : `float` or `astropy.unit.Quantity`, optional
Median reference astrometric scatter (default: milliarcsecond).
Expand All @@ -124,7 +124,7 @@ def build_astrometric_error_model(matchedMultiVisitDataset, brightSnr=100,
blob : `lsst.verify.Blob`
Blob with datums:

- ``brightSnr``: Threshold SNR for bright sources used in this model.
- ``brightSnrMin``: Threshold SNR for bright sources used in this model.
- ``C``: Model scaling factor.
- ``theta``: Seeing (milliarcsecond).
- ``sigmaSys``: Systematic error floor (milliarcsecond).
Expand All @@ -144,29 +144,29 @@ def build_astrometric_error_model(matchedMultiVisitDataset, brightSnr=100,
# _doc['doc'] \
# = "Astrometric astrometry model: mas = C*theta/SNR + sigmaSys"

if not isinstance(brightSnr, u.Quantity):
brightSnr = brightSnr * u.Unit('')
if not isinstance(brightSnrMin, u.Quantity):
brightSnrMin = brightSnrMin * u.Unit('')
if not isinstance(medianRef, u.Quantity):
medianRef = medianRef * u.marcsec

_compute(blob,
matchedMultiVisitDataset['snr'].quantity,
matchedMultiVisitDataset['dist'].quantity,
len(matchedMultiVisitDataset.goodMatches),
brightSnr, medianRef, matchRef)
len(matchedMultiVisitDataset.matchesFaint),
brightSnrMin, medianRef, matchRef)
return blob


def _compute(blob, snr, dist, nMatch, brightSnr, medianRef, matchRef):
def _compute(blob, snr, dist, nMatch, brightSnrMin, medianRef, matchRef):
median_dist = np.median(dist)
msg = 'Median value of the astrometric scatter - all magnitudes: ' \
'{0:.3f}'
print(msg.format(median_dist))

bright = np.where(snr > brightSnr)
bright = np.where(snr > brightSnrMin)
astromScatter = np.median(dist[bright])
msg = 'Astrometric scatter (median) - snr > {0:.1f} : {1:.1f}'
print(msg.format(brightSnr, astromScatter))
print(msg.format(brightSnrMin, astromScatter))

fit_params = fitAstromErrModel(snr[bright], dist[bright])

Expand All @@ -179,10 +179,9 @@ def _compute(blob, snr, dist, nMatch, brightSnr, medianRef, matchRef):
'(should be > {1:d})'
print(msg.format(nMatch, matchRef))

blob['brightSnr'] = Datum(quantity=brightSnr,
label='Bright SNR',
description='Threshold in SNR for bright sources used in this '
'model')
blob['brightSnrMin'] = Datum(quantity=brightSnrMin,
label='Bright SNR',
description='Threshold in SNR for bright sources used in this model')
blob['C'] = Datum(quantity=fit_params['C'],
description='Scaling factor')
blob['theta'] = Datum(quantity=fit_params['theta'],
Expand Down
17 changes: 11 additions & 6 deletions python/lsst/validate/drp/calcnonsrd/model_phot_rep.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# see <https://www.lsstcorp.org/LegalNotices/>.

from lsst.validate.drp.repeatability import measurePhotRepeat
from lsst.validate.drp.matchreduce import reduceSources
from lsst.validate.drp.matchreduce import getKeysFilter, filterSources


def measure_model_phot_rep(metrics, filterName, matchedDataset, snr_bins=None):
Expand Down Expand Up @@ -60,8 +60,10 @@ def measure_model_phot_rep(metrics, filterName, matchedDataset, snr_bins=None):
snr_bins = [((5, 10), (10, 20)), ((20, 40), (40, 80))]
name_flux_all = ["base_PsfFlux", 'slot_ModelFlux']
measurements = []
schema = matchedDataset._matchedCatalog.schema
for name_flux in name_flux_all:
key_model_mag = matchedDataset._matchedCatalog.schema.find(f"{name_flux}_mag").key
keys = getKeysFilter(schema, nameFluxKey=name_flux)
key_model_mag = schema.find(f"{name_flux}_mag").key
if name_flux == 'slot_ModelFlux':
name_sources = ['Gal', 'Star']
prefix_metric = 'model'
Expand All @@ -71,14 +73,17 @@ def measure_model_phot_rep(metrics, filterName, matchedDataset, snr_bins=None):
for idx_bins, ((snr_one_min, snr_one_max), (snr_two_min, snr_two_max)) in enumerate(snr_bins):
bin_base = 1 + 2*idx_bins
for source in name_sources:
reduceSources(matchedDataset, matchedDataset._matchedCatalog, extended=source == 'Gal',
nameFluxKey=name_flux, goodSnr=snr_one_min, goodSnrMax=snr_one_max,
safeSnr=snr_two_min, safeSnrMax=snr_two_max)
matches = filterSources(
matchedDataset._matchedCatalog, keys=keys, extended=(source == 'Gal'),
faintSnrMin=snr_one_min, faintSnrMax=snr_one_max,
brightSnrMin=snr_two_min, brightSnrMax=snr_two_max,
)
for bin_offset in [0, 1]:
model_phot_rep = measurePhotRepeat(
metrics[f'validate_drp.{prefix_metric}PhotRep{source}{bin_base + bin_offset}'],
filterName,
matchedDataset.goodMatches if bin_offset == 0 else matchedDataset.safeMatches,
matches.matchesFaint if bin_offset == 0 else matches.matchesBright,
key_model_mag)
measurements.append(model_phot_rep)

return measurements
2 changes: 1 addition & 1 deletion python/lsst/validate/drp/calcsrd/amx.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def measureAMx(metric, matchedDataset, D, width=2., magRange=None, verbose=False
and to astrometric measurements performed in the r and i bands.
"""

matches = matchedDataset.safeMatches
matches = matchedDataset.matchesBright

datums = {}

Expand Down
2 changes: 1 addition & 1 deletion python/lsst/validate/drp/calcsrd/tex.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def measureTEx(metric, matchedDataset, D, bin_range_operator, verbose=False):
Table 27: These residual PSF ellipticity correlations apply to the r and i bands.
"""

matches = matchedDataset.safeMatches
matches = matchedDataset.matchesBright

datums = {}
datums['D'] = Datum(quantity=D, description="Separation distance")
Expand Down