Coverage for python / lsst / source / injection / utils / _show_source_types.py: 14%

34 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-01 08:57 +0000

1# This file is part of source_injection. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22from __future__ import annotations 

23 

24__all__ = ["show_source_types"] 

25 

26import inspect 

27import textwrap 

28 

29import galsim 

30 

31from ..inject_base import _ALLOWED_SOURCE_TYPES 

32 

33 

34def show_source_types( 

35 allowed_source_types: list[str] = _ALLOWED_SOURCE_TYPES, 

36 wrap_width: int | None = None, 

37) -> None: 

38 """Print the signature of each allowed source type. 

39 

40 Parameters 

41 ---------- 

42 allowed_source_types : list[str] 

43 List of allowed source type names. 

44 wrap_width : int, optional 

45 Width to wrap the signature text. 

46 

47 Notes 

48 ----- 

49 This function prints the signature of each allowed source type, 

50 wrapping the text to the specified width. 

51 """ 

52 if wrap_width is None: 

53 import shutil 

54 

55 wrap_width = shutil.get_terminal_size().columns 

56 wrap_width = int(wrap_width) 

57 for name in sorted(allowed_source_types): 

58 if name == "Star": 

59 cls = getattr(galsim, "DeltaFunction") 

60 elif name == "Trail": 

61 cls = type("_TempTrail", (), {"__init__": lambda self, trail_length, flux=None: None}) 

62 elif name == "Stamp": 

63 cls = type("_TempStamp", (), {"__init__": lambda self, stamp, flux=None: None}) 

64 else: 

65 cls = getattr(galsim, name) 

66 try: 

67 params = [] 

68 for p in inspect.signature(cls).parameters.values(): 

69 if p.name == "gsparams": 

70 continue 

71 elif p.name == "flux": 

72 params.append("mag=None") 

73 else: 

74 default = f"={p.default}" if p.default is not inspect.Parameter.empty else "" 

75 params.append(f"{p.name}{default}") 

76 

77 sig_text = ", ".join(params) 

78 wrapped_sig = textwrap.fill( 

79 f"({sig_text})", width=wrap_width, initial_indent=" ", subsequent_indent=" " 

80 ) 

81 except (TypeError, ValueError): 

82 wrapped_sig = " <no signature available>" 

83 

84 print(name + ":") 

85 print(wrapped_sig)