import pickle


def mergeMaps(mapping_files):
    """
    mapping_files is a list of mapping file names. 

    The result is a dictionary containing all the mappings. 
    Channels are converted to the order in the mapping_files 
    list. It is assumed that channel 0 is the same in all
    of the files.
    """
    assert(len(mapping_files) > 0)
    
    mappings = {}
    for i, filename in enumerate(mapping_files):

        # Load channel to channel mapping.
        with open(filename, 'rb') as fp:
            mp_transform = pickle.load(fp)

        # Add to overall mappings.
        mappings["0_" + str(i+1) + "_x"] = mp_transform["0_1_x"]
        mappings["0_" + str(i+1) + "_y"] = mp_transform["0_1_y"]
        mappings[str(i+1) + "_0_x"] = mp_transform["1_0_x"]
        mappings[str(i+1) + "_0_y"] = mp_transform["1_0_y"]

    return mappings