예제 #1
0
    def test_biome_name_to_index(self):
        self.assertRaises(Exception, biome_name_to_index, "unexisting biome")

        # We do not want these values to change in the future, otherwise the world saved
        # will be not loaded correctly
        self.assertEqual(0, biome_name_to_index('boreal desert'))
        self.assertEqual(1, biome_name_to_index('boreal dry scrub'))
        self.assertEqual(2, biome_name_to_index('boreal moist forest'))
        self.assertEqual(3, biome_name_to_index('boreal rain forest'))
        self.assertEqual(4, biome_name_to_index('boreal wet forest'))
        self.assertEqual(5, biome_name_to_index('cool temperate desert'))
        self.assertEqual(6, biome_name_to_index('cool temperate desert scrub'))
        self.assertEqual(7, biome_name_to_index('cool temperate moist forest'))
        self.assertEqual(8, biome_name_to_index('cool temperate rain forest'))
        self.assertEqual(9, biome_name_to_index('cool temperate steppe'))
        self.assertEqual(10, biome_name_to_index('cool temperate wet forest'))
        self.assertEqual(11, biome_name_to_index('ice'))
        self.assertEqual(12, biome_name_to_index('ocean'))
        self.assertEqual(13, biome_name_to_index('polar desert'))
        self.assertEqual(14, biome_name_to_index('sea'))
        self.assertEqual(15, biome_name_to_index('subpolar dry tundra'))
        self.assertEqual(16, biome_name_to_index('subpolar moist tundra'))
        self.assertEqual(17, biome_name_to_index('subpolar rain tundra'))
        self.assertEqual(18, biome_name_to_index('subpolar wet tundra'))
        self.assertEqual(19, biome_name_to_index('subtropical desert'))
        self.assertEqual(20, biome_name_to_index('subtropical desert scrub'))
        self.assertEqual(21, biome_name_to_index('subtropical dry forest'))
        self.assertEqual(22, biome_name_to_index('subtropical moist forest'))
        self.assertEqual(23, biome_name_to_index('subtropical rain forest'))
        self.assertEqual(24, biome_name_to_index('subtropical thorn woodland'))
        self.assertEqual(25, biome_name_to_index('subtropical wet forest'))
        self.assertEqual(26, biome_name_to_index('tropical desert'))
        self.assertEqual(27, biome_name_to_index('tropical desert scrub'))
        self.assertEqual(28, biome_name_to_index('tropical dry forest'))
        self.assertEqual(29, biome_name_to_index('tropical moist forest'))
        self.assertEqual(30, biome_name_to_index('tropical rain forest'))
        self.assertEqual(31, biome_name_to_index('tropical thorn woodland'))
        self.assertEqual(32, biome_name_to_index('tropical very dry forest'))
        self.assertEqual(33, biome_name_to_index('tropical wet forest'))
        self.assertEqual(34, biome_name_to_index('warm temperate desert'))
        self.assertEqual(35,
                         biome_name_to_index('warm temperate desert scrub'))
        self.assertEqual(36, biome_name_to_index('warm temperate dry forest'))
        self.assertEqual(37,
                         biome_name_to_index('warm temperate moist forest'))
        self.assertEqual(38, biome_name_to_index('warm temperate rain forest'))
        self.assertEqual(39, biome_name_to_index('warm temperate thorn scrub'))
        self.assertEqual(40, biome_name_to_index('warm temperate wet forest'))
예제 #2
0
def save_world_to_hdf5(world, filename):
    f = h5py.File(filename, libver='latest', mode='w')

    general_grp = f.create_group("general")
    general_grp["worldengine_version"] = __version__
    general_grp["name"] = world.name
    general_grp["width"] = world.width
    general_grp["height"] = world.height

    elevation_grp = f.create_group("elevation")
    elevation_ths_grp = elevation_grp.create_group("thresholds")
    elevation_ths_grp["sea"] = world.elevation['thresholds'][0][1]
    elevation_ths_grp["plain"] = world.elevation['thresholds'][1][1]
    elevation_ths_grp["hill"] = world.elevation['thresholds'][2][1]
    elevation_data = elevation_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
    elevation_data.write_direct(world.elevation['data'])

    plates_data = f.create_dataset("plates", (world.height, world.width), dtype=numpy.uint16)
    for y in range(world.height):
        for x in range(world.width):
            plates_data[y, x] = world.plates[y][x]

    ocean_data = f.create_dataset("ocean", (world.height, world.width), dtype=numpy.bool)
    ocean_data.write_direct(world.ocean)

    sea_depth_data = f.create_dataset("sea_depth", (world.height, world.width), dtype=numpy.float)
    sea_depth_data.write_direct(world.sea_depth)

    if hasattr(world, 'biome'):
        biome_data = f.create_dataset("biome", (world.height, world.width), dtype=numpy.uint16)
        for y in range(world.height):
            for x in range(world.width):
                biome_data[y, x] = biome_name_to_index(world.biome[y][x])

    if hasattr(world, 'humidity'):
        humidity_grp = f.create_group("humidity")
        humidity_quantiles_grp = humidity_grp.create_group("quantiles")
        for k in world.humidity['quantiles'].keys():
            humidity_quantiles_grp[k] = world.humidity['quantiles'][k]
        humidity_data = humidity_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
        humidity_data.write_direct(world.humidity['data'])

    if hasattr(world, 'irrigation'):
        irrigation_data = f.create_dataset("irrigation", (world.height, world.width), dtype=numpy.float)
        irrigation_data.write_direct(world.irrigation)

    if hasattr(world, 'permeability'):
        permeability_grp = f.create_group("permeability")
        permeability_ths_grp = permeability_grp.create_group("thresholds")
        permeability_ths_grp['low'] = world.permeability['thresholds'][0][1]
        permeability_ths_grp['med'] = world.permeability['thresholds'][1][1]
        permeability_data = permeability_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
        permeability_data.write_direct(world.permeability['data'])

    if hasattr(world, 'watermap'):
        watermap_grp = f.create_group("watermap")
        watermap_ths_grp = watermap_grp.create_group("thresholds")
        watermap_ths_grp['creek'] = world.watermap['thresholds']['creek']
        watermap_ths_grp['river'] = world.watermap['thresholds']['river']
        watermap_ths_grp['mainriver'] = world.watermap['thresholds']['main river']
        watermap_data = watermap_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
        watermap_data.write_direct(world.watermap['data'])

    if hasattr(world, 'precipitation'):
        precipitation_grp = f.create_group("precipitation")
        precipitation_ths_grp = precipitation_grp.create_group("thresholds")
        precipitation_ths_grp['low'] = world.precipitation['thresholds'][0][1]
        precipitation_ths_grp['med'] = world.precipitation['thresholds'][1][1]
        precipitation_data = precipitation_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
        precipitation_data.write_direct(world.precipitation['data'])

    if hasattr(world, 'temperature'):
        temperature_grp = f.create_group("temperature")
        temperature_ths_grp = temperature_grp.create_group("thresholds")
        temperature_ths_grp['polar'] = world.temperature['thresholds'][0][1]
        temperature_ths_grp['alpine'] = world.temperature['thresholds'][1][1]
        temperature_ths_grp['boreal'] = world.temperature['thresholds'][2][1]
        temperature_ths_grp['cool'] = world.temperature['thresholds'][3][1]
        temperature_ths_grp['warm'] = world.temperature['thresholds'][4][1]
        temperature_ths_grp['subtropical'] = world.temperature['thresholds'][5][1]
        temperature_data = temperature_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
        temperature_data.write_direct(world.temperature['data'])

    if hasattr(world, 'icecap'):
        icecap_data = f.create_dataset("icecap", (world.height, world.width), dtype=numpy.float)
        icecap_data.write_direct(world.icecap)

    if hasattr(world, 'lake_map'):
        lake_map_data = f.create_dataset("lake_map", (world.height, world.width), dtype=numpy.float)
        lake_map_data.write_direct(world.lake_map)

    if hasattr(world, 'river_map'):
        river_map_data = f.create_dataset("river_map", (world.height, world.width), dtype=numpy.float)
        river_map_data.write_direct(world.river_map)

    generation_params_grp = f.create_group("generation_params")
    generation_params_grp['seed'] = world.seed
    generation_params_grp['n_plates'] = world.n_plates
    generation_params_grp['ocean_level'] = world.ocean_level
    generation_params_grp['step'] = world.step.name

    f.close()
예제 #3
0
    def test_biome_name_to_index(self):
        self.assertRaises(Exception, biome_name_to_index, "unexisting biome")

        # We do not want these values to change in the future, otherwise the world saved
        # will be not loaded correctly
        self.assertEqual(0, biome_name_to_index('boreal desert'))
        self.assertEqual(1, biome_name_to_index('boreal dry scrub'))
        self.assertEqual(2, biome_name_to_index('boreal moist forest'))
        self.assertEqual(3, biome_name_to_index('boreal rain forest'))
        self.assertEqual(4, biome_name_to_index('boreal wet forest'))
        self.assertEqual(5, biome_name_to_index('cool temperate desert'))
        self.assertEqual(6, biome_name_to_index('cool temperate desert scrub'))
        self.assertEqual(7, biome_name_to_index('cool temperate moist forest'))
        self.assertEqual(8, biome_name_to_index('cool temperate rain forest'))
        self.assertEqual(9, biome_name_to_index('cool temperate steppe'))
        self.assertEqual(10, biome_name_to_index('cool temperate wet forest'))
        self.assertEqual(11, biome_name_to_index('ice'))
        self.assertEqual(12, biome_name_to_index('ocean'))
        self.assertEqual(13, biome_name_to_index('polar desert'))
        self.assertEqual(14, biome_name_to_index('sea'))
        self.assertEqual(15, biome_name_to_index('subpolar dry tundra'))
        self.assertEqual(16, biome_name_to_index('subpolar moist tundra'))
        self.assertEqual(17, biome_name_to_index('subpolar rain tundra'))
        self.assertEqual(18, biome_name_to_index('subpolar wet tundra'))
        self.assertEqual(19, biome_name_to_index('subtropical desert'))
        self.assertEqual(20, biome_name_to_index('subtropical desert scrub'))
        self.assertEqual(21, biome_name_to_index('subtropical dry forest'))
        self.assertEqual(22, biome_name_to_index('subtropical moist forest'))
        self.assertEqual(23, biome_name_to_index('subtropical rain forest'))
        self.assertEqual(24, biome_name_to_index('subtropical thorn woodland'))
        self.assertEqual(25, biome_name_to_index('subtropical wet forest'))
        self.assertEqual(26, biome_name_to_index('tropical desert'))
        self.assertEqual(27, biome_name_to_index('tropical desert scrub'))
        self.assertEqual(28, biome_name_to_index('tropical dry forest'))
        self.assertEqual(29, biome_name_to_index('tropical moist forest'))
        self.assertEqual(30, biome_name_to_index('tropical rain forest'))
        self.assertEqual(31, biome_name_to_index('tropical thorn woodland'))
        self.assertEqual(32, biome_name_to_index('tropical very dry forest'))
        self.assertEqual(33, biome_name_to_index('tropical wet forest'))
        self.assertEqual(34, biome_name_to_index('warm temperate desert'))
        self.assertEqual(35, biome_name_to_index('warm temperate desert scrub'))
        self.assertEqual(36, biome_name_to_index('warm temperate dry forest'))
        self.assertEqual(37, biome_name_to_index('warm temperate moist forest'))
        self.assertEqual(38, biome_name_to_index('warm temperate rain forest'))
        self.assertEqual(39, biome_name_to_index('warm temperate thorn scrub'))
        self.assertEqual(40, biome_name_to_index('warm temperate wet forest'))
예제 #4
0
def save_world_to_hdf5(world, filename):
    f = h5py.File(filename, libver="latest", mode="w")

    general_grp = f.create_group("general")
    general_grp["worldengine_version"] = __version__
    general_grp["name"] = world.name
    general_grp["width"] = world.width
    general_grp["height"] = world.height

    elevation_grp = f.create_group("elevation")
    elevation_ths_grp = elevation_grp.create_group("thresholds")
    elevation_ths_grp["sea"] = world.layers["elevation"].thresholds[0][1]
    elevation_ths_grp["plain"] = world.layers["elevation"].thresholds[1][1]
    elevation_ths_grp["hill"] = world.layers["elevation"].thresholds[2][1]
    elevation_data = elevation_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
    elevation_data.write_direct(world.layers["elevation"].data)

    plates_data = f.create_dataset("plates", (world.height, world.width), dtype=numpy.uint16)
    plates_data.write_direct(world.layers["plates"].data)

    ocean_data = f.create_dataset("ocean", (world.height, world.width), dtype=numpy.bool)
    ocean_data.write_direct(world.layers["ocean"].data)

    sea_depth_data = f.create_dataset("sea_depth", (world.height, world.width), dtype=numpy.float)
    sea_depth_data.write_direct(world.layers["sea_depth"].data)

    if world.has_biome():
        biome_data = f.create_dataset("biome", (world.height, world.width), dtype=numpy.uint16)
        for y in range(world.height):
            for x in range(world.width):
                biome_data[y, x] = biome_name_to_index(world.layers["biome"].data[y][x])

    if world.has_humidity():
        humidity_grp = f.create_group("humidity")
        humidity_quantiles_grp = humidity_grp.create_group("quantiles")
        for k in world.layers["humidity"].quantiles.keys():
            humidity_quantiles_grp[k] = world.layers["humidity"].quantiles[k]
        humidity_data = humidity_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
        humidity_data.write_direct(world.layers["humidity"].data)

    if world.has_irrigation():
        irrigation_data = f.create_dataset("irrigation", (world.height, world.width), dtype=numpy.float)
        irrigation_data.write_direct(world.layers["irrigation"].data)

    if world.has_permeability():
        permeability_grp = f.create_group("permeability")
        permeability_ths_grp = permeability_grp.create_group("thresholds")
        permeability_ths_grp["low"] = world.layers["permeability"].thresholds[0][1]
        permeability_ths_grp["med"] = world.layers["permeability"].thresholds[1][1]
        permeability_data = permeability_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
        permeability_data.write_direct(world.layers["permeability"].data)

    if world.has_watermap():
        watermap_grp = f.create_group("watermap")
        watermap_ths_grp = watermap_grp.create_group("thresholds")
        watermap_ths_grp["creek"] = world.layers["watermap"].thresholds["creek"]
        watermap_ths_grp["river"] = world.layers["watermap"].thresholds["river"]
        watermap_ths_grp["mainriver"] = world.layers["watermap"].thresholds["main river"]
        watermap_data = watermap_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
        watermap_data.write_direct(world.layers["watermap"].data)

    if world.has_precipitations():
        precipitation_grp = f.create_group("precipitation")
        precipitation_ths_grp = precipitation_grp.create_group("thresholds")
        precipitation_ths_grp["low"] = world.layers["precipitation"].thresholds[0][1]
        precipitation_ths_grp["med"] = world.layers["precipitation"].thresholds[1][1]
        precipitation_data = precipitation_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
        precipitation_data.write_direct(world.layers["precipitation"].data)

    if world.has_temperature():
        temperature_grp = f.create_group("temperature")
        temperature_ths_grp = temperature_grp.create_group("thresholds")
        th = world.layers["temperature"].thresholds
        temperature_ths_grp["polar"] = th[0][1]
        temperature_ths_grp["alpine"] = th[1][1]
        temperature_ths_grp["boreal"] = th[2][1]
        temperature_ths_grp["cool"] = th[3][1]
        temperature_ths_grp["warm"] = th[4][1]
        temperature_ths_grp["subtropical"] = th[5][1]
        temperature_data = temperature_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
        temperature_data.write_direct(world.layers["temperature"].data)

    if world.has_icecap():
        icecap_data = f.create_dataset("icecap", (world.height, world.width), dtype=numpy.float)
        icecap_data.write_direct(world.layers["icecap"].data)

    if world.has_lakemap():
        lake_map_data = f.create_dataset("lake_map", (world.height, world.width), dtype=numpy.float)
        lake_map_data.write_direct(world.layers["lake_map"].data)

    if world.has_rivermap():
        river_map_data = f.create_dataset("river_map", (world.height, world.width), dtype=numpy.float)
        river_map_data.write_direct(world.layers["river_map"].data)

    generation_params_grp = f.create_group("generation_params")
    generation_params_grp["seed"] = world.seed
    generation_params_grp["n_plates"] = world.n_plates
    generation_params_grp["ocean_level"] = world.ocean_level
    generation_params_grp["step"] = world.step.name

    f.close()
예제 #5
0
def save_world_to_hdf5(world, filename):
    f = h5py.File(filename, libver='latest', mode='w')

    general_grp = f.create_group("general")
    general_grp["worldengine_version"] = __version__
    general_grp["name"] = world.name
    general_grp["width"] = world.width
    general_grp["height"] = world.height

    elevation_grp = f.create_group("elevation")
    elevation_ths_grp = elevation_grp.create_group("thresholds")
    elevation_ths_grp["sea"] = world.layers['elevation'].thresholds[0][1]
    elevation_ths_grp["plain"] = world.layers['elevation'].thresholds[1][1]
    elevation_ths_grp["hill"] = world.layers['elevation'].thresholds[2][1]
    elevation_data = elevation_grp.create_dataset("data",
                                                  (world.height, world.width),
                                                  dtype=numpy.float)
    elevation_data.write_direct(world.layers['elevation'].data)

    plates_data = f.create_dataset("plates", (world.height, world.width),
                                   dtype=numpy.uint16)
    plates_data.write_direct(world.layers['plates'].data)

    ocean_data = f.create_dataset("ocean", (world.height, world.width),
                                  dtype=numpy.bool)
    ocean_data.write_direct(world.layers['ocean'].data)

    sea_depth_data = f.create_dataset("sea_depth", (world.height, world.width),
                                      dtype=numpy.float)
    sea_depth_data.write_direct(world.layers['sea_depth'].data)

    if world.has_biome():
        biome_data = f.create_dataset("biome", (world.height, world.width),
                                      dtype=numpy.uint16)
        for y in range(world.height):
            for x in range(world.width):
                biome_data[y, x] = biome_name_to_index(
                    world.layers['biome'].data[y][x])

    if world.has_humidity():
        humidity_grp = f.create_group("humidity")
        humidity_quantiles_grp = humidity_grp.create_group("quantiles")
        for k in world.layers['humidity'].quantiles.keys():
            humidity_quantiles_grp[k] = world.layers['humidity'].quantiles[k]
        humidity_data = humidity_grp.create_dataset(
            "data", (world.height, world.width), dtype=numpy.float)
        humidity_data.write_direct(world.layers['humidity'].data)

    if world.has_irrigation():
        irrigation_data = f.create_dataset("irrigation",
                                           (world.height, world.width),
                                           dtype=numpy.float)
        irrigation_data.write_direct(world.layers['irrigation'].data)

    if world.has_permeability():
        permeability_grp = f.create_group("permeability")
        permeability_ths_grp = permeability_grp.create_group("thresholds")
        permeability_ths_grp['low'] = world.layers['permeability'].thresholds[
            0][1]
        permeability_ths_grp['med'] = world.layers['permeability'].thresholds[
            1][1]
        permeability_data = permeability_grp.create_dataset(
            "data", (world.height, world.width), dtype=numpy.float)
        permeability_data.write_direct(world.layers['permeability'].data)

    if world.has_watermap():
        watermap_grp = f.create_group("watermap")
        watermap_ths_grp = watermap_grp.create_group("thresholds")
        watermap_ths_grp['creek'] = world.layers['watermap'].thresholds[
            'creek']
        watermap_ths_grp['river'] = world.layers['watermap'].thresholds[
            'river']
        watermap_ths_grp['mainriver'] = world.layers['watermap'].thresholds[
            'main river']
        watermap_data = watermap_grp.create_dataset(
            "data", (world.height, world.width), dtype=numpy.float)
        watermap_data.write_direct(world.layers['watermap'].data)

    if world.has_precipitations():
        precipitation_grp = f.create_group("precipitation")
        precipitation_ths_grp = precipitation_grp.create_group("thresholds")
        precipitation_ths_grp['low'] = world.layers[
            'precipitation'].thresholds[0][1]
        precipitation_ths_grp['med'] = world.layers[
            'precipitation'].thresholds[1][1]
        precipitation_data = precipitation_grp.create_dataset(
            "data", (world.height, world.width), dtype=numpy.float)
        precipitation_data.write_direct(world.layers['precipitation'].data)

    if world.has_temperature():
        temperature_grp = f.create_group("temperature")
        temperature_ths_grp = temperature_grp.create_group("thresholds")
        th = world.layers['temperature'].thresholds
        temperature_ths_grp['polar'] = th[0][1]
        temperature_ths_grp['alpine'] = th[1][1]
        temperature_ths_grp['boreal'] = th[2][1]
        temperature_ths_grp['cool'] = th[3][1]
        temperature_ths_grp['warm'] = th[4][1]
        temperature_ths_grp['subtropical'] = th[5][1]
        temperature_data = temperature_grp.create_dataset(
            "data", (world.height, world.width), dtype=numpy.float)
        temperature_data.write_direct(world.layers['temperature'].data)

    if world.has_icecap():
        icecap_data = f.create_dataset("icecap", (world.height, world.width),
                                       dtype=numpy.float)
        icecap_data.write_direct(world.layers['icecap'].data)

    if world.has_lakemap():
        lake_map_data = f.create_dataset("lake_map",
                                         (world.height, world.width),
                                         dtype=numpy.float)
        lake_map_data.write_direct(world.layers['lake_map'].data)

    if world.has_rivermap():
        river_map_data = f.create_dataset("river_map",
                                          (world.height, world.width),
                                          dtype=numpy.float)
        river_map_data.write_direct(world.layers['river_map'].data)

    generation_params_grp = f.create_group("generation_params")
    generation_params_grp['seed'] = world.seed
    generation_params_grp['n_plates'] = world.n_plates
    generation_params_grp['ocean_level'] = world.ocean_level
    generation_params_grp['step'] = world.step.name

    f.close()