Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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/>. 

20 

21from lsst.validate.drp.repeatability import measurePhotRepeat 

22from lsst.validate.drp.matchreduce import reduceSources 

23 

24 

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. 

28 

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. 

42 

43 Returns 

44 ------- 

45 measurements : `list` [`lsst.verify.Measurement`] 

46 A list of metric measurements with associated metadata. 

47 

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. 

53 

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 for name_flux in name_flux_all: 

64 key_model_mag = matchedDataset._matchedCatalog.schema.find(f"{name_flux}_mag").key 

65 if name_flux == 'slot_ModelFlux': 

66 name_sources = ['Gal', 'Star'] 

67 prefix_metric = 'model' 

68 else: 

69 name_sources = ['Star'] 

70 prefix_metric = 'psf' 

71 for idx_bins, ((snr_one_min, snr_one_max), (snr_two_min, snr_two_max)) in enumerate(snr_bins): 

72 bin_base = 1 + 2*idx_bins 

73 for source in name_sources: 

74 reduceSources(matchedDataset, matchedDataset._matchedCatalog, extended=source == 'Gal', 

75 nameFluxKey=name_flux, goodSnr=snr_one_min, goodSnrMax=snr_one_max, 

76 safeSnr=snr_two_min, safeSnrMax=snr_two_max) 

77 for bin_offset in [0, 1]: 

78 model_phot_rep = measurePhotRepeat( 

79 metrics[f'validate_drp.{prefix_metric}PhotRep{source}{bin_base + bin_offset}'], 

80 filterName, 

81 matchedDataset.goodMatches if bin_offset == 0 else matchedDataset.safeMatches, 

82 key_model_mag) 

83 measurements.append(model_phot_rep) 

84 return measurements