Package ComboCode :: Package cc :: Package modeling :: Package tools :: Module Reddening
[hide private]
[frames] | no frames]

Source Code for Module ComboCode.cc.modeling.tools.Reddening

  1  # -*- coding: utf-8 -*- 
  2   
  3  """ 
  4  Toolbox for interstellar Reddening of models or dereddening of data, and  
  5  interstellar extinction laws. 
  6   
  7  Author: R. Lombaert 
  8   
  9  How does reddening in ComboCode work?  
 10   
 11  First and foremost, we define the interstellar extinction in the Johnson K band. 
 12  The magnitude of extinction, Ak, is derived from extinction models. Either from 
 13  Marshall et al. 2006, or from Schlegel et al. 1998 if not available from the  
 14  former. Ak requires the distance to be given, before it can be applied to a  
 15  model. All of our modeling requires a distance as input, so this is not an issue 
 16  in practice. If needed, the extinction model can be changed to a different  
 17  3d galactic map from marshall (or Schlegel), see getAk. 
 18   
 19  A note on the extinction models. Schlegel et al say that they could not verify 
 20  their values at |bb| < 5 degrees, so they should not be trusted. However, Sans 
 21  Fuentes et al 2014 checked those values by comparing them with OGLE maps for the 
 22  |ll| < 10 degrees region and found a very good match. Common practice is to  
 23  compare model values with measurements, in -- for instance -- the IRSA catalog. 
 24  http://irsa.ipac.caltech.edu/applications/DUST/ (based on COBE/DIRBE maps)  
 25  Here, you can find total extinction in several bands. This then needs to be 
 26  converted to the distance you're looking at for your source. It is more  
 27  convenient to use galactic 3D models and do this exercise once for a given 
 28  direction to see how accurate the models are.  
 29   
 30  The interstellar extinction law of preference is that of Chiar and Tielens 2006. 
 31  This law is given normalized per Ak and can be directly combined with the  
 32  interstellar extinction given from Marshall or Schlegel. We use the curve for the 
 33  local ISM. The alternative is a curve for the galactic center, but even in the  
 34  direction of the galactic center the local ISM doesn't change much in terms of  
 35  dust extinction, except at very large distances on the order of 5kpc or more. We 
 36  don't work with sources at those distances for now, so we can safely ignore it. 
 37  For completeness, the GC curve is made as well and provided as an option in the 
 38  reddening module of IvS repo. 
 39   
 40  However, while Marshall gives Ak and presents no issue, other maps give Av. To 
 41  convert Av to Ak, we have to convert the V-band normalization of Drimmel to  
 42  K-band normalization. Chiar and Tielens, however, derived a law only in the IR 
 43  hence no V-band normalization can be defined. We need a different interstellar  
 44  reddening law in V-band to be compared with the infrared law of the 
 45  former. The most recent V-band reddening law is given by Fitzpatrick 2004. 
 46   
 47  We therefore created our own interstellar reddening law from the combination of  
 48  Fitzpatrick 2004 up to the wavelength where Chiar and Tielens 2006 begins. They  
 49  match almost identically in the overlapping region, following a power law of the  
 50  form lambda**-1.8. From there, the combined law follows Chiar and Tielens, and  
 51  is extrapolated to further wavelengths with the same power law with power -1.8  
 52  as mentioned by Chiar & Tielens 2006 between 2 and 5 micron. At long  
 53  wavelengths, the extinction becomes negligible, so the extrapolation is barely  
 54  noticeable, but maintains consistency.  
 55   
 56  To convert Fitzpatrick 2004 to Ak, we do need to assume a Av to Ak conversion 
 57  that does not take into account Chiar and Tielens. The latter suggest their law 
 58  can be converted back to Av with a factor of ak/av = 0.09, which is in very 
 59  good agreement with the factor derived from fitzpatrick 2004 itself: 0.088. 
 60   
 61  Using this self-constructed reddening law, we can now convert Av to Ak from  
 62  Drimmel, and then apply that Ak together with the self-constructed reddening law 
 63  to redden our models. We use the IvS repository for the reddening. 
 64   
 65  """ 
 66   
 67  import os 
 68  from scipy import hstack, array 
 69  import numpy as np 
 70   
 71  import cc.path 
 72  from cc.tools.io import DataIO 
 73   
 74  import cc.ivs.sed.reddening as red 
 75  import cc.ivs.sed.extinctionmodels as em 
 76   
 77   
78 -def getAk(ll,bb,distance=None,map='marshall',law='fitz2004chiar2006',\ 79 lawtype='ism'):
80 81 ''' 82 Find the Johnson K-band interstellar extinction at given longitude and 83 latitude for a given galactic extinction model. 84 85 Default is marshall, and if not available there, schlegel. When marshall is 86 requested, schlegel is always returned for ll and bb outside the range of 87 marshall. 88 89 Alternatives are arenou, drimmel and schlegel, see ivs repo. 90 91 @param ll: The galactic longitude of the star 92 @type ll: float 93 @param bb: The galactic latitude of the star 94 @type bb: float 95 96 @keyword distance: Distance to the star. Default is None, in which case the 97 full extinction to infinity in a given direction is 98 returned 99 100 (default: None) 101 @type distance: float 102 @keyword map: The galactic 3d extinction model. 103 104 (default: 'marshall') 105 @type map: str 106 @keyword law: The reddening law 107 108 (default: 'fitz2004chiar2006') 109 @type law: str 110 @keyword lawtype: The type of Chiar & Tielens reddening law (either ism or 111 gc). Only when relevant. 112 113 (default: 'ism') 114 @type lawtype: str 115 116 @return: The interstellar extinction magnitude in K-band 117 @rtype: float 118 119 ''' 120 121 ak = em.findext(lng=ll,lat=bb,distance=distance,model=map,redlaw=law,\ 122 norm='Ak',curve=lawtype) 123 if map == 'marshall' and not ak: 124 map = 'schlegel' 125 ak = em.findext(lng=ll,lat=bb,distance=distance,model=map,\ 126 redlaw=law,norm='Ak',curve=lawtype) 127 if map == 'drimmel': 128 ak = ak[0] 129 return ak
130 131 132
133 -def redden(wave,flux,ak,law='Fitz2004Chiar2006',lawtype='ism'):
134 135 ''' 136 Redden model fluxes, correcting for interstellar extinction. 137 138 Flux is assumed to be flux, and not magnitudes! 139 140 For dereddening, pass -ak instead. 141 142 The reddening law can be chosen, but should probably be Fitz2004Chiar2006 as 143 it was tailored to infrared reddening of AGB sources in the Solar 144 neighbourhood. 145 146 @param wave: The wavelength grid 147 @type wave: array 148 @param flux: The flux from the models 149 @type flux: array 150 @param ak: The interstellar reddening magnitude in Johnson K-band 151 @type ak: float 152 153 @keyword law: The reddening law 154 155 (default: 'Fitz2004Chiar2006') 156 @type law: str 157 @keyword lawtype: The type of Chiar & Tielens reddening law (either ism or 158 gc) 159 160 (default: 'ism') 161 @type lawtype: str 162 163 @return: The reddened fluxes 164 @rtype: array 165 166 ''' 167 168 wave,a_ak = red.get_law(name=law,wave=wave,curve=lawtype,\ 169 norm='Ak',wave_units='micron') 170 return flux / 10**(a_ak*ak/2.5)
171 172 173
174 -def combineRedLaw(ofn,chiar_curve='ism',power=-1.8):
175 176 ''' 177 A method to combine the Fitzpatrick 2004 and Chiar & Tielens 2006 reddening 178 laws as well as to extrapolate Chiar and Tielens 2006 to longer wavelengths. 179 180 The result is saved in a file and used by the IvS repository as a valid 181 reddening law. 182 183 @param ofn: The output filename with path 184 @type ofn: str 185 186 @keyword chiar_curve: The curve type for Chiar & Tielens 2004. Either 'gc' 187 or 'ism'. 188 189 (default: 'ism') 190 @type chiar_curve: str 191 @keyword power: The power for the power law extrapolation. Default is taken 192 from Chiar and Tielens 2006, as a typical value for local 193 ISM between 2 and 5 micron. gc may require different value 194 but not very important. 195 196 (default: -1.8) 197 @type power: float 198 199 ''' 200 201 chiar_curve = chiar_curve.lower() 202 203 #-- Extract the two relevant extinction laws. 204 xchiar, a_ak_chiar = red.get_law('chiar2006',norm='Ak',wave_units='micron',\ 205 curve=chiar_curve) 206 xfitz, a_ak_fitz = red.get_law('fitzpatrick2004',norm='Ak',\ 207 wave_units='micron') 208 209 #-- Define a power law for the extrapolation 210 def power_law(x,scale,power): return scale*(x)**power 211 212 #-- Determine the scaling factor from specific chiar/tielens law 213 scale = a_ak_chiar[-1]/(xchiar[-1]**power) 214 215 #-- Create an x grid for longer wavelengths. 216 xlong = np.linspace(xchiar[-1]+0.1,1000,1000) 217 a_ak_long = power_law(xlong,scale,power) 218 219 #-- Combine the three sections 220 xcom = hstack([xfitz[xfitz<xchiar[0]],xchiar,xlong]) 221 a_ak_com = hstack([a_ak_fitz[xfitz<xchiar[0]],a_ak_chiar,a_ak_long]) 222 223 #-- Write the result to a file 224 comments = '#-- wavelength (micron) A_lambda/A_k\n' 225 DataIO.writeCols(filename=ofn,cols=[[comments]]) 226 DataIO.writeCols(filename=ofn,cols=[xcom,a_ak_com],mode='a')
227