Coverage for metadetect / lsst / tests / test_lsst_configs.py: 13%
65 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:04 -0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:04 -0800
1"""
2test configs
4note we allow the get_all_metacal to do its own verifiction
5of the metacal sub config
6"""
7import pytest
9from metadetect.lsst.configs import get_config
10from metadetect.lsst.defaults import DEFAULT_FWHM_SMOOTH
13def test_configs_smoke():
14 config = get_config()
16 # make sure the default is verified
17 get_config(config)
19 with pytest.raises(ValueError):
20 get_config({'blah': 3})
23@pytest.mark.parametrize('meas_type', ['am', 'wmom', 'gauss', 'coellip3'])
24def get_weight_config(meas_type):
25 inconfig = {}
27 # make sure the default is verified
28 get_config(inconfig)
30 inconfig = {
31 'meas_type': meas_type,
32 }
33 get_config(inconfig)
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
45 for key in wtc:
46 assert config['weight'][key] == wtc[key]
48 if 'fwhm_smooth' not in wtc:
49 assert config['weight']['fwhm_smooth'] == DEFAULT_FWHM_SMOOTH
51 with pytest.raises(ValueError):
52 get_config({'weight': {'blah': 3}})
55@pytest.mark.parametrize('model', ['am', 'wmom', 'gauss', 'coellip3'])
56def test_psf_configs(model):
58 psf_config = {'model': model}
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 }
70 config = get_config({'psf': psf_config})
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']
82 assert config['psf']['ntry'] == psf_config['ntry']
84 for key in config['psf']['lm_pars']:
85 assert config['psf']['lm_pars'][key] == psf_config['lm_pars'][key]
88@pytest.mark.parametrize('model', ['am', 'wmom', 'gauss', 'coellip3'])
89def test_psf_configs_bad(model):
91 with pytest.raises(ValueError):
92 get_config({'psf': {}})
94 psf_config = {'model': model}
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
108 with pytest.raises(ValueError):
109 get_config({'psf': psf_config})
112def test_detect_config():
113 in_config = {'detect': {'thresh': 5}}
114 config = get_config()
115 assert config['detect']['thresh'] == in_config['detect']['thresh']
117 with pytest.raises(ValueError):
118 get_config({'detect': {'blah': 5}})