Exemple #1
1
def getExtinction(ra, dec, a_lambda=None):
    """
    Estimate the Galactic extinction for HSC filters.

    Parameters:
        ra, dec : The input coordinates can be arrays
    """
    # Check the input, if it's scalar, convert to array
    if not hasattr(ra, "__len__") or not hasattr(dec, "__len__"):
        ra = np.asrray([ra])
        dec = np.asarray([dec])
    if len(ra) != len(dec):
        raise Exception("## The RA and DEC should contain " +
                        "same number of elements!")
    # First try mwdust from Jo Bovy
    try:
        import mwdust
        sfd = mwdust.SFD(sf10=True)

        from astropy.coordinates import SkyCoord
        coords = SkyCoord(ra, dec, frame='icrs', unit='deg')
        galactic = coords.galactic
        l, b = galactic.l, galactic.b
        ebv = sfd(l, b, 0)
    except ImportError:
        try:
            # Then try sncosmo
            from sncosmo import SFD98Map
            dustDir = os.environ.get('DUST_DIR')
            if (not os.path.isfile(
                    os.path.join(dustDir, 'SFD_dust_4096_ngp.fits'))) or (
                        not os.path.isfile(
                            os.path.join(dustDir, 'SFD_dust_4096_sgp.fits'))):
                print('# DUST_DIR : %s' % dustDir)
                raise Exception("# Can not find the SFD dust map!")
            else:
                sfd = SFD98Map(dustDir)
                ebv = sfd.get_ebv((ra, dec))
        except ImportError:
            raise Exception("# Both mwdust and sncosmo are not available")
    if a_lambda is not None:
        return (ebv * a_lambda)
    else:
        return ebv
Exemple #2
0
def radec_extinction(ra, dec, a_lambda=1.0):
    """Estimate the Galactic extinction for HSC filters.

    -----------
    Parameters:
        (ra, dec): (float, float)
            The input coordinates can be arrays

        a_lambda : optional, default=1.0
            Convert the e_bv value into extinction in magnitude unit.

    """
    coords = SkyCoord(ra, dec, frame='icrs', unit='deg')

    try:
        # mwdust by Jo Bovy
        import mwdust
        sfd = mwdust.SFD(sf10=True)
        ebv = sfd(coords.galactic.l.deg, coords.galactic.b.deg, 0)
    except ImportError:
        try:
            # Try querying the IRSA dust map instead
            from astroquery.irsa_dust import IrsaDust
            extinction_tab = IrsaDust.get_extinction_table(coords)
            ebv = (extinction_tab['A_SFD'] / extinction_tab['A_over_E_B_V_SFD'])[1]
        except ImportError:
            raise Exception("# Need mwdust by Jo Bovy or Astroquery")

    return a_lambda * ebv
def load_dust_color(
    color,
    fname,
    df=None,
    distance=None,
    save=True,
    logger=_LOGFILE,
    verbose=None,
):
    """PanSTARRS1 dust color.

    Parameters
    ----------
    color
    fname
    df
    distance
    save
    logger
    verbose

    Returns
    -------
    dust_c

    """
    try:
        dust_c = np.load(fname.format(color)) * u.mag

    except FileNotFoundError:
        if (df is None) or (distance is None):
            raise ValueError(
                f"load_dust_color({color}) needs *df* & *distance*")

        sys.stdout.write(f"could not load {color}")
        sys.stdout.flush()

        SFDc = mwdust.SFD(filter=f"PS1 {color}")
        dust_c = SFDc(df["l"], df["b"], distance.to_value(u.kpc)) * u.mag

        if save:
            dust_c.value.dump(fname.format(color))

        sys.stdout.write(f"\033 -> finised {color}, ")
        sys.stdout.flush()

    else:
        sys.stdout.write(f"\033 {color}, ")
        sys.stdout.flush()

    return dust_c
Exemple #4
0
def getExtinction(ra, dec, a_lambda=None):
    """
    Estimate the Galactic extinction for HSC filters.

    Parameters:
        ra, dec : The input coordinates can be arrays
    """
    # First try mwdust from Jo Bovy
    try:
        import mwdust
        sfd = mwdust.SFD(sf10=True)

        from astropy.coordinates import SkyCoord
        coords = SkyCoord(ra, dec, frame='icrs', unit='deg')
        galactic = coords.galactic
        l, b = galactic.l, galactic.b
        ebv = sfd(l, b, 0)
    except ImportError:
        try:
            # Then try sncosmo
            from sncosmo import SFD98Map
            dustDir = os.environ.get('DUST_DIR')
            if (not os.path.isfile(
                    os.path.join(dustDir, 'SFD_dust_4096_ngp.fits'))) or (
                        not os.path.isfile(
                            os.path.join(dustDir, 'SFD_dust_4096_sgp.fits'))):
                print('# DUST_DIR : %s' % dustDir)
                raise Exception("# Can not find the SFD dust map!")
            else:
                sfd = SFD98Map(dustDir)
                ebv = sfd.get_ebv((ra, dec))
        except ImportError:
            raise Exception("# Both mwdust and sncosmo are not available")
    if a_lambda is not None:
        return (ebv * a_lambda)
    else:
        return ebv