smbinterp/interp/grid/DD.py

58 lines
1.3 KiB
Python
Raw Normal View History

2011-03-23 10:15:05 -07:00
from interp.grid.delaunay import dgrid as basegrid
from interp.tools import baker_exact_2D as exact_func
import numpy as np
class rect_grid(basegrid):
def __init__(self, xres = 5, yres = 5):
2011-05-20 11:40:25 -07:00
xmin = 0.0
xmax = 1.0
xspan = xmax - xmin
xdel = xspan / float(xres - 1)
2011-05-20 11:40:25 -07:00
ymin = 0.0
ymay = 1.0
yspan = ymay - ymin
ydel = yspan / float(yres - 1)
2010-10-23 16:06:57 -07:00
verts = []
2011-05-19 14:44:21 -07:00
q = np.zeros( xres * yres )
for x in xrange(xres):
cur_x = xmin + (x * xdel)
for y in xrange(yres):
cur_y = ymin + (y * ydel)
2010-10-23 16:06:57 -07:00
verts.append([cur_x, cur_y])
2011-05-20 11:40:25 -07:00
2011-03-23 23:27:30 -07:00
basegrid.__init__(self, verts, q)
class random_grid(rect_grid):
2010-10-23 16:06:57 -07:00
def __init__(self, num_verts = 10):
verts = []
2010-10-23 16:06:57 -07:00
appx_side_res = int(np.sqrt(num_verts))
delta = 1.0 / float(appx_side_res)
verts.append([0,0])
verts.append([1,0])
verts.append([0,1])
verts.append([1,1])
for x in xrange(1,appx_side_res):
cur_x = x * delta
for cur_y in (0, 1):
new_point = [cur_x, cur_y]
2010-10-23 16:06:57 -07:00
verts.append(new_point)
for y in xrange(1,appx_side_res):
cur_y = y * delta
for cur_x in (0, 1):
new_point = [cur_x, cur_y]
2010-10-23 16:06:57 -07:00
verts.append(new_point)
verts.extend(np.random.random((num_verts - 4*appx_side_res, 2)))
q = np.zeros(len(verts))
basegrid.__init__(self, np.array(verts), q)