Exemple #1
0
    def __init__(self, data_np=None, metadata=None, logger=None, name=None):

        Callback.Callbacks.__init__(self)

        if logger is not None:
            self.logger = logger
        else:
            self.logger = logging.Logger('BaseImage')
        if data_np is None:
            data_np = numpy.zeros((1, 1))
        self._data = data_np
        self.metadata = {}
        if metadata:
            self.update_metadata(metadata)
        self.order = ''
        self.name = name
        # make sure an image has these attributes
        # TODO: this maybe should have a unique random string or something
        # but we'd have to fix a lot of code that is currently checking for
        # None
        self.metadata.setdefault('name', None)

        self._set_minmax()

        self.autocuts = AutoCuts.Histogram(self.logger)

        # For callbacks
        for name in ('modified', ):
            self.enable_callback(name)
Exemple #2
0
    def config_autocut_params(self, method):
        index = self.autocut_methods.index(method)
        self.w.auto_method.set_index(index)

        # remove old params
        self.w.acvbox.remove_all()

        # Create new autocuts object of the right kind
        ac_class = AutoCuts.get_autocuts(method)

        # Build up a set of control widgets for the autocuts
        # algorithm tweakable parameters
        paramlst = ac_class.get_params_metadata()

        # Get the canonical version of this object stored in our cache
        # and make a ParamSet from it
        params = self.autocuts_cache.setdefault(method, Bunch.Bunch())
        self.ac_params = ParamSet.ParamSet(self.logger, params)

        # Build widgets for the parameter/attribute list
        w = self.ac_params.build_params(paramlst,
                                        orientation=self.orientation)
        self.ac_params.add_callback('changed', self.autocut_params_changed_cb)

        # Add this set of widgets to the pane
        self.w.acvbox.add_widget(w, stretch=1)
Exemple #3
0
    def config_autocut_params(self, method):
        index = self.autocut_methods.index(method)
        self.w.auto_method.set_index(index)

        # remove old params
        self.w.acvbox.remove_all()

        # Create new autocuts object of the right kind
        ac_class = AutoCuts.get_autocuts(method)

        # Build up a set of control widgets for the autocuts
        # algorithm tweakable parameters
        paramlst = ac_class.get_params_metadata()

        # Get the canonical version of this object stored in our cache
        # and make a ParamSet from it
        params = self.autocuts_cache.setdefault(method, Bunch.Bunch())
        self.ac_params = ParamSet.ParamSet(self.logger, params)

        # Build widgets for the parameter/attribute list
        w = self.ac_params.build_params(paramlst, orientation=self.orientation)
        self.ac_params.add_callback('changed', self.autocut_params_changed_cb)

        # Add this set of widgets to the pane
        self.w.acvbox.add_widget(w, stretch=1)
Exemple #4
0
    def __init__(self,
                 data_np=None,
                 metadata=None,
                 logger=None,
                 order=None,
                 name=None):

        ViewerObjectBase.__init__(self,
                                  logger=logger,
                                  metadata=metadata,
                                  name=name)

        if data_np is None:
            data_np = np.zeros((1, 1))
        self._data = data_np
        self.order = ''
        self.name = name

        # For navigating multidimensional data
        self.naxispath = []
        self.revnaxis = []

        self._set_minmax()
        self._calc_order(order)

        self.autocuts = AutoCuts.Histogram(self.logger)
Exemple #5
0
    def __init__(self, data_np=None, metadata=None, logger=None, name=None):

        ViewerObjectBase.__init__(self, logger=logger, metadata=metadata,
                                  name=name)

        if data_np is None:
            data_np = numpy.zeros((1, 1))
        self._data = data_np
        self.order = ''
        self.name = name

        self._set_minmax()

        self.autocuts = AutoCuts.Histogram(self.logger)
Exemple #6
0
    def __init__(self, fv, fitsimage):
        # superclass defines some variables for us, like logger
        super(Histogram, self).__init__(fv, fitsimage)

        self.layertag = 'histogram-canvas'
        self.histtag = None
        # If True, limits X axis to lo/hi cut levels
        self.xlimbycuts = True
        self._split_sizes = [400, 500]

        # get Histogram preferences
        prefs = self.fv.get_preferences()
        self.settings = prefs.create_category('plugin_Histogram')
        self.settings.add_defaults(draw_then_move=True, num_bins=2048,
                                   hist_color='aquamarine', show_stats=True,
                                   maxdigits=7)
        self.settings.load(onError='silent')

        # Set up histogram control parameters
        self.histcolor = self.settings.get('hist_color', 'aquamarine')
        self.numbins = self.settings.get('num_bins', 2048)
        self.autocuts = AutoCuts.Histogram(self.logger)

        # for formatting statistics line
        self.show_stats = self.settings.get('show_stats', True)
        maxdigits = self.settings.get('maxdigits', 7)
        self.fmt_cell = '{:< %d.%dg}' % (maxdigits - 1, maxdigits // 2)

        self.dc = self.fv.get_draw_classes()

        canvas = self.dc.DrawingCanvas()
        canvas.enable_draw(True)
        canvas.enable_edit(True)
        canvas.set_drawtype('rectangle', color='cyan', linestyle='dash',
                            drawdims=True)
        canvas.set_callback('draw-event', self.draw_cb)
        canvas.set_callback('edit-event', self.edit_cb)
        canvas.add_draw_mode('move', down=self.drag,
                             move=self.drag, up=self.update)
        canvas.register_for_cursor_drawing(self.fitsimage)
        canvas.set_surface(self.fitsimage)
        canvas.set_draw_mode('draw')
        self.canvas = canvas

        fitssettings = fitsimage.get_settings()
        for name in ['cuts']:
            fitssettings.get_setting(name).add_callback(
                'set', self.cutset_ext_cb, fitsimage)
        self.gui_up = False
Exemple #7
0
    def pre_init(self, fitsfile=os.path.join(script_dir, "test.fits")):
        #App design
        self.format_string = formats
        self.interface_file = os.path.join(script_dir,
                                           "WebbFITSViewer_interface.yaml")

        #Tunable settings
        self.pan_scale = 0.05
        self.initial_zoom = 1.0
        self.zoom_speed = 0.02

        #initialize the Ginga backend
        self.logger = log.get_logger("ginga",
                                     level=20,
                                     log_file="/tmp/ginga.log")
        self.autocuts = AutoCuts.Histogram(self.logger)
        self.selected_data = None
        self.box_corners = []

        self.pre_fitsfile = fitsfile
Exemple #8
0
    def config_autocut_params(self, method):
        index = self.autocut_methods.index(method)
        self.w.auto_method.set_index(index)
        
        # remove old params
        self.w.acvbox.remove_all()

        # Create new autocuts object of the right kind
        ac = AutoCuts.get_autocuts(method)(self.logger)

        # Build up a set of control widgets for the autocuts
        # algorithm tweakable parameters
        paramlst = ac.get_params_metadata()

        params = self.autocuts_cache.setdefault(method, {})
        self.ac_params = ParamSet.ParamSet(self.logger, params)

        w = self.ac_params.build_params(paramlst)
        self.ac_params.add_callback('changed', self.autocut_params_changed_cb)

        self.w.acvbox.add_widget(w, stretch=1)
Exemple #9
0
    def config_autocut_params(self, method):
        index = self.autocut_methods.index(method)
        self.w.auto_method.set_index(index)
        
        # remove old params
        self.w.acvbox.remove_all()

        # Create new autocuts object of the right kind
        ac = AutoCuts.get_autocuts(method)(self.logger)

        # Build up a set of control widgets for the autocuts
        # algorithm tweakable parameters
        paramlst = ac.get_params_metadata()

        params = self.autocuts_cache.setdefault(method, {})
        self.ac_params = ParamSet.ParamSet(self.logger, params)

        w = self.ac_params.build_params(paramlst,
                                        orientation=self.orientation)
        self.ac_params.add_callback('changed', self.autocut_params_changed_cb)

        self.w.acvbox.add_widget(w, stretch=1)
Exemple #10
0
    def __init__(self, data_np=None, metadata=None, logger=None):

        Callback.Callbacks.__init__(self)

        if logger != None:
            self.logger = logger
        else:
            self.logger = logging.Logger('AstroImage')
        if data_np == None:
            data_np = numpy.zeros((1, 1))
        self._data = data_np
        self.metadata = {}
        if metadata:
            self.update_metadata(metadata)

        self._set_minmax()

        self.autocuts = AutoCuts.AutoCuts(self.logger)

        # For callbacks
        for name in ('modified', ):
            self.enable_callback(name)
Exemple #11
0
    def config_autocut_params(self, method):
        index = self.autocut_methods.index(method)
        self.w.auto_method.setCurrentIndex(index)
        
        # remove old params
        layout = self.w.acvbox.layout()
        for child in QtHelp.children(layout):
            QtHelp.removeWidget(layout, child)

        # Create new autocuts object of the right kind
        ac = AutoCuts.get_autocuts(method)(self.logger)

        # Build up a set of control widgets for the autocuts
        # algorithm tweakable parameters
        paramlst = ac.get_params_metadata()

        params = self.autocuts_cache.setdefault(method, {})
        self.ac_params = QtHelp.ParamSet(self.logger, params)

        w = self.ac_params.build_params(paramlst)
        self.ac_params.add_callback('changed', self.autocut_params_changed_cb)

        self.w.acvbox.layout().addWidget(w, stretch=1)
Exemple #12
0
    def config_autocut_params(self, method):
        index = self.autocut_methods.index(method)
        self.w.auto_method.set_active(index)

        # remove old params
        for child in self.w.acvbox.get_children():
            self.w.acvbox.remove(child)

        # Create new autocuts object of the right kind
        ac = AutoCuts.get_autocuts(method)(self.logger)

        # Build up a set of control widgets for the autocuts
        # algorithm tweakable parameters
        paramlst = ac.get_params_metadata()

        params = self.autocuts_cache.setdefault(method, {})
        self.ac_params = GtkHelp.ParamSet(self.logger, params)

        w = self.ac_params.build_params(paramlst)
        self.ac_params.add_callback('changed', self.autocut_params_changed_cb)

        self.w.acvbox.pack_start(w, fill=True, expand=True)
        w.show()
Exemple #13
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, GwHelp, GwMain

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

        # Use an AstroImage, not RGBImage for now because we get a
        # different default (faster) scaling algorithm
        self.pimage = AstroImage.AstroImage()
        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.enable_autocuts('off')
        fi.set_autocut_params('histogram')
        fi.enable_autozoom('off')
        fi.cut_levels(0, 255)
        fi.defer_redraw = False
        fi.set_bg(0.2, 0.2, 0.2)
        # flip y
        fi.transform(False, False, False)
        fi.ui_setActive(True)
        self.fitsimage = fi

        # Some optomizations to smooth playback at decent FPS
        fi.set_redraw_lag(self.playback_rate)
        #fi.set_redraw_lag(0.0)
        fi._invertY = False
        # PassThruRGBMapper doesn't color map data--data is already colored
        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_pan(True)
        bd.enable_zoom(True)
        bd.enable_cuts(True)
        bd.enable_flip(True)
        bd.enable_cmap(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")
Exemple #14
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")
Exemple #15
0
    def __init__(self, logger=None, rgbmap=None, settings=None):
        Callback.Callbacks.__init__(self)

        if logger != None:
            self.logger = logger
        else:
            self.logger = logging.Logger('FitsImageBase')

        # RGB mapper
        if rgbmap:
            self.rgbmap = rgbmap
        else:
            rgbmap = RGBMap.RGBMapper()
            self.rgbmap = rgbmap

        # Object that calculates auto cut levels
        self.autocuts = AutoCuts.AutoCuts(self.logger)

        # Dummy 1-pixel image
        self.image = AstroImage.AstroImage(numpy.zeros((1, 1)),
                                           logger=self.logger)
        # for debugging
        self.name = str(self)

        # Create settings and set defaults
        if settings == None:
            settings = Settings.SettingGroup(logger=self.logger)
        self.t_ = settings

        # for color mapping
        self.t_.addDefaults(color_map='ramp',
                            intensity_map='ramp',
                            color_algorithm='linear',
                            color_hashsize=65535)
        for name in ('color_map', 'intensity_map', 'color_algorithm',
                     'color_hashsize'):
            self.t_.getSetting(name).add_callback('set', self.cmap_changed_cb)

        # Initialize RGBMap
        cmap_name = self.t_.get('color_map', 'ramp')
        try:
            cm = cmap.get_cmap(cmap_name)
        except KeyError:
            cm = cmap.get_cmap('ramp')
        rgbmap.set_cmap(cm)
        imap_name = self.t_.get('intensity_map', 'ramp')
        try:
            im = imap.get_imap(imap_name)
        except KeyError:
            im = imap.get_imap('ramp')
        rgbmap.set_imap(im)
        hash_size = self.t_.get('color_hashsize', 65535)
        rgbmap.set_hash_size(hash_size)
        hash_alg = self.t_.get('color_algorithm', 'linear')
        rgbmap.set_hash_algorithm(hash_alg)

        rgbmap.add_callback('changed', self.rgbmap_cb)

        # for cut levels
        self.t_.addDefaults(locut=0.0, hicut=0.0)
        for name in ('locut', 'hicut'):
            self.t_.getSetting(name).add_callback('set', self.cut_levels_cb)

        # for auto cut levels
        self.autocuts_options = ('on', 'override', 'off')
        self.t_.addDefaults(
            autocuts='override',
            autocut_method='histogram',
            autocut_hist_pct=AutoCuts.default_autocuts_hist_pct,
            autocut_bins=AutoCuts.default_autocuts_bins)
        for name in ('autocuts', 'autocut_method', 'autocut_hist_pct',
                     'autocut_bins'):
            self.t_.getSetting(name).add_callback('set', self.auto_levels_cb)

        # for zooming
        self.t_.addDefaults(zoomlevel=1.0,
                            zoom_algorithm='step',
                            scale_x_base=1.0,
                            scale_y_base=1.0,
                            zoom_rate=math.sqrt(2.0))
        for name in ('zoom_rate', 'zoom_algorithm', 'scale_x_base',
                     'scale_y_base'):
            self.t_.getSetting(name).add_callback('set',
                                                  self.zoomalg_change_cb)

        # max/min scaling
        self.t_.addDefaults(scale_max=10000.0, scale_min=0.00001)

        # autozoom options
        self.autozoom_options = ('on', 'override', 'off')
        self.t_.addDefaults(autozoom='on')

        # for panning
        self.t_makebg = False
        self.t_.addDefaults(reverse_pan=False, autocenter=True)

        # for transforms
        self.t_.addDefaults(flip_x=False, flip_y=False, swap_xy=False)
        for name in ('flip_x', 'flip_y', 'swap_xy'):
            self.t_.getSetting(name).add_callback('set', self.transform_cb)

        # desired rotation angle
        self.t_.addDefaults(rot_deg=0.0)
        self.t_.getSetting('rot_deg').add_callback('set',
                                                   self.rotation_change_cb)

        # misc
        self.t_.addDefaults(use_embedded_profile=True, auto_orient=False)

        # PRIVATE IMPLEMENTATION STATE

        # image window width and height (see set_window_dimensions())
        self._imgwin_wd = 1
        self._imgwin_ht = 1
        self._imgwin_set = False
        # center (and reference) pixel in the screen image (in pixel coords)
        self._ctr_x = 1
        self._ctr_y = 1
        # data indexes at the reference pixel (in data coords)
        self._org_x = 0
        self._org_y = 0

        # pan position
        self._pan_x = 0.0
        self._pan_y = 0.0

        # Origin in the data array of what is currently displayed (LL, UR)
        self._org_x1 = 0
        self._org_y1 = 0
        self._org_x2 = 0
        self._org_y2 = 0
        # offsets in the screen image for drawing (in screen coords)
        self._dst_x = 0
        self._dst_y = 0
        self._invertY = True
        # offsets in the screen image (in data coords)
        self._off_x = 0
        self._off_y = 0

        # desired scale factors
        self._scale_x = 1.0
        self._scale_y = 1.0
        # actual scale factors produced from desired ones
        self._org_scale_x = 0
        self._org_scale_y = 0

        self._cutout = None
        self._rotimg = None
        self._prergb = None
        self._rgbarr = None

        self.orientMap = {
            # tag: (flip_x, flip_y, swap_xy)
            1: (False, True, False),
            2: (True, True, False),
            3: (True, False, False),
            4: (False, False, False),
            5: (True, False, True),
            6: (True, True, True),
            7: (False, True, True),
            8: (False, False, True),
        }

        # For callbacks
        # TODO: we should be able to deprecate a lot of these with the new
        # settings callbacks
        for name in ('cut-set', 'zoom-set', 'pan-set', 'transform', 'rotate',
                     'image-set', 'configure', 'autocuts', 'autozoom'):
            self.enable_callback(name)
Exemple #16
0
    def __init__(self, qtmain, logger, ev_quit, options):
        super(GingaVision, self).__init__()
        self.qtmain = qtmain
        self.logger = logger
        self.ev_quit = ev_quit

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

        # Use an AstroImage, not RGBImage for now because we get a
        # different default (faster) scaling algorithm
        self.pimage = AstroImage.AstroImage()
        self.pdata = None

        fi = ImageViewZoom(self.logger, render='widget')
        fi.enable_autocuts('off')
        fi.set_autocut_params('histogram')
        fi.enable_autozoom('off')
        fi.cut_levels(0, 255)
        fi.defer_redraw = False
        fi.set_bg(0.2, 0.2, 0.2)
        # flip y
        fi.transform(False, False, False)
        fi.ui_setActive(True)
        self.fitsimage = fi

        # Some optomizations to smooth playback at decent FPS
        fi.set_redraw_lag(self.playback_rate)
        #fi.set_redraw_lag(0.0)
        fi._invertY = False
        # PassThruRGBMapper doesn't color map data--data is already colored
        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_pan(True)
        bd.enable_zoom(True)
        bd.enable_cuts(True)
        bd.enable_flip(True)
        bd.enable_cmap(True)

        w = fi.get_widget()
        w.resize(512, 512)

        vbox = QtGui.QVBoxLayout()
        vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
        vbox.setSpacing(1)
        vbox.addWidget(w, stretch=1)

        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

        wopen = QtGui.QPushButton("Open File")
        #wopen.clicked.connect(self.open_file)
        wquit = QtGui.QPushButton("Quit")
        wquit.clicked.connect(self.quit)

        hbox.addStretch(1)
        for w in (wopen, wquit):
            hbox.addWidget(w, stretch=0)

        hw = QtGui.QWidget()
        hw.setLayout(hbox)
        vbox.addWidget(hw, stretch=0)

        vw = QtGui.QWidget()
        self.setCentralWidget(vw)
        vw.setLayout(vbox)

        self.setWindowTitle("Video Example Viewer")