示例#1
0
文件: main.py 项目: 4144/worldengine
def generate_plates(seed, world_name, output_dir, width, height,
                    num_plates=10):
    """
    Eventually this method should be invoked when generation is called at
    asked to stop at step "plates", it should not be a different operation
    :param seed:
    :param world_name:
    :param output_dir:
    :param width:
    :param height:
    :param num_plates:
    :return:
    """
    elevation, plates = generate_plates_simulation(seed, width, height,
                                                   num_plates=num_plates)

    world = World(world_name, Size(width, height), seed, GenerationParameters(num_plates, -1.0, "plates"))
    world.set_elevation(numpy.array(elevation).reshape(height, width), None)
    world.set_plates(numpy.array(plates, dtype=numpy.uint16).reshape(height, width))

    # Generate images
    filename = '%s/plates_%s.png' % (output_dir, world_name)
    draw_simple_elevation_on_file(world, filename, None)
    print("+ plates image generated in '%s'" % filename)
    geo.center_land(world)
    filename = '%s/centered_plates_%s.png' % (output_dir, world_name)
    draw_simple_elevation_on_file(world, filename, None)
    print("+ centered plates image generated in '%s'" % filename)
示例#2
0
    def test_watermap_rng_stabilty(self):
        seed = 12345
        numpy.random.seed(seed)

        size = Size(16, 8)

        ocean = numpy.fromfunction(lambda y, x: y == x,
                                   (size.height, size.width))

        percipitation = numpy.ones((size.height, size.width))

        elevation = numpy.fromfunction(lambda y, x: y * x,
                                       (size.height, size.width))

        t = numpy.zeros(5)

        w = World("watermap", size, seed, GenerationParameters(0, 1.0, 0))
        w.ocean = ocean
        w.precipitation = (percipitation, t)
        w.elevation = (elevation, t)

        d = numpy.random.randint(0, 100)
        self.assertEqual(d, 98)

        data, t = WatermapSimulation._watermap(w, 200)

        self.assertAlmostEqual(data[4, 4], 0.0)
        self.assertAlmostEqual(data[3, 5], 4.20750776)

        d = numpy.random.randint(0, 100)
        self.assertEqual(d, 59)
示例#3
0
def _plates_simulation(name,
                       width,
                       height,
                       seed,
                       temps=[.874, .765, .594, .439, .366, .124],
                       humids=[.941, .778, .507, .236, 0.073, .014, .002],
                       gamma_curve=1.25,
                       curve_offset=.2,
                       num_plates=10,
                       ocean_level=1.0,
                       step=Step.full(),
                       verbose=get_verbose()):
    e_as_array, p_as_array = generate_plates_simulation(seed,
                                                        width,
                                                        height,
                                                        num_plates=num_plates,
                                                        verbose=verbose)

    world = World(name, Size(width, height), seed,
                  GenerationParameters(num_plates, ocean_level, step), temps,
                  humids, gamma_curve, curve_offset)
    world.elevation = (numpy.array(e_as_array).reshape(height, width), None)
    world.plates = numpy.array(p_as_array,
                               dtype=numpy.uint16).reshape(height, width)
    return world
示例#4
0
    def test_watermap_rng_stabilty(self):
        seed=12345
        numpy.random.seed(seed)

        size = Size(16,8)

        ocean = numpy.fromfunction(lambda y, x: y==x, (size.height, size.width))

        percipitation = numpy.ones((size.height, size.width))

        elevation = numpy.fromfunction(lambda y, x: y*x, (size.height, size.width))

        t = numpy.zeros(5)

        w = World("watermap",  size, seed, GenerationParameters(0, 1.0, 0))
        w.ocean = ocean
        w.precipitation = (percipitation, t)
        w.elevation = (elevation, t)

        d = numpy.random.randint(0,100)
        self.assertEqual(d, 98)

        data, t = WatermapSimulation._watermap(w, 200)

        self.assertAlmostEqual(data[4,4], 0.0)
        self.assertAlmostEqual(data[3,5], 4.20750776)

        d = numpy.random.randint(0,100)
        self.assertEqual(d, 59)
示例#5
0
    def test_watermap_does_not_break_with_no_land(self):
        seed = 12345
        numpy.random.seed(seed)

        size = Size(16, 8)

        ocean = numpy.full((size.height, size.width), True, bool)

        w = World("watermap", size, seed, GenerationParameters(0, 1.0, 0))
        w.ocean = ocean

        data, t = WatermapSimulation._watermap(w, 200)
示例#6
0
    def test_watermap_does_not_break_with_no_land(self):
        seed=12345
        numpy.random.seed(seed)

        size = Size(16,8)

        ocean = numpy.full((size.height, size.width), True, bool)

        w = World("watermap",  size, seed, GenerationParameters(0, 1.0, 0))
        w.ocean = ocean

        data, t = WatermapSimulation._watermap(w, 200)
示例#7
0
    def test_random_land_returns_only_land(self):
        size = Size(100,90)

        ocean = numpy.fromfunction(lambda y, x: y>=x, (size.height, size.width))

        w = World("random_land",  size, 0, GenerationParameters(0, 1.0, 0))
        w.ocean = ocean

        num_samples = 1000

        land_indices = w.random_land(num_samples)

        for i in range(0, num_samples*2, 2):
            self.assertFalse(ocean[land_indices[i+1],land_indices[i]])
示例#8
0
    def test_random_land_returns_only_land(self):
        size = Size(100, 90)

        ocean = numpy.fromfunction(lambda y, x: y >= x,
                                   (size.height, size.width))

        w = World("random_land", size, 0, GenerationParameters(0, 1.0, 0))
        w.ocean = ocean

        num_samples = 1000

        land_indices = w.random_land(num_samples)

        for i in range(0, num_samples * 2, 2):
            self.assertFalse(ocean[land_indices[i + 1], land_indices[i]])
示例#9
0
def _plates_simulation(name, width, height, seed, temps=
                       [.874, .765, .594, .439, .366, .124], humids=
                       [.941, .778, .507, .236, 0.073, .014, .002], gamma_curve=1.25,
                       curve_offset=.2, num_plates=10, ocean_level=1.0,
                       step=Step.full(), verbose=get_verbose()):
    e_as_array, p_as_array = generate_plates_simulation(seed, width, height,
                                                        num_plates=num_plates,
                                                        verbose=verbose)

    world = World(name, Size(width, height), seed,
                  GenerationParameters(num_plates, ocean_level, step),
                  temps, humids, gamma_curve, curve_offset)
    world.set_elevation(numpy.array(e_as_array).reshape(height, width), None)
    world.set_plates(numpy.array(p_as_array, dtype=numpy.uint16).reshape(height, width))
    return world
示例#10
0
    def test_center_land(self):
        w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)

        # We want to have less land than before at the borders
        el_before = TestGeneration._mean_elevation_at_borders(w)
        center_land(w)
        el_after = TestGeneration._mean_elevation_at_borders(w)
        self.assertTrue(el_after <= el_before)
示例#11
0
    def test_center_land(self):
        w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)

        # We want to have less land than before at the borders
        el_before = TestGeneration._mean_elevation_at_borders(w)
        center_land(w)
        el_after = TestGeneration._mean_elevation_at_borders(w)
        self.assertTrue(el_after <= el_before)
示例#12
0
    def test_sea_depth(self):
        ocean_level = 1.0
        extent = 11
        w = World("sea_depth", Size(extent, extent), 0,
                  GenerationParameters(0, ocean_level, 0), None)

        ocean = numpy.full([extent, extent], True)
        ocean[5, 5] = False

        elevation = numpy.zeros([extent, extent], float)
        elevation[5, 5] = 2.0

        t = numpy.zeros([extent, extent])

        w.elevation = (elevation, t)
        w.ocean = ocean

        desired_result = numpy.asarray([0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, \
                                0.9, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.3, 0.3, 0.3, 0.3, 0.3, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.3, 0.0, 0.0, 0.0, 0.3, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.3, 0.0, -1.0, 0.0, 0.3, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.3, 0.0, 0.0, 0.0, 0.3, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.3, 0.3, 0.3, 0.3, 0.3, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.9, \
                                0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9])

        desired_result = desired_result.reshape([extent, extent])

        # this part is verbatim from the function. It's not part of the test
        # Some refactoring is in order to increase test quality
        desired_result = anti_alias(desired_result, 10)

        min_depth = desired_result.min()
        max_depth = desired_result.max()
        desired_result = (desired_result - min_depth) / (max_depth - min_depth)

        # end of verbatim part

        result = sea_depth(w, ocean_level)

        for y in range(extent):
            for x in range(extent):
                self.assertAlmostEqual(desired_result[y, x], result[y, x])
示例#13
0
    def test_sea_depth(self):
        ocean_level = 1.0
        extent = 11
        w = World("sea_depth", Size(extent,extent), 0, GenerationParameters(0, ocean_level, 0), None)

        ocean = numpy.full([extent,extent], True)
        ocean[5,5]=False

        elevation = numpy.zeros([extent,extent], float)
        elevation[5,5] = 2.0

        t = numpy.zeros([extent, extent])

        w.elevation = (elevation, t)
        w.ocean = ocean

        desired_result = numpy.asarray([0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, \
                                0.9, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.3, 0.3, 0.3, 0.3, 0.3, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.3, 0.0, 0.0, 0.0, 0.3, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.3, 0.0, -1.0, 0.0, 0.3, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.3, 0.0, 0.0, 0.0, 0.3, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.3, 0.3, 0.3, 0.3, 0.3, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7, 0.9, \
                                0.9, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.9, \
                                0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9])

        desired_result = desired_result.reshape([extent,extent])

        # this part is verbatim from the function. It's not part of the test
        # Some refactoring is in order to increase test quality
        desired_result = anti_alias(desired_result, 10)

        min_depth = desired_result.min()
        max_depth = desired_result.max()
        desired_result = (desired_result - min_depth) / (max_depth - min_depth)

        # end of verbatim part

        result = sea_depth(w, ocean_level)

        for y in range(extent):
            for x in range(extent):
                self.assertAlmostEqual(desired_result[y,x], result[y,x])
示例#14
0
文件: main.py 项目: 4144/worldengine
def load_world(world_filename):
    pb = __seems_protobuf_worldfile__(world_filename)
    if pb:
        try:
            return World.open_protobuf(world_filename)
        except Exception:
            raise Exception("Unable to load the worldfile as protobuf file")
    else:
        raise Exception("The given worldfile does not seem to be a protobuf file")
示例#15
0
def load_world(world_filename):
    pb = __seems_protobuf_worldfile__(world_filename)
    if pb:
        try:
            return World.open_protobuf(world_filename)
        except Exception:
            raise Exception("Unable to load the worldfile as protobuf file")
    else:
        raise Exception(
            "The given worldfile does not seem to be a protobuf file")
示例#16
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)
示例#17
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)
示例#18
0
def generate_plates(seed,
                    world_name,
                    output_dir,
                    width,
                    height,
                    num_plates=10):
    """
    Eventually this method should be invoked when generation is called at
    asked to stop at step "plates", it should not be a different operation
    :param seed:
    :param world_name:
    :param output_dir:
    :param width:
    :param height:
    :param num_plates:
    :return:
    """
    elevation, plates = generate_plates_simulation(seed,
                                                   width,
                                                   height,
                                                   num_plates=num_plates)

    world = World(world_name, Size(width, height), seed,
                  GenerationParameters(num_plates, -1.0, "plates"))
    world.elevation = (numpy.array(elevation).reshape(height, width), None)
    world.plates = numpy.array(plates,
                               dtype=numpy.uint16).reshape(height, width)

    # Generate images
    filename = '%s/plates_%s.png' % (output_dir, world_name)
    draw_simple_elevation_on_file(world, filename, None)
    print("+ plates image generated in '%s'" % filename)
    geo.center_land(world)
    filename = '%s/centered_plates_%s.png' % (output_dir, world_name)
    draw_simple_elevation_on_file(world, filename, None)
    print("+ centered plates image generated in '%s'" % filename)
示例#19
0
 def test_draw_grayscale_heightmap(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.grayscale_from_array(w.layers['elevation'].data,
                                             scale_to_range=True)
     self._assert_img_equal("grayscale_heightmap_28070", target)
示例#20
0
 def test_draw_ocean(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.rgba_from_dimensions(w.width, w.height)
     draw_ocean(w.layers['ocean'].data, target)
     self._assert_img_equal("ocean_28070", target)
示例#21
0
 def test_locate_biomes(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     cm, biome_cm = BiomeSimulation().execute(w, 28070)
示例#22
0
 def test_draw_elevation_no_shadow(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.rgba_from_dimensions(w.width, w.height)
     draw_elevation(w, False, target)
     self._assert_img_equal("elevation_28070_no_shadow", target)
示例#23
0
 def test_locate_biomes(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     cm, biome_cm = BiomeSimulation().execute(w, 28070)
示例#24
0
def load_world_to_hdf5(filename):
    f = h5py.File(filename, libver='latest', mode='r')

    w = World(f['general/name'].value,
              Size(f['general/width'].value, f['general/height'].value),
              f['generation_params/seed'].value,
              GenerationParameters(f['generation_params/n_plates'].value,
                                   f['generation_params/ocean_level'].value,
                                   Step.get_by_name(f['generation_params/step'].value)))

    # Elevation
    e = numpy.array(f['elevation/data'])
    e_th = [('sea', f['elevation/thresholds/sea'].value),
            ('plain', f['elevation/thresholds/plain'].value),
            ('hill', f['elevation/thresholds/hill'].value),
            ('mountain', None)]
    w.elevation = (e, e_th)

    # Plates
    w.plates = numpy.array(f['plates'])

    # Ocean
    w.ocean = numpy.array(f['ocean'])
    w.sea_depth = numpy.array(f['sea_depth'])

    # Biome
    if 'biome' in f.keys():
        biome_data = []
        for y in range(w.height):
            row = []
            for x in range(w.width):
                value = f['biome'][y, x]
                row.append(biome_index_to_name(value))
            biome_data.append(row)
        biome = numpy.array(biome_data, dtype=object)
        w.biome = biome

    if 'humidity' in f.keys():
        data, quantiles = _from_hdf5_matrix_with_quantiles(f['humidity'])
        w.humidity = (data, quantiles)

    if 'irrigation' in f.keys():
        w.irrigation = numpy.array(f['irrigation'])

    if 'permeability' in f.keys():
        p = numpy.array(f['permeability/data'])
        p_th = [
            ('low', f['permeability/thresholds/low'].value),
            ('med', f['permeability/thresholds/med'].value),
            ('hig', None)
        ]
        w.permeability = (p, p_th)

    if 'watermap' in f.keys():
        data = numpy.array(f['watermap/data'])
        thresholds = {}
        thresholds['creek'] = f['watermap/thresholds/creek'].value
        thresholds['river'] =  f['watermap/thresholds/river'].value
        thresholds['main river'] = f['watermap/thresholds/mainriver'].value
        w.watermap = (data, thresholds)

    if 'precipitation' in f.keys():
        p = numpy.array(f['precipitation/data'])
        p_th = [
            ('low', f['precipitation/thresholds/low'].value),
            ('med', f['precipitation/thresholds/med'].value),
            ('hig', None)
        ]
        w.precipitation = (p, p_th)

    if 'temperature' in f.keys():
        t = numpy.array(f['temperature/data'])
        t_th = [
            ('polar', f['temperature/thresholds/polar'].value),
            ('alpine', f['temperature/thresholds/alpine'].value),
            ('boreal', f['temperature/thresholds/boreal'].value),
            ('cool', f['temperature/thresholds/cool'].value),
            ('warm', f['temperature/thresholds/warm'].value),
            ('subtropical', f['temperature/thresholds/subtropical'].value),
            ('tropical', None)
        ]
        w.temperature = (t, t_th)

    if 'icecap' in f.keys():
        w.icecap = numpy.array(f['icecap'])

    if 'lake_map' in f.keys():
        w.lakemap = numpy.array(f['lake_map'])

    if 'river_map' in f.keys():
        w.rivermap = numpy.array(f['river_map'])

    f.close()

    return w
示例#25
0
 def setUp(self):
     super(TestDrawingFunctions, self).setUp()
     self.w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
示例#26
0
 def test_draw_simple_elevation(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.rgba_from_dimensions(w.width, w.height)
     draw_simple_elevation(w, w.sea_level(), target)
     self._assert_img_equal("simple_elevation_28070", target)
示例#27
0
 def test_draw_simple_elevation(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.rgba_from_dimensions(w.width, w.height)
     draw_simple_elevation(w, w.sea_level(), target)
     self._assert_img_equal("simple_elevation_28070", target)
示例#28
0
 def test_draw_elevation_shadow(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.rgba_from_dimensions(w.width, w.height)
     draw_elevation(w, True, target)
     self._assert_img_equal("elevation_28070_shadow", target)
示例#29
0
 def test_draw_satellite(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.rgba_from_dimensions(w.width, w.height)
     draw_satellite(w, target)
     self._assert_img_equal("satellite_28070", target)
示例#30
0
 def test_draw_scatter_plot(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.rgba_from_dimensions(512, 512)
     draw_scatter_plot(w, 512, target)
     self._assert_img_equal("scatter_28070", target)
示例#31
0
 def test_draw_ocean(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.rgba_from_dimensions(w.width, w.height)
     draw_ocean(w.layers['ocean'].data, target)
     self._assert_img_equal("ocean_28070", target)
示例#32
0
 def test_draw_scatter_plot(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.rgba_from_dimensions(512, 512)
     draw_scatter_plot(w, 512, target)
     self._assert_img_equal("scatter_28070", target)
示例#33
0
def __seems_protobuf_worldfile__(world_filename):
    worldengine_tag = __get_tag__(world_filename)
    return worldengine_tag == World.worldengine_tag()
示例#34
0
 def test_draw_satellite(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.rgba_from_dimensions(w.width, w.height)
     draw_satellite(w, target)
     self._assert_img_equal("satellite_28070", target)
def load_world_to_hdf5(filename):
    f = h5py.File(filename, libver="latest", mode="r")

    w = World(
        f["general/name"].value,
        Size(f["general/width"].value, f["general/height"].value),
        f["generation_params/seed"].value,
        GenerationParameters(
            f["generation_params/n_plates"].value,
            f["generation_params/ocean_level"].value,
            Step.get_by_name(f["generation_params/step"].value),
        ),
    )

    # Elevation
    e = numpy.array(f["elevation/data"])
    e_th = [
        ("sea", f["elevation/thresholds/sea"].value),
        ("plain", f["elevation/thresholds/plain"].value),
        ("hill", f["elevation/thresholds/hill"].value),
        ("mountain", None),
    ]
    w.set_elevation(e, e_th)

    # Plates
    w.set_plates(numpy.array(f["plates"]))

    # Ocean
    w.set_ocean(numpy.array(f["ocean"]))
    w.set_sea_depth(numpy.array(f["sea_depth"]))

    # Biome
    if "biome" in f.keys():
        biome_data = []
        for y in range(w.height):
            row = []
            for x in range(w.width):
                value = f["biome"][y, x]
                row.append(biome_index_to_name(value))
            biome_data.append(row)
        biome = numpy.array(biome_data, dtype=object)
        w.set_biome(biome)

    if "humidity" in f.keys():
        data, quantiles = _from_hdf5_matrix_with_quantiles(f["humidity"])
        w.set_humidity(data, quantiles)

    if "irrigation" in f.keys():
        w.set_irrigation(numpy.array(f["irrigation"]))

    if "permeability" in f.keys():
        p = numpy.array(f["permeability/data"])
        p_th = [
            ("low", f["permeability/thresholds/low"].value),
            ("med", f["permeability/thresholds/med"].value),
            ("hig", None),
        ]
        w.set_permeability(p, p_th)

    if "watermap" in f.keys():
        data = numpy.array(f["watermap/data"])
        thresholds = {}
        thresholds["creek"] = f["watermap/thresholds/creek"].value
        thresholds["river"] = f["watermap/thresholds/river"].value
        thresholds["main river"] = f["watermap/thresholds/mainriver"].value
        w.set_watermap(data, thresholds)

    if "precipitation" in f.keys():
        p = numpy.array(f["precipitation/data"])
        p_th = [
            ("low", f["precipitation/thresholds/low"].value),
            ("med", f["precipitation/thresholds/med"].value),
            ("hig", None),
        ]
        w.set_precipitation(p, p_th)

    if "temperature" in f.keys():
        t = numpy.array(f["temperature/data"])
        t_th = [
            ("polar", f["temperature/thresholds/polar"].value),
            ("alpine", f["temperature/thresholds/alpine"].value),
            ("boreal", f["temperature/thresholds/boreal"].value),
            ("cool", f["temperature/thresholds/cool"].value),
            ("warm", f["temperature/thresholds/warm"].value),
            ("subtropical", f["temperature/thresholds/subtropical"].value),
            ("tropical", None),
        ]
        w.set_temperature(t, t_th)

    if "icecap" in f.keys():
        w.set_icecap(numpy.array(f["icecap"]))

    if "lake_map" in f.keys():
        m = numpy.array(f["lake_map"])
        w.set_lakemap(m)

    if "river_map" in f.keys():
        m = numpy.array(f["river_map"])
        w.set_rivermap(m)

    f.close()

    return w
示例#36
0
def load_world_to_hdf5(filename):
    f = h5py.File(filename, libver='latest', mode='r')

    w = World(
        f['general/name'].value,
        Size(f['general/width'].value, f['general/height'].value),
        f['generation_params/seed'].value,
        GenerationParameters(
            f['generation_params/n_plates'].value,
            f['generation_params/ocean_level'].value,
            Step.get_by_name(f['generation_params/step'].value)))

    # Elevation
    e = numpy.array(f['elevation/data'])
    e_th = [('sea', f['elevation/thresholds/sea'].value),
            ('plain', f['elevation/thresholds/plain'].value),
            ('hill', f['elevation/thresholds/hill'].value), ('mountain', None)]
    w.set_elevation(e, e_th)

    # Plates
    w.set_plates(numpy.array(f['plates']))

    # Ocean
    w.set_ocean(numpy.array(f['ocean']))
    w.set_sea_depth(numpy.array(f['sea_depth']))

    # Biome
    if 'biome' in f.keys():
        biome_data = []
        for y in range(w.height):
            row = []
            for x in range(w.width):
                value = f['biome'][y, x]
                row.append(biome_index_to_name(value))
            biome_data.append(row)
        biome = numpy.array(biome_data, dtype=object)
        w.set_biome(biome)

    if 'humidity' in f.keys():
        data, quantiles = _from_hdf5_matrix_with_quantiles(f['humidity'])
        w.set_humidity(data, quantiles)

    if 'irrigation' in f.keys():
        w.set_irrigation(numpy.array(f['irrigation']))

    if 'permeability' in f.keys():
        p = numpy.array(f['permeability/data'])
        p_th = [('low', f['permeability/thresholds/low'].value),
                ('med', f['permeability/thresholds/med'].value), ('hig', None)]
        w.set_permeability(p, p_th)

    if 'watermap' in f.keys():
        data = numpy.array(f['watermap/data'])
        thresholds = {}
        thresholds['creek'] = f['watermap/thresholds/creek'].value
        thresholds['river'] = f['watermap/thresholds/river'].value
        thresholds['main river'] = f['watermap/thresholds/mainriver'].value
        w.set_watermap(data, thresholds)

    if 'precipitation' in f.keys():
        p = numpy.array(f['precipitation/data'])
        p_th = [('low', f['precipitation/thresholds/low'].value),
                ('med', f['precipitation/thresholds/med'].value),
                ('hig', None)]
        w.set_precipitation(p, p_th)

    if 'temperature' in f.keys():
        t = numpy.array(f['temperature/data'])
        t_th = [('polar', f['temperature/thresholds/polar'].value),
                ('alpine', f['temperature/thresholds/alpine'].value),
                ('boreal', f['temperature/thresholds/boreal'].value),
                ('cool', f['temperature/thresholds/cool'].value),
                ('warm', f['temperature/thresholds/warm'].value),
                ('subtropical', f['temperature/thresholds/subtropical'].value),
                ('tropical', None)]
        w.set_temperature(t, t_th)

    if 'icecap' in f.keys():
        w.set_icecap(numpy.array(f['icecap']))

    if 'lake_map' in f.keys():
        m = numpy.array(f['lake_map'])
        w.set_lakemap(m)

    if 'river_map' in f.keys():
        m = numpy.array(f['river_map'])
        w.set_rivermap(m)

    f.close()

    return w
示例#37
0
文件: main.py 项目: 4144/worldengine
def __seems_protobuf_worldfile__(world_filename):
    worldengine_tag = __get_tag__(world_filename)
    return worldengine_tag == World.worldengine_tag()
示例#38
0
 def test_draw_grayscale_heightmap(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PNGWriter.grayscale_from_array(w.layers['elevation'].data, scale_to_range=True)
     self._assert_img_equal("grayscale_heightmap_28070", target)
 def setUp(self):
     super(TestDrawingFunctions, self).setUp()
     self.w = World.open_protobuf("%s/seed_28070.world" %
                                  self.tests_data_dir)