Ejemplo n.º 1
0
def TimingAccuracyGLQ():
    #---- input parameters ----
    maxdeg = 2800
    ls = np.arange(maxdeg + 1)
    beta = -1.5

    #---- create mask to filter out m<=l ----
    mask = np.zeros(2 * (maxdeg + 1) * (maxdeg + 1),
                    dtype=np.bool).reshape(2, maxdeg + 1, maxdeg + 1)
    mask[0, 0, 0] = True
    for l in ls:
        mask[:, l, :l + 1] = True
    mask[1, :, 0] = False

    #---- create Gaussian powerlaw coefficients ----
    print 'creating {:d} random coefficients'.format(2 * (maxdeg + 1) *
                                                     (maxdeg + 1))
    random_numbers = np.random.normal(loc=0.,
                                      scale=1.,
                                      size=2 * (maxdeg + 1) * (maxdeg + 1))
    cilm = random_numbers.reshape(2, maxdeg + 1, maxdeg + 1)
    cilm[:, 1:, :] *= np.sqrt((ls[1:]**beta) / (2. * ls[1:] + 1.))[None, :,
                                                                   None]

    #---- time spherical harmonics transform for lmax set to increasing powers of 2 ----
    lmax = 2
    print 'lmax    maxerror    rms         tprecompute    tinverse    tforward'
    while lmax <= maxdeg:
        # trim coefficients to lmax
        cilm_trim = cilm[:, :lmax + 1, :lmax + 1]
        mask_trim = mask[:, :lmax + 1, :lmax + 1]

        # precompute grid nodes and associated Legendre functions
        tstart = time.time()
        zeros, weights = shtools.SHGLQ(lmax)
        tend = time.time()
        tprecompute = tend - tstart

        #synthesis / inverse
        tstart = time.time()
        grid = shtools.MakeGridGLQ(cilm_trim, zeros)
        tend = time.time()
        tinverse = tend - tstart

        #analysis / forward
        tstart = time.time()
        cilm2_trim = shtools.SHExpandGLQ(grid, weights, zeros)
        tend = time.time()
        tforward = tend - tstart

        # compute error
        err = np.abs(cilm_trim[mask_trim] - cilm2_trim[mask_trim]) / np.abs(
            cilm_trim[mask_trim])
        maxerr = err.max()
        rmserr = np.mean(err**2)

        print '{:4d}    {:1.2e}    {:1.2e}    {:1.1e}s       {:1.1e}s    {:1.1e}s'.\
            format(lmax, maxerr, rmserr, tprecompute, tinverse, tforward)
        lmax = lmax * 2
Ejemplo n.º 2
0
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))
Ejemplo n.º 3
0
 def calcHarmonics(self, dataCube, radius, sig=(1.0, 1.0, 1.0), maxL=None):
     if maxL is None:
         maxL = self.maxL
     thetaglq, phiglq, nodes, weights = self.prepL(maxL)  # @UnusedVariable
     samps = self.calcSphereOfSamples(dataCube, radius, sig=sig, maxL=maxL)
     return psh.SHExpandGLQ(samps, weights, nodes)
Ejemplo n.º 4
0
 def expand(self, samps):
     _, _, nodes, weights = self.prepL(samps.shape[0] - 1)
     return psh.SHExpandGLQ(samps, weights, nodes)