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

24 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-02-08 17:04 -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, 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( 

18 mbexp, rng, mfrac_mbexp=None, ormasks=None, config=None, show=False, 

19): 

20 """ 

21 Run photometry on the input data 

22 

23 Parameters 

24 ---------- 

25 mbexp: lsst.afw.image.MultibandExposure 

26 The exposures to process 

27 rng: np.random.RandomState 

28 Random number generator 

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

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

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

32 ormasks: list of images, optional 

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

34 into a coadd. 

35 

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

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

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

39 areas such as bright objects or apodized edges. 

40 

41 In the future we expect the MultibandExposure to have an ormask 

42 attribute 

43 config: dict, optional 

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

45 in this dict override defaults; see lsst_configs.py 

46 show: bool, optional 

47 if set to True, images will be shown 

48 

49 Returns 

50 ------- 

51 ndarray of results with measuremens 

52 """ 

53 

54 config = get_config(config) 

55 

56 ormask = combine_ormasks(mbexp, ormasks) 

57 mfrac, wgts = get_mfrac_mbexp(mbexp, mfrac_mbexp) 

58 

59 if config['subtract_sky']: 

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

61 

62 psf_stats = fit_original_psfs_mbexp( 

63 mbexp=mbexp, 

64 wgts=wgts, 

65 rng=rng, 

66 ) 

67 

68 sources, detexp = measure.detect_and_deblend( 

69 mbexp=mbexp, 

70 rng=rng, 

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

72 show=show, 

73 ) 

74 

75 res = measure.measure( 

76 mbexp=mbexp, 

77 detexp=detexp, 

78 sources=sources, 

79 config=config, 

80 rng=rng 

81 ) 

82 

83 if res is not None: 

84 band = mbexp.bands[0] 

85 exp = mbexp[band] 

86 

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

88 add_ormask(ormask, res) 

89 add_original_psf(psf_stats, res) 

90 

91 return res