Comment and clarify

This commit is contained in:
Gael-de-Sailly
2020-04-26 17:13:38 +02:00
parent 49bc397718
commit 6af6795d90
9 changed files with 105 additions and 36 deletions

View File

@ -20,28 +20,29 @@ else:
scale = (mapsize-1) / 2
n = np.zeros((mapsize, mapsize))
#micronoise_depth = 0.05
# Set noise parameters
params = {
"octaves" : int(np.ceil(np.log2(mapsize-1)))+1,
"persistence" : 0.5,
"lacunarity" : 2.,
}
# Determine noise offset randomly
xbase = np.random.randint(65536)
ybase = np.random.randint(65536)
# Generate the noise
for x in range(mapsize):
for y in range(mapsize):
n[x,y] = noise.snoise2(x/scale + xbase, y/scale + ybase, **params)
#micronoise = np.random.rand(mapsize, mapsize)
#nn = np.exp(n*2) + micronoise*micronoise_depth
nn = n*mapsize/5 + mapsize/20
# Initialize landscape evolution model
print('Initializing model')
model = EvolutionModel(nn, K=1, m=0.35, d=1, sea_level=0)
# Run the model's processes: the order in which the processes are run is arbitrary and could be changed.
print('Flow calculation 1')
model.calculate_flow()
@ -68,12 +69,15 @@ model.calculate_flow()
print('Done')
# Twist the grid
bx, by = bounds.make_bounds(model.dirs, model.rivers)
ox, oy = bounds.twist(bx, by, bounds.get_fixed(model.dirs))
# Convert offset in 8-bits
offset_x = np.clip(np.floor(ox * 256), -128, 127)
offset_y = np.clip(np.floor(oy * 256), -128, 127)
# Save the files
save(model.dem, 'dem', dtype='>i2')
save(model.lakes, 'lakes', dtype='>i2')
save(np.abs(bx), 'bounds_x', dtype='>i4')
@ -86,6 +90,7 @@ save(model.rivers, 'rivers', dtype='>u4')
with open('size', 'w') as sfile:
sfile.write('{:d}\n{:d}'.format(mapsize, mapsize))
# Display the map if matplotlib is found
try:
import matplotlib.pyplot as plt
@ -111,7 +116,7 @@ try:
plt.pcolormesh(model.rivers, vmin=0, vmax=mapsize**2/25, cmap='Blues')
plt.gca().set_aspect('equal', 'box')
#plt.colorbar(orientation='horizontal')
plt.title('Rivers discharge')
plt.title('Rivers flux')
plt.show()
except: