Coverage for metadetect / lsst / configs.py: 15%

30 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-02-21 01:40 -0800

1from copy import deepcopy 

2 

3from .defaults import DEFAULT_MDET_CONFIG 

4 

5 

6def get_config(config=None): 

7 """ 

8 extract a full config, overriding defaults with the input 

9 

10 Parameters 

11 ---------- 

12 config: dict, optional 

13 Entries in this dict override defaults stored in 

14 defaults.DEFAULT_MDET_CONFIG 

15 

16 Returns 

17 ------- 

18 Full config 

19 """ 

20 

21 new_config = deepcopy(DEFAULT_MDET_CONFIG) 

22 

23 if config is not None: 

24 for key in config: 

25 if key not in DEFAULT_MDET_CONFIG: 

26 raise ValueError('bad key in mdet config: %s' % key) 

27 

28 # deal with sub-configs 

29 if key in ['detect', 'metacal', 'pgauss']: 

30 new_config[key].update(config[key]) 

31 else: 

32 new_config[key] = config[key] 

33 

34 # do some verification 

35 # note we allow ngmix.metacal.get_all_metacal to do its own verification 

36 _verify_pgauss_config(new_config['pgauss']) 

37 _verify_detect_config(new_config['detect']) 

38 

39 return new_config 

40 

41 

42def _verify_detect_config(config): 

43 

44 name = 'detect' 

45 _check_required_keywords( 

46 config=config, required_keys=['thresh'], name=name, 

47 ) 

48 

49 _check_keywords(config=config, allowed_keys=['thresh'], name=name) 

50 

51 

52def _verify_pgauss_config(config): 

53 

54 name = 'pgauss' 

55 _check_required_keywords( 

56 config=config, 

57 required_keys=['fwhm'], 

58 name=name, 

59 ) 

60 _check_keywords( 

61 config=config, 

62 allowed_keys=['fwhm'], 

63 name=name, 

64 ) 

65 

66 

67def _check_required_keywords(config, required_keys, name): 

68 for key in required_keys: 

69 if key not in config: 

70 raise ValueError(f'key "{key}" must be present in {name} config') 

71 

72 

73def _check_keywords(config, allowed_keys, name): 

74 for key in config: 

75 if key not in allowed_keys: 

76 raise ValueError(f'key "{key}" not allowed in {name} config')