Пример #1
0
 def world(self):
     world = World(self.name, self.width, self.height, self.seed,
                   self.n_plates, self.ocean_level,
                   Step.get_by_name("plates"))
     hm = platec.get_heightmap(self.p)
     pm = platec.get_platesmap(self.p)
     world.set_elevation(array_to_matrix(hm, self.width, self.height), None)
     world.set_plates(array_to_matrix(pm, self.width, self.height))
     return world
Пример #2
0
def _plates_simulation(name, width, height, seed, temps, humids, 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, width, height, seed, num_plates, ocean_level, step, temps, humids)
    world.set_elevation(numpy.array(e_as_array).reshape(height, width), None)
    world.set_plates(array_to_matrix(p_as_array, width, height))
    return world
Пример #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, width, height, seed, 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
Пример #4
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)
Пример #5
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)
Пример #6
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)
Пример #7
0
 def __init__(self, config, world):
     self.groups = []
     self._config = {}
     self.load_config(config)
     self._world = World.open_protobuf(world)
     self._turn = 0
     self._global_events = self._config["Tribe"]["General"]["Global-events"]
Пример #8
0
 def test_draw_ancient_map_factor1(self):
     w_large = World.from_pickle_file(
         "%s/py%s_seed_48956.world" %
         (self.tests_data_dir, platform.python_version_tuple()[0]))
     target = PixelCollector(w_large.width, w_large.height)
     draw_ancientmap(w_large, target, resize_factor=1)
     self._assert_img_equal("ancientmap_48956", target)
Пример #9
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)
Пример #10
0
    def test_center_land(self):
        w = World.from_pickle_file("%s/plates_279.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 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")
Пример #12
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")
Пример #13
0
def load_world(world_filename):
    pb = __seems_protobuf_worldfile__(world_filename)
    pi = __seems_pickle_file__(world_filename)
    if pb and pi:
        print("we cannot distinguish if the file is a pickle or a protobuf worldfile. " +
            "Trying to load first as protobuf then as pickle file")
        try:
            return World.open_protobuf(world_filename)
        except Exception:
            try:
                return World.from_pickle_file(world_filename)
            except Exception:
                raise Exception("Unable to load the worldfile neither as protobuf or pickle file")

    elif pb:
        return World.open_protobuf(world_filename)
    elif pi:
        return World.from_pickle_file(world_filename)
    else:
        raise Exception("The given worldfile does not seem a pickle or a protobuf file")
Пример #14
0
def load_world(world_filename):
    pb = __seems_protobuf_worldfile__(world_filename)
    pi = __seems_pickle_file__(world_filename)
    if pb and pi:
        print("we cannot distinguish if the file is a pickle or a protobuf "
              "world file. Trying to load first as protobuf then as pickle "
              "file")
        try:
            return World.open_protobuf(world_filename)
        except Exception:
            try:
                return World.from_pickle_file(world_filename)
            except Exception:
                raise Exception("Unable to load the worldfile neither as protobuf or pickle file")

    elif pb:
        return World.open_protobuf(world_filename)
    elif pi:
        return World.from_pickle_file(world_filename)
    else:
        raise Exception("The given worldfile does not seem a pickle or a protobuf file")
Пример #15
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, width, height, seed, num_plates, -1.0, "plates")
    world.set_elevation(numpy.array(elevation).reshape(height, width), None)
    world.set_plates(array_to_matrix(plates, width, height))

    # Generate images
    filename = '%s/plates_%s.png' % (output_dir, world_name)
    # TODO calculate appropriate sea_level
    sea_level = 1.0
    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)
Пример #16
0
 def world(self):
     world = World(self.name, self.width, self.height, self.seed,
                   self.n_plates, self.ocean_level,
                   Step.get_by_name("plates"))
     hm = platec.get_heightmap(self.p)
     pm = platec.get_platesmap(self.p)
     world.set_elevation(array_to_matrix(hm, self.width, self.height), None)
     world.set_plates(array_to_matrix(pm, self.width, self.height))
     return world
Пример #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(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)
Пример #18
0
def _plates_simulation(name,
                       width,
                       height,
                       seed,
                       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, width, height, seed, num_plates, ocean_level, step)
    world.set_elevation(numpy.array(e_as_array).reshape(height, width), None)
    world.set_plates(array_to_matrix(p_as_array, width, height))
    return world
Пример #19
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, width, height, seed, 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
Пример #20
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)
Пример #21
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)
Пример #22
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.elevation['data'],
                                             scale_to_range=True)
     #draw_grayscale_heightmap(w, target)
     self._assert_img_equal("grayscale_heightmap_28070", target)
Пример #23
0
 def setUp(self):
     super(TestDrawingFunctions, self).setUp()
     self.w = World.open_protobuf("%s/seed_28070.world" %
                                  self.tests_data_dir)
Пример #24
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)
 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_elevation_no_shadow(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     data = w.elevation['data']
     target = PixelCollector(w.width, w.height)
     draw_elevation(w, False, target)
     self._assert_img_equal("elevation_28070_no_shadow", target)
Пример #28
0
def load_world_to_hdf5(filename):
    f = h5py.File(filename, libver='latest', mode='r')

    w = World(f['general/name'].value,
              f['general/width'].value,
              f['general/height'].value,
              f['generation_params/seed'].value,
              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.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)

    # Humidity
    # FIXME: use setters
    if 'humidity' in f.keys():
        w.humidity = _from_hdf5_matrix_with_quantiles(f['humidity'])
        w.humidity['data'] = numpy.array(w.humidity['data']) # numpy conversion

    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.set_permeability(p, p_th)

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

    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.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
Пример #29
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.elevation['data'], scale_to_range=True)
     #draw_grayscale_heightmap(w, target)
     self._assert_img_equal("grayscale_heightmap_28070", target)
Пример #30
0
 def test_locate_biomes(self):
     w = World.open_protobuf("%s/biome_test.world" % self.tests_data_dir)
     cm, biome_cm = BiomeSimulation().execute(w, 6908)
Пример #31
0
 def test_draw_scatter_plot(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PixelCollector(16, 16)
     draw_scatter_plot(w, 16, target)
Пример #32
0
 def _on_open(self):
     filename = QFileDialog.getOpenFileName(self, "Open world", "",
                                                  "*.world")
     world = World.open_protobuf(filename)
     self.set_world(world)
Пример #33
0
 def test_draw_elevation_no_shadow(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     data = w.elevation['data']
     target = PNGWriter.rgba_from_dimensions(w.width, w.height)
     draw_elevation(w, False, target)
     self._assert_img_equal("elevation_28070_no_shadow", target)
Пример #34
0
 def test_locate_biomes(self):
     w = World.open_protobuf("%s/biome_test.world" % self.tests_data_dir)
     cm, biome_cm = BiomeSimulation().execute(w, 6908)
Пример #35
0
 def test_draw_ancient_map_factor1(self):
     w_large = World.from_pickle_file("%s/seed_48956.world" %
                                      self.tests_data_dir)
     target = PixelCollector(w_large.width, w_large.height)
     draw_ancientmap(w_large, target, resize_factor=1)
     self._assert_img_equal("ancientmap_48956", target)
Пример #36
0
 def test_draw_simple_elevation(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PixelCollector(w.width, w.height)
     draw_simple_elevation(w, w.sea_level(), target)
     self._assert_img_equal("simple_elevation_28070", target)
 def test_draw_ancient_map_factor1(self):
     w_large = World.from_pickle_file("%s/seed_48956.world" % self.tests_data_dir)
     target = PixelCollector(w_large.width, w_large.height)
     draw_ancientmap(w_large, target, resize_factor=1)
     self._assert_img_equal("ancientmap_48956", target)
Пример #38
0
 def test_draw_biome(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PixelCollector(w.width, w.height)
     draw_biome(w, target)
     self._assert_img_equal("biome_28070", target)
 def test_draw_ancient_map_factor1(self):
     w_large = World.from_pickle_file("%s/py%s_seed_48956.world" % (self.tests_data_dir, platform.python_version_tuple()[0]))
     target = PixelCollector(w_large.width, w_large.height)
     draw_ancientmap(w_large, target, resize_factor=1)
     self._assert_img_equal("ancientmap_48956", target)
Пример #40
0
def load_world_to_hdf5(filename):
    f = h5py.File(filename, libver='latest', mode='r')

    w = World(f['general/name'].value,
              f['general/width'].value,
              f['general/height'].value,
              f['generation_params/seed'].value,
              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.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)

    # Humidity
    # FIXME: use setters
    if 'humidity' in f.keys():
        w.humidity = _from_hdf5_matrix_with_quantiles(f['humidity'])
        w.humidity['data'] = numpy.array(w.humidity['data']) # numpy conversion

    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.set_permeability(p, p_th)

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

    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.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
Пример #41
0
 def test_draw_simple_elevation(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     data = w.elevation['data']
     target = PixelCollector(w.width, w.height)
     draw_simple_elevation(data, w.width, w.height, w.sea_level(), target)
     self._assert_img_equal("simple_elevation_28070", target)
Пример #42
0
 def test_draw_elevation_shadow(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     data = w.elevation['data']
     target = PNGWriter.rgba_from_dimensions(w.width, w.height)
     draw_elevation(w, True, target)
     self._assert_img_equal("elevation_28070_shadow", target)
Пример #43
0
 def test_draw_elevation_no_shadow(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     data = w.elevation['data']
     target = PixelCollector(w.width, w.height)
     draw_elevation(w, False, target)
     self._assert_img_equal("elevation_28070_no_shadow", target)
Пример #44
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)
Пример #45
0
 def test_draw_biome(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PixelCollector(w.width, w.height)
     draw_biome(w, target)
     self._assert_img_equal("biome_28070", target)
Пример #46
0
def __seems_protobuf_worldfile__(world_filename):
    worldengine_tag = __get_tag__(world_filename)
    return worldengine_tag == World.worldengine_tag()
Пример #47
0
 def _on_open(self):
     filename = QFileDialog.getOpenFileName(self, "Open world", "",
                                            "*.world")
     world = World.open_protobuf(filename)
     self.set_world(world)
Пример #48
0
 def test_draw_scatter_plot(self):
     w = World.open_protobuf("%s/seed_28070.world" % self.tests_data_dir)
     target = PixelCollector(16, 16)
     draw_scatter_plot(w, 16, target)
Пример #49
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)