Пример #1
0
 def pad_mapByPixel(self, lessI, moreI, lessJ, moreJ, lessK, moreK):
     lessI = int(lessI)
     moreI = int(moreI)
     lessJ = int(lessJ)
     moreJ = int(moreJ)
     lessK = int(lessK)
     moreK = int(moreK)
     assert lessI >= 0
     assert moreI >= 0
     assert lessJ >= 0
     assert moreJ >= 0
     assert lessK >= 0
     assert moreK >= 0
     #
     tmp = self._new()
     tmp.nxstart = self.nxstart - (lessI + moreI - 1)
     tmp.nystart = self.nystart - (lessJ + moreJ - 1)
     tmp.nzstart = self.nzstart - (lessK + moreK - 1)
     tmp.ncstart = tmp.nxstart
     tmp.nrstart = tmp.nystart
     tmp.nsstart = tmp.nzstart
     #
     chargeArray3d = ext.padZero(self.chargeArray3d, lessI, moreI, lessJ, moreJ, lessK, moreK)
     tmp.lx, tmp.ly, tmp.lz = chargeArray3d.shape
     tmp.nc, tmp.nr, tmp.ns = chargeArray3d.shape
     tmp.chargeArray = chargeArray3d.flatten('F')
     #
     tmp.cartArray = ext.build_cart(tmp.lx, tmp.ly, tmp.lz,
                                     tmp.nxstart, tmp.nystart, tmp.nzstart,
                                     tmp.xres, tmp.yres, tmp.zres)
     #
     return tmp
Пример #2
0
def combine_maps(emap1, emap2):
    """
    Loop over all the grid points of emap1, and interpolate them into grid points of emap2.
    """
    # (1) Find Min/Max cartesian values of emap1 and emap2
    xm1, ym1, zm1 = emap1.cartArray.min(axis=0)
    xm2, ym2, zm2 = emap2.cartArray.min(axis=0)
    #
    xmin = xm1 if xm1 < xm2 else xm2
    ymin = ym1 if ym1 < ym2 else ym2
    zmin = zm1 if zm1 < zm2 else zm2
    #
    xm1, ym1, zm1 = emap1.cartArray.max(axis=0)
    xm2, ym2, zm2 = emap2.cartArray.max(axis=0)
    #
    xmax = xm1 if xm1 > xm2 else xm2
    ymax = ym1 if ym1 > ym2 else ym2
    zmax = zm1 if zm1 > zm2 else zm2

    # (2) create valid metadata
    newmap = emap2._new()

    newmap.nxstart = np.int(np.floor(xmin/emap2.xres)) - 1
    newmap.nystart = np.int(np.floor(ymin/emap2.yres)) - 1
    newmap.nzstart = np.int(np.floor(zmin/emap2.zres)) - 1
    newmap.lx = np.int(np.ceil(xmax/emap2.xres)) - newmap.nxstart + 1
    newmap.ly = np.int(np.ceil(ymax/emap2.yres)) - newmap.nystart + 1
    newmap.lz = np.int(np.ceil(zmax/emap2.zres)) - newmap.nzstart + 1

    newmap.nc = newmap.lx
    newmap.nr = newmap.ly
    newmap.ns = newmap.lz
    newmap.ncstart = newmap.nxstart
    newmap.nrstart = newmap.nystart
    newmap.nsstart = newmap.nzstart

    # (3) Create a new blank 3d array using the min/max cartesian values
    # (4) copy data from emap2
    lessX = emap2.nxstart - newmap.nxstart
    moreX = newmap.lx + newmap.nxstart - (emap2.lx + emap2.nxstart)
    lessY = emap2.nystart - newmap.nystart
    moreY = newmap.ly + newmap.nystart - (emap2.ly + emap2.nystart)
    lessZ = emap2.nzstart - newmap.nzstart
    moreZ = newmap.lz + newmap.nzstart - (emap2.lz + emap2.nzstart)

    chargeArray = ext.padZero(emap2.chargeArray3d,
                            lessX, moreX, lessY, moreY, lessZ, moreZ)
    newmap.cartArray = ext.build_cart(newmap.lx, newmap.ly, newmap.lz,
                                       newmap.nxstart, newmap.nystart, newmap.nzstart,
                                       newmap.xres, newmap.yres, newmap.zres)

    # (5) interpolate data from emap1
    newmap.chargeArray = ext.interpolate(emap1.cartArray, emap1.chargeArray, chargeArray,
                            newmap.xres, newmap.yres, newmap.zres).flatten('F')

    return newmap
Пример #3
0
def get_lap(emap):
    rho_1 = ext.padZero(emap.chargeArray3d, 1, 1, 1, 1, 1, 1)
    tmpArray = np.zeros(emap.lx * emap.ly * emap.lz, dtype=np.float64)
    iterator = ( (i, j, k) for k in xrange(1, 1+emap.lz)
                for j in xrange(1, 1+emap.ly) for i in xrange(1, 1+emap.lx) )
    for n, (i, j, k) in enumerate(iterator):
        tmp = np.float64(0)
        tmp += rho_1[i+1, j, k]
        tmp += rho_1[i-1, j, k]
        tmp += rho_1[i, j+1, k]
        tmp += rho_1[i, j-1, k]
        tmp += rho_1[i, j, k+1]
        tmp += rho_1[i, j, k-1]
        tmp -= 6*rho_1[i, j, k]
        tmpArray[n] = tmp
    return tmpArray
Пример #4
0
def get_core(emap):
    # initialize
    chargeMatrix = emap.chargeArray3d
    lapMatrix = emap.laplacianArray3d
    rhocut = emap.rhocut
    tmpArray = np.ones((emap.lx-2, emap.ly-2, emap.lz-2), dtype=np.int)
    tmpArray = ext.padZero(tmpArray, 1)
    #
    def minF(i, j, k):
        tmp = []
        tmp.append(tmpArray[i+1, j, k])
        tmp.append(tmpArray[i-1, j, k])
        tmp.append(tmpArray[i, j+1, k])
        tmp.append(tmpArray[i, j-1, k])
        tmp.append(tmpArray[i, j, k+1])
        tmp.append(tmpArray[i, j, k-1])
        return min(tmp)
    #
    iteration = 1
    while True:
        print "Iteration: %d" % iteration
        nextArray = tmpArray.copy()
        iterator = ( (i, j, k) for k in xrange(1, emap.lz-1) for j in xrange(1, emap.ly-1) for i in xrange(1, emap.lx-1) )
        for i, j, k in iterator:
            if chargeMatrix[i, j, k] <= rhocut and minF(i, j, k) == 0:
                nextArray[i, j, k] = 0
            elif lapMatrix[i, j, k] > 0 and minF(i, j, k) == 0:
                nextArray[i, j, k] = 0
            else:
                nextArray[i, j, k] = minF(i, j, k) + 1
        #
        if (tmpArray == nextArray).all():
            return tmpArray.flatten('F')
        else:
            iteration += 1
            tmpArray = nextArray