code: def make_optimal_phenotype_grid(environment, phenotypes):
      
      world_size = environment.size
      phenotypes = deepcopy(phenotypes)
  
      for i in range(world_size[1]):
          for j in range(world_size[0]):
              for k in range(len(phenotypes[i][j])):
                  phenotype = phenotype_to_res_set(phenotypes[i][j][k],
                                                   environment.tasks)
                  diff = len(environment[i][j].symmetric_difference(phenotype))
                  phenotypes[i][j][k] = diff
  
      return phenotypes
docs: Takes an EnvironmentFile object and a 2d array of phenotypes and returns
      a 2d array in which each location contains an index representing the
      distance between the phenotype in that location and the optimal phenotype
      for that location.
  
      This is acheived by using the task list in the EnvironmentFile to convert
      the phenotypes to sets of tasks, and comparing them to the sets of
      resources in the environment. So if the environment file that you created
      the EnvironmentFile object from for some reason doesn't contain all of the
      tasks, or doesn't contain them in the right order this won't work. If this
      is the environment file that you used for the run of Avida that generated
      this data, you should be fine.