Coverage for python/lsst/validate/drp/calcnonsrd/model_phot_rep.py: 8%
24 statements
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-05 19:03 -0800
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-05 19:03 -0800
1# LSST Data Management System
2# Copyright 2008-2019 AURA/LSST.
3#
4# This product includes software developed by the
5# LSST Project (http://www.lsst.org/).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the LSST License Statement and
18# the GNU General Public License along with this program. If not,
19# see <https://www.lsstcorp.org/LegalNotices/>.
21from lsst.validate.drp.repeatability import measurePhotRepeat
22from lsst.validate.drp.matchreduce import getKeysFilter, filterSources
25def measure_model_phot_rep(metrics, filterName, matchedDataset, snr_bins=None):
26 """Measurement of the model_phot_rep metric: photometric repeatability of
27 measurements of across a set of observations.
29 Parameters
30 ----------
31 metrics : `lsst.verify.metricset.MetricSet`
32 A metric set containing all of the expected validate_drp.*PhotRep* metrics.
33 filterName : `str`
34 Name of filter used for all observations.
35 matchedDataset : `lsst.verify.Blob`
36 Matched dataset blob, as returned by `lsst.validate.drp.matchreduce.build_matched_dataset`.
37 snr_bins : `iterable`
38 An iterable of pairs of SNR bins, each specified as a pair of floats
39 (lower, upper). Default [((5, 10), (10, 20)), ((20, 40), (40, 80))].
40 The total number of bins must not exceed the number of metrics,
41 which is currently four.
43 Returns
44 -------
45 measurements : `list` [`lsst.verify.Measurement`]
46 A list of metric measurements with associated metadata.
48 Notes
49 -----
50 Each SNR bin can be specified independently; their edges don't need to align and could overlap.
51 Bins are paired because reduce_sources already has a mechanism to apply two different SNR cuts,
52 which could be generalized to an iterable if desired.
54 The default SNR bins were chosen in DM-21380
55 (https://jira.lsstcorp.org/browse/DM-21380) and are somewhat arbitrary.
56 It is probably not useful to measure SNR<5, whereas one might reasonably
57 prefer narrower bins or a higher maximum SNR than 80.
58 """
59 if snr_bins is None:
60 snr_bins = [((5, 10), (10, 20)), ((20, 40), (40, 80))]
61 name_flux_all = ["base_PsfFlux", 'slot_ModelFlux']
62 measurements = []
63 schema = matchedDataset._matchedCatalog.schema
64 for name_flux in name_flux_all:
65 keys = getKeysFilter(schema, nameFluxKey=name_flux)
66 key_model_mag = schema.find(f"{name_flux}_mag").key
67 if name_flux == 'slot_ModelFlux':
68 name_sources = ['Gal', 'Star']
69 prefix_metric = 'model'
70 else:
71 name_sources = ['Star']
72 prefix_metric = 'psf'
73 for idx_bins, ((snr_one_min, snr_one_max), (snr_two_min, snr_two_max)) in enumerate(snr_bins):
74 bin_base = 1 + 2*idx_bins
75 for source in name_sources:
76 matches = filterSources(
77 matchedDataset._matchedCatalog, keys=keys, extended=(source == 'Gal'),
78 faintSnrMin=snr_one_min, faintSnrMax=snr_one_max,
79 brightSnrMin=snr_two_min, brightSnrMax=snr_two_max,
80 )
81 for bin_offset in [0, 1]:
82 model_phot_rep = measurePhotRepeat(
83 metrics[f'validate_drp.{prefix_metric}PhotRep{source}{bin_base + bin_offset}'],
84 filterName,
85 matches.matchesFaint if bin_offset == 0 else matches.matchesBright,
86 key_model_mag)
87 measurements.append(model_phot_rep)
89 return measurements