Ejemplo n.º 1
0
def healpix_diagram(a=1, e=0, shade_polar_region=True):
    r"""
    Return a Sage Graphics object diagramming the HEALPix projection
    boundary and polar triangles for the ellipsoid with major radius `a` 
    and eccentricity `e`.
    Inessential graphics method.
    Requires Sage graphics methods.
    """
    from sage.all import Graphics, line2d, point, polygon, text, RealNumber, Integer
    
    # Make Sage types compatible with Numpy.
    RealNumber = float
    Integer = int
    
    R = auth_rad(a, e)
    g = Graphics()
    color = 'black' # Boundary color.
    shade_color = 'blue'  # Polar triangles color.    
    dl = array((R*pi/2,0))
    lu = [(-R*pi, R*pi/4),(-R*3*pi/4, R*pi/2)]
    ld = [(-R*3*pi/4, R*pi/2),(-R*pi/2, R*pi/4)] 
    g += line2d([(-R*pi, -R*pi/4),(-R*pi, R*pi/4)], color=color) 
    g += line2d([(R*pi, R*pi/4),(R*pi, -R*pi/4)], linestyle = '--', 
                color=color)
    for k in range(4):
        g += line2d([array(p) + k*dl for p in lu], color=color) 
        g += line2d([array(p) + k*dl for p in ld], linestyle = '--', 
                    color=color)
        g += line2d([array(p) + array((k*R*pi/2 - R*pi/4, -R*3*pi/4)) 
                     for p in ld], color=color) 
        g += line2d([array(p) + array((k*R*pi/2 + R*pi/4, -R*3*pi/4)) 
                     for p in lu], linestyle = '--', color=color)
    pn = array((-R*3*pi/4, R*pi/2))
    ps = array((-R*3*pi/4, -R*pi/2))
    g += point([pn + k*dl for k in range(4)] +
               [ps + k*dl for k in range(4)], size=20, color=color)
    g += point([pn + k*dl for k in range(1, 4)] + 
               [ps + k*dl for k in range(1, 4)], color='white', size=10, 
               zorder=3)
    npp = [(-R*pi, R*pi/4), (-R*3*pi/4, R*pi/2), (-R*pi/2, R*pi/4)]
    spp = [(-R*pi, -R*pi/4), (-R*3*pi/4, -R*pi/2), (-R*pi/2, -R*pi/4)]

    if shade_polar_region:
        for k in range(4):
            g += polygon([array(p) + k*dl for p in npp], alpha=0.1, 
                         color=shade_color) 
            g += text(str(k), array((-R*3*pi/4, R*5*pi/16)) + k*dl, 
                      color='red', fontsize=20)
            g += polygon([array(p) + k*dl for p in spp], alpha=0.1, 
                         color=shade_color)
            g += text(str(k), array((-R*3*pi/4, -R*5*pi/16)) + k*dl,    
                      color='red', fontsize=20)    
    return g
Ejemplo n.º 2
0
def healpix_diagram(a=1, e=0, shade_polar_region=True):
    r"""
    Return a Sage Graphics object diagramming the HEALPix projection
    boundary and polar triangles for the ellipsoid with major radius `a` 
    and eccentricity `e`.
    Inessential graphics method.
    Requires Sage graphics methods.
    """
    from sage.all import Graphics, line2d, point, polygon, text, RealNumber, Integer
    
    # Make Sage types compatible with Numpy.
    RealNumber = float
    Integer = int
    
    R = auth_rad(a, e)
    g = Graphics()
    color = 'black' # Boundary color.
    shade_color = 'blue'  # Polar triangles color.    
    dl = array((R*pi/2,0))
    lu = [(-R*pi, R*pi/4),(-R*3*pi/4, R*pi/2)]
    ld = [(-R*3*pi/4, R*pi/2),(-R*pi/2, R*pi/4)] 
    g += line2d([(-R*pi, -R*pi/4),(-R*pi, R*pi/4)], color=color) 
    g += line2d([(R*pi, R*pi/4),(R*pi, -R*pi/4)], linestyle = '--', 
                color=color)
    for k in range(4):
        g += line2d([array(p) + k*dl for p in lu], color=color) 
        g += line2d([array(p) + k*dl for p in ld], linestyle = '--', 
                    color=color)
        g += line2d([array(p) + array((k*R*pi/2 - R*pi/4, -R*3*pi/4)) 
                     for p in ld], color=color) 
        g += line2d([array(p) + array((k*R*pi/2 + R*pi/4, -R*3*pi/4)) 
                     for p in lu], linestyle = '--', color=color)
    pn = array((-R*3*pi/4, R*pi/2))
    ps = array((-R*3*pi/4, -R*pi/2))
    g += point([pn + k*dl for k in range(4)] +
               [ps + k*dl for k in range(4)], size=20, color=color)
    g += point([pn + k*dl for k in range(1, 4)] + 
               [ps + k*dl for k in range(1, 4)], color='white', size=10, 
               zorder=3)
    npp = [(-R*pi, R*pi/4), (-R*3*pi/4, R*pi/2), (-R*pi/2, R*pi/4)]
    spp = [(-R*pi, -R*pi/4), (-R*3*pi/4, -R*pi/2), (-R*pi/2, -R*pi/4)]

    if shade_polar_region:
        for k in range(4):
            g += polygon([array(p) + k*dl for p in npp], alpha=0.1, 
                         color=shade_color) 
            g += text(str(k), array((-R*3*pi/4, R*5*pi/16)) + k*dl, 
                      color='red', fontsize=20)
            g += polygon([array(p) + k*dl for p in spp], alpha=0.1, 
                         color=shade_color)
            g += text(str(k), array((-R*3*pi/4, -R*5*pi/16)) + k*dl,    
                      color='red', fontsize=20)    
    return g
    def graph_receivers(cls, pop):
        if not _nographics:
            s = Graphics()
            for i, (popi, popt) in enumerate(pop):
                if popt == 0: color = (.5, 0, 0)
                elif popt == 1: color = (0, 0, .5)
                elif popt == 2: color = (0, .5, 0)
                s += polygon([(i,0),((i+1), 0),((i+1), popi), (i, popi)], rgbcolor=color)

            return s
        else:
            return None
Ejemplo n.º 4
0
    def graph_receivers(cls, pop):
        if not _nographics:
            s = Graphics()
            for i, (popi, popt) in enumerate(pop):
                if popt == 0: color = (.5, 0, 0)
                elif popt == 1: color = (0, 0, .5)
                elif popt == 2: color = (0, .5, 0)
                s += polygon([(i, 0), ((i + 1), 0), ((i + 1), popi),
                              (i, popi)],
                             rgbcolor=color)

            return s
        else:
            return None
Ejemplo n.º 5
0
def graphical(path):
    r"""
    Return a sage graphics representation of `path`.
    """
    from sage.all import Graphics, polygon
    assert is_dyck_path(path)
    result = Graphics()
    # first a row of triangles
    for i in range(len(path)):
        result += polygon([(2*i, 0),
                           (2*i+1, 1),
                           (2*i+2, 0)],
                          color='black', fill=False, thickness=2)
    # then all the boxes
    for i, j in boxes_under_path(path):
        result += polygon([(i+j, j-i),
                           (i+j+1, j-i+1),
                           (i+j+2, j-i),
                           (i+j+1, j-i-1)],
                          color='black', fill=False, thickness=2)
    # reset some annoying options
    result.axes(False)
    result.set_aspect_ratio(1)
    return result
Ejemplo n.º 6
0
def rhealpix_diagram(a=1,
                     e=0,
                     north_square=0,
                     south_square=0,
                     shade_polar_region=True):
    r"""
    Return a Sage Graphics object diagramming the rHEALPix projection
    boundary and polar triangles for the ellipsoid with major radius `a` 
    and eccentricity `e`.
    Inessential graphics method.
    Requires Sage graphics methods.
    """
    from sage.all import Graphics, line2d, point, polygon, text, RealNumber, Integer
    # Make Sage types compatible with Numpy.
    RealNumber = float
    Integer = int

    R = auth_rad(a, e)
    g = Graphics()
    color = 'black'  # Boundary color.
    shade_color = 'blue'  # Polar triangles color.
    north = north_square
    south = south_square
    south_sq = [(-R * pi + R * south * pi / 2, -R * pi / 4),
                (-R * pi + R * south * pi / 2, -R * 3 * pi / 4),
                (-R * pi + R * (south + 1) * pi / 2, -R * 3 * pi / 4),
                (-R * pi + R * (south + 1) * pi / 2, -R * pi / 4)]
    north_sq = [(-R * pi + R * north * pi / 2, R * pi / 4),
                (-R * pi + R * north * pi / 2, R * 3 * pi / 4),
                (-R * pi + R * (north + 1) * pi / 2, R * 3 * pi / 4),
                (-R * pi + R * (north + 1) * pi / 2, R * pi / 4)]
    # Outline.
    g += line2d(south_sq, linestyle='--', color=color)
    g += line2d(north_sq, linestyle='--', color=color)
    g += line2d([(R * pi, -R * pi / 4), (R * pi, R * pi / 4)],
                linestyle='--',
                color=color)
    g += line2d([
        north_sq[0], (-R * pi, R * pi / 4), (-R * pi, -R * pi / 4), south_sq[0]
    ],
                color=color)
    g += line2d([south_sq[3], (R * pi, -R * pi / 4)], color=color)
    g += line2d([north_sq[3], (R * pi, R * pi / 4)], color=color)
    g += point([south_sq[0], south_sq[3]], size=20, zorder=3, color=color)
    g += point([north_sq[0], north_sq[3]], size=20, zorder=3, color=color)
    g += point([(R * pi, -R * pi / 4), (R * pi, R * pi / 4)],
               size=20,
               zorder=3,
               color=color)
    g += point([(R * pi, -R * pi / 4), (R * pi, R * pi / 4)],
               size=10,
               color='white',
               zorder=3)
    if shade_polar_region:
        # Shade.
        g += polygon(south_sq, alpha=0.1, color=shade_color)
        g += polygon(north_sq, alpha=0.1, color=shade_color)

    # Slice square into polar triangles.
    g += line2d([south_sq[0], south_sq[2]], color='lightgray')
    g += line2d([south_sq[1], south_sq[3]], color='lightgray')
    g += line2d([north_sq[0], north_sq[2]], color='lightgray')
    g += line2d([north_sq[1], north_sq[3]], color='lightgray')

    # Label polar triangles.
    sp = south_sq[0] + R * array((pi / 4, -pi / 4))
    np = north_sq[0] + R * array((pi / 4, pi / 4))
    shift = R * 3 * pi / 16
    g += text(str(south), sp + array((0, shift)), color='red', fontsize=20)
    g += text(str((south + 1) % 4),
              sp + array((shift, 0)),
              color='red',
              rotation=90,
              fontsize=20)
    g += text(str((south + 2) % 4),
              sp + array((0, -shift)),
              color='red',
              rotation=180,
              fontsize=20)
    g += text(str((south + 3) % 4),
              sp + array((-shift, 0)),
              color='red',
              rotation=270,
              fontsize=20)
    g += text(str(north), np + array((0, -shift)), color='red', fontsize=20)
    g += text(str((north + 1) % 4),
              np + array((shift, 0)),
              color='red',
              rotation=90,
              fontsize=20)
    g += text(str((north + 2) % 4),
              np + array((0, shift)),
              color='red',
              rotation=180,
              fontsize=20)
    g += text(str((north + 3) % 4),
              np + array((-shift, 0)),
              color='red',
              rotation=270,
              fontsize=20)
    return g
Ejemplo n.º 7
0
def rhealpix_diagram(a=1, e=0, north_square=0, south_square=0,
                     shade_polar_region=True):
    r"""
    Return a Sage Graphics object diagramming the rHEALPix projection
    boundary and polar triangles for the ellipsoid with major radius `a` 
    and eccentricity `e`.
    Inessential graphics method.
    Requires Sage graphics methods.
    """
    from sage.all import Graphics, line2d, point, polygon, text, RealNumber, Integer
    # Make Sage types compatible with Numpy.
    RealNumber = float
    Integer = int

    R = auth_rad(a, e)
    g = Graphics()
    color = 'black' # Boundary color.
    shade_color = 'blue'  # Polar triangles color.    
    north = north_square
    south = south_square
    south_sq = [(-R*pi + R*south*pi/2, -R*pi/4), 
                (-R*pi + R*south*pi/2, -R*3*pi/4), 
                (-R*pi + R*(south + 1)*pi/2, -R*3*pi/4), 
                (-R*pi + R*(south + 1)*pi/2, -R*pi/4)]
    north_sq = [(-R*pi + R*north*pi/2, R*pi/4), 
                (-R*pi + R*north*pi/2, R*3*pi/4), 
                (-R*pi + R*(north + 1)*pi/2, R*3*pi/4), 
                (-R*pi + R*(north + 1)*pi/2, R*pi/4)]
    # Outline.
    g += line2d(south_sq, linestyle = '--', color=color)
    g += line2d(north_sq, linestyle = '--', color=color)
    g += line2d([(R*pi, -R*pi/4), (R*pi, R*pi/4)], linestyle='--',
               color=color)
    g += line2d([north_sq[0], (-R*pi, R*pi/4), (-R*pi, -R*pi/4), 
                south_sq[0]], color=color) 
    g += line2d([south_sq[3], (R*pi, -R*pi/4)], color=color)
    g += line2d([north_sq[3],(R*pi, R*pi/4)], color=color) 
    g += point([south_sq[0], south_sq[3]], size=20, zorder=3, color=color)         
    g += point([north_sq[0], north_sq[3]], size=20, zorder=3, color=color)    
    g += point([(R*pi, -R*pi/4), (R*pi, R*pi/4)], size=20, zorder=3, 
               color=color) 
    g += point([(R*pi, -R*pi/4), (R*pi, R*pi/4)], size=10, color='white', 
               zorder=3)
    if shade_polar_region:
        # Shade.
        g += polygon(south_sq, alpha=0.1, color=shade_color)
        g += polygon(north_sq, alpha=0.1, color=shade_color)

    # Slice square into polar triangles.
    g += line2d([south_sq[0], south_sq[2]], color='lightgray')
    g += line2d([south_sq[1], south_sq[3]], color='lightgray')
    g += line2d([north_sq[0], north_sq[2]], color='lightgray')
    g += line2d([north_sq[1], north_sq[3]], color='lightgray')

    # Label polar triangles.
    sp = south_sq[0] + R*array((pi/4, -pi/4))
    np = north_sq[0] + R*array((pi/4, pi/4))
    shift = R*3*pi/16
    g += text(str(south), sp + array((0, shift)), color='red', 
              fontsize=20)
    g += text(str((south + 1) % 4), sp + array((shift, 0)), 
              color='red', rotation=90, fontsize=20)
    g += text(str((south + 2) % 4), sp + array((0, -shift)), 
              color='red', rotation=180, fontsize=20)
    g += text(str((south + 3) % 4), sp + array((-shift, 0)), 
              color='red', rotation=270, fontsize=20)
    g += text(str(north), np + array((0, -shift)), color='red',
              fontsize=20)
    g += text(str((north + 1) % 4), np + array((shift, 0)), 
              color='red', rotation=90, fontsize=20)
    g += text(str((north + 2) % 4), np + array((0, shift)), 
              color='red', rotation=180, fontsize=20)
    g += text(str((north + 3) % 4), np + array((-shift, 0)), 
              color='red', rotation=270, fontsize=20)
    return g