Esempio n. 1
0
def n2eap(nVectors, flip=True):
    """
    unit vectors to equal-area projection
    """
    nVecs = copy.deepcopy(nVectors)
    nPnts = nVectors.shape[1]
    retval = getMem((2, nPnts))

    belowEquator, = num.where(nVecs[2, :] < -1e-4)
    if len(belowEquator) > 0:
        if flip:
            nVecs[:, belowEquator] = -nVecs[:, belowEquator]
        else:
            'put on the equator'
            nVecs[2, belowEquator] = 0.
            # num.apply_along_axis(num.linalg.norm, 0, nVecs[0:2,belowEquator])
            norms = num.sqrt(nVecs[0, belowEquator] * nVecs[0, belowEquator] +
                             nVecs[1, belowEquator] * nVecs[1, belowEquator])
            nVecs[0:2, belowEquator] = nVecs[0:2, belowEquator] / norms

    r2 = nVecs[0, :] * nVecs[0, :] + nVecs[1, :] * nVecs[1, :]
    r2pos = num.where(r2 > 0.)

    n31 = 1.0 - num.abs(nVecs[2, :])

    den = num.ones(nPnts)
    den[r2pos] = num.sqrt(2.0 * r2[r2pos])

    dist_np = num.zeros(nPnts)
    dist_np = num.sqrt(r2 + n31 * n31) / den

    retval = num.vstack((nVecs[0, :] * dist_np, nVecs[1, :] * dist_np))  # .T

    return retval
Esempio n. 2
0
def n2eap(nVectors, flip=True):
    """
    unit vectors to equal-area projection
    """
    nVecs = copy.deepcopy(nVectors)
    nPnts = nVectors.shape[1]
    retval = getMem((2,nPnts))
    
    belowEquator, = num.where(nVecs[2,:] < -1e-4)
    if len(belowEquator) > 0:
        if flip:
            nVecs[:,belowEquator] = -nVecs[:,belowEquator]
        else:
            'put on the equator'
            nVecs[2,belowEquator] = 0.
            # num.apply_along_axis(num.linalg.norm, 0, nVecs[0:2,belowEquator])
            norms = num.sqrt( nVecs[0,belowEquator]*nVecs[0,belowEquator] + nVecs[1,belowEquator]*nVecs[1,belowEquator] )
            nVecs[0:2,belowEquator] = nVecs[0:2,belowEquator] / norms
    
    r2    = nVecs[0,:]*nVecs[0,:] + nVecs[1,:]*nVecs[1,:]
    r2pos = num.where(r2 > 0.)

    n31 = 1.0 - num.abs(nVecs[2,:])

    den        = num.ones(nPnts)
    den[r2pos] = num.sqrt(2.0*r2[r2pos])

    dist_np = num.zeros(nPnts)
    dist_np = num.sqrt(r2 + n31*n31) / den

    retval = num.vstack((nVecs[0,:] * dist_np, nVecs[1,:] * dist_np)) # .T

    return retval
Esempio n. 3
0
def n2sph(nVectors):
    assert nVectors.shape[0] == 3, 'shape[0] not 3'
    sph = arrayutil.getMem((2, nVectors.shape[1]))
    for iVector in range(nVectors.shape[1]):
        x = nVectors[0, iVector]
        y = nVectors[1, iVector]
        z = nVectors[2, iVector]
        r = sqrt(x * x + y * y)
        sph[0, iVector] = atan2(r, z)
        sph[1, iVector] = atan2(y, x)
    return sph
Esempio n. 4
0
def n2sph(nVectors):
    assert nVectors.shape[0] == 3, 'shape[0] not 3'
    sph = arrayutil.getMem((2,nVectors.shape[1]))
    for iVector in range(nVectors.shape[1]):
        x = nVectors[0,iVector]
        y = nVectors[1,iVector]
        z = nVectors[2,iVector]
        r = sqrt(x*x+y*y)
        sph[0,iVector] = atan2(r,z)
        sph[1,iVector] = atan2(y,x)
    return sph
Esempio n. 5
0
def sph2n(coords_sph):
    '''convert from chi/eta spherical coordinates to normal vectors;
    can use with coords from femODF.FemHemisphere
    '''

    assert coords_sph.shape[0] == 2, 'shape[0] not 2'

    z = num.cos(coords_sph[0, :])
    rho = num.sin(coords_sph[0, :])
    x = rho * num.cos(coords_sph[1, :])
    y = rho * num.sin(coords_sph[1, :])

    # nVectors = arrayutil.toArray(num.vstack((x,y,z)))
    nVectors = getMem((3, coords_sph.shape[1]))
    nVectors[0, :] = x
    nVectors[1, :] = y
    nVectors[2, :] = z

    return nVectors
Esempio n. 6
0
def sph2n(coords_sph):
    '''convert from chi/eta spherical coordinates to normal vectors;
    can use with coords from femODF.FemHemisphere
    '''

    assert coords_sph.shape[0] == 2, 'shape[0] not 2'

    z   = num.cos(coords_sph[0,:])
    rho = num.sin(coords_sph[0,:])
    x = rho * num.cos(coords_sph[1,:])
    y = rho * num.sin(coords_sph[1,:])

    # nVectors = arrayutil.toArray(num.vstack((x,y,z)))
    nVectors = getMem((3,coords_sph.shape[1]))
    nVectors[0,:] = x
    nVectors[1,:] = y
    nVectors[2,:] = z

    return nVectors