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
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
def _processCartData(cls): """ 67 ms """ tmp = cls.map # build cartesian data tmp._cartArray = ext.build_cart(tmp.lx, tmp.ly, tmp.lz, tmp.nxstart, tmp.nystart, tmp.nzstart, tmp.xres, tmp.yres, tmp.zres) if tmp.alpha != np.pi/2 or tmp.beta != np.pi/2 or tmp.gamma != np.pi/2: # skew matrix (un-tested) cg = np.cos(tmp.gamma) sg = np.sin(tmp.gamma) cb = np.cos(tmp.beta) sb = np.sin(tmp.beta) ca = np.cos(tmp.alpha) sa = np.sin(tmp.alpha) skew = np.array([(1, cg, cb), (0, sg, sb * ca), (0, 0, sb * sa)], dtype=np.float64) # tmp._cartArray = np.dot(tmp._cartArray, skew.T)