Esempio n. 1
0
def deredden(data, host_EBV=None, host_RV=None, MW_EBV=None, MW_RV=3.1,
             *args, **kwargs):
    """Correct for extinction."""
    if not _can_deredden:
        return data

    # Milky Way extinction
    if MW_EBV is not None and MW_EBV != 0. and MW_RV is not None:
        data[:, 1], _a, _b = unred(data[:, 0], data[:, 1], MW_EBV, R_V=MW_RV)

    # Host extinction
    if host_EBV is not None and host_EBV != 0. and host_RV is not None:
        data[:, 1], _a, _b = unred(data[:, 0], data[:, 1], host_EBV, R_V=host_RV)

    return data
Esempio n. 2
0
 def __call__(self, x):
     m = num.array([
         deredden.unred(x[i], x[i] * 0 + 1, -self.pars[0],
                        R_V=self.pars[1])[0] for i in range(x.shape[0])
     ])
     #m *= self.pars[0]
     return m
Esempio n. 3
0
    def R(self,
          Rv=3.1,
          wave=None,
          flux=None,
          z=0.0,
          EBV=0.001,
          redlaw='ccm',
          strict_ccm=False):
        '''For a given reddening law Rv (default 3.1), find the ratio of total
      to selective absorption for this filter:  R = A/E(B-V).  You can 
      specify a specific spectrum by supplying a wave and flux and redshift
      (default is defined by filters.reference_wave and 
      filters.refernce_flux at z=0).  You can also specify E(B-V) (EBV) which can
      change the value of R if the spectrum is significantly non-stellar. You
      can specify redlaw='fm' if you prefer a Fitzpatric (1999) reddening 
      law.'''
        global standards

        if wave is None:
            wave,flux = standards['Vega']['VegaB'].wave,\
                        standards['Vega']['VegaB'].resp
        flux0 = self.response(wave, flux, z, photons=1)
        if flux0 <= 0:
            return (num.nan)
        redf = unred(wave,
                     flux,
                     -EBV,
                     Rv,
                     z,
                     redlaw=redlaw,
                     strict_ccm=strict_ccm)[0]
        fluxr = self.response(wave, redf, z, photons=1)
        return (-2.5 * num.log10(fluxr / flux0) / EBV)
Esempio n. 4
0
def preprocess(data,
               z=None,
               wave_range=None,
               normalize=False,
               scale=False,
               E_BV=None):
    '''
    `data` formatted by:
        data[: 0] -> wavelength
        data[: 1] -> flux
        data[: 2] -> flux_err
    '''
    # Get rid of NaN values
    data = data[~np.isnan(data).any(axis=1)]

    # Put wavelength in rest frame
    data[:, 0] = deredshift(data[:, 0], z)

    # Prune to wavelength range
    if wave_range is not None:
        data = prune(data, wave_range)

    # Correct for MW reddening
    if E_BV is not None:
        data[:, 1], _, _0 = unred(data[:, 0], data[:, 1], E_BV, MW_RV)

    if scale:
        data = scale_flux(data)
    elif normalize:
        data = normalize_flux(data)

    return data
Esempio n. 5
0
   def R(self, Rv=3.1, wave=None, flux=None, z=0.0, EBV=0.001, redlaw='ccm',
         strict_ccm=False):
      '''For a given reddening law Rv (default 3.1), find the ratio of total
      to selective absorption for this filter:  R = A/E(B-V).  You can 
      specify a specific spectrum by supplying a wave and flux and redshift
      (default is defined by filters.reference_wave and 
      filters.refernce_flux at z=0).  You can also specify E(B-V) (EBV) which can
      change the value of R if the spectrum is significantly non-stellar. You
      can specify redlaw='fm' if you prefer a Fitzpatric (1999) reddening 
      law.'''
      global standards

      if wave is None:
         wave,flux = standards['Vega']['VegaB'].wave,\
                     standards['Vega']['VegaB'].resp
      flux0 = self.response(wave, flux, z, photons=1)
      if flux0 <= 0:
         return(num.nan)
      redf = unred(wave, flux, -EBV, Rv, z, redlaw=redlaw, 
            strict_ccm=strict_ccm)[0]
      fluxr = self.response(wave, redf, z, photons=1)
      return(-2.5*num.log10(fluxr/flux0)/EBV)
Esempio n. 6
0
 def __call__(self, x):
    m = num.array([deredden.unred(x[i], x[i]*0+1, -self.pars[0], 
       R_V=self.pars[1])[0] for i in range(x.shape[0])])
    #m *= self.pars[0]
    return m