Exemple #1
0
    def table_click(self, item):
      row = item.row()
      entry_id = int(self.wtable.item(row, 0).data(0))
      # print row
      # print "Id:", self.wtable.item(row, 0).data(0)
      # print dir(self.wtable.item(row, 0))
      entry = database.get_entry_by_id(entry_id)
      print entry.path

      image = AstroImage.AstroImage()
      image.load_file(entry.path)
      
      # TODO: Fit image to entire available space?
      chaname = entry.path.split('/')[-1]
      self.fv.add_image(chaname, image, chname=chaname)
      self.fitsimage = self.fv.get_fitsimage(chaname)

      #Create a map with only the already opened metadata for speed
      sunpy_map = sunpy.map.Map((np.zeros([1,1]), image.get_header()))
      cm = "{0}{1}{2}".format(sunpy_map.observatory.lower(),
                              sunpy_map.detector.lower(), sunpy_map.wavelength)
      try:
          cm = cmap.get_cmap(cm)
          rgbmap = self.fitsimage.get_rgbmap()
          rgbmap.set_cmap(cm)
      except KeyError:
          pass
    def rebuild_cmaps(self):
        """Builds a color RGB image containing color bars of all the
        possible color maps and their labels.
        """
        self.logger.info("building color maps image")
        ht, wd, sep = self._cmht, self._cmwd, self._cmsep
        viewer = self.p_view

        # put the canvas into pick mode
        canvas = viewer.get_canvas()
        canvas.delete_all_objects()

        # get the list of color maps
        cm_names = self.cm_names
        num_cmaps = len(cm_names)
        viewer.configure_surface(500, (ht + sep) * num_cmaps)

        # create a bunch of color bars and make one large compound object
        # with callbacks for clicking on individual color bars
        l2 = []
        ColorBar = canvas.get_draw_class('drawablecolorbar')
        Text = canvas.get_draw_class('text')
        #ch_rgbmap = chviewer.get_rgbmap()
        #dist = ch_rgbmap.get_dist()
        dist = None
        #imap = ch_rgbmap.get_imap()
        logger = viewer.get_logger()

        for i, name in enumerate(cm_names):
            rgbmap = RGBMap.RGBMapper(logger, dist=dist)
            rgbmap.set_cmap(cmap.get_cmap(name))
            #rgbmap.set_imap(imap)
            x1, y1 = self._cmxoff, i * (ht + sep)
            x2, y2 = x1 + wd, y1 + ht
            cbar = ColorBar(x1,
                            y1,
                            x2,
                            y2,
                            cm_name=name,
                            showrange=False,
                            rgbmap=rgbmap,
                            coord='canvas')
            l2.append(cbar)
            l2.append(
                Text(x2 + sep,
                     y2,
                     name,
                     color='white',
                     fontsize=16,
                     coord='canvas'))

        Compound = canvas.get_draw_class('compoundobject')
        obj = Compound(*l2)
        canvas.add(obj)

        self._max_y = y2

        rgb_img = self.p_view.get_image_as_array()
        self.r_image.set_data(rgb_img)
Exemple #3
0
 def menu_actions(self):
     acts = []
     for label in ginga_cmap.get_names():
         cmap = ginga_cmap.get_cmap(label)
         a = ColormapAction(label, cmap, self.viewer)
         a.triggered.connect(nonpartial(self.viewer.client.set_cmap, cmap))
         acts.append(a)
     return acts
Exemple #4
0
 def menu_actions(self):
     acts = []
     for label in ginga_cmap.get_names():
         cmap = ginga_cmap.get_cmap(label)
         a = ColormapAction(label, cmap, self.viewer)
         a.triggered.connect(nonpartial(self.viewer.client.set_cmap, cmap))
         acts.append(a)
     return acts
Exemple #5
0
    def __init__(self, logger, threadPool, module_manager, preferences,
                 ev_quit=None, datasrc_length=20, follow_focus=False):
        Callback.Callbacks.__init__(self)

        self.logger = logger
        self.threadPool = threadPool
        self.mm = module_manager
        self.prefs = preferences
        # event for controlling termination of threads executing in this
        # object
        if not ev_quit:
            self.ev_quit = threading.Event()
        else:
            self.ev_quit = ev_quit

        # For callbacks
        for name in ('add-image', 'active-image', 'add-channel',
                     'delete-channel', 'field-info'):
            self.enable_callback(name)

        self.gui_queue = Queue.Queue()
        self.gui_thread_id = None
        # For asynchronous tasks on the thread pool
        self.tag = 'master'
        self.shares = ['threadPool', 'logger']

        self.lock = threading.RLock()
        self.channel = {}
        self.channelNames = []
        self.chinfo = None
        self.chncnt = 0
        self.statustask = None

        # Should channel change as mouse moves between windows
        self.channel_follows_focus = follow_focus
        
        # Number of images to keep around in memory
        self.default_datasrc_length = datasrc_length
        
        self.cm = cmap.get_cmap("ramp")
        self.im = imap.get_imap("ramp")

        self.fn_keys = ('f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8',
                        'f9', 'f10', 'f11', 'f12')
        
        self.global_plugins = {}
        self.local_plugins = {}
        self.operations  = []

        # This plugin manager handles "global" (aka standard) plug ins
        # (unique instances, not per channel)
        self.gpmon = self.getPluginManager(self.logger, self,
                                           None, self.mm)

        # Initialize image server bank
        self.imgsrv = Catalog.ServerBank(self.logger)
        self.dsscnt = 0
Exemple #6
0
    def set_cmap_byname(self, name, redraw=True):
        # Get colormap
        try:
            cm = cmap.get_cmap(name)
        except KeyError:
            raise FitsImageError("No such color map name: '%s'" % (name))

        rgbmap = self.fitsimage.get_rgbmap()
        rgbmap.set_cmap(cm)
Exemple #7
0
    def set_cmap_byname(self, name):
        # Get colormap
        try:
            cm = cmap.get_cmap(name)
        except KeyError:
            raise ValueError("No such color map name: '%s'" % (name))

        rgbmap = self.fitsimage.get_rgbmap()
        rgbmap.set_cmap(cm)
Exemple #8
0
    def set_cmap_cb(self, kind):
        index = self.wcmap.currentIndex()
        cmap_name = self.cmaps[index]
        self.cm = cmap.get_cmap(cmap_name)
        index = self.wimap.currentIndex()
        imap_name = self.imaps[index]
        self.im = imap.get_imap(imap_name)

        self.fitsimage.set_cmap(self.cm)
        self.fitsimage.set_imap(self.im)
Exemple #9
0
    def set_cmap_cb(self, kind):
        index = self.wcmap.currentIndex()
        cmap_name = self.cmaps[index]
        self.cm = cmap.get_cmap(cmap_name)
        index = self.wimap.currentIndex()
        imap_name = self.imaps[index]
        self.im = imap.get_imap(imap_name)

        self.fitsimage.set_cmap(self.cm)
        self.fitsimage.set_imap(self.im)
Exemple #10
0
    def rebuild_cmaps(self):
        """Builds a color RGB image containing color bars of all the
        possible color maps and their labels.
        """
        self.logger.info("building color maps image")
        ht, wd, sep = self._cmht, self._cmwd, self._cmsep
        viewer = self.p_view

        # put the canvas into pick mode
        canvas = viewer.get_canvas()
        canvas.delete_all_objects()

        # get the list of color maps
        cm_names = self.cm_names
        num_cmaps = len(cm_names)
        viewer.configure_surface(500, (ht + sep) * num_cmaps)

        # create a bunch of color bars and make one large compound object
        # with callbacks for clicking on individual color bars
        l2 = []
        ColorBar = canvas.get_draw_class('drawablecolorbar')
        Text = canvas.get_draw_class('text')
        #ch_rgbmap = chviewer.get_rgbmap()
        #dist = ch_rgbmap.get_dist()
        dist = None
        #imap = ch_rgbmap.get_imap()
        logger = viewer.get_logger()

        for i, name in enumerate(cm_names):
            rgbmap = RGBMap.RGBMapper(logger, dist=dist)
            rgbmap.set_cmap(cmap.get_cmap(name))
            #rgbmap.set_imap(imap)
            x1, y1 = self._cmxoff, i * (ht + sep)
            x2, y2 = x1 + wd, y1 + ht
            cbar = ColorBar(x1, y1, x2, y2, cm_name=name, showrange=False,
                            rgbmap=rgbmap, coord='canvas')
            l2.append(cbar)
            l2.append(Text(x2+sep, y2, name, color='white', fontsize=16,
                           coord='canvas'))

        Compound = canvas.get_draw_class('compoundobject')
        obj = Compound(*l2)
        canvas.add(obj)

        self._max_y = y2

        rgb_img = self.p_view.get_image_as_array()
        self.r_image.set_data(rgb_img)
Exemple #11
0
    def cmap_changed_cb(self, setting, value):
        self.logger.info("Color settings have changed.")

        cmap_name = self.t_.get('color_map', "ramp")
        cm = cmap.get_cmap(cmap_name)
        self.rgbmap.set_cmap(cm, callback=False)

        imap_name = self.t_.get('intensity_map', "ramp")
        im = imap.get_imap(imap_name)
        self.rgbmap.set_imap(im, callback=False)

        hash_size = self.t_.get('color_hashsize', 65535)
        self.rgbmap.set_hash_size(hash_size, callback=False)

        hash_alg = self.t_.get('color_algorithm', "linear")
        self.rgbmap.set_hash_algorithm(hash_alg, callback=True)
Exemple #12
0
    def cmap_changed_cb(self, setting, value):
        self.logger.info("Color settings have changed.")

        cmap_name = self.t_.get('color_map', "ramp")
        cm = cmap.get_cmap(cmap_name)
        self.rgbmap.set_cmap(cm, callback=False)
        
        imap_name = self.t_.get('intensity_map', "ramp")
        im = imap.get_imap(imap_name)
        self.rgbmap.set_imap(im, callback=False)
        
        hash_size = self.t_.get('color_hashsize', 65535)
        self.rgbmap.set_hash_size(hash_size, callback=False)
        
        hash_alg = self.t_.get('color_algorithm', "linear")
        self.rgbmap.set_hash_algorithm(hash_alg, callback=True)
Exemple #13
0
    def __init__(self, logger, container):
        super(CatalogListing, self).__init__()

        self.logger = logger
        self.tag = None
        self.cmap_names = cmap.get_names()
        self.imap_names = imap.get_names()
        self.magcmap = 'stairs8'
        self.magimap = 'ramp'

        self.mag_field = 'mag'
        self.mag_max = 25.0
        self.mag_min = 0.0
        self.color_default = 'skyblue'

        # keys: are name, ra, dec, mag, flag, b_r, preference, priority, dst
        # TODO: automate this generation
        self.columns = [
            ('Name', 'name'),
            ('RA', 'ra'),
            ('DEC', 'dec'),
            ('Mag', 'mag'),
            ('Preference', 'preference'),
            ('Priority', 'priority'),
            ('Description', 'description'),
            ('Index', 'index'),
        ]

        self.catalog = None
        self.cursor = 0
        self.color_selected = 'skyblue'
        self.selection_mode = 'single'
        self.selected = []
        self.moving_cursor = False

        self.btn = Bunch.Bunch()

        self.cmap = cmap.get_cmap(self.magcmap)
        self.imap = imap.get_imap('ramp')
        self.cbar_ht = 32

        self.operation_table = []
        self._select_flag = False

        self._build_gui(container)
Exemple #14
0
    def __init__(self, logger, container):
        super(CatalogListing, self).__init__()

        self.logger = logger
        self.tag = None
        self.cmap_names = cmap.get_names()
        self.imap_names = imap.get_names()
        self.magcmap = 'stairs8'
        self.magimap = 'ramp'

        self.mag_field = 'mag'
        self.mag_max = 25.0
        self.mag_min = 0.0
        self.color_default = 'skyblue'

        # keys: are name, ra, dec, mag, flag, b_r, preference, priority, dst
        # TODO: automate this generation
        self.columns = [('Name', 'name'),
                        ('RA', 'ra'),
                        ('DEC', 'dec'),
                        ('Mag', 'mag'),
                        ('Preference', 'preference'),
                        ('Priority', 'priority'),
                        ('Description', 'description'),
                        ('Index', 'index'),
                        ]

        self.catalog = None
        self.cursor = 0
        self.color_selected = 'skyblue'
        self.selection_mode = 'single'
        self.selected = []
        self.moving_cursor = False

        self.btn = Bunch.Bunch()

        self.cmap = cmap.get_cmap(self.magcmap)
        self.imap = imap.get_imap('ramp')
        self.cbar_ht = 32

        self.operation_table = []
        self._select_flag = False

        self._build_gui(container)
Exemple #15
0
    def cmap_changed_cb(self, setting, value):
        # This method is a callback that is invoked when the color settings
        # have changed in some way.
        self.logger.info("Color settings have changed.")

        # Update our RGBMapper with any changes
        cmap_name = self.t_.get('color_map', "ramp")
        cm = cmap.get_cmap(cmap_name)
        self.rgbmap.set_cmap(cm, callback=False)
        
        imap_name = self.t_.get('intensity_map', "ramp")
        im = imap.get_imap(imap_name)
        self.rgbmap.set_imap(im, callback=False)
        
        hash_size = self.t_.get('color_hashsize', 65535)
        self.rgbmap.set_hash_size(hash_size, callback=False)
        
        hash_alg = self.t_.get('color_algorithm', "linear")
        self.rgbmap.set_hash_algorithm(hash_alg, callback=True)
Exemple #16
0
def _colormap_mode(parent, on_trigger):

    # actions for each colormap
    acts = []
    # for label, cmap in config.colormaps:
    for label in ginga_cmap.get_names():
        cmap = ginga_cmap.get_cmap(label)
        a = ColormapAction(label, cmap, parent)
        a.triggered.connect(nonpartial(on_trigger, cmap))
        acts.append(a)

    # Toolbar button
    tb = QtWidgets.QToolButton()
    tb.setWhatsThis("Set color scale")
    tb.setToolTip("Set color scale")
    icon = get_icon('glue_rainbow')
    tb.setIcon(icon)
    tb.setPopupMode(QtWidgets.QToolButton.InstantPopup)
    tb.addActions(acts)

    return tb
Exemple #17
0
def _colormap_mode(parent, on_trigger):

    # actions for each colormap
    acts = []
    # for label, cmap in config.colormaps:
    for label in ginga_cmap.get_names():
        cmap = ginga_cmap.get_cmap(label)
        a = ColormapAction(label, cmap, parent)
        a.triggered.connect(nonpartial(on_trigger, cmap))
        acts.append(a)

    # Toolbar button
    tb = QToolButton()
    tb.setWhatsThis("Set color scale")
    tb.setToolTip("Set color scale")
    icon = get_icon('glue_rainbow')
    tb.setIcon(icon)
    tb.setPopupMode(QToolButton.InstantPopup)
    tb.addActions(acts)

    return tb
Exemple #18
0
    def on_table_row_click(self, item):
        '''
    		Event handler for opening a new image when a particular row entry if
    		clicked
    	'''
        row = item.row()
        col = item.column()

        entry_id = int(self.wtable.item(row, 0).data(0))

        entry = database.get_entry_by_id(entry_id)

        if col == self.table_headers.index('Starred'):
            if entry.starred:
                database.unstar(entry)
            else:
                database.star(entry)

            database.commit()
            self.view_database()

        image = AstroImage.AstroImage()
        image.load_file(entry.path)

        # TODO: Fit image to entire available space?
        chaname = entry.path.split('/')[-1]
        self.fv.add_image(chaname, image, chname=chaname)
        self.fitsimage = self.fv.get_fitsimage(chaname)

        #Create a map with only the already opened metadata for speed
        sunpy_map = sunpy.map.Map((np.zeros([1, 1]), image.get_header()))
        cm = "{0}{1}{2}".format(sunpy_map.observatory.lower(),
                                sunpy_map.detector.lower(),
                                sunpy_map.wavelength)
        try:
            cm = cmap.get_cmap(cm)
            rgbmap = self.fitsimage.get_rgbmap()
            rgbmap.set_cmap(cm)
        except KeyError:
            pass
Exemple #19
0
    def __init__(self, logger, container):
        super(CatalogListingBase, self).__init__()
        
        self.logger = logger
        self.tag = None
        self.mycolor = 'skyblue'
        self.magmap = 'stairs8'

        self.mag_max = 25.0
        self.mag_min = 0.0

        # keys: are name, ra, dec, mag, flag, b_r, preference, priority, dst
        # TODO: automate this generation
        self.columns = [('Name', 'name'),
                        ('RA', 'ra'),
                        ('DEC', 'dec'),
                        ('Mag', 'mag'),
                        ('Preference', 'preference'),
                        ('Priority', 'priority'),
                        ('Flag', 'flag'),
                        ('b-r', 'b_r'),
                        ('Dst', 'dst'),
                        ('Description', 'description'),
                        ]

        self.catalog = None
        self.cursor = 0
        self.color_cursor = 'red'
        self.color_selected = 'skyblue'
        self.selection_mode = 'single'
        self.selected = []
        self.moving_cursor = False

        self.btn = Bunch.Bunch()

        self.cmap = cmap.get_cmap(self.magmap)
        self.imap = imap.get_imap('ramp')

        self._build_gui(container)
Exemple #20
0
    def on_table_row_click(self, item):
        """
    		Event handler for opening a new image when a particular row entry if
    		clicked
    	"""
        row = item.row()
        col = item.column()

        entry_id = int(self.wtable.item(row, 0).data(0))

        entry = database.get_entry_by_id(entry_id)

        if col == self.table_headers.index("Starred"):
            if entry.starred:
                database.unstar(entry)
            else:
                database.star(entry)

            database.commit()
            self.view_database()

        image = AstroImage.AstroImage()
        image.load_file(entry.path)

        # TODO: Fit image to entire available space?
        chaname = entry.path.split("/")[-1]
        self.fv.add_image(chaname, image, chname=chaname)
        self.fitsimage = self.fv.get_fitsimage(chaname)

        # Create a map with only the already opened metadata for speed
        sunpy_map = sunpy.map.Map((np.zeros([1, 1]), image.get_header()))
        cm = "{0}{1}{2}".format(sunpy_map.observatory.lower(), sunpy_map.detector.lower(), sunpy_map.wavelength)
        try:
            cm = cmap.get_cmap(cm)
            rgbmap = self.fitsimage.get_rgbmap()
            rgbmap.set_cmap(cm)
        except KeyError:
            pass
Exemple #21
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 #22
0
    def __init__(self, logger):
        super(FitsViewer, self).__init__()
        self.logger = logger

        menubar = self.menuBar()

        # create a File pulldown menu, and add it to the menu bar
        filemenu = menubar.addMenu("File")

        item = QtGui.QAction("Open File", menubar)
        item.triggered.connect(self.open_file)
        filemenu.addAction(item)

        sep = QtGui.QAction(menubar)
        sep.setSeparator(True)
        filemenu.addAction(sep)

        item = QtGui.QAction("Quit", menubar)
        item.triggered.connect(self.close)
        filemenu.addAction(item)

        # Add matplotlib color maps to our built in ones
        cmap.add_matplotlib_cmaps()
        self.cmaps = cmap.get_names()
        self.imaps = imap.get_names()

        wd, ht = 500, 500

        # Create a Ginga widget
        fi = ImageViewCanvas(logger, render='widget')
        fi.enable_autocuts('on')
        fi.set_autocut_params('zscale')
        fi.enable_autozoom('on')
        fi.enable_draw(False)
        fi.set_callback('drag-drop', self.drop_file_cb)
        fi.set_callback('cursor-changed', self.cursor_cb)
        fi.set_bg(0.2, 0.2, 0.2)
        fi.ui_set_active(True)
        self.fitsimage = fi

        fi.show_color_bar(True)

        # enable various key and mouse controlled actions
        bd = fi.get_bindings()
        bd.enable_all(True)

        self.cp_tag = 'compass'

        # pack widget into layout
        gingaw = fi.get_widget()
        gingaw.resize(wd, ht)

        vbox1 = QtGui.QWidget()
        layout = QtGui.QVBoxLayout()
        layout.addWidget(gingaw, stretch=1)

        self.cm = cmap.get_cmap('gray')
        self.im = imap.get_imap('ramp')

        # color map selection widget
        wcmap = QtGui.QComboBox()
        for name in self.cmaps:
            wcmap.addItem(name)
        index = self.cmaps.index('gray')
        wcmap.setCurrentIndex(index)
        wcmap.activated.connect(self.set_cmap_cb)
        self.wcmap = wcmap

        # intensity map selection widget
        wimap = QtGui.QComboBox()
        for name in self.imaps:
            wimap.addItem(name)
        index = self.imaps.index('ramp')
        wimap.setCurrentIndex(index)
        wimap.activated.connect(self.set_cmap_cb)
        self.wimap = wimap

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

        # add buttons to layout
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))
        hbox.addStretch(1)
        for w in (wcmap, wimap):
            hbox.addWidget(w, stretch=0)

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

        # Create a matplotlib Figure
        #self.fig = matplotlib.figure.Figure(figsize=(wd, ht))
        self.fig = matplotlib.figure.Figure()
        self.canvas = FigureCanvas(self.fig)

        vbox2 = QtGui.QWidget()
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.canvas, stretch=1)

        # Add matplotlib buttons
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

        wgetimg = QtGui.QPushButton("Get Data")
        wgetimg.clicked.connect(self.get_image)
        wgetrgb = QtGui.QPushButton("Get RGB")
        wgetrgb.clicked.connect(self.get_rgb_image)
        #wquit = QtGui.QPushButton("Quit")
        #wquit.clicked.connect(self.close)

        hbox.addStretch(1)
        for w in (wgetimg, wgetrgb):
            hbox.addWidget(w, stretch=0)

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

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

        w = QtGui.QWidget()
        layout = QtGui.QHBoxLayout()
        layout.addWidget(vbox1, stretch=1.0)
        layout.addWidget(vbox2, stretch=1.0)
        w.setLayout(layout)

        vbox.addWidget(w, stretch=1)

        self.readout = QtGui.QLabel("")
        vbox.addWidget(self.readout,
                       stretch=0,
                       alignment=QtCore.Qt.AlignCenter)

        vw = QtGui.QWidget()
        vw.setLayout(vbox)
        self.setCentralWidget(vw)
Exemple #23
0
    def __init__(self, logger, container):
        self.logger = logger
        self.tag = None
        self.mycolor = 'skyblue'
        self.magmap = 'stairs8'

        self.mag_max = 25.0
        self.mag_min = 0.0

        # keys: are name, ra, dec, mag, flag, b_r, preference, priority, dst
        # TODO: automate this generation
        self.columns = [
            ('Name', 'name'),
            ('RA', 'ra'),
            ('DEC', 'dec'),
            ('Mag', 'mag'),
            ('Preference', 'preference'),
            ('Priority', 'priority'),
            ('Flag', 'flag'),
            ('b-r', 'b_r'),
            ('Dst', 'dst'),
            ('Description', 'description'),
        ]
        self.cell_sort_funcs = []
        for kwd, key in self.columns:
            self.cell_sort_funcs.append(self._mksrtfnN(key))

        self.catalog = None
        self.cursor = 0
        self.color_cursor = 'red'
        self.color_selected = 'skyblue'
        self.selection_mode = 'single'
        self.selected = []
        self.moving_cursor = False

        self.btn = Bunch.Bunch()

        self.mframe = container

        vbox = gtk.VBox()

        sw = gtk.ScrolledWindow()
        sw.set_border_width(2)
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        #self.font = pango.FontDescription('Monospace 10')

        # create the TreeView
        treeview = gtk.TreeView()
        self.treeview = treeview

        # create the TreeViewColumns to display the data
        tvcolumn = [None] * len(self.columns)
        for n in range(0, len(self.columns)):
            cell = gtk.CellRendererText()
            cell.set_padding(2, 0)
            header, kwd = self.columns[n]
            tvc = gtk.TreeViewColumn(header, cell)
            tvc.set_spacing(4)
            tvc.set_resizable(True)
            tvc.connect('clicked', self.sort_cb, n)
            tvc.set_clickable(True)
            tvcolumn[n] = tvc
            fn_data = self._mkcolfnN(kwd)
            tvcolumn[n].set_cell_data_func(cell, fn_data)
            treeview.append_column(tvcolumn[n])

        sw.add(treeview)
        self.treeview.connect('cursor-changed', self.select_star)
        sw.show_all()
        vbox.pack_start(sw, fill=True, expand=True)

        self.cbar = ColorBar.ColorBar(self.logger)
        self.cmap = cmap.get_cmap(self.magmap)
        self.imap = imap.get_imap('ramp')
        self.cbar.set_cmap(self.cmap)
        self.cbar.set_imap(self.imap)
        self.cbar.set_size_request(-1, 20)

        vbox.pack_start(self.cbar, padding=4, fill=True, expand=False)

        btns = gtk.HButtonBox()
        btns.set_layout(gtk.BUTTONBOX_CENTER)
        btns.set_spacing(5)

        for name in (
                'Plot',
                'Clear',  #'Close'
        ):
            btn = gtk.Button(name)
            btns.add(btn)
            self.btn[name.lower()] = btn

        self.btn.plot.connect('clicked', lambda w: self.replot_stars())
        self.btn.clear.connect('clicked', lambda w: self.clear())
        #self.btn.close.connect('clicked', lambda w: self.close())

        vbox.pack_start(btns, padding=4, fill=True, expand=False)
        vbox.show_all()

        self.mframe.pack_start(vbox, expand=True, fill=True)
        self.mframe.show_all()
Exemple #24
0
    def __init__(self, logger):
        super(FitsViewer, self).__init__()
        self.logger = logger

        menubar = self.menuBar()

        # create a File pulldown menu, and add it to the menu bar
        filemenu = menubar.addMenu("File")

        item = QtGui.QAction("Open File", menubar)
        item.triggered.connect(self.open_file)
        filemenu.addAction(item)

        sep = QtGui.QAction(menubar)
        sep.setSeparator(True)
        filemenu.addAction(sep)

        item = QtGui.QAction("Quit", menubar)
        item.triggered.connect(self.close)
        filemenu.addAction(item)

        # Add matplotlib color maps to our built in ones
        cmap.add_matplotlib_cmaps()
        self.cmaps = cmap.get_names()
        self.imaps = imap.get_names()

        wd, ht = 500, 500

        # Create a Ginga widget
        fi = ImageViewCanvas(logger, render='widget')
        fi.enable_autocuts('on')
        fi.set_autocut_params('zscale')
        fi.enable_autozoom('on')
        fi.enable_draw(False)
        fi.set_callback('drag-drop', self.drop_file)
        fi.set_callback('none-move', self.motion)
        fi.set_bg(0.2, 0.2, 0.2)
        fi.ui_setActive(True)
        self.fitsimage = fi

        # enable various key and mouse controlled actions
        bd = fi.get_bindings()
        bd.enable_all(True)

        self.cp_tag = 'compass'

        # pack widget into layout
        gingaw = fi.get_widget()
        gingaw.resize(wd, ht)

        vbox1 = QtGui.QWidget()
        layout = QtGui.QVBoxLayout()
        layout.addWidget(gingaw, stretch=1)

        self.cm = cmap.get_cmap('gray')
        self.im = imap.get_imap('ramp')

        # add color bar
        rgbmap = fi.get_rgbmap()
        rgbmap.set_hash_size(256)
        cbar = ColorBar.ColorBar(self.logger, rgbmap=rgbmap,
                                 link=True)
        cbar.resize(-1, 15)
        #cbar.show()
        self.colorbar = cbar
        layout.addWidget(cbar, stretch=0)

        settings = fi.get_settings()
        settings.getSetting('cuts').add_callback('set',
                                                 self.change_range_cb, fi,
                                                 self.colorbar)

        # color map selection widget
        wcmap = QtGui.QComboBox()
        for name in self.cmaps:
            wcmap.addItem(name)
        index = self.cmaps.index('gray')
        wcmap.setCurrentIndex(index)
        wcmap.activated.connect(self.set_cmap_cb)
        self.wcmap = wcmap

        # intensity map selection widget
        wimap = QtGui.QComboBox()
        for name in self.imaps:
            wimap.addItem(name)
        index = self.imaps.index('ramp')
        wimap.setCurrentIndex(index)
        wimap.activated.connect(self.set_cmap_cb)
        self.wimap = wimap

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

        # add buttons to layout
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))
        hbox.addStretch(1)
        for w in (wcmap, wimap):
            hbox.addWidget(w, stretch=0)

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

        # Create a matplotlib Figure
        #self.fig = matplotlib.figure.Figure(figsize=(wd, ht))
        self.fig = matplotlib.figure.Figure()
        self.canvas = FigureCanvas(self.fig)

        vbox2 = QtGui.QWidget()
        layout = QtGui.QVBoxLayout()
        # scrw = QtGui.QScrollArea()
        # scrw.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        # scrw.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        # scrw.setWidgetResizable(True)
        # layout.addWidget(scrw, stretch=1)
        # scrw.setWidget(self.canvas)
        layout.addWidget(self.canvas, stretch=1)

        # Add matplotlib buttons
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

        wgetimg = QtGui.QPushButton("Get Data")
        wgetimg.clicked.connect(self.get_image)
        wgetrgb = QtGui.QPushButton("Get RGB")
        wgetrgb.clicked.connect(self.get_rgb_image)
        #wquit = QtGui.QPushButton("Quit")
        #wquit.clicked.connect(self.close)

        hbox.addStretch(1)
        for w in (wgetimg, wgetrgb):
            hbox.addWidget(w, stretch=0)

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

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

        w = QtGui.QWidget()
        layout = QtGui.QHBoxLayout()
        layout.addWidget(vbox1, stretch=1.0)
        layout.addWidget(vbox2, stretch=1.0)
        w.setLayout(layout)

        vbox.addWidget(w, stretch=1)

        self.readout = QtGui.QLabel("")
        vbox.addWidget(self.readout, stretch=0,
                       alignment=QtCore.Qt.AlignCenter)

        vw = QtGui.QWidget()
        vw.setLayout(vbox)
        self.setCentralWidget(vw)
Exemple #25
0
    def __init__(self, logger, container):
        self.logger = logger
        self.tag = None
        self.mycolor = 'skyblue'
        self.magmap = 'stairs8'

        self.mag_max = 25.0
        self.mag_min = 0.0

        # keys: are name, ra, dec, mag, flag, b_r, preference, priority, dst
        # TODO: automate this generation
        self.columns = [('Name', 'name'),
                        ('RA', 'ra'),
                        ('DEC', 'dec'),
                        ('Mag', 'mag'),
                        ('Preference', 'preference'),
                        ('Priority', 'priority'),
                        ('Flag', 'flag'),
                        ('b-r', 'b_r'),
                        ('Dst', 'dst'),
                        ('Description', 'description'),
                        ]
        self.cell_sort_funcs = []
        for kwd, key in self.columns:
            self.cell_sort_funcs.append(self._mksrtfnN(key))

        self.catalog = None
        self.cursor = 0
        self.color_cursor = 'red'
        self.color_selected = 'skyblue'
        self.selection_mode = 'single'
        self.selected = []
        self.moving_cursor = False

        self.btn = Bunch.Bunch()

        self.mframe = container
            
        vbox = gtk.VBox()

        sw = gtk.ScrolledWindow()
        sw.set_border_width(2)
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        #self.font = pango.FontDescription('Monospace 10')
        
        # create the TreeView
        treeview = gtk.TreeView()
        self.treeview = treeview
        
        # create the TreeViewColumns to display the data
        tvcolumn = [None] * len(self.columns)
        for n in range(0, len(self.columns)):
            cell = gtk.CellRendererText()
            cell.set_padding(2, 0)
            header, kwd = self.columns[n]
            tvc = gtk.TreeViewColumn(header, cell)
            tvc.set_spacing(4)
            tvc.set_resizable(True)
            tvc.connect('clicked', self.sort_cb, n)
            tvc.set_clickable(True)
            tvcolumn[n] = tvc
            fn_data = self._mkcolfnN(kwd)
            tvcolumn[n].set_cell_data_func(cell, fn_data)
            treeview.append_column(tvcolumn[n])

        sw.add(treeview)
        self.treeview.connect('cursor-changed', self.select_star)
        sw.show_all()
        vbox.pack_start(sw, fill=True, expand=True)

        self.cbar = ColorBar.ColorBar(self.logger)
        self.cmap = cmap.get_cmap(self.magmap)
        self.imap = imap.get_imap('ramp')
        self.cbar.set_cmap(self.cmap)
        self.cbar.set_imap(self.imap)
        self.cbar.set_size_request(-1, 20)

        vbox.pack_start(self.cbar, padding=4, fill=True, expand=False)

        btns = gtk.HButtonBox()
        btns.set_layout(gtk.BUTTONBOX_CENTER)
        btns.set_spacing(5)

        for name in ('Plot', 'Clear', #'Close'
                     ):
            btn = gtk.Button(name)
            btns.add(btn)
            self.btn[name.lower()] = btn

        self.btn.plot.connect('clicked', lambda w: self.replot_stars())
        self.btn.clear.connect('clicked', lambda w: self.clear())
        #self.btn.close.connect('clicked', lambda w: self.close())

        vbox.pack_start(btns, padding=4, fill=True, expand=False)
        vbox.show_all()
        
        self.mframe.pack_start(vbox, expand=True, fill=True)
        self.mframe.show_all()
Exemple #26
0
import sys
from ginga.qtw.QtHelp import QtGui, QtCore

from ginga.qtw import ColorBar
from ginga import cmap, imap
import logging

app = QtGui.QApplication([])

logger = logging.getLogger('cbar')
w = ColorBar.ColorBar(logger)
w.set_cmap(cmap.get_cmap('rainbow'))
w.set_imap(imap.get_imap('ramp'))
w.show()

app.exec_()
Exemple #27
0
    def __init__(self, logger, threadPool, module_manager, preferences,
                 ev_quit=None):
        Callback.Callbacks.__init__(self)

        self.logger = logger
        self.threadPool = threadPool
        self.mm = module_manager
        self.prefs = preferences
        # event for controlling termination of threads executing in this
        # object
        if not ev_quit:
            self.ev_quit = threading.Event()
        else:
            self.ev_quit = ev_quit

        # For callbacks
        for name in ('add-image', 'active-image', 'add-channel',
                     'delete-channel', 'field-info'):
            self.enable_callback(name)

        self.gui_queue = Queue.Queue()
        self.gui_thread_id = None
        # For asynchronous tasks on the thread pool
        self.tag = 'master'
        self.shares = ['threadPool', 'logger']

        # Initialize the timer factory
        self.timer_factory = Timer.TimerFactory(ev_quit=self.ev_quit)
        task = Task.FuncTask2(self.timer_factory.mainloop)
        task.init_and_start(self)
        
        self.lock = threading.RLock()
        self.channel = {}
        self.channelNames = []
        self.chinfo = None
        self.chncnt = 0
        self.wscount = 0
        self.statustask = None
        self.preloadLock = threading.RLock()
        self.preloadList = []

        # Create general preferences
        self.settings = self.prefs.createCategory('general')
        self.settings.load(onError='silent')

        self.settings.addDefaults(fixedFont='Monospace',
                                  sansFont='Sans',
                                  channelFollowsFocus=False,
                                  shareReadout=True,
                                  numImages=10)

        # Should channel change as mouse moves between windows
        self.channel_follows_focus = self.settings['channelFollowsFocus']

        self.cm = cmap.get_cmap("ramp")
        self.im = imap.get_imap("ramp")

        self.fn_keys = ('f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8',
                        'f9', 'f10', 'f11', 'f12')
        
        self.global_plugins = {}
        self.local_plugins = {}
        self.operations  = []

        # This plugin manager handles "global" (aka standard) plug ins
        # (unique instances, not per channel)
        self.gpmon = self.getPluginManager(self.logger, self,
                                           None, self.mm)

        # Initialize catalog and image server bank
        self.imgsrv = catalog.ServerBank(self.logger)
        self.dsscnt = 0
Exemple #28
0
    def __init__(self,
                 logger,
                 threadPool,
                 module_manager,
                 preferences,
                 ev_quit=None,
                 datasrc_length=20,
                 follow_focus=False):
        Callback.Callbacks.__init__(self)

        self.logger = logger
        self.threadPool = threadPool
        self.mm = module_manager
        self.prefs = preferences
        # event for controlling termination of threads executing in this
        # object
        if not ev_quit:
            self.ev_quit = threading.Event()
        else:
            self.ev_quit = ev_quit

        # For callbacks
        for name in ('add-image', 'active-image', 'add-channel',
                     'delete-channel', 'field-info'):
            self.enable_callback(name)

        self.gui_queue = Queue.Queue()
        self.gui_thread_id = None
        # For asynchronous tasks on the thread pool
        self.tag = 'master'
        self.shares = ['threadPool', 'logger']

        self.lock = threading.RLock()
        self.channel = {}
        self.channelNames = []
        self.chinfo = None
        self.chncnt = 0
        self.statustask = None

        # Should channel change as mouse moves between windows
        self.channel_follows_focus = follow_focus

        # Number of images to keep around in memory
        self.default_datasrc_length = datasrc_length

        self.cm = cmap.get_cmap("ramp")
        self.im = imap.get_imap("ramp")

        self.fn_keys = ('f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
                        'f10', 'f11', 'f12')

        self.global_plugins = {}
        self.local_plugins = {}
        self.operations = []

        # This plugin manager handles "global" (aka standard) plug ins
        # (unique instances, not per channel)
        self.gpmon = self.getPluginManager(self.logger, self, None, self.mm)

        # Initialize image server bank
        self.imgsrv = Catalog.ServerBank(self.logger)
        self.dsscnt = 0
Exemple #29
0
    def __init__(self, logger, container):
        self.logger = logger
        self.tag = None
        self.mycolor = 'skyblue'
        self.magmap = 'stairs8'

        self.mag_max = 25.0
        self.mag_min = 0.0

        # keys: are name, ra, dec, mag, flag, b_r, preference, priority, dst
        # TODO: automate this generation
        self.columns = [('Name', 'name'),
                        ('RA', 'ra'),
                        ('DEC', 'dec'),
                        ('Mag', 'mag'),
                        ('Preference', 'preference'),
                        ('Priority', 'priority'),
                        ('Flag', 'flag'),
                        ('b-r', 'b_r'),
                        ('Dst', 'dst'),
                        ('Description', 'description'),
                        ]

        self.catalog = None
        self.cursor = 0
        self.color_cursor = 'red'
        self.color_selected = 'skyblue'
        self.selection_mode = 'single'
        self.selected = []
        self.moving_cursor = False

        self.btn = Bunch.Bunch()

        self.mframe = container
            
        vbox = QtHelp.VBox()

        # create the table
        table = QtGui.QTableWidget()
        table.setColumnCount(len(self.columns))
        table.cellClicked.connect(self.select_star)
        self.table = table
        
        col = 0
        for hdr, kwd in self.columns:
            item = QtGui.QTableWidgetItem(hdr)
            table.setHorizontalHeaderItem(col, item)
            col += 1

        vbox.addWidget(table, stretch=1)

        self.cbar = ColorBar.ColorBar(self.logger)
        self.cmap = cmap.get_cmap(self.magmap)
        self.imap = imap.get_imap('ramp')
        self.cbar.set_cmap(self.cmap)
        self.cbar.set_imap(self.imap)
        #self.cbar.set_size_request(-1, 20)

        vbox.addWidget(self.cbar, stretch=0)

        btns = QtHelp.HBox()
        btns.setSpacing(5)

        for name in ('Plot', 'Clear', #'Close'
                     ):
            btn = QtGui.QPushButton(name)
            btns.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignCenter)
            self.btn[name.lower()] = btn

        self.btn.plot.clicked.connect(self.replot_stars)
        self.btn.clear.clicked.connect(self.clear)
        #self.btn.close.clicked.connect(self.close)

        vbox.addWidget(btns, stretch=0, alignment=QtCore.Qt.AlignTop)
        
        self.mframe.addWidget(vbox, stretch=1)
Exemple #30
0
 def color_map_set_cb(self, setting, cmap_name):
     cm = mod_cmap.get_cmap(cmap_name)
     self.set_cmap(cm, callback=True)
Exemple #31
0
    def __init__(self, logger, threadPool, module_manager, preferences,
                 ev_quit=None):
        Callback.Callbacks.__init__(self)

        self.logger = logger
        self.threadPool = threadPool
        self.mm = module_manager
        self.prefs = preferences
        # event for controlling termination of threads executing in this
        # object
        if not ev_quit:
            self.ev_quit = threading.Event()
        else:
            self.ev_quit = ev_quit

        self.tmpdir = tempfile.mkdtemp()
        # remove temporary directory on exit
        atexit.register(_rmtmpdir, self.tmpdir)

        # For callbacks
        for name in ('add-image', 'active-image', 'remove-image',
                     'add-channel', 'delete-channel', 'field-info'):
            self.enable_callback(name)

        self.gui_queue = Queue.Queue()
        self.gui_thread_id = None
        # For asynchronous tasks on the thread pool
        self.tag = 'master'
        self.shares = ['threadPool', 'logger']

        # Initialize the timer factory
        self.timer_factory = Timer.TimerFactory(ev_quit=self.ev_quit,
                                                logger=self.logger)
        self.timer_factory.wind()

        self.lock = threading.RLock()
        self.channel = {}
        self.channelNames = []
        self.chinfo = None
        self.wscount = 0
        self.statustask = None
        self.preloadLock = threading.RLock()
        self.preloadList = []

        # Create general preferences
        self.settings = self.prefs.createCategory('general')
        self.settings.load(onError='silent')
        # Load bindings preferences
        bindprefs = self.prefs.createCategory('bindings')
        bindprefs.load(onError='silent')

        self.settings.addDefaults(fixedFont='Monospace',
                                  sansFont='Sans',
                                  channel_follows_focus=False,
                                  share_readout=True,
                                  numImages=10,
                                  # Offset to add to numpy-based coords
                                  pixel_coords_offset=1.0,
                                  # inherit from primary header
                                  inherit_primary_header=False)

        # Should channel change as mouse moves between windows
        self.channel_follows_focus = self.settings['channel_follows_focus']

        self.cm = cmap.get_cmap("gray")
        self.im = imap.get_imap("ramp")

        self.fn_keys = ('f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8',
                        'f9', 'f10', 'f11', 'f12')

        self.global_plugins = {}
        self.local_plugins = {}
        self.operations  = []

        # This plugin manager handles "global" (aka standard) plug ins
        # (unique instances, not per channel)
        self.gpmon = self.getPluginManager(self.logger, self,
                                           None, self.mm)

        # Initialize catalog and image server bank
        self.imgsrv = catalog.ServerBank(self.logger)
Exemple #32
0
    def __init__(self,
                 logger,
                 threadPool,
                 module_manager,
                 preferences,
                 ev_quit=None):
        Callback.Callbacks.__init__(self)

        self.logger = logger
        self.threadPool = threadPool
        self.mm = module_manager
        self.prefs = preferences
        # event for controlling termination of threads executing in this
        # object
        if not ev_quit:
            self.ev_quit = threading.Event()
        else:
            self.ev_quit = ev_quit

        # For callbacks
        for name in ('add-image', 'active-image', 'add-channel',
                     'delete-channel', 'field-info'):
            self.enable_callback(name)

        self.gui_queue = Queue.Queue()
        self.gui_thread_id = None
        # For asynchronous tasks on the thread pool
        self.tag = 'master'
        self.shares = ['threadPool', 'logger']

        # Initialize the timer factory
        self.timer_factory = Timer.TimerFactory(ev_quit=self.ev_quit)
        task = Task.FuncTask2(self.timer_factory.mainloop)
        task.init_and_start(self)

        self.lock = threading.RLock()
        self.channel = {}
        self.channelNames = []
        self.chinfo = None
        self.chncnt = 0
        self.wscount = 0
        self.statustask = None
        self.preloadLock = threading.RLock()
        self.preloadList = []

        # Create general preferences
        self.settings = self.prefs.createCategory('general')
        self.settings.load(onError='silent')
        # Load bindings preferences
        bindprefs = self.prefs.createCategory('bindings')
        bindprefs.load(onError='silent')

        self.settings.addDefaults(fixedFont='Monospace',
                                  sansFont='Sans',
                                  channelFollowsFocus=False,
                                  shareReadout=True,
                                  numImages=10)

        # Should channel change as mouse moves between windows
        self.channel_follows_focus = self.settings['channelFollowsFocus']

        self.cm = cmap.get_cmap("ramp")
        self.im = imap.get_imap("ramp")

        self.fn_keys = ('f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
                        'f10', 'f11', 'f12')

        self.global_plugins = {}
        self.local_plugins = {}
        self.operations = []

        # This plugin manager handles "global" (aka standard) plug ins
        # (unique instances, not per channel)
        self.gpmon = self.getPluginManager(self.logger, self, None, self.mm)

        # Initialize catalog and image server bank
        self.imgsrv = catalog.ServerBank(self.logger)
Exemple #33
0
 def set_cmap_byname(self, name):
     # Get colormap
     cm = cmap.get_cmap(name)
     self.cbar.set_cmap(cm)
     self.replot_stars()
Exemple #34
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 #35
0
 def set_cmap_byname(self, name):
     # Get colormap
     cm = cmap.get_cmap(name)
     self.cbar.set_cmap(cm)
     self.replot_stars()
Exemple #36
0
 def color_map_set_cb(self, setting, cmap_name):
     cm = mod_cmap.get_cmap(cmap_name)
     self.set_cmap(cm, callback=True)