def parse_mp_id(mp_id):
    """ Return MP ID string for valid MP ID
        Modified from mp_phot package, util.py, .get_mp_and_an_string().
    :param mp_id: raw MP identification, either number or other ID, e.g., 5802 (int), '5802', or
         '1992 SG4'. [int or string]
    :return: for numbered MP, give simply the string, e.g. '5802'.
             for other MP ID, give the string prepended wtih '~', e.g., '~1992 SG4'.
         """
    if isinstance(mp_id, int):
        if mp_id < 1:
            raise ValueError('MP ID must be a positive integer.')
        mp_id_string = str(mp_id)  # e.g., '1108' for numbered MP ID 1108 (if passed in as int).
    elif isinstance(mp_id, str):
        if mp_id[0] not in '0123456789':
            raise ValueError('MP ID does not appear valid.')
        try:
            _ = int(mp_id)  # a test only
        except ValueError:
            mp_id_string = '~' + mp_id   # e.g., '*1997 TX3' for unnumbered MP ID '1997 TX3'.
        else:
            mp_id_string = mp_id.strip()  # e.g., '1108' for numbered MP ID 1108 (if passed in as string).
    else:
        raise TypeError('mp_id must be an integer or string representing a valid MP ID.')
    return mp_id_string