def map_to_ta_modes(ins, max_group, min_group):
    """Turns the min/max groups into the closest allowable
    TA group mode.

    Parameters
    ----------
    ins : str
        Instrument.
    max_group : int
        The maximum number of groups without oversaturating.
    
    min_group : int
        The groups needed to hit the target SNR.
    
    Returns
    -------
    min_ta_groups : int
        The min possible groups to hit target SNR.
    max_ta_groups : int
        The max possible groups before saturation.
    """
    groups = {'miri': [3, 5, 9, 15, 23, 33, 45, 59, 75, 93, 113, 135, 159, 
        185, 243, 275, 513], 'niriss': [3, 5, 7, 9, 1, 13, 15, 17, 19],
        'nirspec': [3], 'nircam': [3, 5, 9, 17, 33, 65]}
    allowable_groups = groups[ins]
    min_ta_groups = min(allowable_groups, key=lambda x: abs(x - min_group))
    max_ta_groups = min(allowable_groups, key=lambda x: abs(x - max_group))
    if min_group == 0:
        min_ta_groups = 0
        max_ta_groups = 0
    if min_group > max(allowable_groups):
        min_ta_groups = -1
        max_ta_groups = 0
    return max_ta_groups, min_ta_groups
