Makes an animation overlaying colored circles representing phenotypes over
    an imshow() plot indicating the resources present in each cell. By default,
    color is determined using the palettes in the EnvironmentFile object
    passed as the first parameter. The easiest way to change color palettes
    is to assign new palettes to environment.task_palette and
    environment.resource_palette before calling this function. If either the
    environment or phenotypes grids contain integers greater than 1, you should
    pass a `denom` keyword argument indicating how to normalize them. Using
    differnet denoms for the environment and phenotypes is not currently
    supported (if you need to, you should probably just divide everything by
    the appropraite denoms before passing them to this funciton).

    Inputs:
          environment - an EnvironmentFile object indicatng the distribution
                         of resources and the appropriate palettes to use.
          phenotypes  - a 2d array of numbers or binary strings representing
                        the placement of phenotypes across the environment

    kwargs:
          denom - an integer indicating how to normalize numbers in the
                  environment and phenotype grids if neccesary.
    Outputs:
         Returns a matplotlib animation object.
         Saves animation in the file:
            [environment_file_identifier]_phenotype_overlay.mp4

def paired_environment_phenotype_movie(environment, phenotypes, **kwargs):
    """
    Makes an animation overlaying colored circles representing phenotypes over
    an imshow() plot indicating the resources present in each cell. By default,
    color is determined using the palettes in the EnvironmentFile object
    passed as the first parameter. The easiest way to change color palettes
    is to assign new palettes to environment.task_palette and
    environment.resource_palette before calling this function. If either the
    environment or phenotypes grids contain integers greater than 1, you should
    pass a `denom` keyword argument indicating how to normalize them. Using
    differnet denoms for the environment and phenotypes is not currently
    supported (if you need to, you should probably just divide everything by
    the appropraite denoms before passing them to this funciton).

    Inputs:
          environment - an EnvironmentFile object indicatng the distribution
                         of resources and the appropriate palettes to use.
          phenotypes  - a 2d array of numbers or binary strings representing
                        the placement of phenotypes across the environment

    kwargs:
          denom - an integer indicating how to normalize numbers in the
                  environment and phenotype grids if neccesary.
    Outputs:
         Returns a matplotlib animation object.
         Saves animation in the file:
            [environment_file_identifier]_phenotype_overlay.mp4
    """
    denom, palette = get_kwargs(environment, kwargs)

    # Create figure to do plotting
    fig = plt.figure(figsize=(20, 20))

    # Create list of circles at every place in environment
    patches = []

    for i in range(len(phenotypes)):
        for j in range(len(phenotypes[i])):
            patches.append(plt.Circle((j, i), radius=.3,
                                      lw=2, ec="black",
                                      facecolor=None, zorder=2))

    # This will be called to color niches, which are always in background

    def init():
        plot_world(environment, palette=environment.resource_palette,
                   denom=denom)
        for p in patches:
            fig.gca().add_patch(p)
        return patches

    # Change colors of circles as appropriate for new time step
    def animate(n):
        phen_grid = slice_3d_grid(phenotypes, n)
        # Recolor circles
        plot_phens_blits(phen_grid, patches,
                         palette=environment.task_palette, denom=denom)
        return patches

    # Do actual animation
    anim = matplotlib.animation.FuncAnimation(
        fig, animate, init_func=init,
        frames=len(phenotypes[0][0]), blit=True, interval=750)
    print(environment.name)
    # print(anim.to_html5_video())
    anim.save(environment.name + "_phenotype_overlay.mov",
              writer=matplotlib.animation.ImageMagickWriter())
    return anim