mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2025-01-01 05:50:34 +01:00
Enhanced visualization code to display colormaps, and reuse the same code for initial and further viewing, in view_map.py
This commit is contained in:
parent
206c68813e
commit
cd90a21df4
@ -91,32 +91,7 @@ with open('size', 'w') as sfile:
|
|||||||
|
|
||||||
# Display the map if matplotlib is found
|
# Display the map if matplotlib is found
|
||||||
try:
|
try:
|
||||||
import matplotlib.pyplot as plt
|
from view_map import view_map
|
||||||
|
view_map(model.dem, model.lakes, model.rivers)
|
||||||
plt.subplot(2,2,1)
|
|
||||||
plt.pcolormesh(nn, cmap='viridis')
|
|
||||||
plt.gca().set_aspect('equal', 'box')
|
|
||||||
#plt.colorbar(orientation='horizontal')
|
|
||||||
plt.title('Raw elevation')
|
|
||||||
|
|
||||||
plt.subplot(2,2,2)
|
|
||||||
plt.pcolormesh(model.lakes, cmap='viridis')
|
|
||||||
plt.gca().set_aspect('equal', 'box')
|
|
||||||
#plt.colorbar(orientation='horizontal')
|
|
||||||
plt.title('Lake surface elevation')
|
|
||||||
|
|
||||||
plt.subplot(2,2,3)
|
|
||||||
plt.pcolormesh(model.dem, cmap='viridis')
|
|
||||||
plt.gca().set_aspect('equal', 'box')
|
|
||||||
#plt.colorbar(orientation='horizontal')
|
|
||||||
plt.title('Elevation after advection')
|
|
||||||
|
|
||||||
plt.subplot(2,2,4)
|
|
||||||
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 flux')
|
|
||||||
|
|
||||||
plt.show()
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
60
view_map.py
60
view_map.py
@ -2,38 +2,42 @@
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import zlib
|
import zlib
|
||||||
|
import matplotlib.colors as mcol
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
def load_map(name, dtype, shape):
|
def view_map(dem, lakes, rivers):
|
||||||
dtype = np.dtype(dtype)
|
plt.subplot(1,3,1)
|
||||||
with open(name, 'rb') as f:
|
plt.pcolormesh(dem, cmap='viridis')
|
||||||
data = f.read()
|
plt.gca().set_aspect('equal', 'box')
|
||||||
if len(data) < shape[0]*shape[1]*dtype.itemsize:
|
plt.colorbar(orientation='horizontal')
|
||||||
data = zlib.decompress(data)
|
plt.title('Raw elevation')
|
||||||
return np.frombuffer(data, dtype=dtype).reshape(shape)
|
|
||||||
|
|
||||||
shape = np.loadtxt('size', dtype='u4')
|
plt.subplot(1,3,2)
|
||||||
n = shape[0] * shape[1]
|
plt.pcolormesh(lakes, cmap='viridis')
|
||||||
dem = load_map('dem', '>i2', shape)
|
plt.gca().set_aspect('equal', 'box')
|
||||||
lakes = load_map('lakes', '>i2', shape)
|
plt.colorbar(orientation='horizontal')
|
||||||
rivers = load_map('rivers', '>u4', shape)
|
plt.title('Lake surface elevation')
|
||||||
|
|
||||||
plt.subplot(1,3,1)
|
plt.subplot(1,3,3)
|
||||||
plt.pcolormesh(dem, cmap='viridis')
|
plt.pcolormesh(rivers, cmap='Blues', norm=mcol.LogNorm())
|
||||||
plt.gca().set_aspect('equal', 'box')
|
plt.gca().set_aspect('equal', 'box')
|
||||||
#plt.colorbar(orientation='horizontal')
|
plt.colorbar(orientation='horizontal')
|
||||||
plt.title('Raw elevation')
|
plt.title('Rivers flux')
|
||||||
|
|
||||||
plt.subplot(1,3,2)
|
plt.show()
|
||||||
plt.pcolormesh(lakes, cmap='viridis')
|
|
||||||
plt.gca().set_aspect('equal', 'box')
|
|
||||||
#plt.colorbar(orientation='horizontal')
|
|
||||||
plt.title('Lake surface elevation')
|
|
||||||
|
|
||||||
plt.subplot(1,3,3)
|
if __name__ == "__main__":
|
||||||
plt.pcolormesh(np.log(rivers), vmin=0, vmax=np.log(n/25), cmap='Blues')
|
def load_map(name, dtype, shape):
|
||||||
plt.gca().set_aspect('equal', 'box')
|
dtype = np.dtype(dtype)
|
||||||
#plt.colorbar(orientation='horizontal')
|
with open(name, 'rb') as f:
|
||||||
plt.title('Rivers flux')
|
data = f.read()
|
||||||
|
if len(data) < shape[0]*shape[1]*dtype.itemsize:
|
||||||
|
data = zlib.decompress(data)
|
||||||
|
return np.frombuffer(data, dtype=dtype).reshape(shape)
|
||||||
|
|
||||||
plt.show()
|
shape = np.loadtxt('size', dtype='u4')
|
||||||
|
dem = load_map('dem', '>i2', shape)
|
||||||
|
lakes = load_map('lakes', '>i2', shape)
|
||||||
|
rivers = load_map('rivers', '>u4', shape)
|
||||||
|
|
||||||
|
view_map(dem, lakes, rivers)
|
||||||
|
Loading…
Reference in New Issue
Block a user