示例#1
0
def draw_MAP_residuals(objectsA, objectsB, P, scaled='no'):
    from pyBA.distortion import compute_displacements, compute_residual
    from numpy import array
    
    # Compute displacements between frames for tie objects
    xobs, yobs, vxobs, vyobs, sxobs, syobs = compute_displacements(objectsA, objectsB)

    # Compute residual
    dx, dy = compute_residual(objectsA, objectsB, P)

    # Draw residuals
    fig = figure(figsize=(16,16))
    ax = fig.add_subplot(111, aspect='equal')
    if scaled is 'yes':
        # Allow relative scaling of arrows
        quiver(xobs,yobs,dx,dy)
    else:
        # Show residuals in absolute size (often very tiny), with uncertainties

        # Also plot error ellipses
        ellipses = array([ Bivarg( mu = array([xobs[i] + dx[i], yobs[i] + dy[i]]),
                                   sigma = objectsA[i].sigma + objectsB[i].sigma )
                           for i in range(len(objectsA)) ])
        draw_objects(ellipses, replot='yes')

        # Residuals
        quiver(xobs,yobs,dx,dy,color='r', angles='xy', scale_units='xy', scale=1)
    ax.autoscale(enable=None, axis='both', tight=True)
    show()
示例#2
0
def draw_MAP_residuals(objectsA, objectsB, P, scaled='no'):
    from pyBA.distortion import compute_displacements, compute_residual
    from numpy import array
    
    # Compute displacements between frames for tie objects
    xobs, yobs, vxobs, vyobs, sxobs, syobs = compute_displacements(objectsA, objectsB)

    # Compute residual
    dx, dy = compute_residual(objectsA, objectsB, P)

    # Draw residuals
    fig = figure(figsize=(16,16))
    ax = fig.add_subplot(111, aspect='equal')
    if scaled is 'yes':
        # Allow relative scaling of arrows
        quiver(xobs,yobs,dx,dy)
    else:
        # Show residuals in absolute size (often very tiny), with uncertainties

        # Also plot error ellipses
        ellipses = array([ Bivarg( mu = array([xobs[i] + dx[i], yobs[i] + dy[i]]),
                                   sigma = objectsA[i].sigma + objectsB[i].sigma )
                           for i in range(len(objectsA)) ])
        draw_objects(ellipses, replot='yes')

        # Residuals
        quiver(xobs,yobs,dx,dy,color='r', angles='xy', scale_units='xy', scale=1)
    ax.autoscale(enable=None, axis='both', tight=True)
    show()
示例#3
0
def draw_realisation(objectsA, objectsB, P, scale, amp, chol, res = 30):

    # Grid for regression
    x,y = make_grid(objectsA,res=res)
    xyarr = np.array([x.flatten(),y.flatten()]).T

    # If no cholesky matrix A provided, assume that we are
    #  drawing realisation on grid without using observed data
    if chol == None:
        
        from pyBA.distortion import realise
        vx, vy = realise(xyarr, P, scale, amp)
        sx, sy = None, None

    # Otherwise, use cholesky data to perform regression
    else:

        from pyBA.distortion import regression
        vx, vy, sx, sy = regression(objectsA, objectsB, xyarr, P, 
                                    scale, amp, chol)

    # Get xy coordinates of base of vectors
    from pyBA.distortion import compute_displacements
    xobs, yobs, vxobs, vyobs, _, _ = compute_displacements(objectsA, objectsB)

    # Matplotlib plotting
    fig = figure(figsize=(16,16))
    ax = fig.add_subplot(111, aspect='equal')
    quiver(x,y,vx,vy,scale_units='width',scale=res*res)
    
    # If uncertainties are provided, plot them as a background image and colour the
    #  data vectors in white
    if sx != None:
        quiver(xobs,yobs,vxobs,vyobs,color='w',scale_units='width',scale=res*res)

        sarr = np.array(sx + sy).reshape( x.shape )
        imshow(np.sqrt(sarr), origin='upper', extent=(x.min(), x.max(), y.min(), y.max()),
               interpolation=None)
        colorbar()

    else:
        # Otherwise, no background and data vectors in red
        quiver(xobs,yobs,vxobs,vyobs,color='r',scale_units='width',scale=res*res)

            
    ax.autoscale(enable=None, axis='both', tight=True)
    show()

    return 
示例#4
0
def draw_realisation(objectsA, objectsB, P, scale, amp, chol, res = 30):

    # Grid for regression
    x,y = make_grid(objectsA,res=res)
    xyarr = np.array([x.flatten(),y.flatten()]).T

    # If no cholesky matrix A provided, assume that we are
    #  drawing realisation on grid without using observed data
    if chol == None:
        
        from pyBA.distortion import realise
        vx, vy = realise(xyarr, P, scale, amp)
        sx, sy = None, None

    # Otherwise, use cholesky data to perform regression
    else:

        from pyBA.distortion import regression
        vx, vy, sx, sy = regression(objectsA, objectsB, xyarr, P, 
                                    scale, amp, chol)

    # Get xy coordinates of base of vectors
    from pyBA.distortion import compute_displacements
    xobs, yobs, vxobs, vyobs, _, _ = compute_displacements(objectsA, objectsB)

    # Matplotlib plotting
    fig = figure(figsize=(16,16))
    ax = fig.add_subplot(111, aspect='equal')
    quiver(x,y,vx,vy,scale_units='width',scale=res*res)
    
    # If uncertainties are provided, plot them as a background image and colour the
    #  data vectors in white
    if sx is not None:
        quiver(xobs,yobs,vxobs,vyobs,color='w',scale_units='width',scale=res*res)

        sarr = np.array(sx + sy).reshape( x.shape )
        imshow(np.sqrt(sarr), origin='upper', extent=(x.min(), x.max(), y.min(), y.max()),
               interpolation=None)
        colorbar()

    else:
        # Otherwise, no background and data vectors in red
        quiver(xobs,yobs,vxobs,vyobs,color='r',scale_units='width',scale=res*res)

            
    ax.autoscale(enable=None, axis='both', tight=True)
    show()

    return 
示例#5
0
def draw_MAP_background(objectsA=np.array([Bivarg()]),
                        objectsB=np.array([Bivarg()]),
                        P=Bgmap(),
                        res=30):
    """ Plot the background parametric mapping between frames (the mean function
    for the gaussian process) on a grid of given resolution. Overplot observed
    displacements from lists of tie objects.
    """

    from pyBA.distortion import compute_displacements, astrometry_mean
    from numpy import array, sqrt

    # Grid for regression
    x, y = make_grid(objectsA, res=res)

    # Perform evaluation of background function on grid
    xy = np.array([x.flatten(), y.flatten()]).T
    vxy = astrometry_mean(xy, P)
    vx, vy = vxy[:, 0], vxy[:, 1]

    # Compute empirical displacements
    xobs, yobs, vxobs, vyobs, sxobs, syobs = compute_displacements(
        objectsA, objectsB)

    # Matplotlib plotting
    fig = figure(figsize=(16, 16))
    ax = fig.add_subplot(111, aspect='equal')
    quiver(x, y, vx, vy, scale_units='width', scale=res * res)
    quiver(xobs,
           yobs,
           vxobs,
           vyobs,
           color='r',
           scale_units='width',
           scale=res * res)
    ax.autoscale(enable=None, axis='both', tight=True)

    # Also plot error ellipses on interpolated points
    #ellipses = array([ Bivarg( mu = array([xarr[i,0] + vx[i], xarr[i,1] + vy[i]]),
    #                           sigma = array([ sx[i], sy[i] ]) )
    #                   for i in range(len(xarr)) ])
    #draw_objects(ellipses, replot='yes')

    show()

    return
示例#6
0
def draw_MAP_background(objectsA = np.array([ Bivarg() ]),
                        objectsB = np.array([ Bivarg() ]),
                        P = Bgmap(),
                        res = 30):
    """ Plot the background parametric mapping between frames (the mean function
    for the gaussian process) on a grid of given resolution. Overplot observed
    displacements from lists of tie objects.
    """

    from pyBA.distortion import compute_displacements, astrometry_mean
    from numpy import array, sqrt

    # Grid for regression
    x,y = make_grid(objectsA,res=res)

    # Perform evaluation of background function on grid
    xy = np.array([x.flatten(),y.flatten()]).T
    vxy = astrometry_mean(xy, P)
    vx, vy = vxy[:,0], vxy[:,1]

    # Compute empirical displacements
    xobs, yobs, vxobs, vyobs, sxobs, syobs = compute_displacements(objectsA, objectsB)

    # Matplotlib plotting
    fig = figure(figsize=(16,16))
    ax = fig.add_subplot(111, aspect='equal')
    quiver(x,y,vx,vy,scale_units='width',scale=res*res)
    quiver(xobs,yobs,vxobs,vyobs,color='r',scale_units='width',scale=res*res)
    ax.autoscale(enable=None, axis='both', tight=True)

    # Also plot error ellipses on interpolated points
    #ellipses = array([ Bivarg( mu = array([xarr[i,0] + vx[i], xarr[i,1] + vy[i]]),
    #                           sigma = array([ sx[i], sy[i] ]) )
    #                   for i in range(len(xarr)) ])
    #draw_objects(ellipses, replot='yes')

    show()

    return