import json


def convert_sat(sat_max, sat_mode, ins, infile, ta=False):
    """ Converts full well fraction to a saturation in counts OR provides the 
    max fullwell for TA mode.

    Parameters
    ----------
    sat_max : float
        Either a full well fraction or counts.
    sat_mode : str
        'well' or 'counts'.
    ins : str
        The instrument.
    infile : str
        The path to the data file.
    ta : bool, optional
        Whether or not it's TA mode.
    
    Returns
    -------
    sat_max : float
        The fullwell to use in counts.
    """

    with open(infile) as f:
        dat = json.load(f)

    ins_dict = dat['fullwell'] 
    
    if sat_mode == 'well':
        sat_max = sat_max*ins_dict[ins]
    
    if ta:
        sat_max = ins_dict[ins]
    
    return sat_max