Lakes map: keep initial height (reduces file size)

Lake height is calculated for every basin, and there is a lake if lake height is higher than ground height. If it is lower, there is no lake.
In that case, it was previously raised to ground level, but since this can be done in Lua, we can write initial lakes height in the files.
This has the advantage of reducing file size, since there are bigger areas of equal values, that are more efficiently compressed.
This commit is contained in:
Gael-de-Sailly 2020-12-05 14:24:50 +01:00
parent ecd2c7d3f9
commit f0dddee33c
3 changed files with 8 additions and 14 deletions

View File

@ -11,12 +11,6 @@ def advection(dem, dirs, rivers, time, K=1, m=0.5, sea_level=0):
v = K * flux^m
"""
dirs = dirs.copy()
dirs[0,:] = 0
dirs[-1,:] = 0
dirs[:,0] = 0
dirs[:,-1] = 0
adv_time = 1 / (K*rivers**m) # For every pixel, calculate the time an "erosion wave" will need to cross it.
dem = np.maximum(dem, sea_level)
dem_new = np.zeros(dem.shape)
@ -51,7 +45,7 @@ def advection(dem, dirs, rivers, time, K=1, m=0.5, sea_level=0):
c = remaining / adv_time[y0,x0]
dem_new[y,x] = c*dem[y1,x1] + (1-c)*dem[y0,x0] # If between 2 pixels, perform linear interpolation.
return np.minimum(dem, dem_new)
return dem_new
def diffusion(dem, time, d=1):
radius = d * time**.5
@ -80,7 +74,7 @@ class EvolutionModel:
self.flow_uptodate = True
def advection(self, time):
dem = advection(self.lakes, self.dirs, self.rivers, time, K=self.K, m=self.m, sea_level=self.sea_level)
dem = advection(np.maximum(self.dem, self.lakes), self.dirs, self.rivers, time, K=self.K, m=self.m, sea_level=self.sea_level)
self.dem = np.minimum(dem, self.dem)
self.flow_uptodate = False

View File

@ -153,7 +153,7 @@ def flow(dem):
waterq = accumulate_flow(dirs2)
return dirs2, np.maximum(basins[basin_id], dem), waterq
return dirs2, basins[basin_id], waterq
def accumulate_flow(dirs):
ndonors = np.zeros(dirs.shape, dtype=int)

View File

@ -22,11 +22,11 @@ if has_matplotlib:
def view_map(dem, lakes, scale=1, title=None):
lakes_sea = np.maximum(lakes, 0)
water = np.maximum(lakes_sea - dem, 0)
max_elev = lakes_sea.max()
max_elev = dem.max()
max_depth = water.max()
ls = mcl.LightSource(azdeg=315, altdeg=45)
rgb = ls.shade(lakes_sea, cmap=cmap1, vert_exag=1/scale, blend_mode='soft', vmin=0, vmax=max_elev)
rgb = ls.shade(dem, cmap=cmap1, vert_exag=1/scale, blend_mode='soft', vmin=0, vmax=max_elev)
(X, Y) = dem.shape
extent = (0, Y*scale, 0, X*scale)
@ -69,13 +69,13 @@ else:
def plot(*args, **kwargs):
pass
def stats(dem, lake_dem, scale=1):
def stats(dem, lakes, scale=1):
surface = dem.size
continent = lake_dem >= 0
continent = np.maximum(dem, lakes) >= 0
continent_surface = continent.sum()
lake = continent & (lake_dem>dem)
lake = continent & (lakes>dem)
lake_surface = lake.sum()
print('--- General ---')