Beispiel #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
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
Beispiel #3
0
def EC_nf_plot(K, ainvs, base_field_gen_name):
    try:
        n1 = K.signature()[0]
        if n1 == 0:
            return plot([])
        R=[]
        S=K.embeddings(RDF)
        for s in S:
            A=[s(c) for c in ainvs]
            R.append(EC_R_plot_zone(Rx([A[4],A[3],A[1],1]),Rx([A[2],A[0]]))) 
        xmin = min([r[0] for r in R])
        xmax = max([r[1] for r in R])
        ymin = min([r[2] for r in R])
        ymax = max([r[3] for r in R])
        cols = rainbow(n1) # Default choice of n colours
        # However, these tend to be too pale, so we preset them for small values of n
        if n1==1:
            cols=["blue"]
        elif n1==2:
            cols=["red","blue"]
        elif n1==3:
            cols=["red","limegreen","blue"]
        elif n1==4:
            cols = ["red", "orange", "forestgreen", "blue"]
        elif n1==5:
            cols = ["red", "orange", "forestgreen", "blue", "darkviolet"]
        elif n1==6:
            cols = ["red", "darkorange", "gold", "forestgreen", "blue", "darkviolet"]
        elif n1==7:
            cols = ["red", "darkorange", "gold", "forestgreen", "blue", "darkviolet", "fuchsia"]
        return sum([EC_R_plot([S[i](c) for c in ainvs], xmin, xmax, ymin, ymax, cols[i], "$" + base_field_gen_name + " \mapsto$ " + str(S[i].im_gens()[0].n(20))+"$\dots$") for i in range(n1)]) 
    except:
        return text("Unable to plot", (1, 1), fontsize=36)
def EC_nf_plot(K, ainvs, base_field_gen_name):
    try:
        n1 = K.signature()[0]
        if n1 == 0:
            return plot([])
        R=[]
        S=K.embeddings(RDF)
        for s in S:
            A=[s(c) for c in ainvs]
            R.append(EC_R_plot_zone(Rx([A[4],A[3],A[1],1]),Rx([A[2],A[0]]))) 
        xmin = min([r[0] for r in R])
        xmax = max([r[1] for r in R])
        ymin = min([r[2] for r in R])
        ymax = max([r[3] for r in R])
        cols = rainbow(n1) # Default choice of n colours
        # However, these tend to be too pale, so we preset them for small values of n
        if n1==1:
            cols=["blue"]
        elif n1==2:
            cols=["red","blue"]
        elif n1==3:
            cols=["red","limegreen","blue"]
        elif n1==4:
            cols = ["red", "orange", "forestgreen", "blue"]
        elif n1==5:
            cols = ["red", "orange", "forestgreen", "blue", "darkviolet"]
        elif n1==6:
            cols = ["red", "darkorange", "gold", "forestgreen", "blue", "darkviolet"]
        elif n1==7:
            cols = ["red", "darkorange", "gold", "forestgreen", "blue", "darkviolet", "fuchsia"]
        return sum([EC_R_plot([S[i](c) for c in ainvs], xmin, xmax, ymin, ymax, cols[i], "$" + base_field_gen_name + " \mapsto$ " + str(S[i].im_gens()[0].n(20))+"$\dots$") for i in range(n1)]) 
    except:
        return text("Unable to plot", (1, 1), fontsize=36)
Beispiel #5
0
def EC_nf_plot(E, base_field_gen_name):
    K = E.base_field()
    n1 = K.signature()[0]
    if n1 == 0:
        return plot([])
    prec = 53
    maxprec = 10 ** 6
    while prec < maxprec:  # Try to base change to R. May fail if resulting curve is almost singular, so increase precision.
        try:
            SR = K.embeddings(RealField(prec))
            X = [E.base_extend(s) for s in SR]
            break
        except ArithmeticError:
            prec *= 2
    if prec >= maxprec:
        return text("Unable to plot", (1, 1), fontsize="xx-large")
    X = [e.plot() for e in X]
    xmin = min([x.xmin() for x in X])
    xmax = max([x.xmax() for x in X])
    ymin = min([x.ymin() for x in X])
    ymax = max([x.ymax() for x in X])
    cols = ["blue", "red", "green", "orange", "brown"]  # Preset colours, because rainbow tends to return too pale ones
    if n1 > len(cols):
        cols = rainbow(n1)
    return sum([EC_R_plot([SR[i](a) for a in E.ainvs()], xmin, xmax, ymin, ymax, cols[i], "$" + base_field_gen_name + " \mapsto$ " + str(SR[i].im_gens()[0].n(20))) for i in range(n1)])
Beispiel #6
0
def EC_nf_plot(E,base_field_gen_name):
    K = E.base_field()
    n1 = K.signature()[0]
    if n1 == 0:
        return plot([])
    prec = 53
    maxprec = 10**6
    while prec < maxprec: # Try to base change to R. May fail if resulting curve is almost singular, so increase precision.
        try:
            SR = K.embeddings(RealField(prec))
            X = [E.base_extend(s) for s in SR]
            break
        except ArithmeticError:
            prec *= 2
    if prec >= maxprec:
        return text("Unable to plot",(1,1),fontsize="xx-large")
    X = [e.plot() for e in X]
    xmin = min([x.xmin() for x in X])
    xmax = max([x.xmax() for x in X])
    ymin = min([x.ymin() for x in X])
    ymax = max([x.ymax() for x in X])
    cols = ["blue","red","green","orange","brown"] # Preset colours, because rainbow tends to return too pale ones
    if n1 > len(cols):
        cols = rainbow(n1)
    return sum([EC_R_plot([SR[i](a) for a in E.ainvs()],xmin,xmax,ymin,ymax,cols[i],"$"+base_field_gen_name+" \mapsto$ "+str(SR[i].im_gens()[0].n(20))) for i in range(n1)])
Beispiel #7
0
def EC_nf_plot(E, base_field_gen_name):
    K = E.base_field()
    n1 = K.signature()[0]
    if n1 == 0:
        return plot([])
    prec = 53
    maxprec = 10 ** 6
    while prec < maxprec:  # Try to base change to RR. May fail if resulting curve is almost singular, so increase precision.
        try:
            SR = K.embeddings(RealField(prec))
            X = [E.base_extend(s) for s in SR]
            break
        except ArithmeticError:
            prec *= 2
    if prec >= maxprec:
        return text("Unable to plot", (1, 1), fontsize=36)
    try:
        X = [e.plot() for e in X]
    except:
        return text("Unable to plot", (1, 1), fontsize=36)
    xmin = min([x.xmin() for x in X])
    xmax = max([x.xmax() for x in X])
    ymin = min([x.ymin() for x in X])
    ymax = max([x.ymax() for x in X])
    cols = rainbow(n1) # Default choice of n colours
    # Howver, these tend to be too pale, so we preset them for small values of n
    if n1==1:
        cols=["blue"]
    elif n1==2:
        cols=["red","blue"]
    elif n1==3:
        cols=["red","limegreen","blue"]
    elif n1==4:
        cols = ["red", "orange", "forestgreen", "blue"]
    elif n1==5:
        cols = ["red", "orange", "forestgreen", "blue", "darkviolet"] 
    elif n1==6:
        cols = ["red", "darkorange", "gold", "forestgreen", "blue", "darkviolet"] 
    elif n1==7:
        cols = ["red", "darkorange", "gold", "forestgreen", "blue", "darkviolet", "fuchsia"] 
    return sum([EC_R_plot([SR[i](a) for a in E.ainvs()], xmin, xmax, ymin, ymax, cols[i], "$" + base_field_gen_name + " \mapsto$ " + str(SR[i].im_gens()[0].n(20))+"$\dots$") for i in range(n1)])
Beispiel #8
0
 def show(self, unit=10, labels=True):
     from sage.all import circle, text, line, Graphics
     pos = self.basic_grid_embedding()
     for v, (a, b) in pos.items():
         pos[v] = (unit * a, unit * b)
     if not labels:
         verts = [circle(p, 1, fill=True) for p in pos.values()]
     else:
         verts = [
             text(repr(v), p, fontsize=20, color='black')
             for v, p in pos.items()
         ]
         verts += [circle(p, 1.5, fill=False) for p in pos.values()]
     edges = [
         line([pos[e.tail], pos[e.head]]) for e in self.edges
         if e not in self.dummy
     ]
     G = sum(verts + edges, Graphics())
     G.axes(False)
     return G
Beispiel #9
0
def EC_nf_plot(E, base_field_gen_name):
    K = E.base_field()
    n1 = K.signature()[0]
    if n1 == 0:
        return plot([])
    prec = 53
    maxprec = 10 ** 6
    while prec < maxprec:  # Try to base change to RR. May fail if resulting curve is almost singular, so increase precision.
        try:
            SR = K.embeddings(RealField(prec))
            X = [E.base_extend(s) for s in SR]
            break
        except ArithmeticError:
            prec *= 2
    if prec >= maxprec:
        return text("Unable to plot", (1, 1), fontsize="xx-large")
    X = [e.plot() for e in X]
    xmin = min([x.xmin() for x in X])
    xmax = max([x.xmax() for x in X])
    ymin = min([x.ymin() for x in X])
    ymax = max([x.ymax() for x in X])
    cols = rainbow(n1) # Default choice of n colours
    # Howver, these tend to be too pale, so we preset them for small values of n
    if n1==1:
        cols=["blue"]
    elif n1==2:
        cols=["red","blue"]
    elif n1==3:
        cols=["red","limegreen","blue"]
    elif n1==4:
        cols = ["red", "orange", "forestgreen", "blue"]
    elif n1==5:
        cols = ["red", "orange", "forestgreen", "blue", "darkviolet"] 
    elif n1==6:
        cols = ["red", "darkorange", "gold", "forestgreen", "blue", "darkviolet"] 
    elif n1==7:
        cols = ["red", "darkorange", "gold", "forestgreen", "blue", "darkviolet", "fuchsia"] 
    return sum([EC_R_plot([SR[i](a) for a in E.ainvs()], xmin, xmax, ymin, ymax, cols[i], "$" + base_field_gen_name + " \mapsto$ " + str(SR[i].im_gens()[0].n(20))+"$\dots$") for i in range(n1)])
Beispiel #10
0
    def plot(self,
             textvertices=False,
             only_simple=False,
             fontsize=18,
             sort=False,
             fact=0.5,
             thickness=4,
             edges_thickness=4,
             arrowshorten=8,
             linestyle_simple='solid',
             linestyle_nonsimple='dashed',
             arrowsize=2,
             arrows=False,
             **options):
        r"""
          Plots a SimpleModulesGraph.
        """
        vertex_colors = self._vertex_colors
        simple_color = self._simple_color
        nonsimple_color = self._nonsimple_color
        heights = self._heights
        if only_simple:
            for v in vertex_colors[nonsimple_color]:
                if self.has_vertex(v):
                    self.delete_vertex(v)
                # while vertex_colors[nonsimple_color].count(v)>0:
                #    vertex_colors[nonsimple_color].remove(v)
                for j in range(len(heights)):
                    while heights[j].count(v) > 0:
                        heights[j].remove(v)
            vertex_colors[nonsimple_color] = dict()

        pos = dict()
        labels = list()
        vertices = list()
        edges = list()
        min_d = 0.5
        widths = [
            float(sum([len(str(v)) / float(6) + min_d for v in heights[i]]))
            for i in range(len(heights))
        ]
        print widths
        max_w = max(widths)
        if len(widths) > 1:
            min_w = min([w for w in widths if w > 3])
        else:
            min_w = 0
        print min_w, max_w, widths
        max_vert = max([len(_) for _ in heights.values()])
        for i in range(len(heights)):
            if sort:
                heights[i] = sorted(heights[i])
            #print heights[i]
            real_w = widths[i]
            prev_w = min_w if i == 0 else widths[i - 1]
            next_w = min_w if i == len(heights) - 1 else widths[i + 1]
            cur_w = max(float(next_w) * 0.9, float(prev_w) * 0.9, real_w)
            d = max(2 * float(cur_w - real_w) / len(heights[i]), min_d)
            print real_w, cur_w
            print "d = ", d
            p = [-(cur_w), float(max_vert) * fact * i]
            w = 0
            for j in range(len(heights[i])):
                v = heights[i][j]
                p = [p[0] + w + 0.2, p[1]]
                w = float(len(str(v))) / float(6)
                p[0] = p[0] + w + d
                pos[heights[i][j]] = p
                c = simple_color if vertex_colors[simple_color].count(
                    v) > 0 else nonsimple_color
                if textvertices:
                    ct = colors.black.rgb()
                else:
                    ct = colors.white.rgb()
                labels.append(
                    text("$\mathbf{" + str(v)[1:len(str(v)) - 1] + "}$",
                         (p[0] + 0.2, p[1]),
                         rgbcolor=ct,
                         zorder=8,
                         fontsize=fontsize))
                print w
                if textvertices:
                    P = line2d(
                        [[p[0] - w, p[1] - 0.9], [p[0] - w, p[1] + 1.1]],
                        rgbcolor=c,
                        thickness=thickness,
                        linestyle=linestyle_simple
                        if c == simple_color else linestyle_nonsimple)
                    P += line2d(
                        [[p[0] - w, p[1] + 1.1], [p[0] + w + 0.2, p[1] + 1.1]],
                        rgbcolor=c,
                        thickness=thickness,
                        linestyle=linestyle_simple
                        if c == simple_color else linestyle_nonsimple)
                    P += line2d([[p[0] + w + 0.2, p[1] + 1.1],
                                 [p[0] + w + 0.2, p[1] - 0.9]],
                                rgbcolor=c,
                                thickness=thickness,
                                linestyle=linestyle_simple
                                if c == simple_color else linestyle_nonsimple)
                    P += line2d(
                        [[p[0] + w + 0.2, p[1] - 0.9], [p[0] - w, p[1] - 0.9]],
                        rgbcolor=c,
                        thickness=thickness,
                        linestyle=linestyle_simple
                        if c == simple_color else linestyle_nonsimple)
                else:
                    polygon2d([[p[0] - w, p[1] - 0.9], [p[0] - w, p[1] + 1.1],
                               [p[0] + w + 0.2, p[1] + 1.1],
                               [p[0] + w + 0.2, p[1] - 0.9]],
                              fill=(not textvertices),
                              rgbcolor=c,
                              thickness=thickness,
                              linestyle=linestyle_simple
                              if c == simple_color else linestyle_nonsimple)
                vertices.append(P)
        for e in self.edges():
            v = e[0]
            if not self.has_vertex(e[0]) or not self.has_vertex(e[1]):
                print "deleting edge ", e
                self.delete_edge(e[0], e[1])
            else:
                c = simple_color if vertex_colors[simple_color].count(
                    v) > 0 else nonsimple_color
                if arrows:
                    edges.append(
                        arrow([pos[e[0]][0], pos[e[0]][1] + 1.1],
                              [pos[e[1]][0], pos[e[1]][1] - 0.9],
                              rgbcolor=c,
                              zorder=-1,
                              arrowsize=arrowsize,
                              arrowshorten=arrowshorten,
                              width=edges_thickness,
                              linestyle=linestyle_simple
                              if c == simple_color else linestyle_nonsimple))
                else:
                    edges.append(
                        line2d([[pos[e[0]][0], pos[e[0]][1] + 1.1],
                                [pos[e[1]][0], pos[e[1]][1] - 0.9]],
                               rgbcolor=c,
                               zorder=-1,
                               thickness=edges_thickness,
                               linestyle=linestyle_simple
                               if c == simple_color else linestyle_nonsimple))
        print "calculation ended"
        gp = self.graphplot(dpi=300,
                            pos=pos,
                            vertex_size=2050,
                            figsize=round(float(max_vert) * 1.5),
                            vertex_colors=vertex_colors)
        gp._plot_components['vertex_labels'] = labels
        gp._plot_components['vertices'] = vertices
        gp._plot_components['edges'] = edges
        #self._pos = pos
        return gp.plot(**options)
Beispiel #11
0
def draw_fundamental_domain(N,group='Gamma0',model="H",axes=None,filename=None,**kwds):
    r""" Draw fundamental domain
    INPUT:
        - ''model'' -- (default ''H'')
        - ''H'' -- Upper halfplane
        - ''D'' -- Disk model
        - ''filename''-- filename to print to
        - ''**kwds''-- additional arguments to matplotlib 
        - ''axes''  -- set geometry of output
        =[x0,x1,y0,y1] -- restrict figure to [x0,x1]x[y0,y1]

    EXAMPLES::

        sage: G=MySubgroup(Gamma0(3))
        sage: G.draw_fundamental_domain()

    """
    G=eval(group+'('+str(N)+')')
    #print G
    name ="$"+latex(G)+"$"
    ## need a "nice" set of coset representatives to draw a connected fundamental domain. Only implemented for Gamma_0(N)
    coset_reps = nice_coset_reps(G)
    if(model=="D"):
        g=draw_funddom_d(coset_reps,format,I)
    else:
        g=draw_funddom(coset_reps,format)
    if(axes<>None):
        [x0,x1,y0,y1]=axes
    elif(model=="D"):
        x0=-1 ; x1=1 ; y0=-1.1 ; y1=1 
    else:
        # find the width of the fundamental domain
        w=0  #self.cusp_width(Cusp(Infinity))
        wmin=0 ; wmax=1
        max_x = RR(0.55)
        rho = CC( exp(2*pi*I/3))
        for V in coset_reps:
            ## we also compare the real parts of where rho and infinity are mapped
            r1 = (V.acton(rho)).real()
            if(V[1,0]<>0):
                inf1 = RR(V[0,0] / V[1,0])
            else:
                inf1 = 0
            if(V[1 ,0 ]==0  and V[0 ,0 ]==1 ):
                if(V[0 ,1 ]>wmax):
                    wmax=V[0 ,1 ]
                if(V[0 ,1 ]<wmin):
                    wmin=V[0 ,1 ]
            if( max(r1,inf1) > max_x):
                max_x = max(r1,inf1)
            #print "wmin,wmax=",wmin,wmax
            #x0=-1; x1=1; y0=-0.2; y1=1.5
        x0=RR(-max_x) ; x1=RR(max_x) ; y0=RR(-0.15) ; y1=RR(1.5) 
    ## Draw the axes manually (since  can't figure out how to do it automatically)
    ax = line([[x0,0.0],[x1,0.0]],color='black')
        #ax = ax + line([[0.0,y0],[0.0,y1]],color='black')
        ## ticks
    ax = ax + line([[-0.5,-0.01],[-0.5,0.01]],color='black')
    ax = ax + line([[0.5,-0.01],[0.5,0.01]],color='black')
    g = g + ax
    if model=="H":
        t = text(name, (0, -0.1), fontsize=16, color='black')
    else:
        t = text(name, (0, -1.1), fontsize=16, color='black')
        g = g + t
        g.set_aspect_ratio(1)
        g.set_axes_range(x0,x1,y0,y1)
        g.axes(False)
        if(filename<>None):
            fig = g.matplotlib()
            fig.set_canvas(FigureCanvasAgg(fig))
            axes = fig.get_axes()[0]
            axes.minorticks_off()
            axes.set_yticks([])
            fig.savefig(filename,**kwds)
        else:
            return g
Beispiel #12
0
def draw_fundamental_domain(N,
                            group='Gamma0',
                            model="H",
                            axes=None,
                            filename=None,
                            **kwds):
    r""" Draw fundamental domain
    INPUT:
        - ''model'' -- (default ''H'')
        - ''H'' -- Upper halfplane
        - ''D'' -- Disk model
        - ''filename''-- filename to print to
        - ''**kwds''-- additional arguments to matplotlib 
        - ''axes''  -- set geometry of output
        =[x0,x1,y0,y1] -- restrict figure to [x0,x1]x[y0,y1]

    EXAMPLES::

        sage: G=MySubgroup(Gamma0(3))
        sage: G.draw_fundamental_domain()

    """
    G = eval(group + '(' + str(N) + ')')
    #print G
    name = "$" + latex(G) + "$"
    ## need a "nice" set of coset representatives to draw a connected fundamental domain. Only implemented for Gamma_0(N)
    coset_reps = nice_coset_reps(G)
    if (model == "D"):
        g = draw_funddom_d(coset_reps, format, I)
    else:
        g = draw_funddom(coset_reps, format)
    if (axes <> None):
        [x0, x1, y0, y1] = axes
    elif (model == "D"):
        x0 = -1
        x1 = 1
        y0 = -1.1
        y1 = 1
    else:
        # find the width of the fundamental domain
        w = 0  #self.cusp_width(Cusp(Infinity))
        wmin = 0
        wmax = 1
        max_x = RR(0.55)
        rho = CC(exp(2 * pi * I / 3))
        for V in coset_reps:
            ## we also compare the real parts of where rho and infinity are mapped
            r1 = (V.acton(rho)).real()
            if (V[1, 0] <> 0):
                inf1 = RR(V[0, 0] / V[1, 0])
            else:
                inf1 = 0
            if (V[1, 0] == 0 and V[0, 0] == 1):
                if (V[0, 1] > wmax):
                    wmax = V[0, 1]
                if (V[0, 1] < wmin):
                    wmin = V[0, 1]
            if (max(r1, inf1) > max_x):
                max_x = max(r1, inf1)
            #print "wmin,wmax=",wmin,wmax
            #x0=-1; x1=1; y0=-0.2; y1=1.5
        x0 = RR(-max_x)
        x1 = RR(max_x)
        y0 = RR(-0.15)
        y1 = RR(1.5)
    ## Draw the axes manually (since  can't figure out how to do it automatically)
    ax = line([[x0, 0.0], [x1, 0.0]], color='black')
    #ax = ax + line([[0.0,y0],[0.0,y1]],color='black')
    ## ticks
    ax = ax + line([[-0.5, -0.01], [-0.5, 0.01]], color='black')
    ax = ax + line([[0.5, -0.01], [0.5, 0.01]], color='black')
    g = g + ax
    if model == "H":
        t = text(name, (0, -0.1), fontsize=16, color='black')
    else:
        t = text(name, (0, -1.1), fontsize=16, color='black')
        g = g + t
        g.set_aspect_ratio(1)
        g.set_axes_range(x0, x1, y0, y1)
        g.axes(False)
        if (filename <> None):
            fig = g.matplotlib()
            fig.set_canvas(FigureCanvasAgg(fig))
            axes = fig.get_axes()[0]
            axes.minorticks_off()
            axes.set_yticks([])
            fig.savefig(filename, **kwds)
        else:
            return g
Beispiel #13
0
def draw_fundamental_domain(N,
                            group='Gamma0',
                            model="H",
                            axes=None,
                            filename=None,
                            **kwds):
    r""" Draw fundamental domain
    INPUT:
    - ''model'' -- (default ''H'')
    = ''H'' -- Upper halfplane
    = ''D'' -- Disk model
    - ''filename''-- filename to print to
    - ''**kwds''-- additional arguments to matplotlib
    - ''axes''  -- set geometry of output
    =[x0,x1,y0,y1] -- restrict figure to [x0,x1]x[y0,y1]

    EXAMPLES::

    sage: G=MySubgroup(Gamma0(3))
    sage: G.draw_fundamental_domain()

    """
    if group.strip() == 'Gamma0':
        G = Gamma0(N)
    elif group.strip() == 'Gamma1':
        G = Gamma1(N)
    elif group.strip() == 'Gamma':
        G = Gamma(N)
    else:
        raise ValueError('group must be one of: "Gamma0", "Gamma1", "Gamma"')
    s = "$" + latex(G) + "$"
    s = s.replace("mbox", "mathrm")
    s = s.replace("Bold", "mathbb")
    name = s
    # name ="$\mbox{SL}_{2}(\mathbb{Z})$"
    # need a "nice" set of coset representatives to draw a connected
    # fundamental domain. Only implemented for Gamma_0(N)
    coset_reps = nice_coset_reps(G)
    # if(group=='Gamma0'):
    # else:
    # coset_reps = list(G.coset_reps())
    from matplotlib.backends.backend_agg import FigureCanvasAgg
    if (model == "D"):
        g = _draw_funddom_d(coset_reps, format, I)
    else:
        g = _draw_funddom(coset_reps, format)
    if (axes is not None):
        [x0, x1, y0, y1] = axes
    elif (model == "D"):
        x0 = -1
        x1 = 1
        y0 = -1.1
        y1 = 1
    else:
        # find the width of the fundamental domain
        # w = 0  # self.cusp_width(Cusp(Infinity)) FIXME: w is never used
        wmin = 0
        wmax = 1
        max_x = RR(0.55)
        rho = CC(exp(2 * pi * I / 3))
        for V in coset_reps:
            ## we also compare the real parts of where rho and infinity are mapped
            r1 = (V.acton(rho)).real()
            if (V[1, 0] != 0):
                inf1 = RR(V[0, 0] / V[1, 0])
            else:
                inf1 = 0
            if (V[1, 0] == 0 and V[0, 0] == 1):
                if (V[0, 1] > wmax):
                    wmax = V[0, 1]
                if (V[0, 1] < wmin):
                    wmin = V[0, 1]
            if (max(r1, inf1) > max_x):
                max_x = max(r1, inf1)
            logging.debug("wmin,wmax=%s,%s" % (wmin, wmax))
        # x0=-1; x1=1; y0=-0.2; y1=1.5
        x0 = RR(-max_x)
        x1 = RR(max_x)
        y0 = RR(-0.15)
        y1 = RR(1.5)
        ## Draw the axes manually (since  can't figure out how to do it automatically)
    ax = line([[x0, 0.0], [x1, 0.0]], color='black')
    # ax = ax + line([[0.0,y0],[0.0,y1]],color='black')
    ## ticks
    ax = ax + line([[-0.5, -0.01], [-0.5, 0.01]], color='black')
    ax = ax + line([[0.5, -0.01], [0.5, 0.01]], color='black')
    g = g + ax
    if model == "H":
        t = text(name, (0, -0.1), fontsize=16, color='black')
        t = t + text(
            "$ -\\frac{1}{2} $", (-0.5, -0.1), fontsize=12, color='black')
        t = t + text(
            "$ \\frac{1}{2} $", (0.5, -0.1), fontsize=12, color='black')
    else:
        t = text(name, (0, -1.1), fontsize=16, color='black')
    g = g + t
    g.set_aspect_ratio(1)
    g.set_axes_range(x0, x1, y0, y1)
    g.axes(False)

    if (filename is not None):
        fig = g.matplotlib()
        fig.set_canvas(FigureCanvasAgg(fig))
        axes = fig.get_axes()[0]
        axes.minorticks_off()
        axes.set_yticks([])
        fig.savefig(filename, **kwds)
    else:
        return g
Beispiel #14
0
    def plot(self, textvertices=False, only_simple=False, fontsize=18, sort=False, fact = 0.5, thickness=4, edges_thickness=4, arrowshorten=8,
              linestyle_simple='solid', linestyle_nonsimple='dashed', arrowsize=2, arrows=False, **options):
        r"""
          Plots a SimpleModulesGraph.
        """
        vertex_colors = self._vertex_colors
        simple_color = self._simple_color
        nonsimple_color = self._nonsimple_color
        heights = self._heights
        if only_simple:
            for v in vertex_colors[nonsimple_color]:
                if self.has_vertex(v):
                    self.delete_vertex(v)
                # while vertex_colors[nonsimple_color].count(v)>0:
                #    vertex_colors[nonsimple_color].remove(v)
                for j in range(len(heights)):
                    while heights[j].count(v) > 0:
                        heights[j].remove(v)
            vertex_colors[nonsimple_color] = dict()

        pos = dict()
        labels = list()
        vertices = list()
        edges = list()
        min_d = 0.5
        widths = [float(sum([len(str(v)) / float(6) + min_d for v in heights[i]]))
                  for i in range(len(heights))]
        print widths
        max_w = max(widths)
        if len(widths) > 1:
            min_w = min([w for w in widths if w > 3])
        else:
            min_w = 0
        print min_w, max_w, widths
        max_vert = max([len(_) for _ in heights.values()])
        for i in range(len(heights)):
            if sort:
                heights[i] = sorted(heights[i])
            #print heights[i]
            real_w = widths[i]
            prev_w = min_w if i == 0 else widths[i - 1]
            next_w = min_w if i == len(heights) - 1 else widths[i + 1]
            cur_w = max(float(next_w) * 0.9, float(prev_w) * 0.9, real_w)
            d = max(2 * float(cur_w - real_w) / len(heights[i]), min_d)
            print real_w, cur_w
            print "d = ", d
            p = [-(cur_w), float(max_vert) * fact * i]
            w = 0
            for j in range(len(heights[i])):
                v = heights[i][j]
                p = [p[0] + w + 0.2, p[1]]
                w = float(len(str(v))) / float(6)
                p[0] = p[0] + w + d
                pos[heights[i][j]] = p
                c = simple_color if vertex_colors[
                    simple_color].count(v) > 0 else nonsimple_color
                if textvertices:
                    ct = colors.black.rgb()
                else:
                    ct = colors.white.rgb()
                labels.append(
                    text("$\mathbf{" + str(v)[1:len(str(v))-1] + "}$", (p[0] + 0.2, p[1]), rgbcolor=ct, zorder=8, fontsize=fontsize))
                print w
                if textvertices:
                    P = line2d([[p[0] - w, p[1] - 0.9], [p[0] - w, p[1] + 1.1]], rgbcolor=c, thickness=thickness,  linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple)
                    P += line2d([[p[0] - w, p[1] + 1.1], [p[0] + w + 0.2, p[1] + 1.1]], rgbcolor=c, thickness=thickness,  linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple)
                    P += line2d([[p[0] + w + 0.2, p[1] + 1.1], [p[0] + w + 0.2, p[1] - 0.9]], rgbcolor=c, thickness=thickness,  linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple)
                    P += line2d([[p[0] + w + 0.2, p[1] - 0.9], [p[0] - w, p[1] - 0.9]], rgbcolor=c, thickness=thickness,  linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple)
                else:
                    polygon2d([[p[0] - w, p[1] - 0.9], [p[0] - w, p[1] + 1.1], [
                              p[0] + w + 0.2, p[1] + 1.1], [p[0] + w + 0.2, p[1] - 0.9]], fill=(not textvertices), rgbcolor=c, thickness=thickness,  linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple)
                vertices.append(P)
        for e in self.edges():
            v = e[0]
            if not self.has_vertex(e[0]) or not self.has_vertex(e[1]):
                print "deleting edge ", e
                self.delete_edge(e[0], e[1])
            else:
                c = simple_color if vertex_colors[
                    simple_color].count(v) > 0 else nonsimple_color
                if arrows:
                    edges.append(arrow([pos[e[0]][0], pos[e[0]][
                             1] + 1.1], [pos[e[1]][0], pos[e[1]][1] - 0.9], rgbcolor=c, zorder=-1, arrowsize=arrowsize, arrowshorten=arrowshorten, width=edges_thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple))
                else:
                    edges.append(line2d([[pos[e[0]][0], pos[e[0]][1] + 1.1], [pos[e[1]][0], pos[e[1]][1] - 0.9]], rgbcolor=c, zorder=-1, thickness=edges_thickness, linestyle=linestyle_simple if c == simple_color else linestyle_nonsimple))
        print "calculation ended"
        gp = self.graphplot(dpi=300, pos=pos, vertex_size=2050, figsize=round(
            float(max_vert) * 1.5), vertex_colors=vertex_colors)
        gp._plot_components['vertex_labels'] = labels
        gp._plot_components['vertices'] = vertices
        gp._plot_components['edges'] = edges
        #self._pos = pos
        return gp.plot(**options)
Beispiel #15
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
Beispiel #16
0
def draw_fundamental_domain(N, group="Gamma0", model="H", axes=None, filename=None, **kwds):
    r""" Draw fundamental domain
    INPUT:
    - ''model'' -- (default ''H'')
    = ''H'' -- Upper halfplane
    = ''D'' -- Disk model
    - ''filename''-- filename to print to
    - ''**kwds''-- additional arguments to matplotlib
    - ''axes''  -- set geometry of output
    =[x0,x1,y0,y1] -- restrict figure to [x0,x1]x[y0,y1]

    EXAMPLES::

    sage: G=MySubgroup(Gamma0(3))
    sage: G.draw_fundamental_domain()

    """
    if group.strip() == "Gamma0":
        G = Gamma0(N)
    elif group.strip() == "Gamma1":
        G = Gamma1(N)
    elif group.strip() == "Gamma":
        G = Gamma(N)
    else:
        raise ValueError('group must be one of: "Gamma0", "Gamma1", "Gamma"')
    s = "$" + latex(G) + "$"
    s = s.replace("mbox", "mathrm")
    s = s.replace("Bold", "mathbb")
    name = s
    # name ="$\mbox{SL}_{2}(\mathbb{Z})$"
    # need a "nice" set of coset representatives to draw a connected
    # fundamental domain. Only implemented for Gamma_0(N)
    coset_reps = nice_coset_reps(G)
    # if(group=='Gamma0'):
    # else:
    # coset_reps = list(G.coset_reps())
    from matplotlib.backends.backend_agg import FigureCanvasAgg

    if model == "D":
        g = _draw_funddom_d(coset_reps, format, I)
    else:
        g = _draw_funddom(coset_reps, format)
    if axes is not None:
        [x0, x1, y0, y1] = axes
    elif model == "D":
        x0 = -1
        x1 = 1
        y0 = -1.1
        y1 = 1
    else:
        # find the width of the fundamental domain
        # w = 0  # self.cusp_width(Cusp(Infinity)) FIXME: w is never used
        wmin = 0
        wmax = 1
        max_x = RR(0.55)
        rho = CC(exp(2 * pi * I / 3))
        for V in coset_reps:
            ## we also compare the real parts of where rho and infinity are mapped
            r1 = (V.acton(rho)).real()
            if V[1, 0] != 0:
                inf1 = RR(V[0, 0] / V[1, 0])
            else:
                inf1 = 0
            if V[1, 0] == 0 and V[0, 0] == 1:
                if V[0, 1] > wmax:
                    wmax = V[0, 1]
                if V[0, 1] < wmin:
                    wmin = V[0, 1]
            if max(r1, inf1) > max_x:
                max_x = max(r1, inf1)
            logging.debug("wmin,wmax=%s,%s" % (wmin, wmax))
        # x0=-1; x1=1; y0=-0.2; y1=1.5
        x0 = RR(-max_x)
        x1 = RR(max_x)
        y0 = RR(-0.15)
        y1 = RR(1.5)
        ## Draw the axes manually (since  can't figure out how to do it automatically)
    ax = line([[x0, 0.0], [x1, 0.0]], color="black")
    # ax = ax + line([[0.0,y0],[0.0,y1]],color='black')
    ## ticks
    ax = ax + line([[-0.5, -0.01], [-0.5, 0.01]], color="black")
    ax = ax + line([[0.5, -0.01], [0.5, 0.01]], color="black")
    g = g + ax
    if model == "H":
        t = text(name, (0, -0.1), fontsize=16, color="black")
        t = t + text("$ -\\frac{1}{2} $", (-0.5, -0.1), fontsize=12, color="black")
        t = t + text("$ \\frac{1}{2} $", (0.5, -0.1), fontsize=12, color="black")
    else:
        t = text(name, (0, -1.1), fontsize=16, color="black")
    g = g + t
    g.set_aspect_ratio(1)
    g.set_axes_range(x0, x1, y0, y1)
    g.axes(False)

    if filename is not None:
        fig = g.matplotlib()
        fig.set_canvas(FigureCanvasAgg(fig))
        axes = fig.get_axes()[0]
        axes.minorticks_off()
        axes.set_yticks([])
        fig.savefig(filename, **kwds)
    else:
        return g
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