Exemple #1
0
  def load_organism(self, name, grid, position):
    logger.debug("Loading '%s' from '%s'." % (name, self.__library))

    name = name.lower()
    # Add underscore
    name = name.replace(" ", "_")

    organism_file = open("%s/%s.yaml" % (self.__library, name))
    data = yaml.load(organism_file, Loader=Loader)
    organism_file.close()

    # Read defaults and use them to populate anything not specified.
    defaults_file = open("%s/defaults.yaml" % (self.__library))
    defaults = yaml.load(defaults_file, Loader=Loader)
    defaults_file.close()

    # Incorporate the defaults into our original data.
    merged = _merge_trees(data, defaults)

    organism = Organism(grid, position)
    organism.set_attributes(merged)

    if grid.scale() < 0:
      # This is the first organism we added.
      logger.info("Setting grid scale to %f." % (organism.Scale))
      grid.set_scale(organism.Scale)
    elif organism.Scale != grid.scale():
      logger.log_and_raise(LibraryError,
          "Mismatch between object scale %f and grid scale %f." % \
          (organism.Scale, grid.scale()))

    return organism