Пример #1
0
 def test_world_gen_does_not_explode_badly(self):
     # FIXME remove me when proper tests are in place
     # Very stupid test that just verify nothing explode badly
     world_gen("Dummy",
               32,
               16,
               1, [.874, .765, .594, .439, .366, .124],
               [.941, .778, .507, .236, 0.073, .014, .002],
               step=Step.get_by_name("full"))
Пример #2
0
 def test_hdf5_serialize_unserialize(self):
     filename = None
     try:
         w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
         f = tempfile.NamedTemporaryFile(delete=False)
         f.close()
         filename = f.name
         serialized = save_world_to_hdf5(w, filename)
         unserialized = load_world_to_hdf5(filename)
         self.assertEqual(Set(w.layers.keys()),
                          Set(unserialized.layers.keys()))
         self.assertEqual(w.layers['humidity'].quantiles,
                          unserialized.layers['humidity'].quantiles)
         for l in w.layers.keys():
             self.assertEqual(w.layers[l], unserialized.layers[l],
                              "Comparing %s" % l)
         self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level))
         self.assertEquals(w.seed, unserialized.seed)
         self.assertEquals(w.n_plates, unserialized.n_plates)
         self.assertEquals(w.step, unserialized.step)
         self.assertEqual(sorted(dir(w)), sorted(dir(unserialized)))
         #self.assertEqual(w, unserialized)
     finally:
         if filename:
             os.remove(filename)
Пример #3
0
 def test_pickle_serialize_unserialize(self):
     w = world_gen("Dummy", 32, 16, 1, [.874, .765, .594, .439, .366, .124], [.941, .778, .507, .236, 0.073, .014, .002], step=Step.get_by_name("full"))
     f = tempfile.NamedTemporaryFile(delete=False).name
     w.to_pickle_file(f)
     unserialized = World.from_pickle_file(f)
     os.remove(f)
     self.assertTrue(_equal(w.elevation['data'], unserialized.elevation['data']))
     self.assertEqual(w.elevation['thresholds'], unserialized.elevation['thresholds'])
     self.assertTrue(_equal(w.ocean,             unserialized.ocean))
     self.assertTrue(_equal(w.biome,             unserialized.biome))
     self.assertTrue(_equal(w.humidity,          unserialized.humidity))
     self.assertTrue(_equal(w.irrigation,        unserialized.irrigation))
     self.assertTrue(_equal(w.permeability,      unserialized.permeability))
     self.assertTrue(_equal(w.watermap,          unserialized.watermap))
     self.assertTrue(_equal(w.precipitation,     unserialized.precipitation))
     self.assertTrue(_equal(w.temperature,       unserialized.temperature))
     self.assertTrue(_equal(w.sea_depth,         unserialized.sea_depth))
     self.assertEquals(w.seed,                   unserialized.seed)
     self.assertEquals(w.n_plates,               unserialized.n_plates)
     self.assertTrue(_equal(w.ocean_level,       unserialized.ocean_level))
     self.assertTrue(_equal(w.lake_map,          unserialized.lake_map))
     self.assertTrue(_equal(w.river_map,         unserialized.river_map))
     self.assertEquals(w.step,                   unserialized.step)
     self.assertEqual(sorted(dir(w)),            sorted(dir(unserialized)))
     self.assertEqual(w, unserialized)
Пример #4
0
 def test_pickle_serialize_unserialize(self):
     w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
     f = tempfile.NamedTemporaryFile(delete=False).name
     w.to_pickle_file(f)
     unserialized = World.from_pickle_file(f)
     os.remove(f)
     self.assertEqual(w.elevation['data'],       unserialized.elevation['data'])
     self.assertEqual(w.elevation['thresholds'], unserialized.elevation['thresholds'])
     self.assertEqual(w.ocean,                   unserialized.ocean)
     self.assertEqual(w.biome,                   unserialized.biome)
     self.assertEqual(w.humidity,                unserialized.humidity)
     self.assertEqual(w.irrigation,              unserialized.irrigation)
     self.assertEqual(w.permeability,            unserialized.permeability)
     self.assertEqual(w.watermap,                unserialized.watermap)
     self.assertEqual(w.precipitation,           unserialized.precipitation)
     self.assertEqual(w.temperature,             unserialized.temperature)
     self.assertEqual(w.sea_depth,               unserialized.sea_depth)
     self.assertEquals(w.seed,                   unserialized.seed)
     self.assertEquals(w.n_plates,               unserialized.n_plates)
     self.assertEquals(w.ocean_level,            unserialized.ocean_level)
     self.assertEquals(w.lake_map,               unserialized.lake_map)
     self.assertEquals(w.river_map,              unserialized.river_map)
     self.assertEquals(w.step,                   unserialized.step)
     self.assertEqual(_sort(dir(w)), _sort(dir(unserialized)))
     self.assertEqual(w, unserialized)
Пример #5
0
 def test_protobuf_serialize_unserialize(self):
     w = world_gen("Dummy",
                   32,
                   16,
                   1, [.874, .765, .594, .439, .366, .124],
                   [.941, .778, .507, .236, 0.073, .014, .002],
                   step=Step.get_by_name("full"))
     serialized = w.protobuf_serialize()
     unserialized = World.protobuf_unserialize(serialized)
     self.assertTrue(
         _equal(w.elevation['data'], unserialized.elevation['data']))
     self.assertEqual(w.elevation['thresholds'],
                      unserialized.elevation['thresholds'])
     self.assertTrue(_equal(w.ocean, unserialized.ocean))
     self.assertTrue(_equal(w.biome, unserialized.biome))
     self.assertTrue(_equal(w.humidity, unserialized.humidity))
     self.assertTrue(_equal(w.irrigation, unserialized.irrigation))
     self.assertTrue(_equal(w.permeability, unserialized.permeability))
     self.assertTrue(_equal(w.watermap, unserialized.watermap))
     self.assertTrue(_equal(w.precipitation, unserialized.precipitation))
     self.assertTrue(_equal(w.temperature, unserialized.temperature))
     self.assertTrue(_equal(w.sea_depth, unserialized.sea_depth))
     self.assertEquals(w.seed, unserialized.seed)
     self.assertEquals(w.n_plates, unserialized.n_plates)
     self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level))
     self.assertTrue(_equal(w.lake_map, unserialized.lake_map))
     self.assertTrue(_equal(w.river_map, unserialized.river_map))
     self.assertEquals(w.step, unserialized.step)
     self.assertEqual(sorted(dir(w)), sorted(dir(unserialized)))
     self.assertEqual(w, unserialized)
Пример #6
0
 def test_protobuf_serialize_unserialize(self):
     w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
     serialized = w.protobuf_serialize()
     unserialized = World.protobuf_unserialize(serialized)
     self.assertEqual(set(w.layers.keys()), set(unserialized.layers.keys()))
     for l in w.layers.keys():
         self.assertEqual(w.layers[l], unserialized.layers[l], "Comparing %s" % l)
     self.assertTrue(_equal(w.ocean_level,       unserialized.ocean_level))
     self.assertEquals(w.seed,                   unserialized.seed)
     self.assertEquals(w.n_plates,               unserialized.n_plates)
     self.assertEquals(w.step,                   unserialized.step)
     self.assertEqual(sorted(dir(w)),            sorted(dir(unserialized)))
     self.assertEqual(w, unserialized)
Пример #7
0
 def test_protobuf_serialize_unserialize(self):
     w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
     serialized = w.protobuf_serialize()
     unserialized = World.protobuf_unserialize(serialized)
     self.assertEqual(Set(w.layers.keys()), Set(unserialized.layers.keys()))
     for l in w.layers.keys():
         self.assertEqual(w.layers[l], unserialized.layers[l],
                          "Comparing %s" % l)
     self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level))
     self.assertEquals(w.seed, unserialized.seed)
     self.assertEquals(w.n_plates, unserialized.n_plates)
     self.assertEquals(w.step, unserialized.step)
     self.assertEqual(sorted(dir(w)), sorted(dir(unserialized)))
     self.assertEqual(w, unserialized)
Пример #8
0
 def test_hdf5_serialize_unserialize(self):
     filename = None
     try:
         w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
         f = tempfile.NamedTemporaryFile(delete=False)
         f.close()
         filename = f.name
         serialized = save_world_to_hdf5(w, filename)
         unserialized = load_world_to_hdf5(filename)
         self.assertTrue(
             _equal(w.elevation['data'], unserialized.elevation['data']))
         self.assertEqual(w.elevation['thresholds'],
                          unserialized.elevation['thresholds'])
         self.assertTrue(_equal(w.plates, unserialized.plates))
         self.assertTrue(_equal(w.ocean, unserialized.ocean))
         self.assertTrue(_equal(w.biome, unserialized.biome))
         self.assertTrue(
             _equal(w.humidity['quantiles'],
                    unserialized.humidity['quantiles']))
         self.assertTrue(
             _equal(w.humidity['data'], unserialized.humidity['data']))
         self.assertTrue(_equal(w.humidity, unserialized.humidity))
         self.assertTrue(_equal(w.irrigation, unserialized.irrigation))
         self.assertTrue(_equal(w.permeability, unserialized.permeability))
         self.assertTrue(_equal(w.watermap, unserialized.watermap))
         self.assertTrue(
             _equal(w.precipitation['thresholds'],
                    unserialized.precipitation['thresholds']))
         self.assertTrue(
             _equal(w.precipitation['data'],
                    unserialized.precipitation['data']))
         self.assertTrue(_equal(w.precipitation,
                                unserialized.precipitation))
         self.assertTrue(_equal(w.temperature, unserialized.temperature))
         self.assertTrue(_equal(w.sea_depth, unserialized.sea_depth))
         self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level))
         self.assertTrue(_equal(w.lake_map, unserialized.lake_map))
         self.assertTrue(_equal(w.river_map, unserialized.river_map))
         self.assertTrue(_equal(w.icecap, unserialized.icecap))
         self.assertEquals(w.seed, unserialized.seed)
         self.assertEquals(w.n_plates, unserialized.n_plates)
         self.assertEquals(w.step, unserialized.step)
         self.assertEqual(sorted(dir(w)), sorted(dir(unserialized)))
         #self.assertEqual(w, unserialized)
     finally:
         if filename:
             os.remove(filename)
Пример #9
0
def generate_world(world_name, width, height, seed, num_plates, output_dir,
                   step, ocean_level, temps, humids, world_format='protobuf',
                   gamma_curve=1.25, curve_offset=.2, fade_borders=True,
                   verbose=True, black_and_white=False):
    w = world_gen(world_name, width, height, seed, temps, humids, num_plates, ocean_level,
                  step, gamma_curve=gamma_curve, curve_offset=curve_offset,
                  fade_borders=fade_borders, verbose=verbose)

    print('')  # empty line
    print('Producing ouput:')
    sys.stdout.flush()

    # Save data
    filename = "%s/%s.world" % (output_dir, world_name)
    with open(filename, "wb") as f:
        if world_format == 'pickle':
            pickle.dump(w, f, pickle.HIGHEST_PROTOCOL)
        elif world_format == 'protobuf':
            f.write(w.protobuf_serialize())
        else:
            print("Unknown format '%s', not saving " % world_format)
    print("* world data saved in '%s'" % filename)
    sys.stdout.flush()

    # Generate images
    filename = '%s/%s_ocean.png' % (output_dir, world_name)
    draw_ocean_on_file(w.ocean, filename)
    print("* ocean image generated in '%s'" % filename)

    if step.include_precipitations:
        filename = '%s/%s_precipitation.png' % (output_dir, world_name)
        draw_precipitation_on_file(w, filename, black_and_white)
        print("* precipitation image generated in '%s'" % filename)
        filename = '%s/%s_temperature.png' % (output_dir, world_name)
        draw_temperature_levels_on_file(w, filename, black_and_white)
        print("* temperature image generated in '%s'" % filename)

    if step.include_biome:
        filename = '%s/%s_biome.png' % (output_dir, world_name)
        draw_biome_on_file(w, filename)
        print("* biome image generated in '%s'" % filename)

    filename = '%s/%s_elevation.png' % (output_dir, world_name)
    sea_level = w.sea_level()
    draw_simple_elevation_on_file(w, filename, sea_level=sea_level)
    print("* elevation image generated in '%s'" % filename)
    return w
Пример #10
0
def generate_world(world_name, width, height, seed, num_plates, output_dir,
                   step, ocean_level, temps, humids,
                   world_format='pickle', fade_borders=True,
                   verbose=True, black_and_white=False):
    w = world_gen(world_name, width, height, seed, temps, humids, num_plates, ocean_level,
                  step, fade_borders=fade_borders, verbose=verbose)

    print('')  # empty line
    print('Producing ouput:')
    sys.stdout.flush()

    # Save data
    filename = "%s/%s.world" % (output_dir, world_name)
    with open(filename, "wb") as f:
        if world_format == 'pickle':
            pickle.dump(w, f, pickle.HIGHEST_PROTOCOL)
        elif world_format == 'protobuf':
            f.write(w.protobuf_serialize())
        else:
            print("Unknown format '%s', not saving " % world_format)
    print("* world data saved in '%s'" % filename)
    sys.stdout.flush()

    # Generate images
    filename = '%s/%s_ocean.png' % (output_dir, world_name)
    draw_ocean_on_file(w.ocean, filename)
    print("* ocean image generated in '%s'" % filename)

    if step.include_precipitations:
        filename = '%s/%s_precipitation.png' % (output_dir, world_name)
        draw_precipitation_on_file(w, filename, black_and_white)
        print("* precipitation image generated in '%s'" % filename)
        filename = '%s/%s_temperature.png' % (output_dir, world_name)
        draw_temperature_levels_on_file(w, filename, black_and_white)
        print("* temperature image generated in '%s'" % filename)

    if step.include_biome:
        filename = '%s/%s_biome.png' % (output_dir, world_name)
        draw_biome_on_file(w, filename)
        print("* biome image generated in '%s'" % filename)

    filename = '%s/%s_elevation.png' % (output_dir, world_name)
    sea_level = w.sea_level()
    draw_simple_elevation_on_file(w, filename, sea_level=sea_level)
    print("* elevation image generated in '%s'" % filename)
    return w
Пример #11
0
 def test_hdf5_serialize_unserialize(self):
     filename = None
     try:
         w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
         f = tempfile.NamedTemporaryFile(delete=False)
         f.close()
         filename = f.name
         serialized = save_world_to_hdf5(w, filename)
         unserialized = load_world_to_hdf5(filename)
         self.assertEqual(set(w.layers.keys()), set(unserialized.layers.keys()))
         self.assertEqual(w.layers['humidity'].quantiles, unserialized.layers['humidity'].quantiles)
         for l in w.layers.keys():
             self.assertEqual(w.layers[l], unserialized.layers[l], "Comparing %s" % l)
         self.assertTrue(_equal(w.ocean_level,       unserialized.ocean_level))
         self.assertEquals(w.seed,                   unserialized.seed)
         self.assertEquals(w.n_plates,               unserialized.n_plates)
         self.assertEquals(w.step,                   unserialized.step)
         self.assertEqual(sorted(dir(w)),            sorted(dir(unserialized)))
         #self.assertEqual(w, unserialized)
     finally:
         if filename:
             os.remove(filename)
Пример #12
0
 def test_protobuf_serialize_unserialize(self):
     w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
     serialized = w.protobuf_serialize()
     unserialized = World.protobuf_unserialize(serialized)
     self.assertEqual(w.elevation['data'],       unserialized.elevation['data'])
     self.assertEqual(w.elevation['thresholds'], unserialized.elevation['thresholds'])
     self.assertEqual(w.ocean,                   unserialized.ocean)
     self.assertEqual(w.biome,                   unserialized.biome)
     self.assertEqual(w.humidity,                unserialized.humidity)
     self.assertEqual(w.irrigation,              unserialized.irrigation)
     self.assertEqual(w.permeability,            unserialized.permeability)
     self.assertEqual(w.watermap,                unserialized.watermap)
     self.assertEqual(w.precipitation,           unserialized.precipitation)
     self.assertEqual(w.temperature,             unserialized.temperature)
     self.assertEqual(w.sea_depth,               unserialized.sea_depth)
     self.assertEquals(w.seed,                   unserialized.seed)
     self.assertEquals(w.n_plates,               unserialized.n_plates)
     self.assertEquals(w.ocean_level,            unserialized.ocean_level)
     self.assertEquals(w.lake_map,               unserialized.lake_map)
     self.assertEquals(w.river_map,              unserialized.river_map)
     self.assertEquals(w.step,                   unserialized.step)
     self.assertEqual(_sort(dir(w)), _sort(dir(unserialized)))
     self.assertEqual(w, unserialized)
Пример #13
0
 def test_hdf5_serialize_unserialize(self):
     filename = None
     try:
         w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
         f = tempfile.NamedTemporaryFile(delete=False)
         f.close()
         filename = f.name
         serialized = save_world_to_hdf5(w, filename)
         unserialized = load_world_to_hdf5(filename)
         self.assertTrue(_equal(w.elevation['data'], unserialized.elevation['data']))
         self.assertEqual(w.elevation['thresholds'], unserialized.elevation['thresholds'])
         self.assertTrue(_equal(w.ocean,             unserialized.ocean))
         self.assertTrue(_equal(w.biome,             unserialized.biome))
         self.assertTrue(_equal(w.humidity['quantiles'], unserialized.humidity['quantiles']))
         self.assertTrue(_equal(w.humidity['data'],  unserialized.humidity['data']))
         self.assertTrue(_equal(w.humidity,          unserialized.humidity))
         self.assertTrue(_equal(w.irrigation,        unserialized.irrigation))
         self.assertTrue(_equal(w.permeability,      unserialized.permeability))
         self.assertTrue(_equal(w.watermap,          unserialized.watermap))
         self.assertTrue(_equal(w.precipitation['thresholds'], unserialized.precipitation['thresholds']))
         self.assertTrue(_equal(w.precipitation['data'], unserialized.precipitation['data']))
         self.assertTrue(_equal(w.precipitation,     unserialized.precipitation))
         self.assertTrue(_equal(w.temperature,       unserialized.temperature))
         self.assertTrue(_equal(w.sea_depth,         unserialized.sea_depth))
         self.assertTrue(_equal(w.ocean_level,       unserialized.ocean_level))
         self.assertTrue(_equal(w.lake_map,          unserialized.lake_map))
         self.assertTrue(_equal(w.river_map,         unserialized.river_map))
         self.assertTrue(_equal(w.icecap,            unserialized.icecap))
         self.assertEquals(w.seed,                   unserialized.seed)
         self.assertEquals(w.n_plates,               unserialized.n_plates)
         self.assertEquals(w.step,                   unserialized.step)
         self.assertEqual(sorted(dir(w)),            sorted(dir(unserialized)))
         #self.assertEqual(w, unserialized)
     finally:
         if filename:
             os.remove(filename)
Пример #14
0
def main(tests_data_dir):
    numpy.random.seed(28070)
    w = world_gen("seed_28070", 300, 200, 28070)
    w.protobuf_to_file("%s/seed_28070.world" % tests_data_dir)
Пример #15
0
 def test_world_gen_does_not_explode_badly(self):
     # FIXME remove me when proper tests are in place
     # Very stupid test that just verify nothing explode badly
     world_gen("Dummy", 32, 16, 1, [.874, .765, .594, .439, .366, .124], [.941, .778, .507, .236, 0.073, .014, .002], step=Step.get_by_name("full"))
Пример #16
0
 def test_world_gen_does_not_explode_badly(self):
     # FIXME remove me when proper tests are in place
     # Very stupid test that just verify nothing explode badly
     world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
Пример #17
0
def main(tests_data_dir):
    numpy.random.seed(28070)
    w = world_gen("seed_28070", 300, 200, 28070)
    w.protobuf_to_file("%s/seed_28070.world" % tests_data_dir)