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VEUCXG5ZJAC
PG7KSKJLFLANZCTTVYVCHO6IHYL5QA22OGFM7M2DAF2CKMFVMT7QC
IGYI5RVVRFQUQBDH6KQ2MH6ADCZ455Z634BRXKLCEYFF4ZKQ3TMQC
6AXPZL5PQMW5P6BPRTGWO3AOWAU5OC33UYBY3TVOHUVQXCRVVTPQC
FL3C6ERZKQLTMETYALWADCLGP2CXFEHTDFE2PDXHTSSSIY452PUAC
SJHJS463IU7LHBM4C6FO2PJSLZLT7LCN26W2D3V2NIQEQKA4HCLAC
ZM2EMAZOPZDZ2VUIE6NGAXS2OM7MYNWTMHIKM7KPIKSYXXR4D4CQC
2ABZP2KNBJEMIR46B5UM7JXNYLM7CTFA5YA7VFQIS5JYYH4W5PYAC
4IXWCEHMWCEXNCDYUV3H44UPQ7R4HKS3RWRWII7LU4PA6ZZRAS3AC
def __init__(self, stream):
def check(item):
if type(item) == dict:
return {k: check(v) for k, v in item.items()}
elif type(item) == list:
return list(map(check, item))
elif type(item) == str and item.startswith('buffer:'):
return base64.b64decode(item[len('buffer:'):])
else:
return item
self.raw = check(json.load(stream))
def vertex(obj):
return [obj['x'], obj['y'], obj['z']]
self.vertices = tf.convert_to_tensor(list(map(vertex, self.raw['model']['bodies']['world']['grid']['vertices'])), dtype=tf.float32)
crust = tf.convert_to_tensor(list(map(lambda x: x[0], struct.iter_unpack('f', self.raw['model']['bodies']['world']['lithosphere']['total_crust']))))
crust = tf.reshape(crust, (8, self.vertices.shape[0]))
self.crust_layers = {SimResult.crust_columns()[i]: crust[i] for i in range(0,8)}
total_crust = tf.zeros((self.vertices.shape[0],), dtype=tf.float32)
for k, v in self.crust_layers.items():
if k != 'age':
total_crust += v
self.crust_layers['total'] = total_crust
def __init__(self, stream):
def check(item):
if type(item) == dict:
return {k: check(v) for k, v in item.items()}
elif type(item) == list:
return list(map(check, item))
elif type(item) == str and item.startswith('buffer:'):
return base64.b64decode(item[len('buffer:'):])
else:
return item
self.raw = check(json.load(stream))
def vertex(obj):
return [obj['x'], obj['y'], obj['z']]
def seed(self):
return self.raw['seed']
self.vertices = tf.convert_to_tensor(list(
map(vertex, self.raw['model']['bodies']['world']['grid']['vertices'])),
dtype=tf.float32)
crust = tf.convert_to_tensor(
list(
map(
lambda x: x[0],
struct.iter_unpack(
'f', self.raw['model']['bodies']['world']['lithosphere']
['total_crust']))))
crust = tf.reshape(crust, (8, self.vertices.shape[0]))
self.crust_layers = {
SimResult.crust_columns()[i]: crust[i]
for i in range(0, 8)
}
total_crust = tf.zeros((self.vertices.shape[0], ), dtype=tf.float32)
for k, v in self.crust_layers.items():
if k != 'age':
total_crust += v
self.crust_layers['total'] = total_crust
def crust_columns():
return [
'sediment', 'sedimentary', 'metamorphic', 'felsic_plutonic',
'felsic_volcanic', 'mafic_volcanic', 'mafic_plutonic', 'age'
]
native = ctypes.cdll.LoadLibrary(os.path.dirname(os.path.realpath(__file__)) + '/helpers.' + ('dylib' if platform.system() == 'Darwin' else 'so'))
native = ctypes.cdll.LoadLibrary(
os.path.dirname(os.path.realpath(__file__)) + '/helpers.' +
('dylib' if platform.system() == 'Darwin' else 'so'))
native.colourize_heightmap.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int, ctypes.c_int]
native.colourize_heightmap.argtypes = [
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double), ctypes.c_int, ctypes.c_int
]
layer1 = keras.layers.Dense(20, activation=keras.activations.softplus)(inputs)
layer2 = keras.layers.Dense(20, activation=keras.activations.softplus)(layer1)
layer3 = keras.layers.Dense(20, activation=keras.activations.softplus)(keras.layers.concatenate([layer1,layer2]))
layer4 = keras.layers.Dense(20, activation=keras.activations.softplus)(keras.layers.concatenate([layer1,layer2]))
layer5 = keras.layers.Dense(88, activation=keras.activations.relu)(keras.layers.concatenate([layer2,layer3]))
layer6 = keras.layers.Dense(88, activation=keras.activations.relu)(keras.layers.concatenate([layer2,layer4,layer5]))
layer7 = keras.layers.Dense(88, activation=keras.activations.relu)(keras.layers.concatenate([layer5,layer6]))
layer8 = keras.layers.Dense(20, activation=keras.activations.softplus)(keras.layers.concatenate([layer3,layer5,layer7]))
layer9 = keras.layers.Dense(20, activation=keras.activations.softplus)(keras.layers.concatenate([layer4,layer6,layer7]))
layer10 = keras.layers.Dense(20, activation=keras.activations.softplus)(keras.layers.concatenate([layer7,layer8,layer9]))
layer11 = keras.layers.Dense(20, activation=keras.activations.softplus)(keras.layers.concatenate([layer1,layer3,layer8,layer10]))
layer12 = keras.layers.Dense(20, activation=keras.activations.softplus)(keras.layers.concatenate([layer1,layer4,layer9,layer10,layer11]))
return keras.layers.concatenate([layer11,layer12])
layer1 = keras.layers.Dense(20,
activation=keras.activations.softplus)(inputs)
layer2 = keras.layers.Dense(20,
activation=keras.activations.softplus)(layer1)
layer3 = keras.layers.Dense(20, activation=keras.activations.softplus)(
keras.layers.concatenate([layer1, layer2]))
layer4 = keras.layers.Dense(20, activation=keras.activations.softplus)(
keras.layers.concatenate([layer1, layer2]))
layer5 = keras.layers.Dense(88, activation=keras.activations.relu)(
keras.layers.concatenate([layer2, layer3]))
layer6 = keras.layers.Dense(88, activation=keras.activations.relu)(
keras.layers.concatenate([layer2, layer4, layer5]))
layer7 = keras.layers.Dense(88, activation=keras.activations.relu)(
keras.layers.concatenate([layer5, layer6]))
layer8 = keras.layers.Dense(20, activation=keras.activations.softplus)(
keras.layers.concatenate([layer3, layer5, layer7]))
layer9 = keras.layers.Dense(20, activation=keras.activations.softplus)(
keras.layers.concatenate([layer4, layer6, layer7]))
layer10 = keras.layers.Dense(20, activation=keras.activations.softplus)(
keras.layers.concatenate([layer7, layer8, layer9]))
layer11 = keras.layers.Dense(20, activation=keras.activations.softplus)(
keras.layers.concatenate([layer1, layer3, layer8, layer10]))
layer12 = keras.layers.Dense(20, activation=keras.activations.softplus)(
keras.layers.concatenate([layer1, layer4, layer9, layer10, layer11]))
return keras.layers.concatenate([layer11, layer12])
inputs = keras.Input(shape=(3,))
d1 = icosahedral(inputs)
d2 = icosahedral(inputs)
outputs = keras.layers.Dense(1, activation=keras.activations.sigmoid)(keras.layers.concatenate([d1,d2]))
return keras.Model(inputs=inputs, outputs=outputs, name="geology_model")
inputs = keras.Input(shape=(3, ))
d1 = icosahedral(inputs)
d2 = icosahedral(inputs)
outputs = keras.layers.Dense(1, activation=keras.activations.sigmoid)(
keras.layers.concatenate([d1, d2]))
return keras.Model(inputs=inputs, outputs=outputs, name="geology_model")
y_true = tf.math.asinh((y_true - 0.1) * 5.) / 5.
y_pred = tf.math.asinh((y_pred - 0.1) * 5.) / 5.
return tf.math.reduce_mean((y_true - y_pred) ** 2)
y_true = tf.math.asinh((y_true - 0.1) * 5.) / 5.
y_pred = tf.math.asinh((y_pred - 0.1) * 5.) / 5.
return tf.math.reduce_mean((y_true - y_pred)**2)
custom_objects = {"asinh": tf.math.asinh}
with keras.utils.custom_object_scope(custom_objects):
return keras.models.clone_model(source)
custom_objects = {"asinh": tf.math.asinh}
with keras.utils.custom_object_scope(custom_objects):
return keras.models.clone_model(source)
'fine_sediment': 1500.,
'voarse_sediment': 1500.,
'sediment': 1500.,
'sedimentary': 2600.,
'metamorphic': 2800.,
'felsic_plutonic': 2600.,
'felsic_volcanic': 2600.,
'mafic_volcanic_min': 2890., # Carlson & Raskin 1984
'mafic_volcanic_max': 3300.,
'mantle': 3075., # derived empirically using isostatic model
'ocean': 1026.,
}
'fine_sediment': 1500.,
'voarse_sediment': 1500.,
'sediment': 1500.,
'sedimentary': 2600.,
'metamorphic': 2800.,
'felsic_plutonic': 2600.,
'felsic_volcanic': 2600.,
'mafic_volcanic_min': 2890., # Carlson & Raskin 1984
'mafic_volcanic_max': 3300.,
'mantle': 3075., # derived empirically using isostatic model
'ocean': 1026.,
}
fraction_of_lifetime = saved.crust_layers['age'] / 7889537440886400.0
mafic_density = material_density['mafic_volcanic_min'] + (material_density['mafic_volcanic_max'] - material_density['mafic_volcanic_min']) * fraction_of_lifetime
total_thickness = (saved.crust_layers['mafic_volcanic'] + saved.crust_layers['mafic_plutonic']) / mafic_density
for rocktype, density in material_density.items():
if rocktype in saved.crust_layers:
total_thickness += saved.crust_layers[rocktype] / density
return total_thickness
fraction_of_lifetime = saved.crust_layers['age'] / 7889537440886400.0
mafic_density = material_density['mafic_volcanic_min'] + (
material_density['mafic_volcanic_max'] -
material_density['mafic_volcanic_min']) * fraction_of_lifetime
total_thickness = (saved.crust_layers['mafic_volcanic'] +
saved.crust_layers['mafic_plutonic']) / mafic_density
for rocktype, density in material_density.items():
if rocktype in saved.crust_layers:
total_thickness += saved.crust_layers[rocktype] / density
return total_thickness
if time.monotonic() - last_rendered > 15:
outputs = m(inputs)
image = tensor_to_surface(tf.math.multiply(255, colourize_heightmap(tf.reshape(outputs, (512, 1024, outputs.shape[1])))))
sdl2.SDL_BlitSurface(image, None, windowsurface, None)
last_rendered = time.monotonic()
sdl2.SDL_FreeSurface(image)
events = sdl2.ext.get_events()
for event in events:
if event.type == sdl2.SDL_QUIT:
running = False
break
elif event.type == sdl2.SDL_MOUSEBUTTONUP:
point = list(inputs[event.button.y * 1024 + event.button.x].numpy())
solid_angle = landmass_steradians(tf.reshape(outputs, (512,1024,1)), event.button.x, event.button.y)
print('Clicked land mass: %s square Km | %s square miles' % (solid_angle * planet_radius_km**2, solid_angle * planet_radius_miles**2))
if last_clicked != None:
dug = math.sqrt(sum(map((lambda p: (p[0]-p[1])**2), zip(last_clicked, point))))
arc = math.acos(1 - dug**2 / 2) # cosine rule, a == b == 1
print('%s Km | %s miles' % (arc * planet_radius_km, arc * planet_radius_miles))
print(point)
last_clicked = point
window.refresh()
if time.monotonic() - last_rendered > 15:
outputs = m(inputs)
image = tensor_to_surface(
tf.math.multiply(
255,
colourize_heightmap(
tf.reshape(outputs, (512, 1024, outputs.shape[1])))))
sdl2.SDL_BlitSurface(image, None, windowsurface, None)
last_rendered = time.monotonic()
sdl2.SDL_FreeSurface(image)
events = sdl2.ext.get_events()
for event in events:
if event.type == sdl2.SDL_QUIT:
running = False
break
elif event.type == sdl2.SDL_MOUSEBUTTONUP:
point = list(inputs[event.button.y * 1024 + event.button.x].numpy())
solid_angle = landmass_steradians(tf.reshape(outputs, (512, 1024, 1)),
event.button.x, event.button.y)
print('Clicked land mass: %s square Km | %s square miles' %
(solid_angle * planet_radius_km**2,
solid_angle * planet_radius_miles**2))
if last_clicked != None:
dug = math.sqrt(
sum(map((lambda p: (p[0] - p[1])**2), zip(last_clicked, point))))
arc = math.acos(1 - dug**2 / 2) # cosine rule, a == b == 1
print('%s Km | %s miles' %
(arc * planet_radius_km, arc * planet_radius_miles))
print(point)
last_clicked = point
window.refresh()
n = numpy.zeros((height, width, 3), numpy.float64)
helpers.equirectangular(ctypes.cast(ctypes.c_voidp(n.ctypes.data), ctypes.POINTER(ctypes.c_double)), ctypes.c_int(width), ctypes.c_int(height))
return tf.constant(n)
n = numpy.zeros((height, width, 3), numpy.float64)
helpers.equirectangular(
ctypes.cast(ctypes.c_voidp(n.ctypes.data),
ctypes.POINTER(ctypes.c_double)), ctypes.c_int(width),
ctypes.c_int(height))
return tf.constant(n)
shape = source.shape
source = tf.cast(source, tf.uint8).numpy()
return helpers.render_tensor(ctypes.c_void_p(source.ctypes.data), ctypes.c_int(shape[1]), ctypes.c_int(shape[0]), ctypes.c_int(shape[2]))
shape = source.shape
source = tf.cast(source, tf.uint8).numpy()
return helpers.render_tensor(ctypes.c_void_p(source.ctypes.data),
ctypes.c_int(shape[1]), ctypes.c_int(shape[0]),
ctypes.c_int(shape[2]))
shape = source.shape
n = numpy.zeros((shape[0],shape[1],3), numpy.float64)
source = tf.cast(source, tf.float64).numpy()
helpers.colourize_heightmap(ctypes.cast(ctypes.c_voidp(n.ctypes.data), ctypes.POINTER(ctypes.c_double)), ctypes.cast(ctypes.c_voidp(source.ctypes.data), ctypes.POINTER(ctypes.c_double)), ctypes.c_int(shape[1]), ctypes.c_int(shape[0]))
return tf.constant(n)
shape = source.shape
n = numpy.zeros((shape[0], shape[1], 3), numpy.float64)
source = tf.cast(source, tf.float64).numpy()
helpers.colourize_heightmap(
ctypes.cast(ctypes.c_voidp(n.ctypes.data),
ctypes.POINTER(ctypes.c_double)),
ctypes.cast(ctypes.c_voidp(source.ctypes.data),
ctypes.POINTER(ctypes.c_double)), ctypes.c_int(shape[1]),
ctypes.c_int(shape[0]))
return tf.constant(n)
shape = source.shape
source = tf.cast(source, tf.float64).numpy()
return helpers.landmass_steradians(ctypes.cast(ctypes.c_voidp(source.ctypes.data), ctypes.POINTER(ctypes.c_double)), ctypes.c_int(shape[1]), ctypes.c_int(shape[0]), ctypes.c_int(x), ctypes.c_int(y))
shape = source.shape
source = tf.cast(source, tf.float64).numpy()
return helpers.landmass_steradians(
ctypes.cast(ctypes.c_voidp(source.ctypes.data),
ctypes.POINTER(ctypes.c_double)), ctypes.c_int(shape[1]),
ctypes.c_int(shape[0]), ctypes.c_int(x), ctypes.c_int(y))
source = simsave.SimResult(open(filename, 'r'))
training_data = model.training_data(source)
m.fit(x=training_data[0], y=training_data[1], batch_size=100, epochs=5000)
tfjs.converters.save_keras_model(m, 'tfjs_model')
source = simsave.SimResult(open(filename, 'r'))
training_data = model.training_data(source)
m.fit(x=training_data[0], y=training_data[1], batch_size=100, epochs=5000)
tfjs.converters.save_keras_model(m, 'tfjs_model')
inputs = tf.reshape(drawmap.inputs_equirectangular(2048,1024), (2048 * 1024, 3))
outputs = tf.reshape(m(inputs), (1024,2048, 1))
outputs = tf.cast(drawmap.colourize_heightmap(outputs) * 255, tf.uint8)
outputs = tf.io.encode_png(outputs).numpy()
f = open("map.png", 'wb')
f.write(outputs)
f.close()
inputs = tf.reshape(drawmap.inputs_equirectangular(2048, 1024),
(2048 * 1024, 3))
outputs = tf.reshape(m(inputs), (1024, 2048, 1))
outputs = tf.cast(drawmap.colourize_heightmap(outputs) * 255, tf.uint8)
outputs = tf.io.encode_png(outputs).numpy()
f = open("map.png", 'wb')
f.write(outputs)
f.close()
m = model.model()
m.compile(
optimizer=keras.optimizers.RMSprop(),
loss=model.shore_focused_loss
)
bg_thread = threading.Thread(target=train, args=(m, sys.argv[1]), kwargs={})
bg_thread.start()
drawmap.run(m)
bg_thread.join()
m = model.model()
m.compile(optimizer=keras.optimizers.RMSprop(),
loss=model.shore_focused_loss)
bg_thread = threading.Thread(target=train, args=(m, sys.argv[1]), kwargs={})
bg_thread.start()
drawmap.run(m)
bg_thread.join()