def fix_filename(s):
    """
    Clean up a file name by removing invalid characters and converting 
    spaces to underscores.
    
    Parameters
    ----------
    s : `str`
        File name
    
    Returns
    -------
    `str`
        Cleaned file name
    """
    fname = "".join(c for c in s if c.isalnum() or c in (" ._~"))
    fname = fname.replace(" ", "_")
    return fname