def test_indexing(): from dials.algorithms.profile_model.modeller import GridSampler width = 1000 height = 1000 scan_range = (2, 12) nx = 10 ny = 10 nz = 2 sampler = GridSampler((width, height), scan_range, (nx, ny, nz)) xstep, ystep, zstep = sampler.step_size() xind = [[i for i in range(nx)]] * ny * nz yind = [[j] * nx for j in range(ny)] * nz zind = [[k] * nx * ny for k in range(nz)] xind = [i for j in xind for i in j] yind = [i for j in yind for i in j] zind = [i for j in zind for i in j] xp = [(x + 0.5) * xstep for x in xind] yp = [(y + 0.5) * ystep for y in yind] zp = [(z + 0.5) * zstep + scan_range[0] for z in zind] eps = 1e-10 for x0, y0, z0, i in zip(xp, yp, zp, range(len(sampler))): x1, y1, z1 = sampler.coord(i) assert abs(x0 - x1) <= eps assert abs(y0 - y1) <= eps assert abs(z0 - z1) <= eps
def tst_indexing(self): from dials.algorithms.profile_model.modeller import GridSampler width = 1000 height = 1000 scan_range = (2, 12) depth = scan_range[1] - scan_range[0] nx = 10 ny = 10 nz = 2 sampler = GridSampler((width, height), scan_range, (nx, ny, nz)) xstep, ystep, zstep = sampler.step_size() xind = [[i for i in range(nx)]] * ny * nz yind = [[j] * nx for j in range(ny)] * nz zind = [[k] * nx * ny for k in range(nz)] xind = [i for j in xind for i in j] yind = [i for j in yind for i in j] zind = [i for j in zind for i in j] xp = [(x + 0.5) * xstep for x in xind] yp = [(y + 0.5) * ystep for y in yind] zp = [(z + 0.5) * zstep + scan_range[0] for z in zind] eps = 1e-10 for x0, y0, z0, i in zip(xp, yp, zp, range(len(sampler))): x1, y1, z1 = sampler.coord(i) assert(abs(x0 - x1) <= eps) assert(abs(y0 - y1) <= eps) assert(abs(z0 - z1) <= eps) print 'OK'
def test_self_consistent(): from dials.algorithms.profile_model.modeller import GridSampler width = 1000 height = 1000 scan_range = (2, 12) nx = 10 ny = 10 nz = 2 sampler = GridSampler((width, height), scan_range, (nx, ny, nz)) for i in range(len(sampler)): coord = sampler.coord(i) index = sampler.nearest(0, coord) assert index == i
def tst_self_consistent(self): from dials.algorithms.profile_model.modeller import GridSampler width = 1000 height = 1000 scan_range = (2, 12) depth = scan_range[1] - scan_range[0] nx = 10 ny = 10 nz = 2 sampler = GridSampler((width, height), scan_range, (nx, ny, nz)) for i in range(len(sampler)): coord = sampler.coord(i) index = sampler.nearest(coord) assert(index == i) print 'OK'
def test_weights(): from scitbx import matrix from dials.algorithms.profile_model.modeller import GridSampler width = 1000 height = 1000 scan_range = (2, 12) nx = 10 ny = 10 nz = 2 sampler = GridSampler((width, height), scan_range, (nx, ny, nz)) # Check the weight at the coord in 1.0 eps = 1e-7 for i in range(len(sampler)): coord = sampler.coord(i) weight = sampler.weight(i, 0, coord) assert abs(weight - 1.0) < eps # Ensure we get the expected weight at the next grid point at half way # between grid points expected = math.exp(-4.0 * math.log(2.0)) for k in range(nz): for j in range(ny): for i in range(nx): l1 = (i + 0) + ((j + 0) + (k + 0) * ny) * nx l2 = (i + 1) + ((j + 0) + (k + 0) * ny) * nx l3 = (i - 1) + ((j + 0) + (k + 0) * ny) * nx l4 = (i + 0) + ((j + 1) + (k + 0) * ny) * nx l5 = (i + 0) + ((j - 1) + (k + 0) * ny) * nx l6 = (i + 0) + ((j + 0) + (k + 1) * ny) * nx l7 = (i + 0) + ((j + 0) + (k - 1) * ny) * nx coord1 = matrix.col(sampler.coord(l1)) if i < nx - 1: coord = matrix.col(sampler.coord(l2)) weight = sampler.weight(l1, 0, coord) assert abs(weight - expected) < eps weight = sampler.weight(l1, 0, (coord + coord1) / 2.0) assert abs(weight - 0.5) < eps if i > 0: coord = matrix.col(sampler.coord(l3)) weight = sampler.weight(l1, 0, coord) assert abs(weight - expected) < eps weight = sampler.weight(l1, 0, (coord1 + coord) / 2.0) assert abs(weight - 0.5) < eps if j < ny - 1: coord = matrix.col(sampler.coord(l4)) weight = sampler.weight(l1, 0, coord) assert abs(weight - expected) < eps weight = sampler.weight(l1, 0, (coord + coord1) / 2.0) assert abs(weight - 0.5) < eps if j > 0: coord = matrix.col(sampler.coord(l5)) weight = sampler.weight(l1, 0, coord) assert abs(weight - expected) < eps weight = sampler.weight(l1, 0, (coord1 + coord) / 2.0) assert abs(weight - 0.5) < eps if k < nz - 1: coord = matrix.col(sampler.coord(l6)) weight = sampler.weight(l1, 0, coord) assert abs(weight - expected) < eps weight = sampler.weight(l1, 0, (coord + coord1) / 2.0) assert abs(weight - 0.5) < eps if k > 0: coord = matrix.col(sampler.coord(l7)) weight = sampler.weight(l1, 0, coord) assert abs(weight - expected) < eps weight = sampler.weight(l1, 0, (coord1 + coord) / 2.0) assert abs(weight - 0.5) < eps
def tst_weights(self): from dials.algorithms.profile_model.modeller import GridSampler from scitbx import matrix from math import log, exp width = 1000 height = 1000 scan_range = (2, 12) depth = scan_range[1] - scan_range[0] nx = 10 ny = 10 nz = 2 sampler = GridSampler((width, height), scan_range, (nx, ny, nz)) # Check the weight at the coord in 1.0 eps = 1e-7 for i in range(len(sampler)): coord = sampler.coord(i) weight = sampler.weight(i, coord) assert(abs(weight - 1.0) < eps) # Ensure we get the expected weight at the next grid point at half way # between grid points expected = exp(-4.0 * log(2.0)) for k in range(nz): for j in range(ny): for i in range(nx): l1 = (i + 0) + ((j + 0) + (k + 0) * ny) * nx l2 = (i + 1) + ((j + 0) + (k + 0) * ny) * nx l3 = (i - 1) + ((j + 0) + (k + 0) * ny) * nx l4 = (i + 0) + ((j + 1) + (k + 0) * ny) * nx l5 = (i + 0) + ((j - 1) + (k + 0) * ny) * nx l6 = (i + 0) + ((j + 0) + (k + 1) * ny) * nx l7 = (i + 0) + ((j + 0) + (k - 1) * ny) * nx coord1 = matrix.col(sampler.coord(l1)) if i < nx-1: coord = matrix.col(sampler.coord(l2)) weight = sampler.weight(l1, coord) assert(abs(weight - expected) < eps) weight = sampler.weight(l1, ( coord + coord1 )/2.0) assert(abs(weight - 0.5) < eps) if i > 0: coord = matrix.col(sampler.coord(l3)) weight = sampler.weight(l1, coord) assert(abs(weight - expected) < eps) weight = sampler.weight(l1, ( coord1 + coord )/2.0) assert(abs(weight - 0.5) < eps) if j < ny-1: coord = matrix.col(sampler.coord(l4)) weight = sampler.weight(l1, coord) assert(abs(weight - expected) < eps) weight = sampler.weight(l1, ( coord + coord1 )/2.0) assert(abs(weight - 0.5) < eps) if j > 0: coord = matrix.col(sampler.coord(l5)) weight = sampler.weight(l1, coord) assert(abs(weight - expected) < eps) weight = sampler.weight(l1, ( coord1 + coord )/2.0) assert(abs(weight - 0.5) < eps) if k < nz-1: coord = matrix.col(sampler.coord(l6)) weight = sampler.weight(l1, coord) assert(abs(weight - expected) < eps) weight = sampler.weight(l1, ( coord + coord1 )/2.0) assert(abs(weight - 0.5) < eps) if k > 0: coord = matrix.col(sampler.coord(l7)) weight = sampler.weight(l1, coord) assert(abs(weight - expected) < eps) weight = sampler.weight(l1, ( coord1 + coord )/2.0) assert(abs(weight - 0.5) < eps) print 'OK'