Coverage for python/lsst/faro/utils/extinction_corr.py: 30%
21 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-25 01:47 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-25 01:47 -0700
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/>.
22import logging
23from astropy.coordinates import SkyCoord
25log = logging.getLogger(__name__)
27try:
28 from dustmaps.sfd import SFDQuery
29except ModuleNotFoundError as e:
30 log.debug(
31 "The extinction_corr method is not available without first installing the dustmaps module:\n"
32 "$> pip install --user dustmaps\n\n"
33 "Then in a python interpreter:\n"
34 ">>> import dustmaps.sfd\n"
35 ">>> dustmaps.sfd.fetch()\n"
36 "%s",
37 e.msg,
38 )
40__all__ = ("extinction_corr",)
43def extinction_corr(catalog, bands):
45 # Extinction coefficients for HSC filters for conversion from E(B-V) to extinction, A_filter.
46 # Numbers provided by Masayuki Tanaka (NAOJ).
47 #
48 # Band, A_filter/E(B-V)
49 extinctionCoeffs_HSC = {
50 # See https://www.sdss.org/dr16/spectro/sspp/
51 # Assuming diff of ~0.65, given 0.553, 0.475, 0.453 for gri
52 "u": 4.505,
53 "g": 3.240,
54 "r": 2.276,
55 "i": 1.633,
56 "z": 1.263,
57 "y": 1.075,
58 "HSC-G": 3.240,
59 "HSC-R": 2.276,
60 "HSC-I": 1.633,
61 "HSC-Z": 1.263,
62 "HSC-Y": 1.075,
63 "NB0387": 4.007,
64 "NB0816": 1.458,
65 "NB0921": 1.187,
66 }
68 bands = list(bands)
69 sfd = SFDQuery()
70 coord_string_ra = "coord_ra_" + str(bands[0])
71 coord_string_dec = "coord_dec_" + str(bands[0])
72 coords = SkyCoord(catalog[coord_string_ra], catalog[coord_string_dec])
73 ebvValues = sfd(coords)
74 extinction_dict = {"E(B-V)": ebvValues}
76 # Create a dict with the extinction values for each band (and E(B-V), too):
77 for band in bands:
78 coeff_name = "A_" + str(band)
79 extinction_dict[coeff_name] = ebvValues * extinctionCoeffs_HSC[band]
81 return extinction_dict