def test_biome_index_to_name(self): self.assertRaises(Exception, biome_index_to_name, -1) self.assertRaises(Exception, biome_index_to_name, 41) self.assertRaises(Exception, biome_index_to_name, 100) # We do not want these values to change in the future, otherwise the world saved # will be not loaded correctly self.assertEqual('boreal desert', biome_index_to_name(0)) self.assertEqual('boreal dry scrub', biome_index_to_name(1)) self.assertEqual('boreal moist forest', biome_index_to_name(2)) self.assertEqual('boreal rain forest', biome_index_to_name(3)) self.assertEqual('boreal wet forest', biome_index_to_name(4)) self.assertEqual('cool temperate desert', biome_index_to_name(5)) self.assertEqual('cool temperate desert scrub', biome_index_to_name(6)) self.assertEqual('cool temperate moist forest', biome_index_to_name(7)) self.assertEqual('cool temperate rain forest', biome_index_to_name(8)) self.assertEqual('cool temperate steppe', biome_index_to_name(9)) self.assertEqual('cool temperate wet forest', biome_index_to_name(10)) self.assertEqual('ice', biome_index_to_name(11)) self.assertEqual('ocean', biome_index_to_name(12)) self.assertEqual('polar desert', biome_index_to_name(13)) self.assertEqual('sea', biome_index_to_name(14)) self.assertEqual('subpolar dry tundra', biome_index_to_name(15)) self.assertEqual('subpolar moist tundra', biome_index_to_name(16)) self.assertEqual('subpolar rain tundra', biome_index_to_name(17)) self.assertEqual('subpolar wet tundra', biome_index_to_name(18)) self.assertEqual('subtropical desert', biome_index_to_name(19)) self.assertEqual('subtropical desert scrub', biome_index_to_name(20)) self.assertEqual('subtropical dry forest', biome_index_to_name(21)) self.assertEqual('subtropical moist forest', biome_index_to_name(22)) self.assertEqual('subtropical rain forest', biome_index_to_name(23)) self.assertEqual('subtropical thorn woodland', biome_index_to_name(24)) self.assertEqual('subtropical wet forest', biome_index_to_name(25)) self.assertEqual('tropical desert', biome_index_to_name(26)) self.assertEqual('tropical desert scrub', biome_index_to_name(27)) self.assertEqual('tropical dry forest', biome_index_to_name(28)) self.assertEqual('tropical moist forest', biome_index_to_name(29)) self.assertEqual('tropical rain forest', biome_index_to_name(30)) self.assertEqual('tropical thorn woodland', biome_index_to_name(31)) self.assertEqual('tropical very dry forest', biome_index_to_name(32)) self.assertEqual('tropical wet forest', biome_index_to_name(33)) self.assertEqual('warm temperate desert', biome_index_to_name(34)) self.assertEqual('warm temperate desert scrub', biome_index_to_name(35)) self.assertEqual('warm temperate dry forest', biome_index_to_name(36)) self.assertEqual('warm temperate moist forest', biome_index_to_name(37)) self.assertEqual('warm temperate rain forest', biome_index_to_name(38)) self.assertEqual('warm temperate thorn scrub', biome_index_to_name(39)) self.assertEqual('warm temperate wet forest', biome_index_to_name(40))
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
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