Ejemplo 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 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
Ejemplo n.º 2
0
def drawLines(pw, pointLists=[], 
              netStyle = None, netNDiv = 12, netAlpha = 0.5, rMat=None, 
              southern=False, invertFromSouthern=True,
              origin=(0.,0.), r=1.0):
    
    x0, y0 = origin
    
    lines = pw.a.get_lines()
    for line in lines:
        line.remove()
    
    ringAngs = num.linspace(0,num.pi*2.,181)
    if netStyle:
        arcAngsM  = num.linspace(-num.pi/2.,num.pi/2.,91)
        arcAngsL  = num.linspace(0, num.pi, 181)
        rMat_yDiv = ors.RotInv(-num.pi/netNDiv, [0,1,0]).toMatrix()
    pw(r*num.cos(ringAngs)+x0,r*num.sin(ringAngs)+y0,style='k-')
    
    if netStyle:
        nVMerid = num.vstack( ( num.cos(arcAngsM), num.sin(arcAngsM), num.zeros(len(arcAngsM)) ) )
        for iDiv in range(netNDiv-1):
            nVMerid = num.dot(rMat_yDiv, nVMerid)
            eaProj = n2eap(nVMerid, flip=False)
            pw(r*eaProj[0,:]+x0, r*eaProj[1,:]+y0, alpha=netAlpha, style=netStyle)
        for latAng in num.pi/netNDiv*num.arange(1,netNDiv):
            polZ = num.cos(latAng)
            polR = num.sin(latAng)
            nVLat = num.vstack( ( polR*num.cos(arcAngsL), polZ*num.ones(len(arcAngsL)), polR*num.sin(arcAngsL)) )
            eaProj = n2eap(nVLat, flip=False)
            pw(r*eaProj[0,:]+x0, r*eaProj[1,:]+y0, alpha=netAlpha, style=netStyle)
    'done with drawing net'

    for points, pwKWArgs in pointLists:
        nVecs  = matrixUtils.unitVector(points)
        if rMat is not None:
            'rotate as did elsewhere'
            nVecs = num.dot(rMat, nVecs)
        bNVecsS = nVecs[2,:] < 0
        if southern:
            nVecsS = nVecs[:,bNVecsS]
            nVecsS = fromSouthern(nVecsS, invertFromSouthern)
            eaProj = n2eap(nVecsS, flip=False)
            pw(r*eaProj[0,:]+x0, r*eaProj[1,:]+y0, **pwKWArgs)
        else:
            nVecsN = nVecs[:,num.logical_not(bNVecsS)]
            eaProj = n2eap(nVecsN, flip=False)
            pw(r*eaProj[0,:]+x0, r*eaProj[1,:]+x0, **pwKWArgs)
    'done with pointLists'
    
    return