def fitz2004chiar2006(Rv=3.1,curve='ism',**kwargs):
    """
    Combined and extrapolated extinction curve Fitzpatrick 2004 and 
    from Chiar and Tielens (2006).
    
    We return A(lambda)/E(B-V), by multiplying A(lambda)/Av with Rv.
    
    This is only defined for Rv=3.1. If it is different, this will raise an
    AssertionError
    
    Extra kwags are to catch unwanted keyword arguments.
    
    @param Rv: Rv
    @type Rv: float
    @param curve: extinction curve
    @type curve: string (one of 'gc' or 'ism', galactic centre or local ISM)
    @return: wavelengths (A), A(lambda)/Av
    @rtype: (ndarray,ndarray)
    """
    
    if curve.lower() not in ['ism','gc']:
        raise ValueError,'No Fitzpatrick2004/Chiar2006 curve available for %s.'\
                         %(curve)
                         
    fn = 'fitzpatrick2004_chiar2006%s_extrapol.dat'%curve
    source = os.path.join(basename,fn)
    
    #-- check Rv
    assert(Rv==3.1)
    wavelengths,alam_ak = ascii.read2array(source).T
    
    #-- Convert to AA
    wavelengths *= 1e4
    
    #-- Convert from Ak normalization to Av normalization.
    norm_reddening = model.synthetic_flux(wavelengths,alam_ak,\
                                         ['JOHNSON.V','JOHNSON.K'])
    ak_to_av = norm_reddening[1]/norm_reddening[0]
    alam_aV = alam_ak * ak_to_av
    
    return wavelengths,alam_aV
Example #2
0
def fitz2004chiar2006(Rv=3.1, curve='ism', **kwargs):
    """
    Combined and extrapolated extinction curve Fitzpatrick 2004 and 
    from Chiar and Tielens (2006).
    
    We return A(lambda)/E(B-V), by multiplying A(lambda)/Av with Rv.
    
    This is only defined for Rv=3.1. If it is different, this will raise an
    AssertionError
    
    Extra kwags are to catch unwanted keyword arguments.
    
    @param Rv: Rv
    @type Rv: float
    @param curve: extinction curve
    @type curve: string (one of 'gc' or 'ism', galactic centre or local ISM)
    @return: wavelengths (A), A(lambda)/Av
    @rtype: (ndarray,ndarray)
    """

    if curve.lower() not in ['ism', 'gc']:
        raise ValueError,'No Fitzpatrick2004/Chiar2006 curve available for %s.'\
                         %(curve)

    fn = 'fitzpatrick2004_chiar2006%s_extrapol.dat' % curve
    source = os.path.join(basename, fn)

    #-- check Rv
    assert (Rv == 3.1)
    wavelengths, alam_ak = ascii.read2array(source).T

    #-- Convert to AA
    wavelengths *= 1e4

    #-- Convert from Ak normalization to Av normalization.
    norm_reddening = model.synthetic_flux(wavelengths,alam_ak,\
                                         ['JOHNSON.V','JOHNSON.K'])
    ak_to_av = norm_reddening[1] / norm_reddening[0]
    alam_aV = alam_ak * ak_to_av

    return wavelengths, alam_aV
def get_law(name,norm='E(B-V)',wave_units='AA',photbands=None,**kwargs):
    """
    Retrieve an interstellar reddening law.
    
    Parameter C{name} must be the function name of one of the laws defined in
    this module.
    
    By default, the law will be interpolated on a grid from 100 angstrom to
    10 micron in steps of 10 angstrom. This can be adjusted with the parameter
    C{wave} (array), which B{must} be in angstrom. You can change the units
    ouf the returned wavelength array via C{wave_units}.
    
    By default, the curve is normalised with respect to E(B-V) (you get
    A(l)/E(B-V)). You can set the C{norm} keyword to Av if you want A(l)/Av.
    Remember that
    
    A(V) = Rv * E(B-V)
    
    The parameter C{Rv} is by default 3.1, other reasonable values lie between
    2.0 and 5.1
    
    Extra accepted keywords depend on the type of reddening law used.
    
    Example usage:
    
    >>> wave = np.r_[1e3:1e5:10]
    >>> wave,mag = get_law('cardelli1989',wave=wave,Rv=3.1)
    
    @param name: name of the interstellar law
    @type name: str, one of the functions defined here
    @param norm: type of normalisation of the curve
    @type norm: str (one of E(B-V), Av)
    @param wave_units: wavelength units
    @type wave_units: str (interpretable for units.conversions.convert)
    @param photbands: list of photometric passbands
    @type photbands: list of strings
    @keyword wave: wavelength array to interpolate the law on
    @type wave: ndarray
    @return: wavelength, reddening magnitude
    @rtype: (ndarray,ndarray)
    """
    #-- get the inputs
    wave_ = kwargs.pop('wave',None)
    Rv = kwargs.setdefault('Rv',3.1)
    
    #-- get the curve
    wave,mag = globals()[name.lower()](**kwargs)
    wave_orig,mag_orig = wave.copy(),mag.copy()
    
    #-- interpolate on user defined grid
    if wave_ is not None:
        if wave_units != 'AA':
            wave_ = conversions.convert(wave_units,'AA',wave_)
        mag = np.interp(wave_,wave,mag,right=0)
        wave = wave_
           
    #-- pick right normalisation: convert to A(lambda)/Av if needed
    if norm.lower()=='e(b-v)':
        mag *= Rv
    else:
        #-- we allow ak and av as shortcuts for normalisation in JOHNSON K and
        #   V bands
        if norm.lower()=='ak':
            norm = 'JOHNSON.K'
        elif norm.lower()=='av':
            norm = 'JOHNSON.V'
        norm_reddening = model.synthetic_flux(wave_orig,mag_orig,[norm])[0]
        logger.info('Normalisation via %s: Av/%s = %.6g'%(norm,norm,1./norm_reddening))
        mag /= norm_reddening
    
    #-- maybe we want the curve in photometric filters
    if photbands is not None:
        mag = model.synthetic_flux(wave,mag,photbands)
        wave = filters.get_info(photbands)['eff_wave']
    
    
    #-- set the units of the wavelengths
    if wave_units != 'AA':
        wave = conversions.convert('AA',wave_units,wave)
    
    return wave,mag
Example #4
0
def get_law(name, norm='E(B-V)', wave_units='AA', photbands=None, **kwargs):
    """
    Retrieve an interstellar reddening law.
    
    Parameter C{name} must be the function name of one of the laws defined in
    this module.
    
    By default, the law will be interpolated on a grid from 100 angstrom to
    10 micron in steps of 10 angstrom. This can be adjusted with the parameter
    C{wave} (array), which B{must} be in angstrom. You can change the units
    ouf the returned wavelength array via C{wave_units}.
    
    By default, the curve is normalised with respect to E(B-V) (you get
    A(l)/E(B-V)). You can set the C{norm} keyword to Av if you want A(l)/Av.
    Remember that
    
    A(V) = Rv * E(B-V)
    
    The parameter C{Rv} is by default 3.1, other reasonable values lie between
    2.0 and 5.1
    
    Extra accepted keywords depend on the type of reddening law used.
    
    Example usage:
    
    >>> wave = np.r_[1e3:1e5:10]
    >>> wave,mag = get_law('cardelli1989',wave=wave,Rv=3.1)
    
    @param name: name of the interstellar law
    @type name: str, one of the functions defined here
    @param norm: type of normalisation of the curve
    @type norm: str (one of E(B-V), Av)
    @param wave_units: wavelength units
    @type wave_units: str (interpretable for units.conversions.convert)
    @param photbands: list of photometric passbands
    @type photbands: list of strings
    @keyword wave: wavelength array to interpolate the law on
    @type wave: ndarray
    @return: wavelength, reddening magnitude
    @rtype: (ndarray,ndarray)
    """
    #-- get the inputs
    wave_ = kwargs.pop('wave', None)
    Rv = kwargs.setdefault('Rv', 3.1)

    #-- get the curve
    wave, mag = globals()[name.lower()](**kwargs)
    wave_orig, mag_orig = wave.copy(), mag.copy()

    #-- interpolate on user defined grid
    if wave_ is not None:
        if wave_units != 'AA':
            wave_ = conversions.convert(wave_units, 'AA', wave_)
        mag = np.interp(wave_, wave, mag, right=0)
        wave = wave_

    #-- pick right normalisation: convert to A(lambda)/Av if needed
    if norm.lower() == 'e(b-v)':
        mag *= Rv
    else:
        #-- we allow ak and av as shortcuts for normalisation in JOHNSON K and
        #   V bands
        if norm.lower() == 'ak':
            norm = 'JOHNSON.K'
        elif norm.lower() == 'av':
            norm = 'JOHNSON.V'
        norm_reddening = model.synthetic_flux(wave_orig, mag_orig, [norm])[0]
        logger.info('Normalisation via %s: Av/%s = %.6g' %
                    (norm, norm, 1. / norm_reddening))
        mag /= norm_reddening

    #-- maybe we want the curve in photometric filters
    if photbands is not None:
        mag = model.synthetic_flux(wave, mag, photbands)
        wave = filters.get_info(photbands)['eff_wave']

    #-- set the units of the wavelengths
    if wave_units != 'AA' and photbands is not None:
        wave = conversions.convert('AA', wave_units, wave)

    return wave, mag