Coverage for python/lsst/faro/utils/extinction_corr.py: 48%

25 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-18 11:21 +0000

1# This file is part of faro. 

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 

22import logging 

23import os 

24from contextlib import redirect_stdout 

25 

26from astropy.coordinates import SkyCoord 

27 

28log = logging.getLogger(__name__) 

29 

30try: 

31 # Suppress unnecessary .dustmapsrc log message on import. 

32 with open(os.devnull, "w") as devnull: 

33 with redirect_stdout(devnull): 

34 from dustmaps.sfd import SFDQuery 

35except ModuleNotFoundError as e: 

36 log.debug( 

37 "The extinction_corr method is not available without first installing the dustmaps module:\n" 

38 "$> pip install --user dustmaps\n\n" 

39 "Then in a python interpreter:\n" 

40 ">>> import dustmaps.sfd\n" 

41 ">>> dustmaps.sfd.fetch()\n" 

42 "%s", 

43 e.msg, 

44 ) 

45 

46__all__ = ("extinction_corr",) 

47 

48 

49def extinction_corr(catalog, bands): 

50 

51 # Extinction coefficients for HSC filters for conversion from E(B-V) to extinction, A_filter. 

52 # Numbers provided by Masayuki Tanaka (NAOJ). 

53 # 

54 # Band, A_filter/E(B-V) 

55 extinctionCoeffs_HSC = { 

56 # See https://www.sdss.org/dr16/spectro/sspp/ 

57 # Assuming diff of ~0.65, given 0.553, 0.475, 0.453 for gri 

58 "u": 4.505, 

59 "g": 3.240, 

60 "r": 2.276, 

61 "i": 1.633, 

62 "z": 1.263, 

63 "y": 1.075, 

64 "HSC-G": 3.240, 

65 "HSC-R": 2.276, 

66 "HSC-I": 1.633, 

67 "HSC-Z": 1.263, 

68 "HSC-Y": 1.075, 

69 "NB0387": 4.007, 

70 "NB0816": 1.458, 

71 "NB0921": 1.187, 

72 } 

73 

74 bands = list(bands) 

75 sfd = SFDQuery() 

76 coord_string_ra = "coord_ra_" + str(bands[0]) 

77 coord_string_dec = "coord_dec_" + str(bands[0]) 

78 coords = SkyCoord(catalog[coord_string_ra], catalog[coord_string_dec]) 

79 ebvValues = sfd(coords) 

80 extinction_dict = {"E(B-V)": ebvValues} 

81 

82 # Create a dict with the extinction values for each band (and E(B-V), too): 

83 for band in bands: 

84 coeff_name = "A_" + str(band) 

85 extinction_dict[coeff_name] = ebvValues * extinctionCoeffs_HSC[band] 

86 

87 return extinction_dict