import pickle


def save_pixel_lookup(lookup, X, Y, lons, lats, filename=None):
    """ 
    Save the pixel lookup information and the corresponding pixel IDs
    (as produced by create_pixel_lookup, plus the input lons and lats to that
    function) to filename, or if filename is not provided return a byte string 
    representing the pickle.
    """
    obj = (lookup, X, Y, lons, lats)
    if filename:
        with open(filename, 'wb') as f:
            pickle.dump(obj, f)
    else:
        return pickle.dumps(obj)