def test_SHRotations(): # ---- input parameters ---- lmax = 3 alpha, beta, gamma = 20.0, 90.0, 90.0 # ---- derived parameters ---- mask = np.zeros((2, lmax + 1, lmax + 1), dtype=np.bool) for l in np.arange(lmax + 1): mask[:, l, : l + 1] = True mask[1, :, 0] = False angles = np.radians([alpha, beta, gamma]) print "\n---- testing djpi2 ----" print "computing rotation matrix for Euler angles: ({:2.2f},{:2.2f},{:2.2f})".format(alpha, beta, gamma) dj_matrix = shtools.djpi2(lmax) print "\n---- testing SHRotateRealCoef ----" print "generating normal distributed complex coefficients with variance 1..." rcoeffs = np.random.normal(size=2 * (lmax + 1) * (lmax + 1)).reshape(2, lmax + 1, lmax + 1) rcoeffs[np.invert(mask)] = 0.0 rcoeffs_rot = shtools.SHRotateRealCoef(rcoeffs, angles, dj_matrix) print rcoeffs_rot print "\n---- testing SHRotateCoef ----" print "generating normal distributed complex coefficients with variance 1..." ccoeffs = np.random.normal(loc=0.0, scale=1.0, size=(lmax + 1) * (lmax + 2)) ccoeffs = ccoeffs.reshape(2, (lmax + 1) * (lmax + 2) / 2) ccoeffs_rot = shtools.SHRotateCoef(angles, ccoeffs, dj_matrix) print ccoeffs_rot
def rotateHarmonics(self, harmonics, thetaZ0, thetaY, thetaZ1, maxL=None): if maxL is None: maxL = self.maxL rotMatrix = psh.djpi2(maxL) rotHarm = psh.SHRotateRealCoef(harmonics, np.array([-thetaZ1, -thetaY, -thetaZ0]), rotMatrix) return rotHarm
def SHRotations(coeff): #---- input parameters ----# lmax = 8 #order of the SH alpha, beta, gamma = 159., 80., 145. #angles for rotation #--derived parameters --# angles = np.radians([alpha, beta, gamma]) dj_matrix = shtools.djpi2(lmax) return shtools.SHRotateRealCoef(coeff, angles, dj_matrix)
def main(): edgeLen = 2 * radPixels + 1 rMax = float(radPixels) transformer = SHTransformer(edgeLen, maxL) # baseName = 'block' # vId = 5619494 baseName = 'synth' vId = 0 yamlDict = parseBlock(vId, edgeLen, baseName=baseName) sampler = BlockSampler(yamlDict) byteCube = sampler.sample(None) assert byteCube.shape == (edgeLen, edgeLen, edgeLen), 'wrong size cube' doubleCube = np.require(byteCube, dtype=np.double, requirements=['C']) zMat = np.outer(np.cos(transformer.thetaglq), np.ones_like(transformer.phiglq)) xMat = np.outer(np.sin(transformer.thetaglq), np.cos(transformer.phiglq)) yMat = np.outer(np.sin(transformer.thetaglq), np.sin(transformer.phiglq)) edgeMat = np.zeros((len(transformer.thetaglq), len(transformer.phiglq)), dtype=np.float64) for edge in yamlDict['edges']: cosMat = (xMat * edge[0]) + (yMat * edge[1]) + (zMat * edge[2]) edgeMat += np.power(cosMat, 20.0) samples = transformer.calcSphereOfSamples(doubleCube, rMax) harmonics = transformer.calcHarmonics(doubleCube, rMax) unRotReconSamples = transformer.reconstructSamples(harmonics) rotMatrix = psh.djpi2(maxL) thetaZ0, thetaY, thetaZ1 = yamlDict['eulerZYZ'] rotClim = psh.SHRotateRealCoef(harmonics, np.array([-thetaZ1, -thetaY, -thetaZ0]), rotMatrix) reconHarm = transformer.reconstructSamples(rotClim) edgeHarm = psh.SHExpandGLQ(edgeMat, transformer.weights, transformer.nodes) rotEdgeHarm = psh.SHRotateRealCoef(edgeHarm, np.array([-thetaZ1, -thetaY, -thetaZ0]), rotMatrix) rotEdge = transformer.reconstructSamples(rotEdgeHarm) plotSphere(transformer.thetaglq, transformer.phiglq, { 'samples': samples.transpose(), 'unrotated': unRotReconSamples.transpose(), 'rotated': reconHarm.transpose(), 'unrotEdges': edgeMat.transpose(), 'rotEdges': rotEdge.transpose() }, fname="%s_%d_spheres.vtk" % (baseName, vId))
weights = numpy.ones(stacks[0].shape) for j in range(0, weights.shape[0]): angle = j * (180.0 / float(weights.shape[0])) * numpy.pi / 180.0 weights[j, :] *= -2 * numpy.pi * (numpy.cos(angle + (180.0 / float(weights.shape[0])) * numpy.pi / 180.0) - numpy.cos(angle))#numpy.max(histogram[i, :]) #weights /= sum(weights.flatten()) hist, bins, patches = plt.hist(stacks[0].flatten(), weights = weights.flatten(), bins = 250) plt.show() plt.imshow(stacks[0]) plt.show() #bincenters = 0.5 * (bin_edges[1:] + bin_edges[:-1]) #plt.bar(bincenters, hist, align='center') #%% dj = pyshtools.djpi2(90) #%% thetas, phis, Ntheta, Nphi = pyshtools.GLQGridCoord(histogram.shape[0] - 1) phis = numpy.linspace(0, 360, histogram.shape[1], endpoint = False) thetas, phis = numpy.meshgrid(90 - thetas, phis, indexing = 'ij') xs = numpy.sin(numpy.pi * thetas / 180.0) * numpy.cos(numpy.pi * phis / 180.0) ys = numpy.sin(numpy.pi * thetas / 180.0) * numpy.sin(numpy.pi * phis / 180.0) zs = numpy.cos(numpy.pi * thetas / 180.0) #ys = numpy.sin(numpy.pi * thetas / 180.0) #zs = numpy.cos(numpy.pi * thetas / 180.0) xx = pyshtools.SHExpandDH(ys * ys + zs * zs, sampling = 2) yy = pyshtools.SHExpandDH(xs * xs + zs * zs, sampling = 2)