def deredden(wl, Av, thres=None, mags=True):
    'Takes in wavelength array in microns. Valid between .1200 um and 1e4 microns.'
    if (thres is not None):
        Av_lo = thresh
    else:
        Av_lo = 0.0
    Av_me = 2.325
    if (Av_lo >= Av_me):
        Av_lo = 0.0
    Av_hi = 7.75
    if (Av >= Av_hi):
        AA = A3
        AvAk = 7.75
    if ((Av >= Av_me) and (Av < Av_hi)):
        AA = A2
        AvAk = 7.75
    if ((Av >= Av_lo) and (Av < Av_me)):
        AA = A2
        AvAk = 7.75
    if (Av < Av_lo):
        AA = A1
        AvAk = 9.03
    AK_AV = (1.0 / AvAk)
    Alambda_func = interp1d(awl, ((Av * AK_AV) * AA))
    Alambda = Alambda_func(wl)
    if mags:
        return Alambda
    else:
        return (10.0 ** (0.4 * Alambda))
Takes in wavelength array in microns. Valid between .1200 um and 1e4 microns.
def deredden(wl, Av, thres=None, mags=True):
    
    if (thres is not None):
        Av_lo = thresh
    else:
        Av_lo = 0.0
    Av_me = 2.325
    if (Av_lo >= Av_me):
        Av_lo = 0.0
    Av_hi = 7.75
    if (Av >= Av_hi):
        AA = A3
        AvAk = 7.75
    if ((Av >= Av_me) and (Av < Av_hi)):
        AA = A2
        AvAk = 7.75
    if ((Av >= Av_lo) and (Av < Av_me)):
        AA = A2
        AvAk = 7.75
    if (Av < Av_lo):
        AA = A1
        AvAk = 9.03
    AK_AV = (1.0 / AvAk)
    Alambda_func = interp1d(awl, ((Av * AK_AV) * AA))
    Alambda = Alambda_func(wl)
    if mags:
        return Alambda
    else:
        return (10.0 ** (0.4 * Alambda))