def draw_points_lines_crs(points: torch.Tensor,
                          lines: torch.Tensor,
                          crs: torch.Tensor,
                          filename,
                          size=1,
                          lw=1,
                          clw=1,
                          pcols=None,
                          lcols=None,
                          crscols=None,
                          canvas_clip=None,
                          svg=False):
    if canvas_clip is not None:
        c = canvas.canvas([canvas.clip(path.rect(*canvas_clip))])
    else:
        c = canvas.canvas()

    draw_points_to_canvas(c, points, size, pcols)
    draw_lines_to_canvas(c, lines, lw, lcols)
    draw_crs_to_canvas(c, crs, clw, crscols)

    if svg:
        c.writeSVGfile(file=filename)
    else:
        c.writePDFfile(file=filename)
Exemple #2
0
def guide_layer(holes):
    guide_size = 1.2

    # Get guide fiber information
    iguide = np.nonzero(np.array(holes['holetype']) == b'GUIDE')[0]
    guide_xfocal = np.array(holes['xfocal'])[iguide]
    guide_yfocal = np.array(holes['yfocal'])[iguide]
    guidenum = np.array(holes['iguide'])[iguide]

    # Set up object to print
    clippath = path.circle(0., 0., interior_radius)
    clipobject = canvas.clip(clippath)
    interior = canvas.canvas([clipobject])

    for indx in range(len(guide_xfocal)):
        interior.stroke(
            path.rect((guide_yfocal[indx] / 10.) - guide_size * 0.5,
                      (guide_xfocal[indx] / 10.) - guide_size * 0.5,
                      guide_size, guide_size),
            [style.linewidth.THick, color.cmyk.Black])
        interior.text(
            (guide_yfocal[indx] / 10.) + guide_size * 0.66,
            (guide_xfocal[indx] / 10.),
            r"\font\myfont=cmr10 at 35pt {\myfont " + str(guidenum[indx]) +
            "}", [text.halign.boxleft, text.valign.middle, text.size.Huge])

    return interior
Exemple #3
0
 def clear(self):
     """
     Erases the contents of this Window
     
     All Turtles and Pens are eliminated from the Window. Any attempt to use a 
     previously created :class:`Turtle` or :class:`Pen` will fail.
     """
     from pyx import canvas
     from pyx import path
     clippath = path.rect(self.x, self.y, self.width, self.height)
     self._canvas = canvas.canvas([canvas.clip(clippath)])
     self._turtles = []
     self._pencils = []
Exemple #4
0
def plate_circle_layer(plate, information, message, plate_radius=32.6):
    outerclip = 39.6
    box_xoffset = 1.
    box_xsize = 4.
    box_ysize = 16.
    text_ybuffer = 0.5
    text_xbuffer = 0.3

    clippath = path.circle(0., 0., outerclip)
    plate_clipobject = canvas.clip(clippath)
    plate_circle = canvas.canvas([plate_clipobject])

    plate_circle.stroke(path.circle(0., 0., plate_radius),
                        [style.linewidth.THICk])
    plate_circle.stroke(
        path.line(-plate_radius + box_xoffset, -box_ysize * 0.5,
                  -plate_radius + box_xoffset - box_xsize, -box_ysize * 0.5),
        [style.linewidth.THICk])
    plate_circle.stroke(
        path.line(-plate_radius + box_xoffset - box_xsize, -box_ysize * 0.5,
                  -plate_radius + box_xoffset - box_xsize, box_ysize * 0.5),
        [style.linewidth.THICk])
    plate_circle.stroke(
        path.line(-plate_radius + box_xoffset, box_ysize * 0.5,
                  -plate_radius + box_xoffset - box_xsize, box_ysize * 0.5),
        [style.linewidth.THICk])
    tab_path = path.line(-plate_radius - text_xbuffer,
                         -box_ysize * 0.5 + text_ybuffer,
                         -plate_radius - text_xbuffer,
                         box_ysize * 0.5 - text_ybuffer)
    tab_text = r"\font\myfont=cmr10 at 100pt {\myfont " + str(plate) + "}"
    plate_circle.draw(tab_path, [deco.curvedtext(tab_text)])

    information_path = (path.circle(0., 0., plate_radius).transformed(
        trafo.rotate(90.)))
    plate_circle.draw(information_path, [
        deco.curvedtext(information,
                        textattrs=[text.valign.top, text.vshift.topzero])
    ])

    message_path = (path.circle(0., 0.,
                                plate_radius).transformed(trafo.rotate(-90.)))
    plate_circle.draw(message_path, [
        deco.curvedtext(message,
                        textattrs=[text.valign.top, text.vshift.topzero])
    ])
    return plate_circle
Exemple #5
0
def outline_layer():
    tab_xsize = 1.3
    tab_ysize = 2.0
    clippath = path.circle(0., 0., limit_radius)
    clipobject = canvas.clip(clippath)
    outline = canvas.canvas([clipobject])
    outline.stroke(path.circle(0., 0., full_radius), [style.linewidth.thick])
    outline.stroke(
        path.line(-full_radius, -tab_ysize * 0.5, -full_radius - tab_xsize,
                  -tab_ysize * 0.5), [style.linewidth.thick])
    outline.stroke(
        path.line(-full_radius, tab_ysize * 0.5, -full_radius - tab_xsize,
                  tab_ysize * 0.5), [style.linewidth.thick])
    outline.stroke(
        path.line(-full_radius - tab_xsize, -tab_ysize * 0.5,
                  -full_radius - tab_xsize, tab_ysize * 0.5),
        [style.linewidth.thick])
    outline.stroke(path.line(-full_radius - tab_xsize, 0., -limit_radius, 0.),
                   [style.linewidth.thick])
    return outline
Exemple #6
0
    def pyx_plotter(self):
        from pyx import canvas, path, color

        st = Stats(self.points)

        if self.plot_range == AUTO:
            xmax, xmin, ymax, ymin = st.bbox_auto(self.points)
        else:
            xmax, xmin, ymax, ymin = st.bbox()
        wd, ht = xmax - xmin, ymax - ymin

        sx = self.default_width / wd
        sy = self.aspect_ratio * self.default_width / ht
        #print 'WD:', wd, 'HT:', ht, sx, sy

        clip = canvas.clip(path.rect(sx * xmin, sy * ymin, sx * wd, sy * ht))

        c = canvas.canvas([clip])
        #c.stroke(path.rect(sx*xmin, sy*ymin, sx*wd, sy*ht))

        pth = path.path()
        first_point = True

        for p in self.points:
            if first_point:
                pth.append(path.moveto(sx * p.x, sy * p.y))
                first_point = False
            else:
                pth.append(path.lineto(sx * p.x, sy * p.y))

        c.stroke(pth)

        for p in self.points:
            if st.is_extreme_outlier(p):
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03), [color.rgb.red])
            else:
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03))
        return c
    def pyx_plotter(self):
        from pyx import canvas, path, color

        st = Stats(self.points)

        if self.plot_range == AUTO:
            xmax, xmin, ymax, ymin = st.bbox_auto(self.points)
        else:
            xmax, xmin, ymax, ymin = st.bbox()
        wd, ht = xmax - xmin, ymax - ymin

        sx = self.default_width / wd
        sy = self.aspect_ratio * self.default_width / ht
        #print 'WD:', wd, 'HT:', ht, sx, sy

        clip = canvas.clip(path.rect(sx * xmin, sy * ymin, sx * wd, sy * ht))

        c = canvas.canvas([clip])
        #c.stroke(path.rect(sx*xmin, sy*ymin, sx*wd, sy*ht))

        pth = path.path()
        first_point = True

        for p in self.points:
            if first_point:
                pth.append(path.moveto(sx * p.x, sy * p.y))
                first_point = False
            else:
                pth.append(path.lineto(sx * p.x, sy * p.y))

        c.stroke(pth)

        for p in self.points:
            if st.is_extreme_outlier(p):
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03), [color.rgb.red])
            else:
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03))
        return c
Exemple #8
0
def acquisition_layer(holes):

    # Get camera info
    icenter = np.nonzero(
        np.array(holes['holetype']) == b'ACQUISITION_CENTER')[0]
    if (len(icenter) == 0):
        return None
    if (len(icenter) > 1):
        print("Expect just one central acquisition camera.")
    center_xfocal = np.array(holes['xfocal'])[icenter[0]]
    center_yfocal = np.array(holes['yfocal'])[icenter[0]]

    ioffaxis = np.nonzero(
        np.array(holes['holetype']) == b'ACQUISITION_OFFAXIS')[0]
    if (len(ioffaxis) == 0):
        print("If there is a center acquisition camera we expect an off-axis.")
        sys.exit()
    if (len(ioffaxis) > 1):
        print("Expect just one off-axis acquisition camera.")
        sys.exit()
    offaxis_xfocal = np.array(holes['xfocal'])[ioffaxis[0]]
    offaxis_yfocal = np.array(holes['yfocal'])[ioffaxis[0]]

    # Set up object to print
    clippath = path.circle(0., 0., interior_radius)
    clipobject = canvas.clip(clippath)
    interior = canvas.canvas([clipobject])

    interior.stroke(
        path.circle(center_yfocal / 10., center_xfocal / 10., center_radius),
        [style.linewidth.THick, color.cmyk.Black])

    interior.stroke(
        path.rect((offaxis_yfocal / 10.) - offaxis_ysize * 0.5,
                  (offaxis_xfocal / 10.) - offaxis_xsize * 0.5, offaxis_ysize,
                  offaxis_xsize), [style.linewidth.THick, color.cmyk.Black])

    return interior
Exemple #9
0
    def write(self, filename='schematic'):
        schpath = self.place(0, 0)
        for cdev, devpath in enumerate(schpath):
            for clay, laypath in enumerate(devpath):
                laypath, laybbox, laytext = laypath
                laybbox_path = laybbox.to_path()
                laycanv = pyxcanvas.canvas([pyxcanvas.clip(laybbox_path)])

                for cfea, feapath in enumerate(laypath):
                    feapath, color, stroke_color = feapath
                    laycanv.fill(feapath, [color])
                    if stroke_color is None:
                        laycanv.stroke(feapath, [stroke_color])

                if laytext != '':
                    xc = (laybbox.x1 + laybbox.x2) / 2
                    yc = (laybbox.y1 + laybbox.y2) / 2
                    t = text.Text(laytext, scale=2)
                    laycanv.text(xc, yc, t)

                self.canvas.insert(laycanv)

        self.canvas.writeEPSfile(filename)
Exemple #10
0
def ellipse(r, scaley, fillcolor):
    ce = canvas.canvas()
    ce.fill(path.circle(0, 0, r), [trafo.scale(1, scaley), fillcolor])
    return ce


c = canvas.canvas()
dx = 0.3
h = 4
w = 6.5
p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx)
p = deformer.smoothed(0.5).deform(p)
c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)])

c1 = canvas.canvas([canvas.clip(p)])
c1.fill(p, [color.grey(0.9)])

r = 1
brown1 = color.rgb(148 / 255, 77 / 255, 48 / 255)
brown2 = color.rgb(193 / 255, 91 / 255, 49 / 255)
red1 = color.rgb(200 / 255, 0, 0)
red2 = color.rgb(220 / 255, 0.5, 0.5)
flame = color.rgb(248 / 255, 212 / 255, 27 / 255)
c2 = canvas.canvas()
c2.insert(ellipse(r, 0.5, brown1))
c2.fill(path.rect(-r, 0, 2 * r, 0.5 * r), [brown1])
c2.insert(ellipse(r, 0.5, brown2), [trafo.translate(0, 0.5 * r)])
c2.insert(ellipse(0.2 * r, 0.5, red1), [trafo.translate(0, 0.5 * r)])
c2.fill(path.rect(-0.2 * r, 0.5 * r, 0.4 * r, r), [red1])
c2.insert(ellipse(0.2 * r, 0.5, red2), [trafo.translate(0, 1.5 * r)])
Exemple #11
0
ulx, uly = to_chart_coord(sun_set[0], chart)
urx, ury = to_chart_coord(sun_rise[0], chart)
top_line = path.path(path.moveto(ulx, uly),
                     path.lineto(urx, ury))

llx, lly = to_chart_coord(sun_set[-1], chart)
lrx, lry = to_chart_coord(sun_rise[-1], chart)
bot_line = path.path(path.moveto(llx, lly),
                     path.lineto(lrx, lry))

rev_sun_set = sun_set[:]
rev_sun_set.reverse()
clippath = event_to_path(rev_sun_set[:] + sun_rise[:], chart, do_check=False)
clippath.append(path.closepath())

clc = canvas.canvas([canvas.clip(clippath)]) # clipped canvas for paths, text and moon
bclc = canvas.canvas([canvas.clip(clippath)]) # clipped canvas for the background and the dots

# a seperate (larger) clipping canvas for Moon phases
clippath2 = event_to_path([rev_sun_set[0]+2.0] +
        rev_sun_set[:] + [rev_sun_set[-1]-2.0], chart, do_check=False,
            xoffset=-1.6)
clippath2 = clippath2.joined(event_to_path([sun_rise[0]-2.0] +
            sun_rise[:] + [sun_rise[-1]+2.0], chart, do_check=False,
            xoffset=1.6))
clippath2.append(path.closepath())
mclc = canvas.canvas([canvas.clip(clippath2)])

make_alm_bg(bclc, begin_day_datetime, no_days, chart,
        obs, sun, sun_set, sun_rise) 
make_alm_bg_vdots(bclc, first_sunday, no_days, chart) 
Exemple #12
0
def apogee_layer(holes, numbers=False, renumber=False):
    offset_amount = -0.03
    hole_radius = 0.4

    # Read in APOGEE blocks information
    blocks = apogee_south_blocks()

    # Set up colors
    pyxcolor = dict()
    pyxcolor['red'] = color.cmyk.Red
    pyxcolor['black'] = color.cmyk.Black
    pyxcolor['blue'] = color.cmyk.CornflowerBlue

    # Get science fiber information
    isci = np.nonzero(np.array(holes['holetype']) == b'APOGEE_SOUTH')[0]
    xfocal = np.array(holes['xfocal'])[isci]
    yfocal = np.array(holes['yfocal'])[isci]
    fiberid = np.array(holes['fiberid'])[isci]
    block = np.array(holes['block'])[isci]

    if (renumber):
        fiberid = np.array(blocks.fibers['fiberid'])[fiberid - 1]
        block = np.array(blocks.fibers['blockid'])[fiberid - 1]

    # Create Voronoi tessellation
    xy = np.array([xfocal, yfocal]).transpose()
    vor = Voronoi(xy)
    nridges = vor.ridge_points.shape[0]

    # Set up object to print
    clippath = path.circle(0., 0., interior_radius)
    clipobject = canvas.clip(clippath)
    interior = canvas.canvas([clipobject])

    # Print lines separating blocks
    for indx in range(nridges):
        iv0 = vor.ridge_vertices[indx][0]
        iv1 = vor.ridge_vertices[indx][1]
        ip0 = vor.ridge_points[indx][0]
        ip1 = vor.ridge_points[indx][1]
        point0 = vor.points[ip0, :] / 10.
        point1 = vor.points[ip1, :] / 10.
        ib0 = block[ip0]
        ib1 = block[ip1]
        if (iv0 > 0 and iv1 > 0 and ib0 != ib1):
            if (ib0 <= 25):
                side0 = 'Red'
            else:
                side0 = 'Blue'
            if (ib1 <= 25):
                side1 = 'Red'
            else:
                side1 = 'Blue'
            if (side0 == side1):
                if (side0 == 'Red'):
                    color0 = color.cmyk.Red
                    color1 = color.cmyk.Red
                else:
                    color0 = color.cmyk.Blue
                    color1 = color.cmyk.Blue
            else:
                color0 = color.cmyk.Black
                color1 = color.cmyk.Black

            vertex_start = vor.vertices[iv0, :] / 10.
            vertex_end = vor.vertices[iv1, :] / 10.
            (start0, end0) = offset_line(offset_amount, vertex_start,
                                         vertex_end, point0)
            interior.stroke(path.line(start0[1], start0[0], end0[1], end0[0]),
                            [style.linewidth.THick, color0])
            (start1, end1) = offset_line(offset_amount, vertex_start,
                                         vertex_end, point1)
            interior.stroke(path.line(start1[1], start1[0], end1[1], end1[0]),
                            [style.linewidth.THick, color1])

    # Print circles around holes
    for indx in range(len(xfocal)):
        hole_color = pyxcolor[blocks.fcolor(fiberid[indx])]
        interior.stroke(
            path.circle(yfocal[indx] / 10., xfocal[indx] / 10., hole_radius),
            [style.linewidth.THick, hole_color])

    if (numbers is True):
        #  Print numbers near holes
        for indx in range(len(xfocal)):
            if (indx <= 150):
                props = [text.halign.boxleft, text.valign.middle]
            else:
                props = [
                    text.halign.boxright, text.valign.middle,
                    trafo.rotate(180.)
                ]
            interior.text(
                (yfocal[indx] / 10.) + hole_radius * 1.2, (xfocal[indx] / 10.),
                r"\font\myfont=cmr10 at 20pt {\myfont " + str(fiberid[indx]) +
                "}", props)
    return interior