fix(map_generator): distance_to_water distribution sync
This commit is contained in:
parent
c9c7f26910
commit
8ffeff179f
@ -17,11 +17,11 @@ from utils import *
|
|||||||
|
|
||||||
parameters = {
|
parameters = {
|
||||||
'width': {
|
'width': {
|
||||||
'default': 700,
|
'default': 360,
|
||||||
'type': 'int',
|
'type': 'int',
|
||||||
},
|
},
|
||||||
'height': {
|
'height': {
|
||||||
'default': 450,
|
'default': 180,
|
||||||
'type': 'int',
|
'type': 'int',
|
||||||
},
|
},
|
||||||
'mountain_ratio': {
|
'mountain_ratio': {
|
||||||
@ -32,7 +32,7 @@ parameters = {
|
|||||||
'step': 0.01
|
'step': 0.01
|
||||||
},
|
},
|
||||||
'sharpness': {
|
'sharpness': {
|
||||||
'default': 0.7,
|
'default': 0.9,
|
||||||
'type': 'float',
|
'type': 'float',
|
||||||
'min': 0,
|
'min': 0,
|
||||||
'max': 1,
|
'max': 1,
|
||||||
@ -57,7 +57,7 @@ parameters = {
|
|||||||
'max': 1e5,
|
'max': 1e5,
|
||||||
},
|
},
|
||||||
'water_proportion': {
|
'water_proportion': {
|
||||||
'default': 0.8,
|
'default': 0.3,
|
||||||
'type': 'float',
|
'type': 'float',
|
||||||
'min': 0,
|
'min': 0,
|
||||||
'max': 0.99,
|
'max': 0.99,
|
||||||
@ -280,13 +280,15 @@ def generate_map(biomes=False, **kwargs):
|
|||||||
|
|
||||||
p.update(kwargs)
|
p.update(kwargs)
|
||||||
|
|
||||||
np.random.seed(p['seed'] or None)
|
rs = np.random.randint(0, 999)
|
||||||
|
np.random.seed(p['seed'] or rs)
|
||||||
|
print('seed', rs)
|
||||||
|
|
||||||
width, height = p['width'], p['height']
|
width, height = p['width'], p['height']
|
||||||
continents = p['continents']
|
continents = p['continents']
|
||||||
|
|
||||||
ground = np.zeros((width, height))
|
ground = np.zeros((width, height))
|
||||||
ground_size = width * height * (1 - p['water_proportion'])
|
ground_size = width * height * (1 - p['water_proportion'])**3
|
||||||
print(ground_size / ground.size)
|
print(ground_size / ground.size)
|
||||||
|
|
||||||
# position = (int(width / 2), int(height / 2))
|
# position = (int(width / 2), int(height / 2))
|
||||||
@ -313,11 +315,11 @@ def generate_map(biomes=False, **kwargs):
|
|||||||
greys = cm.get_cmap('Greys')
|
greys = cm.get_cmap('Greys')
|
||||||
greys.set_under(color=SEA_COLOR)
|
greys.set_under(color=SEA_COLOR)
|
||||||
|
|
||||||
ground = ndimage.gaussian_filter(ground, sigma=4)
|
# ground = ndimage.gaussian_filter(ground, sigma=4)
|
||||||
ground = ndimage.generic_filter(ground, constant_filter, size=1)
|
ground = ndimage.generic_filter(ground, constant_filter, size=1)
|
||||||
print(np.min(ground), np.max(ground), p['max_elevation'])
|
print(np.min(ground), np.max(ground), p['max_elevation'])
|
||||||
|
|
||||||
print('water proportion', np.count_nonzero(ground) / ground.size)
|
print('water proportion', 1 - (np.count_nonzero(ground) / ground.size))
|
||||||
|
|
||||||
plt.gca().invert_yaxis()
|
plt.gca().invert_yaxis()
|
||||||
plt.imshow(ground.T, cmap=greys, norm=norm)
|
plt.imshow(ground.T, cmap=greys, norm=norm)
|
||||||
@ -355,19 +357,33 @@ def generate_biomes(ground):
|
|||||||
data['latitude'].append(height_to_latitude(y))
|
data['latitude'].append(height_to_latitude(y))
|
||||||
data['elevation'].append(v)
|
data['elevation'].append(v)
|
||||||
|
|
||||||
print(len(points))
|
|
||||||
print('buffering points')
|
|
||||||
points = MultiPoint(points)
|
points = MultiPoint(points)
|
||||||
boundary = points.buffer(1).boundary
|
boundary = points.convex_hull.boundary
|
||||||
|
|
||||||
|
# fig = plt.figure()
|
||||||
|
# ax = fig.add_subplot(111)
|
||||||
|
# minx, miny, maxx, maxy = boundary.bounds
|
||||||
|
# w, h = maxx - minx, maxy - miny
|
||||||
|
# ax.set_xlim(minx - 0.2 * w, maxx + 0.2 * w)
|
||||||
|
# ax.set_ylim(miny - 0.2 * h, maxy + 0.2 * h)
|
||||||
|
# ax.set_aspect(1)
|
||||||
|
|
||||||
|
# ax.add_collection(PatchCollection([PolygonPatch(boundary_buf, fc='red', ec='black', zorder=1)], match_original=True))
|
||||||
|
# plt.show()
|
||||||
|
|
||||||
for x, y in np.ndindex(ground.shape):
|
for x, y in np.ndindex(ground.shape):
|
||||||
if ground[x, y] > p['water_level']:
|
if ground[x, y] > p['water_level']:
|
||||||
data['distance_to_water'].append(Point(x, y).distance(boundary))
|
d = Point(x, y).distance(boundary)
|
||||||
|
d = (d - root_df['distance_to_water'].mean()) / root_df['distance_to_water'].std()
|
||||||
|
d = max(0, d)
|
||||||
|
|
||||||
|
data['distance_to_water'].append(d)
|
||||||
|
|
||||||
|
|
||||||
df = pd.DataFrame(data)
|
df = pd.DataFrame(data)
|
||||||
print(df['elevation'].min(), df['elevation'].max())
|
print(df['elevation'].min(), df['elevation'].max())
|
||||||
print(df['distance_to_water'].min(), df['distance_to_water'].max())
|
print('distance_to_water', df['distance_to_water'].min(), df['distance_to_water'].max())
|
||||||
|
print('dtw', df['distance_to_water'].mean(), df['distance_to_water'].std())
|
||||||
print(df['latitude'].min(), df['latitude'].max())
|
print(df['latitude'].min(), df['latitude'].max())
|
||||||
|
|
||||||
print('running prediction models')
|
print('running prediction models')
|
||||||
@ -387,8 +403,10 @@ def generate_biomes(ground):
|
|||||||
# plt.show()
|
# plt.show()
|
||||||
|
|
||||||
df = pd.read_pickle('data.p')
|
df = pd.read_pickle('data.p')
|
||||||
|
root_df = df
|
||||||
print(df['elevation'].min(), df['elevation'].max())
|
print(df['elevation'].min(), df['elevation'].max())
|
||||||
print(df['distance_to_water'].min(), df['distance_to_water'].max())
|
print('distance_to_water', df['distance_to_water'].min(), df['distance_to_water'].max())
|
||||||
|
print('dtw', df['distance_to_water'].mean(), df['distance_to_water'].std())
|
||||||
print(df['latitude'].min(), df['latitude'].max())
|
print(df['latitude'].min(), df['latitude'].max())
|
||||||
|
|
||||||
def predict_end_to_end(input_df, checkpoint_temp='checkpoints/temp.h5', checkpoint_precip='checkpoints/precip.h5', checkpoint_biomes='checkpoints/b.h5', year=2000):
|
def predict_end_to_end(input_df, checkpoint_temp='checkpoints/temp.h5', checkpoint_precip='checkpoints/precip.h5', checkpoint_biomes='checkpoints/b.h5', year=2000):
|
||||||
@ -489,7 +507,7 @@ def predict_end_to_end(input_df, checkpoint_temp='checkpoints/temp.h5', checkpoi
|
|||||||
draw(new_data, earth=False, only_draw=True, longitude_max=p['width'], latitude_max=p['height'], alpha=0.7)
|
draw(new_data, earth=False, only_draw=True, longitude_max=p['width'], latitude_max=p['height'], alpha=0.7)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# p['width'] = 50
|
# p['width'] = 300
|
||||||
# p['height'] = 50
|
# p['height'] = 250
|
||||||
generate_map(True)
|
generate_map(True)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
@ -2,6 +2,11 @@ from map_generator import generate_map
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
grid = {
|
||||||
|
'water_proportion': (0.3, 0.7),
|
||||||
|
'mountain_ratio': ()
|
||||||
|
}
|
||||||
|
|
||||||
seed = 0
|
seed = 0
|
||||||
while True:
|
while True:
|
||||||
generate_map(biomes=True, seed=seed)
|
generate_map(biomes=True, seed=seed)
|
||||||
|
Loading…
Reference in New Issue
Block a user