def get_flux(ab_magnitude, filt, survey):
    """Convert source magnitude to flux.

    The calculation includes the effects of atmospheric extinction.
    Credit: WeakLensingDeblending (https://github.com/LSSTDESC/WeakLensingDeblending)

    Args:
        ab_magnitude(float): AB magnitude of source.
        filt (btk.survey.Filter): BTK Filter object
        survey (btk.survey.Survey): BTK Survey object

    Returns:
        Flux in detected electrons.
    """
    mag = ab_magnitude + filt.extinction * (survey.airmass - survey.zeropoint_airmass)
    return filt.exp_time * 10 ** (-0.4 * (mag - filt.zeropoint))