forked from mathuin/TopoMC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crust.py
29 lines (24 loc) · 1.06 KB
/
crust.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# crust module
import numpy as np
from itertools import product
from random import randint, uniform
from idt import IDT
class Crust(object):
"""Smoothly irregular crust between the surface and the underlying stone."""
# these constants chosen by observation
minwidth = 1
maxwidth = 5
coverage = 0.05
def __init__(self, xsize, zsize, wantCL=True):
xsize = xsize
zsize = zsize
wantCL = wantCL
numcoords = int(xsize * zsize * Crust.coverage)
self.shape = (zsize, xsize)
coords = np.array([(randint(0, zsize-1), randint(0, xsize-1)) for dummy in xrange(numcoords)], dtype=np.float32)
values = np.array([uniform(Crust.minwidth, Crust.maxwidth) for elem in xrange(numcoords)], dtype=np.int32)
self.base = np.array([(z, x) for z, x in product(xrange(zsize), xrange(xsize))], dtype=np.float32)
self.idt = IDT(coords, values, wantCL=wantCL)
def __call__(self, pickle_name=None):
retval = self.idt(self.base, self.shape, majority=False, pickle_name=pickle_name)
return retval