Example #1
0
def generate_world(w, step):
    if isinstance(step, str):
        step = Step.get_by_name(step)

    if not step.include_precipitations:
        return w

    # Prepare sufficient seeds for the different steps of the generation
    rng = numpy.random.RandomState(w.seed)  # create a fresh RNG in case the global RNG is compromised (i.e. has been queried an indefinite amount of times before generate_world() was called)
    sub_seeds = rng.randint(0, numpy.iinfo(numpy.int32).max, size=100)  # choose lowest common denominator (32 bit Windows numpy cannot handle a larger value)
    seed_dict = {
                 'PrecipitationSimulation': sub_seeds[ 0],  # after 0.19.0 do not ever switch out the seeds here to maximize seed-compatibility
                 'ErosionSimulation':       sub_seeds[ 1],
                 'WatermapSimulation':      sub_seeds[ 2],
                 'IrrigationSimulation':    sub_seeds[ 3],
                 'TemperatureSimulation':   sub_seeds[ 4],
                 'HumiditySimulation':      sub_seeds[ 5],
                 'PermeabilitySimulation':  sub_seeds[ 6],
                 'BiomeSimulation':         sub_seeds[ 7],
                 'IcecapSimulation':        sub_seeds[ 8],
                 '':                        sub_seeds[99]
    }

    TemperatureSimulation().execute(w, seed_dict['TemperatureSimulation'])
    # Precipitation with thresholds
    PrecipitationSimulation().execute(w, seed_dict['PrecipitationSimulation'])

    if not step.include_erosion:
        return w
    ErosionSimulation().execute(w, seed_dict['ErosionSimulation'])  # seed not currently used
    if get_verbose():
        print("...erosion calculated")

    WatermapSimulation().execute(w, seed_dict['WatermapSimulation'])  # seed not currently used

    # FIXME: create setters
    IrrigationSimulation().execute(w, seed_dict['IrrigationSimulation'])  # seed not currently used
    HumiditySimulation().execute(w, seed_dict['HumiditySimulation'])  # seed not currently used

    PermeabilitySimulation().execute(w, seed_dict['PermeabilitySimulation'])

    cm, biome_cm = BiomeSimulation().execute(w, seed_dict['BiomeSimulation'])  # seed not currently used
    for cl in cm.keys():
        count = cm[cl]
        if get_verbose():
            print("%s = %i" % (str(cl), count))

    if get_verbose():
        print('')  # empty line
        print('Biome obtained:')

    for cl in biome_cm.keys():
        count = biome_cm[cl]
        if get_verbose():
            print(" %30s = %7i" % (str(cl), count))

    IcecapSimulation().execute(w, seed_dict['IcecapSimulation'])  # makes use of temperature-map

    return w
Example #2
0
def generate_world(w, step):
    if isinstance(step, str):
        step = Step.get_by_name(step)

    if not step.include_precipitations:
        return w

    # Prepare sufficient seeds for the different steps of the generation
    rng = numpy.random.RandomState(
        w.seed
    )  # create a fresh RNG in case the global RNG is compromised (i.e. has been queried an indefinite amount of times before generate_world() was called)
    sub_seeds = rng.randint(
        0, numpy.iinfo(numpy.int32).max, size=100
    )  # choose lowest common denominator (32 bit Windows numpy cannot handle a larger value)
    seed_dict = {
        'PrecipitationSimulation': sub_seeds[
            0],  # after 0.19.0 do not ever switch out the seeds here to maximize seed-compatibility
        'ErosionSimulation': sub_seeds[1],
        'WatermapSimulation': sub_seeds[2],
        'IrrigationSimulation': sub_seeds[3],
        'TemperatureSimulation': sub_seeds[4],
        'HumiditySimulation': sub_seeds[5],
        'PermeabilitySimulation': sub_seeds[6],
        'BiomeSimulation': sub_seeds[7],
        'IcecapSimulation': sub_seeds[8],
        '': sub_seeds[99]
    }

    TemperatureSimulation().execute(w, seed_dict['TemperatureSimulation'])
    # Precipitation with thresholds
    PrecipitationSimulation().execute(w, seed_dict['PrecipitationSimulation'])

    if not step.include_erosion:
        return w
    ErosionSimulation().execute(
        w, seed_dict['ErosionSimulation'])  # seed not currently used
    if get_verbose():
        print("...erosion calculated")

    WatermapSimulation().execute(
        w, seed_dict['WatermapSimulation'])  # seed not currently used

    # FIXME: create setters
    IrrigationSimulation().execute(
        w, seed_dict['IrrigationSimulation'])  # seed not currently used
    HumiditySimulation().execute(
        w, seed_dict['HumiditySimulation'])  # seed not currently used

    PermeabilitySimulation().execute(w, seed_dict['PermeabilitySimulation'])

    cm, biome_cm = BiomeSimulation().execute(
        w, seed_dict['BiomeSimulation'])  # seed not currently used
    for cl in cm.keys():
        count = cm[cl]
        if get_verbose():
            print("%s = %i" % (str(cl), count))

    if get_verbose():
        print('')  # empty line
        print('Biome obtained:')

    for cl in biome_cm.keys():
        count = biome_cm[cl]
        if get_verbose():
            print(" %30s = %7i" % (str(cl), count))

    IcecapSimulation().execute(
        w, seed_dict['IcecapSimulation'])  # makes use of temperature-map

    return w
Example #3
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
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
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