Coverage for metadetect / lsst / photometry.py: 31%

25 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-13 01:57 -0800

1import logging 

2import warnings 

3from .skysub import subtract_sky_mbexp 

4 

5from .configs import get_config 

6from . import measure 

7from .metadetect import ( 

8 fit_original_psfs_mbexp, get_mfrac_mbexp, get_fitter, combine_ormasks, 

9 add_ormask, add_original_psf, add_mfrac, 

10) 

11 

12warnings.filterwarnings('ignore', category=FutureWarning) 

13 

14LOG = logging.getLogger('lsst_photometry') 

15 

16 

17def run_photometry(mbexp, rng, mfrac_mbexp=None, ormasks=None, config=None, show=False): 

18 """ 

19 Run photometry on the input data 

20 

21 Parameters 

22 ---------- 

23 mbexp: lsst.afw.image.MultibandExposure 

24 The exposures to process 

25 rng: np.random.RandomState 

26 Random number generator 

27 mfrac_mbexp: lsst.afw.image.MultibandExposure, optional 

28 The fraction of masked exposures for the pixel; for coadds this is the 

29 fraction of input images contributing to each pixel that were masked 

30 ormasks: list of images, optional 

31 A list of logical or masks, such as created for all images that went 

32 into a coadd. 

33 

34 Note when coadding an ormask is created in the .mask attribute. But 

35 this code expects the mask attribute for each exposure to be not an or 

36 of all masks from the original exposures, but a mask indicating problem 

37 areas such as bright objects or apodized edges. 

38 

39 In the future we expect the MultibandExposure to have an ormask attribute 

40 config: dict, optional 

41 Configuration for the fitter, metacal, psf, detect, Entries 

42 in this dict override defaults; see lsst_configs.py 

43 show: bool, optional 

44 if set to True, images will be shown 

45 

46 Returns 

47 ------- 

48 ndarray of results with measuremens 

49 """ 

50 

51 config = get_config(config) 

52 

53 ormask = combine_ormasks(mbexp, ormasks) 

54 mfrac, wgts = get_mfrac_mbexp(mbexp, mfrac_mbexp) 

55 

56 if config['subtract_sky']: 

57 subtract_sky_mbexp(mbexp=mbexp, thresh=config['detect']['thresh']) 

58 

59 psf_stats = fit_original_psfs_mbexp( 

60 mbexp=mbexp, 

61 wgts=wgts, 

62 rng=rng, 

63 ) 

64 

65 fitter = get_fitter(config, rng=rng) 

66 

67 sources, detexp = measure.detect_and_deblend( 

68 mbexp=mbexp, 

69 rng=rng, 

70 thresh=config['detect']['thresh'], 

71 show=show, 

72 ) 

73 

74 res = measure.measure( 

75 mbexp=mbexp, 

76 detexp=detexp, 

77 sources=sources, 

78 fitter=fitter, 

79 stamp_size=config['stamp_size'], 

80 ) 

81 

82 if res is not None: 

83 band = mbexp.bands[0] 

84 exp = mbexp[band] 

85 

86 add_mfrac(config=config, mfrac=mfrac, res=res, exp=exp) 

87 add_ormask(ormask, res) 

88 add_original_psf(psf_stats, res) 

89 

90 return res