Exemplo n.º 1
0
    def __init__(self, fv):
        # superclass defines some variables for us, like logger
        super(ColorMapPicker, self).__init__(fv)

        # read preferences for this plugin
        prefs = self.fv.get_preferences()
        self.settings = prefs.createCategory('plugin_ColorMapPicker')
        self.settings.addDefaults(cbar_ht=20,
                                  cbar_wd=300,
                                  cbar_sep=10,
                                  cbar_pan_accel=1.0)
        self.settings.load(onError='silent')

        self._cmht = self.settings.get('cbar_ht', 20)
        self._cmwd = self.settings.get('cbar_wd', 300)
        self._cmsep = self.settings.get('cbar_sep', 10)
        self._cmxoff = 20
        self._wd = 300
        self._ht = 400
        self._max_y = 0

        # create a PIL viewer that we use to construct an RGB image
        # containing all the possible color bars and their labels
        self.p_view = CanvasView(logger=self.logger)
        p_v = self.p_view
        p_v.configure_surface(self._wd, self._ht)
        p_v.enable_autozoom('off')
        p_v.enable_autocuts('off')
        p_v.set_scale_limits(1.0, 1.0)
        p_v.set_pan(0, 0)
        p_v.zoom_to(1)
        p_v.cut_levels(0, 255)
        p_v.set_bg(0.4, 0.4, 0.4)

        # this will hold the resulting RGB image
        self.r_image = RGBImage.RGBImage(logger=self.logger)
        self.c_view = None
        self.cm_names = []
Exemplo n.º 2
0
    def load_image(self, filepath):
        # Create an image.  Assume type to be an AstroImage unless
        # the MIME association says it is something different.
        try:
            typ, subtyp = self.guess_filetype(filepath)

        except Exception as e:
            self.logger.warn(
                "error determining file type: %s; assuming 'image/fits'" %
                (str(e)))
            # Can't determine file type: assume and attempt FITS
            typ, subtyp = 'image', 'fits'

        self.logger.debug("assuming file type: %s/%s'" % (typ, subtyp))
        if (typ == 'image') and (subtyp not in ('fits', 'x-fits')):
            image = RGBImage.RGBImage(logger=self.logger)
        else:
            image = AstroImage.AstroImage(logger=self.logger)

        try:
            self.logger.info("Loading image from %s" % (filepath))
            image.load_file(filepath)
            #self.gui_do(chinfo.fitsimage.onscreen_message, "")

        except Exception as e:
            errmsg = "Failed to load file '%s': %s" % (filepath, str(e))
            self.logger.error(errmsg)
            try:
                (type, value, tb) = sys.exc_info()
                tb_str = "\n".join(traceback.format_tb(tb))
            except Exception as e:
                tb_str = "Traceback information unavailable."
            self.gui_do(self.show_error, errmsg + '\n' + tb_str)
            #chinfo.fitsimage.onscreen_message("Failed to load file", delay=1.0)
            raise ControlError(errmsg)

        self.logger.debug("Successfully loaded file into image object.")
        return image
Exemplo n.º 3
0
    def __init__(self, fv, fitsimage):
        # superclass defines some variables for us, like logger
        super(Overlays, self).__init__(fv, fitsimage)

        self.layertag = 'overlays-canvas'

        self.dc = fv.get_draw_classes()
        canvas = self.dc.DrawingCanvas()
        canvas.enable_draw(False)
        canvas.set_surface(self.fitsimage)
        self.canvas = canvas

        self.colornames = colors.get_colors()
        # TODO: there is some problem with basic "red", at least on Linux
        #self.hi_color = 'red'
        self.hi_color = 'palevioletred'
        self.hi_value = None
        self.lo_color = 'blue'
        self.lo_value = None
        self.opacity = 0.5
        self.arrsize = None
        self.rgbarr = numpy.zeros((1, 1, 4), dtype=numpy.uint8)
        self.rgbobj = RGBImage.RGBImage(self.rgbarr, logger=self.logger)
        self.canvas_img = None
Exemplo n.º 4
0
    def __init__(self, logger, ev_quit, options):
        super(GingaVision, self).__init__()
        self.logger = logger
        self.ev_quit = ev_quit

        from ginga.gw import Widgets, Viewers, GwMain

        self.card = 'default'
        # playback rate; changed when we know the actual rate
        self.fps = options.fps
        self.playback_rate = 1.0 / 30.0

        self.pimage = RGBImage.RGBImage()
        self.pdata = None

        self.app = Widgets.Application(logger=logger)
        self.app.add_callback('shutdown', self.quit)
        self.top = self.app.make_window("Ginga example2")
        self.top.add_callback('close', lambda *args: self.quit())

        thread_pool = Task.ThreadPool(2, logger, ev_quit=ev_quit)
        thread_pool.startall()
        self.main = GwMain.GwMain(logger=logger, ev_quit=ev_quit,
                                  app=self.app, thread_pool=thread_pool)

        vbox = Widgets.VBox()
        vbox.set_border_width(2)
        vbox.set_spacing(1)

        fi = Viewers.CanvasView(logger=logger)
        fi.set_autocut_params('histogram')
        fi.enable_autozoom('off')
        fi.enable_autocenter('once')
        fi.enable_autocuts('off')
        fi.cut_levels(0, 255)
        fi.scale_to(1, 1)
        fi.set_bg(0.2, 0.2, 0.2)
        fi.ui_set_active(True)
        self.viewer = fi

        if options.optimize:
            # Some optimizations to smooth playback at decent FPS
            # PassThruRGBMapper is the most efficient mapper
            rgbmap = RGBMap.PassThruRGBMapper(self.logger)
            fi.set_rgbmap(rgbmap)

            # Clip cuts assumes data does not need to be scaled in cut levels--
            # only clipped
            fi.set_autocuts(AutoCuts.Clip(logger=self.logger))

        bd = fi.get_bindings()
        bd.enable_all(True)

        fi.set_desired_size(512, 512)
        iw = Viewers.GingaViewerWidget(viewer=fi)
        vbox.add_widget(iw, stretch=1)

        hbox = Widgets.HBox()
        hbox.set_margins(4, 2, 4, 2)

        wopen = Widgets.Button("Open File")
        #wopen.clicked.connect(self.open_file)
        wquit = Widgets.Button("Quit")
        wquit.add_callback('activated', lambda *args: self.quit())

        for w in (wopen, wquit):
            hbox.add_widget(w, stretch=0)
        hbox.add_widget(Widgets.Label(''), stretch=1)

        vbox.add_widget(hbox, stretch=0)

        self.top.set_widget(vbox)
        self.top.set_title("Video Example Viewer")
Exemplo n.º 5
0
 def make_reduced_image(self, image):
     wd, ht = image.get_size()[:2]
     res = image.get_scaled_cutout_basic(0, 0, wd, ht, self.pct_reduce,
                                         self.pct_reduce)
     sm_img = RGBImage.RGBImage(data_np=res.data, order=image.order)
     return sm_img