Skip to content

Commit d00788b

Browse files
committed
Merge pull request #189 from tcld/freeze_ocean
Frozen oceans on satellite map
2 parents c773405 + 93f14d2 commit d00788b

File tree

13 files changed

+186
-45
lines changed

13 files changed

+186
-45
lines changed

generate_protobuf_stubs.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
'console_scripts': ['worldengine=worldengine.cli.main:main'],
2727
},
2828
'install_requires': ['PyPlatec==1.4.0', 'pypng>=0.0.18', 'numpy>=1.9.2, <= 1.10.0.post2',
29-
'argparse==1.2.1', 'noise==1.2.2', 'protobuf>=2.6.0'],
29+
'argparse==1.2.1', 'noise==1.2.2', 'protobuf==3.0.0a3'],
3030
'license': 'MIT License'
3131
}
3232

tests/serialization_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ def test_protobuf_serialize_unserialize(self):
2727
self.assertTrue(_equal(w.precipitation, unserialized.precipitation))
2828
self.assertTrue(_equal(w.temperature, unserialized.temperature))
2929
self.assertTrue(_equal(w.sea_depth, unserialized.sea_depth))
30-
self.assertEquals(w.seed, unserialized.seed)
31-
self.assertEquals(w.n_plates, unserialized.n_plates)
3230
self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level))
3331
self.assertTrue(_equal(w.lake_map, unserialized.lake_map))
3432
self.assertTrue(_equal(w.river_map, unserialized.river_map))
33+
self.assertTrue(_equal(w.icecap, unserialized.icecap))
34+
self.assertEquals(w.seed, unserialized.seed)
35+
self.assertEquals(w.n_plates, unserialized.n_plates)
3536
self.assertEquals(w.step, unserialized.step)
3637
self.assertEqual(sorted(dir(w)), sorted(dir(unserialized)))
3738
self.assertEqual(w, unserialized)
@@ -60,11 +61,12 @@ def test_hdf5_serialize_unserialize(self):
6061
self.assertTrue(_equal(w.precipitation, unserialized.precipitation))
6162
self.assertTrue(_equal(w.temperature, unserialized.temperature))
6263
self.assertTrue(_equal(w.sea_depth, unserialized.sea_depth))
63-
self.assertEquals(w.seed, unserialized.seed)
64-
self.assertEquals(w.n_plates, unserialized.n_plates)
6564
self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level))
6665
self.assertTrue(_equal(w.lake_map, unserialized.lake_map))
6766
self.assertTrue(_equal(w.river_map, unserialized.river_map))
67+
self.assertTrue(_equal(w.icecap, unserialized.icecap))
68+
self.assertEquals(w.seed, unserialized.seed)
69+
self.assertEquals(w.n_plates, unserialized.n_plates)
6870
self.assertEquals(w.step, unserialized.step)
6971
self.assertEqual(sorted(dir(w)), sorted(dir(unserialized)))
7072
#self.assertEqual(w, unserialized)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ deps =
88
PyPlatec
99
noise
1010
nose
11-
protobuf
1211
six
1312
pypng
1413
h5py
@@ -18,6 +17,7 @@ deps =
1817
coverage
1918
numpy==1.9.2
2019
pygdal==1.10.0.1
20+
protobuf==3.0.0a3
2121
{[base]deps}
2222

2323

worldengine/World.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
syntax = "proto2";
12
package World;
23

34
message World {
@@ -56,7 +57,6 @@ message World {
5657
required int32 height = 5;
5758

5859
// Elevation
59-
6060
required DoubleMatrix heightMapData = 6;
6161
required double heightMapTh_sea = 7;
6262
required double heightMapTh_plain = 8;
@@ -111,6 +111,8 @@ message World {
111111
optional DoubleMatrix lakemap = 34;
112112
optional DoubleMatrix rivermap = 35;
113113

114+
// Ice-caps
115+
optional DoubleMatrix icecap = 36;
114116
}
115117

116118

worldengine/cli/main.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from worldengine.common import array_to_matrix, set_verbose, print_verbose
77
from worldengine.draw import draw_ancientmap_on_file, draw_biome_on_file, draw_ocean_on_file, \
88
draw_precipitation_on_file, draw_grayscale_heightmap_on_file, draw_simple_elevation_on_file, \
9-
draw_temperature_levels_on_file, draw_riversmap_on_file, draw_scatter_plot_on_file, draw_satellite_on_file
9+
draw_temperature_levels_on_file, draw_riversmap_on_file, draw_scatter_plot_on_file, \
10+
draw_satellite_on_file, draw_icecaps_on_file
1011
from worldengine.plates import world_gen, generate_plates_simulation
1112
from worldengine.imex import export
1213
from worldengine.step import Step
@@ -91,6 +92,10 @@ def draw_satellite_map(world, filename):
9192
draw_satellite_on_file(world, filename)
9293
print("+ satellite map generated in '%s'" % filename)
9394

95+
def draw_icecaps_map(world, filename):
96+
draw_icecaps_on_file(world, filename)
97+
print("+ icecap map generated in '%s'" % filename)
98+
9499
def generate_plates(seed, world_name, output_dir, width, height,
95100
num_plates=10):
96101
"""
@@ -314,9 +319,10 @@ def main():
314319
default=True)
315320
g_generate.add_argument('--scatter', dest='scatter_plot',
316321
action="store_true", help="generate scatter plot")
317-
318322
g_generate.add_argument('--sat', dest='satelite_map',
319323
action="store_true", help="generate satellite map")
324+
g_generate.add_argument('--ice', dest='icecaps_map',
325+
action="store_true", help="generate ice caps map")
320326

321327
# -----------------------------------------------------
322328
g_ancient_map = parser.add_argument_group(
@@ -477,6 +483,7 @@ def main():
477483
print(' black and white maps : %s' % args.black_and_white)
478484
print(' step : %s' % step.name)
479485
print(' greyscale heightmap : %s' % args.grayscale_heightmap)
486+
print(' icecaps heightmap : %s' % args.icecaps_map)
480487
print(' rivers map : %s' % args.rivers_map)
481488
print(' scatter plot : %s' % args.scatter_plot)
482489
print(' satellite map : %s' % args.satelite_map)
@@ -540,7 +547,10 @@ def main():
540547
'%s/%s_scatter.png' % (args.output_dir, world_name))
541548
if args.satelite_map:
542549
draw_satellite_map(world,
543-
'%s/%s_satellite.png' % (args.output_dir, world_name))
550+
'%s/%s_satellite.png' % (args.output_dir, world_name))
551+
if args.icecaps_map:
552+
draw_icecaps_map(world,
553+
'%s/%s_icecaps.png' % (args.output_dir, world_name))
544554

545555
elif operation == 'plates':
546556
print('') # empty line

worldengine/draw.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ def draw_satellite(world, target):
373373

374374
# Get an elevation mask where heights are normalized between 0 and 255
375375
elevation_mask = get_normalized_elevation_array(world)
376+
smooth_mask = numpy.invert(world.ocean) # all land shall be smoothed (other tiles can be included by setting them to True)
376377

377378
rng = numpy.random.RandomState(world.seed) # create our own random generator; necessary for now to make the tests reproducible, even though it is a bit ugly
378379

@@ -390,11 +391,20 @@ def draw_satellite(world, target):
390391
# the map is smoothed and shaded.
391392
target.set_pixel(x, y, (r, g, b, 255))
392393

394+
# Paint frozen areas.
395+
ice_color_variation = int(30) # 0 means perfectly white ice; must be in [0, 255]; only affects R- and G-channel
396+
for y in range(world.height):
397+
for x in range(world.width):
398+
if world.icecap[y, x] > 0.0:
399+
smooth_mask[y, x] = True # smooth the frozen areas, too
400+
variation = rng.randint(0, ice_color_variation)
401+
target.set_pixel(x, y, (255 - ice_color_variation + variation, 255 - ice_color_variation + variation, 255, 255))
402+
393403
# Loop through and average a pixel with its neighbors to smooth transitions between biomes
394404
for y in range(1, world.height-1):
395405
for x in range(1, world.width-1):
396406
## Only smooth land tiles
397-
if world.is_land((x, y)):
407+
if smooth_mask[y, x]:
398408
# Lists to hold the separated rgb values of the neighboring pixels
399409
all_r = []
400410
all_g = []
@@ -404,7 +414,7 @@ def draw_satellite(world, target):
404414
for j in range(y-1, y+2):
405415
for i in range(x-1, x+2):
406416
# Don't include ocean in the smoothing, if this tile happens to border an ocean
407-
if world.is_land((i, j)):
417+
if smooth_mask[j, i]:
408418
# Grab each rgb value and append to the list
409419
r, g, b, a = target[j, i]
410420
all_r.append(r)
@@ -805,3 +815,8 @@ def draw_satellite_on_file(world, filename):
805815
img = PNGWriter.rgba_from_dimensions(world.width, world.height, filename)
806816
draw_satellite(world, img)
807817
img.complete()
818+
819+
820+
def draw_icecaps_on_file(world, filename):
821+
img = PNGWriter.grayscale_from_array(world.icecap, filename, scale_to_range=True)
822+
img.complete()

worldengine/generation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from worldengine.simulations.erosion import ErosionSimulation
1010
from worldengine.simulations.precipitation import PrecipitationSimulation
1111
from worldengine.simulations.biome import BiomeSimulation
12+
from worldengine.simulations.icecap import IcecapSimulation
1213
from worldengine.common import anti_alias, get_verbose
1314
import numpy
1415

@@ -210,6 +211,7 @@ def generate_world(w, step):
210211
'HumiditySimulation': sub_seeds[ 5],
211212
'PermeabilitySimulation': sub_seeds[ 6],
212213
'BiomeSimulation': sub_seeds[ 7],
214+
'IcecapSimulation': sub_seeds[ 8],
213215
'': sub_seeds[99]
214216
}
215217

@@ -229,7 +231,6 @@ def generate_world(w, step):
229231
IrrigationSimulation().execute(w, seed_dict['IrrigationSimulation']) # seed not currently used
230232
HumiditySimulation().execute(w, seed_dict['HumiditySimulation']) # seed not currently used
231233

232-
233234
PermeabilitySimulation().execute(w, seed_dict['PermeabilitySimulation'])
234235

235236
cm, biome_cm = BiomeSimulation().execute(w, seed_dict['BiomeSimulation']) # seed not currently used
@@ -247,4 +248,6 @@ def generate_world(w, step):
247248
if get_verbose():
248249
print(" %30s = %7i" % (str(cl), count))
249250

251+
IcecapSimulation().execute(w, seed_dict['IcecapSimulation']) # makes use of temperature-map
252+
250253
return w

worldengine/hdf5_serialization.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ def save_world_to_hdf5(world, filename):
8888
temperature_data = temperature_grp.create_dataset("data", (world.height, world.width), dtype=numpy.float)
8989
temperature_data.write_direct(world.temperature['data'])
9090

91-
# lake_map and river_map have inverted coordinates
91+
if hasattr(world, 'icecap'):
92+
icecap_data = f.create_dataset("icecap", (world.height, world.width), dtype=numpy.float)
93+
icecap_data.write_direct(world.icecap)
94+
9295
if hasattr(world, 'lake_map'):
9396
lake_map_data = f.create_dataset("lake_map", (world.height, world.width), dtype=numpy.float)
9497
lake_map_data.write_direct(world.lake_map)
9598

96-
# lake_map and river_map have inverted coordinates
9799
if hasattr(world, 'river_map'):
98100
river_map_data = f.create_dataset("river_map", (world.height, world.width), dtype=numpy.float)
99101
river_map_data.write_direct(world.river_map)
@@ -207,6 +209,9 @@ def load_world_to_hdf5(filename):
207209
]
208210
w.set_temperature(t, t_th)
209211

212+
if 'icecap' in f.keys():
213+
w.icecap = numpy.array(f['icecap'])
214+
210215
if 'lake_map' in f.keys():
211216
m = numpy.array(f['lake_map'])
212217
w.set_lakemap(m)

0 commit comments

Comments
 (0)