Coverage for metadetect / lsst / tests / test_lsst_configs.py: 13%

65 statements  

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

1""" 

2test configs 

3 

4note we allow the get_all_metacal to do its own verifiction 

5of the metacal sub config 

6""" 

7import pytest 

8 

9from metadetect.lsst.configs import get_config 

10from metadetect.lsst.defaults import DEFAULT_FWHM_SMOOTH 

11 

12 

13def test_configs_smoke(): 

14 config = get_config() 

15 

16 # make sure the default is verified 

17 get_config(config) 

18 

19 with pytest.raises(ValueError): 

20 get_config({'blah': 3}) 

21 

22 

23@pytest.mark.parametrize('meas_type', ['am', 'wmom', 'gauss', 'coellip3']) 

24def get_weight_config(meas_type): 

25 inconfig = {} 

26 

27 # make sure the default is verified 

28 get_config(inconfig) 

29 

30 inconfig = { 

31 'meas_type': meas_type, 

32 } 

33 get_config(inconfig) 

34 

35 fwhm = 1.2 

36 fwhm_smooth = 0.8 

37 for wtc in [{'fwhm': fwhm}, {'fwhm': fwhm, 'fwhm_smooth': fwhm_smooth}]: 

38 inconfig = { 

39 'meas_type': meas_type, 

40 'weight': wtc, 

41 } 

42 config = get_config(inconfig) 

43 assert config['weight']['fwhm'] == fwhm 

44 

45 for key in wtc: 

46 assert config['weight'][key] == wtc[key] 

47 

48 if 'fwhm_smooth' not in wtc: 

49 assert config['weight']['fwhm_smooth'] == DEFAULT_FWHM_SMOOTH 

50 

51 with pytest.raises(ValueError): 

52 get_config({'weight': {'blah': 3}}) 

53 

54 

55@pytest.mark.parametrize('model', ['am', 'wmom', 'gauss', 'coellip3']) 

56def test_psf_configs(model): 

57 

58 psf_config = {'model': model} 

59 

60 if model == 'am': 

61 psf_config['ntry'] = 3 

62 elif model == 'wmom': 

63 psf_config['weight_fwhm'] = 1.2 

64 else: 

65 psf_config['ntry'] = 3 

66 psf_config['lm_pars'] = { 

67 "maxfev": 4000, "ftol": 1.0e-5, "xtol": 1.0e-5, 

68 } 

69 

70 config = get_config({'psf': psf_config}) 

71 

72 if model == 'am': 

73 assert 'ntry' in config['psf'] 

74 assert config['psf']['ntry'] == psf_config['ntry'] 

75 elif model == 'wmom': 

76 assert 'weight_fwhm' in config['psf'] 

77 assert config['psf']['weight_fwhm'] == psf_config['weight_fwhm'] 

78 else: 

79 assert 'ntry' in config['psf'] 

80 assert 'lm_pars' in config['psf'] 

81 

82 assert config['psf']['ntry'] == psf_config['ntry'] 

83 

84 for key in config['psf']['lm_pars']: 

85 assert config['psf']['lm_pars'][key] == psf_config['lm_pars'][key] 

86 

87 

88@pytest.mark.parametrize('model', ['am', 'wmom', 'gauss', 'coellip3']) 

89def test_psf_configs_bad(model): 

90 

91 with pytest.raises(ValueError): 

92 get_config({'psf': {}}) 

93 

94 psf_config = {'model': model} 

95 

96 if model == 'am': 

97 # lm_pars not allowed for adaptive moments 

98 psf_config['lm_pars'] = { 

99 "maxfev": 4000, "ftol": 1.0e-5, "xtol": 1.0e-5, 

100 } 

101 elif model == 'wmom': 

102 # ntry not allowed for wmom 

103 psf_config['ntry'] = 3 

104 else: 

105 # just leave out lm_pars 

106 psf_config['blah'] = 3 

107 

108 with pytest.raises(ValueError): 

109 get_config({'psf': psf_config}) 

110 

111 

112def test_detect_config(): 

113 in_config = {'detect': {'thresh': 5}} 

114 config = get_config() 

115 assert config['detect']['thresh'] == in_config['detect']['thresh'] 

116 

117 with pytest.raises(ValueError): 

118 get_config({'detect': {'blah': 5}})