Esempio n. 1
0
 def __init__(self):
     super(GllSourceProfile, self).__init__(ll.source_profile)
     self.main_widget = GllImageView(self.get_pixbuf)
     self.config_widget = GllConfigBox()
     self.config_widget.add_radio_buttons("profile_type",
                                          "Source profile type", "flat",
                                          [("Flat", "flat"),
                                           ("Gaussian", "gaussian")])
     show_profile = GllConfigCheckButton("Show profile")
     show_profile.set_active(True)
     self.config_widget.add_items([("source_radius", "Source radius",
                                    (0.01, 0.0, 1e10, 0.001), 4),
                                   ("export_kernel", show_profile)])
Esempio n. 2
0
 def __init__(self):
     super(GllSourcePath, self).__init__()
     self.main_widget = GllImageView(self.get_pixbuf)
     self.tool = ImageToolSourcePath()
     self.main_widget.imageview.set_tool(self.tool)
     self.config_widget = GllConfigBox([
         ("curve_x0", "Start x coordinate", (-1.0, -1e10, 1e10, 0.01), 4),
         ("curve_y0", "Start y coordinate", (0.0, -1e10, 1e10, 0.01), 4),
         ("curve_x1", "End x coordinate", (1.0, -1e10, 1e10, 0.01), 4),
         ("curve_y1", "End y coordinate", (0.0, -1e10, 1e10, 0.01), 4),
         ("curve_samples", "Number of samples", (256, 0, 1000000, 16), 0)
     ])
     for key in ["curve_x0", "curve_y0", "curve_x1", "curve_y1"]:
         self.config_widget[key].adjustment.connect("value_changed",
                                                    self.coords_changed)
Esempio n. 3
0
 def __init__(self):
     super(GllRayshooter, self).__init__(ll.Rayshooter)
     self.main_widget = GllImageView(self.get_pixbuf)
     self.imageview = self.main_widget.imageview
     self.imageview.add_events(gtk.gdk.BUTTON_PRESS_MASK |
                               gtk.gdk.POINTER_MOTION_MASK |
                               gtk.gdk.LEAVE_NOTIFY_MASK)
     self.imageview.connect("button-press-event", self.imageview_clicked)
     self.imageview.connect("motion-notify-event", self.imageview_motion)
     self.imageview.connect("leave-notify-event", self.imageview_leave)
     self.main_widget.connect("parent-set", self.imageview_leave)
     self.dragger = self.imageview.get_tool()
     self.selector = gtkimageview.ImageToolSelector(self.imageview)
     self.config_widget = GllConfigBox(
         [("xpixels", "Resolution x", (1024, 0, 16384, 16), 0),
          ("ypixels", "Resolution y", (1024, 0, 16384, 16), 0),
          ("density", "Ray density", (100.0, 0.0, 100000.0, 1.0), 1),
          ("num_threads", "Number of threads", (2, 0, 32, 1), 0)])
     self.config_widget.add_radio_buttons(
         "kernel", "Ray shooting kernel", "triangulated",
         [("Simple", "simple"),
          ("Bilinear", "bilinear"),
          ("Triangulated", "triangulated")])
     self.config_widget.add_toggle_group(
         "export_region", "Magnification pattern region", False,
         [("region_x0", "Left coordinate",  (-1.0, -1e10, 1e10, 0.01), 4),
          ("region_y0", "Lower coordinate", (-1.0, -1e10, 1e10, 0.01), 4),
          ("region_x1", "Right coordinate", ( 1.0, -1e10, 1e10, 0.01), 4),
          ("region_y1", "Upper coordinate", ( 1.0, -1e10, 1e10, 0.01), 4)])
     self.config_widget.declare_record("region", "export_region")
     self.magpat = None
     self.region = None
Esempio n. 4
0
class GllConvolution(GllPlugin):
    name = "Convolution"

    def __init__(self):
        super(GllConvolution, self).__init__(ll.convolve)
        self.main_widget = GllImageView(self.get_pixbuf)

    def update(self, data):
        magpat = data["magpat"]
        ypixels, xpixels = magpat.shape
        self.pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
                                     xpixels, ypixels)
        data["magpat_pixbuf"] = self.pixbuf
        self.buf = magpat.render_gradient(
            min_mag=data["min_mag"], max_mag=data["max_mag"],
            buf=self.pixbuf.get_pixels_array())
        self.main_widget.mark_dirty()

    def get_pixbuf(self):
        return self.pixbuf
Esempio n. 5
0
class GllSourceProfile(GllPlugin):
    name = "Source profile"

    def __init__(self):
        super(GllSourceProfile, self).__init__(ll.source_profile)
        self.main_widget = GllImageView(self.get_pixbuf)
        self.config_widget = GllConfigBox()
        self.config_widget.add_radio_buttons("profile_type",
                                             "Source profile type", "flat",
                                             [("Flat", "flat"),
                                              ("Gaussian", "gaussian")])
        show_profile = GllConfigCheckButton("Show profile")
        show_profile.set_active(True)
        self.config_widget.add_items([("source_radius", "Source radius",
                                       (0.01, 0.0, 1e10, 0.001), 4),
                                      ("export_kernel", show_profile)])

    def update(self, data):
        self.show = data["export_kernel"]
        if self.show:
            self.source = data["source_profile"]
        self.main_widget.mark_dirty()

    def set_config(self, config):
        config.setdefault("export_kernel", True)
        GllPlugin.set_config(self, config)

    def get_pixbuf(self):
        if self.show:
            source = self.source
        else:
            source = numpy.ones((1, 1))
        ypixels, xpixels = source.shape
        source = numpy.vstack((source[ypixels // 2:], source[:ypixels // 2]))
        source = numpy.hstack(
            (source[:, xpixels // 2:], source[:, :xpixels // 2]))
        pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, xpixels,
                                ypixels)
        array = numpy.rollaxis(pixbuf.get_pixels_array(), 2, 0)
        array[:] = source * (255 / source.max())
        return pixbuf
Esempio n. 6
0
 def __init__(self):
     super(GllSourceProfile, self).__init__(ll.source_profile)
     self.main_widget = GllImageView(self.get_pixbuf)
     self.config_widget = GllConfigBox()
     self.config_widget.add_radio_buttons(
         "profile_type", "Source profile type", "flat",
         [("Flat", "flat"), ("Gaussian", "gaussian")])
     show_profile = GllConfigCheckButton("Show profile")
     show_profile.set_active(True)
     self.config_widget.add_items(
         [("source_radius", "Source radius", (0.01, 0.0, 1e10, 0.001), 4),
          ("export_kernel", show_profile)])
Esempio n. 7
0
class GllSourceProfile(GllPlugin):
    name = "Source profile"

    def __init__(self):
        super(GllSourceProfile, self).__init__(ll.source_profile)
        self.main_widget = GllImageView(self.get_pixbuf)
        self.config_widget = GllConfigBox()
        self.config_widget.add_radio_buttons(
            "profile_type", "Source profile type", "flat",
            [("Flat", "flat"), ("Gaussian", "gaussian")])
        show_profile = GllConfigCheckButton("Show profile")
        show_profile.set_active(True)
        self.config_widget.add_items(
            [("source_radius", "Source radius", (0.01, 0.0, 1e10, 0.001), 4),
             ("export_kernel", show_profile)])

    def update(self, data):
        self.show = data["export_kernel"]
        if self.show:
            self.source = data["source_profile"]
        self.main_widget.mark_dirty()

    def set_config(self, config):
        config.setdefault("export_kernel", True)
        GllPlugin.set_config(self, config)

    def get_pixbuf(self):
        if self.show:
            source = self.source
        else:
            source = numpy.ones((1, 1))
        ypixels, xpixels = source.shape
        source = numpy.vstack((source[ypixels//2:], source[:ypixels//2]))
        source = numpy.hstack((source[:,xpixels//2:], source[:,:xpixels//2]))
        pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
                                xpixels, ypixels)
        array = numpy.rollaxis(pixbuf.get_pixels_array(), 2, 0)
        array[:] = source*(255/source.max())
        return pixbuf
Esempio n. 8
0
 def __init__(self):
     super(GllSourcePath, self).__init__()
     self.main_widget = GllImageView(self.get_pixbuf)
     self.tool = ImageToolSourcePath()
     self.main_widget.imageview.set_tool(self.tool)
     self.config_widget = GllConfigBox(
         [("curve_x0", "Start x coordinate", (-1.0, -1e10, 1e10, 0.01), 4),
          ("curve_y0", "Start y coordinate", (0.0, -1e10, 1e10, 0.01), 4),
          ("curve_x1", "End x coordinate", (1.0, -1e10, 1e10, 0.01), 4),
          ("curve_y1", "End y coordinate", (0.0, -1e10, 1e10, 0.01), 4),
          ("curve_samples", "Number of samples", (256, 0, 1000000, 16), 0)])
     for key in ["curve_x0", "curve_y0", "curve_x1", "curve_y1"]:
         self.config_widget[key].adjustment.connect(
             "value_changed", self.coords_changed)
Esempio n. 9
0
 def __init__(self):
     super(GllConvolution, self).__init__(ll.convolve)
     self.main_widget = GllImageView(self.get_pixbuf)
Esempio n. 10
0
class GllRayshooter(GllPlugin):
    name = "Magnification pattern"

    def __init__(self):
        super(GllRayshooter, self).__init__(ll.Rayshooter)
        self.main_widget = GllImageView(self.get_pixbuf)
        self.imageview = self.main_widget.imageview
        self.imageview.add_events(gtk.gdk.BUTTON_PRESS_MASK |
                                  gtk.gdk.POINTER_MOTION_MASK |
                                  gtk.gdk.LEAVE_NOTIFY_MASK)
        self.imageview.connect("button-press-event", self.imageview_clicked)
        self.imageview.connect("motion-notify-event", self.imageview_motion)
        self.imageview.connect("leave-notify-event", self.imageview_leave)
        self.main_widget.connect("parent-set", self.imageview_leave)
        self.dragger = self.imageview.get_tool()
        self.selector = gtkimageview.ImageToolSelector(self.imageview)
        self.config_widget = GllConfigBox(
            [("xpixels", "Resolution x", (1024, 0, 16384, 16), 0),
             ("ypixels", "Resolution y", (1024, 0, 16384, 16), 0),
             ("density", "Ray density", (100.0, 0.0, 100000.0, 1.0), 1),
             ("num_threads", "Number of threads", (2, 0, 32, 1), 0)])
        self.config_widget.add_radio_buttons(
            "kernel", "Ray shooting kernel", "triangulated",
            [("Simple", "simple"),
             ("Bilinear", "bilinear"),
             ("Triangulated", "triangulated")])
        self.config_widget.add_toggle_group(
            "export_region", "Magnification pattern region", False,
            [("region_x0", "Left coordinate",  (-1.0, -1e10, 1e10, 0.01), 4),
             ("region_y0", "Lower coordinate", (-1.0, -1e10, 1e10, 0.01), 4),
             ("region_x1", "Right coordinate", ( 1.0, -1e10, 1e10, 0.01), 4),
             ("region_y1", "Upper coordinate", ( 1.0, -1e10, 1e10, 0.01), 4)])
        self.config_widget.declare_record("region", "export_region")
        self.magpat = None
        self.region = None

    def get_config(self):
        config = self.config_widget.get_config()
        if self.region is not None and self.imageview.get_tool() is self.selector:
            rect = self.selector.get_selection()
            width = max(rect.width, rect.height*self.xpixels//self.ypixels)
            x = rect.x + (rect.width - width)//2
            x0 = self.region.x0 + x * self.xfactor
            height = max(rect.height, rect.width*self.ypixels//self.xpixels)
            y = rect.y + (rect.height - height)//2
            y0 = self.region.y1 - y * self.yfactor - height * self.yfactor
            config["region"] = dict(x0=x0, y0=y0,
                                    x1=x0 + width * self.xfactor,
                                    y1=y0 + height * self.yfactor)
        return config

    def update(self, data):
        self.magpat = data["magpat"]
        data["min_mag"] = self.magpat.min()
        data["max_mag"] = self.magpat.max()
        self.ypixels, self.xpixels = self.magpat.shape
        self.pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
                                     self.xpixels, self.ypixels)
        data["magpat_pixbuf"] = self.pixbuf
        self.magpat.render_gradient(buf=self.pixbuf.get_pixels_array())
        self.imageview.set_tool(self.dragger)
        self.main_widget.mark_dirty()
        self.region = self.magpat.region
        for key in ["x0", "x1", "y0", "y1"]:
            self.config_widget["region_" + key].set_value(
                getattr(self.region, key))
        self.xfactor = self.region.width / self.xpixels
        self.yfactor = self.region.height / self.ypixels
        xlog = log10(abs(self.region.x0) + abs(self.region.x1))
        if -2.0 <= xlog < 0.0:
            xprec = int(-log10(self.xfactor) + 1)
        else:
            xprec = int(xlog - log10(self.xfactor) + 1)
        if xlog < -2.0:
            self.xformat = "%" + (".%ie" % xprec)
        else:
            self.xformat = "%" + (".%if" % xprec)
        ylog = log10(abs(self.region.y0) + abs(self.region.y1))
        if -2.0 <= ylog < 0.0:
            yprec = int(-log10(self.yfactor) + 1)
        else:
            yprec = int(ylog - log10(self.yfactor) + 1)
        if ylog < -2.0:
            self.yformat = "%" + (".%ie" % yprec)
        else:
            self.yformat = "%" + (".%if" % yprec)

    def get_pixbuf(self):
        return self.pixbuf

    def imageview_clicked(self, imageview, event):
        if event.button == 1:
            if event.type == gtk.gdk._2BUTTON_PRESS:
                self.emit("run-pipeline")
        if event.button == 3:
            if imageview.get_tool() is self.dragger:
                imageview.set_tool(self.selector)
                self.config_widget["export_region"].set_active(True)
            else:
                imageview.set_tool(self.dragger)

    def imageview_motion(self, imageview, event):
        draw_rect = self.imageview.get_draw_rect()
        if self.region is None or draw_rect is None:
            return
        zoom = self.imageview.get_zoom()
        viewport = self.imageview.get_viewport()
        mag_x = (event.x - draw_rect.x + viewport.x) / zoom
        mag_y = self.ypixels - (event.y - draw_rect.y + viewport.y + 1) / zoom
        if (mag_x < 0 or mag_x >= self.xpixels or
            mag_y < 0 or mag_y >= self.ypixels):
            self.emit("statusbar-pop")
            return
        x = self.region.x0 + mag_x * self.xfactor
        y = self.region.y0 + mag_y * self.yfactor
        mag = self.magpat[mag_y][mag_x]
        text = (("x: " + self.xformat + ", y: " + self.yformat +
                 ", magnification: %.2f") % (x, y, mag))
        self.emit("statusbar-push", text)

    def imageview_leave(self, imageview, event):
        self.emit("statusbar-pop")

    def save_png(self, *args):
        filename = save_dialog("Save Magnification Pattern Image",
                               [("PNG Image Files", "*.png")])
        if filename is not None:
            self.pixbuf.save(filename, "png")

    def save_fits(self, *args):
        filename = save_dialog("Save Magnification Pattern",
                               [("FITS Image Files", "*.fits")])
        if filename is not None:
            self.magpat.write_fits(filename)

    def get_actions(self):
        save_sensitive = hasattr(self, "pixbuf")
        return [("Save FITS", self.save_fits, save_sensitive),
                ("Save PNG", self.save_png, save_sensitive)]
Esempio n. 11
0
class GllSourcePath(GllPlugin):
    name = "Source path"

    def __init__(self):
        super(GllSourcePath, self).__init__()
        self.main_widget = GllImageView(self.get_pixbuf)
        self.tool = ImageToolSourcePath()
        self.main_widget.imageview.set_tool(self.tool)
        self.config_widget = GllConfigBox([
            ("curve_x0", "Start x coordinate", (-1.0, -1e10, 1e10, 0.01), 4),
            ("curve_y0", "Start y coordinate", (0.0, -1e10, 1e10, 0.01), 4),
            ("curve_x1", "End x coordinate", (1.0, -1e10, 1e10, 0.01), 4),
            ("curve_y1", "End y coordinate", (0.0, -1e10, 1e10, 0.01), 4),
            ("curve_samples", "Number of samples", (256, 0, 1000000, 16), 0)
        ])
        for key in ["curve_x0", "curve_y0", "curve_x1", "curve_y1"]:
            self.config_widget[key].adjustment.connect("value_changed",
                                                       self.coords_changed)

    def update(self, data):
        try:
            self.xpixels = data["xpixels"]
            self.ypixels = data["ypixels"]
            self.region = data["magpat"].region
            self.pixbuf = data["magpat_pixbuf"]
        except KeyError:
            return
        self.update_coords(data)

    def update_coords(self, data):
        pixels_per_width = self.xpixels / self.region.width
        pixels_per_height = self.ypixels / self.region.height
        self.tool.coords = (
            (data["curve_x0"] - self.region.x0) * pixels_per_width,
            (self.region.y1 - data["curve_y0"]) * pixels_per_height,
            (data["curve_x1"] - self.region.x0) * pixels_per_width,
            (self.region.y1 - data["curve_y1"]) * pixels_per_height)
        self.main_widget.mark_dirty()

    def get_pixbuf(self):
        return self.pixbuf

    def coords_changed(self, *args):
        if hasattr(self, "pixbuf"):
            self.update_coords(self.config_widget.get_config())

    def save_png(self, *args):
        filename = save_dialog("Save Magnification Pattern Image",
                               [("PNG Image Files", "*.png")])
        if filename is None:
            return
        pixmap = gtk.gdk.Pixmap(None, self.xpixels, self.ypixels, 24)
        cr = pixmap.cairo_create()
        cr.set_source_pixbuf(self.pixbuf, 0, 0)
        cr.paint()
        cr.move_to(*self.tool.coords[:2])
        cr.line_to(*self.tool.coords[2:])
        cr.set_source_rgb(1.0, 1.0, 1.0)
        cr.stroke()
        cr.get_target().write_to_png(filename)

    def get_actions(self):
        return [("Save PNG", self.save_png, hasattr(self, "pixbuf"))]
Esempio n. 12
0
class GllSourcePath(GllPlugin):
    name = "Source path"

    def __init__(self):
        super(GllSourcePath, self).__init__()
        self.main_widget = GllImageView(self.get_pixbuf)
        self.tool = ImageToolSourcePath()
        self.main_widget.imageview.set_tool(self.tool)
        self.config_widget = GllConfigBox(
            [("curve_x0", "Start x coordinate", (-1.0, -1e10, 1e10, 0.01), 4),
             ("curve_y0", "Start y coordinate", (0.0, -1e10, 1e10, 0.01), 4),
             ("curve_x1", "End x coordinate", (1.0, -1e10, 1e10, 0.01), 4),
             ("curve_y1", "End y coordinate", (0.0, -1e10, 1e10, 0.01), 4),
             ("curve_samples", "Number of samples", (256, 0, 1000000, 16), 0)])
        for key in ["curve_x0", "curve_y0", "curve_x1", "curve_y1"]:
            self.config_widget[key].adjustment.connect(
                "value_changed", self.coords_changed)

    def update(self, data):
        try:
            self.xpixels = data["xpixels"]
            self.ypixels = data["ypixels"]
            self.region = data["magpat"].region
            self.pixbuf = data["magpat_pixbuf"]
        except KeyError:
            return
        self.update_coords(data)

    def update_coords(self, data):
        pixels_per_width = self.xpixels / self.region.width
        pixels_per_height = self.ypixels / self.region.height
        self.tool.coords = (
            (data["curve_x0"] - self.region.x0) * pixels_per_width,
            (self.region.y1 - data["curve_y0"]) * pixels_per_height,
            (data["curve_x1"] - self.region.x0) * pixels_per_width,
            (self.region.y1 - data["curve_y1"]) * pixels_per_height)
        self.main_widget.mark_dirty()

    def get_pixbuf(self):
        return self.pixbuf

    def coords_changed(self, *args):
        if hasattr(self, "pixbuf"):
            self.update_coords(self.config_widget.get_config())

    def save_png(self, *args):
        filename = save_dialog("Save Magnification Pattern Image",
                               [("PNG Image Files", "*.png")])
        if filename is None:
            return
        pixmap = gtk.gdk.Pixmap(None, self.xpixels, self.ypixels, 24)
        cr = pixmap.cairo_create()
        cr.set_source_pixbuf(self.pixbuf, 0, 0)
        cr.paint()
        cr.move_to(*self.tool.coords[:2])
        cr.line_to(*self.tool.coords[2:])
        cr.set_source_rgb(1.0, 1.0, 1.0)
        cr.stroke()
        cr.get_target().write_to_png(filename)

    def get_actions(self):
        return [("Save PNG", self.save_png, hasattr(self, "pixbuf"))]