def get_range_bins_to_avg(rad1_rng, rad2_rng):
    """
    Compares the resolution of two radars and determines if and which radar
    has to be averaged and the length of the averaging window

    Parameters
    ----------
    rad1_rng : array
        the range of radar 1
    rad2_rng : datetime
        the range of radar 2

    Returns
    -------
    avg_rad1, avg_rad2 : Boolean
        Booleans specifying if the radar data has to be average in range
    avg_rad_lim : array with two elements
        the limits to the average (centered on each range gate)

    """
    rad1_res = rad1_rng[1] - rad1_rng[0]
    rad2_res = rad2_rng[1] - rad2_rng[0]
    res_ratio = rad1_res / rad2_res
    avg_rad1 = False
    avg_rad2 = False
    avg_rad_lim = None
    if res_ratio > 1.5:
        avg_rad2 = True
        nbins = int(res_ratio)
        if nbins % 2 == 0:
            avg_rad_lim = [-int(nbins / 2) - 1, int(nbins / 2)]
        else:
            avg_rad_lim = [-int((nbins - 1) / 2), int((nbins - 1) / 2)]
    elif res_ratio < 1.0 / 1.5:
        avg_rad1 = True
        nbins = int(1.0 / res_ratio)
        if nbins % 2 == 0:
            avg_rad_lim = [-int(nbins / 2) - 1, int(nbins / 2)]
        else:
            avg_rad_lim = [-int((nbins - 1) / 2), int((nbins - 1) / 2)]
    return avg_rad1, avg_rad2, avg_rad_lim
