Esempio n. 1
0
    def build_param_gui(self, container):
        """Call this in ``build_gui()`` to create 'Load Param' and 'Save Param'
        buttons.

        Parameters
        ----------
        container : widget
            The widget to contain these buttons.

        """
        captions = (('Load Param', 'button', 'Save Param', 'button'), )
        w, b = Widgets.build_info(captions, orientation=self.orientation)
        self.w.update(b)

        b.load_param.set_tooltip('Load previously saved parameters')
        b.load_param.add_callback(
            'activated', lambda w: self.load_params_cb())

        b.save_param.set_tooltip(f'Save {str(self)} parameters')
        b.save_param.add_callback(
            'activated', lambda w: self.save_params())

        container.add_widget(w, stretch=0)

        # Initialize file save dialog
        self.filesel = FileSelection(self.fv.w.root.get_widget())
Esempio n. 2
0
    def build_gui(self, container):
        super(ProgramsTab, self).build_gui(container)

        self.tableview.doubleClicked.connect(self.doubleClicked)

        load_plan = self.filemenu.add_name('Load Plan')
        load_plan.set_enabled(True)
        load_plan.add_callback('activated', self.load_plan_cb)

        save_plan = self.filemenu.add_name('Save As Plan')
        save_plan.set_enabled(True)
        save_plan.add_callback('activated', self.save_plan_cb)

        self.file_sel = FileSelection(container.get_widget())
Esempio n. 3
0
    def __init__(self, fv, fitsimage):
        super(MultiBars, self).__init__(fv, fitsimage)

        self.layertag = 'bars-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()
        self.canvas_img = None
        
        self.mfilesel = FileSelection(self.fv.w.root.get_widget())
Esempio n. 4
0
    def build_gui(self, container):
        top = Widgets.VBox()
        top.set_border_width(4)

        vbox, sw, orientation = Widgets.get_oriented_box(container)
        vbox.set_border_width(4)
        vbox.set_spacing(2)

        fr = Widgets.Frame("Bar Input")

        captions = (('Overlay', 'button'),
		    ('Clear', 'button'))
	
        w, b = Widgets.build_info(captions, orientation=orientation)
        self.w.update(b)

	b.overlay.add_callback('activated',
			       lambda w: self.load_cb())

        b.clear.add_callback('activated', lambda w: self.clear_canvas())
	fr.set_widget(w)
        vbox.add_widget(fr, stretch=0)

        spacer = Widgets.Label('')
        vbox.add_widget(spacer, stretch=1)

        top.add_widget(sw, stretch=1)

        btns = Widgets.HBox()
        btns.set_spacing(3)

        btn = Widgets.Button("Close")
        btn.add_callback('activated', lambda w: self.close())
        btns.add_widget(btn, stretch=0)
        btn = Widgets.Button("Help")
        btn.add_callback('activated', lambda w: self.help())
        btns.add_widget(btn, stretch=0)
        btns.add_widget(Widgets.Label(''), stretch=1)
        top.add_widget(btns, stretch=0)

        container.add_widget(top, stretch=1)
	
	self.mfilesel = FileSelection(self.fv.w.root.get_widget())
Esempio n. 5
0
    def build_gui(self, container):
        top = Widgets.VBox()
        top.set_border_width(4)

        vbox, sw, orientation = Widgets.get_oriented_box(container)
        vbox.set_border_width(4)
        vbox.set_spacing(2)

        fr = Widgets.Frame("Keck Mosaic")

        captions = (('Load a multi-extension FITS file, create a mosaic',
                     'label'), ('Load', 'button'))

        w, b = Widgets.build_info(captions, orientation=orientation)
        self.w.update(b)

        b.load.add_callback('activated', lambda w: self.load_cb())

        fr.set_widget(w)
        vbox.add_widget(fr, stretch=0)

        spacer = Widgets.Label('')
        vbox.add_widget(spacer, stretch=1)

        top.add_widget(sw, stretch=1)

        btns = Widgets.HBox()
        btns.set_spacing(3)

        btn = Widgets.Button("Close")
        btn.add_callback('activated', lambda w: self.close())
        btns.add_widget(btn, stretch=0)
        btn = Widgets.Button("Help")
        btn.add_callback('activated', lambda w: self.help())
        btns.add_widget(btn, stretch=0)
        btns.add_widget(Widgets.Label(''), stretch=1)
        top.add_widget(btns, stretch=0)

        container.add_widget(top, stretch=1)

        self.mfilesel = FileSelection(self.fv.w.root.get_widget())
Esempio n. 6
0
    def __init__(self, fv, fitsimage):
        """
        This method is called when the plugin is loaded for the  first
        time.  ``fv`` is a reference to the Ginga (reference viewer) shell
        and ``fitsimage`` is a reference to the specific ImageViewCanvas
        object associated with the channel on which the plugin is being
        invoked.
        You need to call the superclass initializer and then do any local
        initialization.
        """
        super(CSU_initializer, self).__init__(fv, fitsimage)

        # Load plugin preferences
        prefs = self.fv.get_preferences()
        self.settings = prefs.createCategory('plugin_CSU_initializer')
        self.settings.setDefaults(
            bar_num=1,
            move_to_open=False,
            overlay_bar_positions_from_csu_bar_state_file=False,
            overlay_bar_positions_from_fits_header=False,
            overlay_bar_positions_from_analyzed_image=False,
            bar_dist=0.0,
        )
        self.settings.load(onError='silent')

        self.layertag = 'bars-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()
        self.canvas_img = None

        self.mfilesel = FileSelection(self.fv.w.root.get_widget())

        ## Define dimensions and angles relative to the pixels of the image
        #         self.slit_angle = (4.00-0.22) * np.pi/180.
        #         pixels = np.array([ (721, 2022), # pixels
        #                             (1068, 1934),
        #                             (984, 1804),
        #                             (1112, 40),
        #                           ])
        #         physical = np.array([ (179.155, self.bar_to_slit(2)), # mm, slit number
        #                               (133.901, self.bar_to_slit(6)),
        #                               (144.962, self.bar_to_slit(12)),
        #                               (129.033, self.bar_to_slit(92))
        #                             ])

        pixels = np.array([
            (1026.6847023205248, 31.815757489924671),
            (1031.1293065907989, 31.815757489924671),
            (1100.0527926274958, 76.568051304306408),
            (1104.4723170387663, 76.568051304306408),
            (869.79921202733158, 119.71402079180322),
            (874.17468615739256, 119.71402079180322),
            (790.04504261037619, 163.97941699869187),
            (794.38269316256697, 163.97941699869187),
            (844.76764696920873, 208.45498973235158),
            (849.06840834451555, 208.45498973235158),
            (918.16119587182891, 253.46863795483193),
            (922.57167115281891, 253.46863795483193),
            (667.1708458173706, 296.83477802171569),
            (671.58750566149126, 296.83477802171569),
            (1210.6743343816352, 342.85304935109269),
            (1215.1047501727178, 342.85304935109269),
            (1037.1504738673596, 386.56200191364559),
            (1041.5376839155629, 386.56200191364559),
            (1380.9733624348846, 431.75478066748974),
            (1385.3923546613969, 431.75478066748974),
            (1392.3137244788115, 476.40898670973735),
            (1396.5838727543558, 476.40898670973735),
            (701.99737614209846, 518.12290417047029),
            (706.31972548163674, 518.12290417047029),
            (775.43118955263321, 562.76481942553085),
            (779.76336695630744, 562.76481942553085),
            (695.39446696825667, 606.9386852721824),
            (699.68592870194686, 606.9386852721824),
            (1225.8966927438423, 652.79237015375304),
            (1230.2681865131638, 652.79237015375304),
            (1299.3047613957535, 697.52305237026349),
            (1303.6542557465727, 697.52305237026349),
            (953.60567493512144, 740.39597570556316),
            (957.91890612112604, 740.39597570556316),
            (1027.0080928255736, 784.70486151318767),
            (1031.3650789520013, 784.70486151318767),
            (1241.625753053888, 830.10892664282756),
            (1245.9181149708163, 830.10892664282756),
            (1266.796600696397, 874.17188807394371),
            (1271.1082253968038, 874.17188807394371),
            (1404.8881828516335, 919.85774261912377),
            (1409.9449171925908, 919.85774261912377),
            (1325.0207484270156, 963.32163630950686),
            (1329.3681702175545, 963.32163630950686),
            (1185.9570564396361, 1007.0164717446025),
            (1190.2368155733498, 1007.0164717446025),
            (1306.6628878384579, 1051.9073888851103),
            (1310.9679069215179, 1051.9073888851103),
            (1151.3860791138529, 1095.4860726831637),
            (1155.7367238283309, 1095.4860726831637),
            (1224.7162502034391, 1140.436681012593),
            (1229.0598756552718, 1140.436681012593),
            (904.70409145100268, 1183.267412335555),
            (908.99297982589781, 1183.267412335555),
            (978.00762214758913, 1227.9731804278615),
            (982.41054057239705, 1227.9731804278615),
            (869.65543493075677, 1271.3564678397893),
            (873.95299108698168, 1271.3564678397893),
            (942.99396243198464, 1316.2391922602001),
            (947.36667894787513, 1316.2391922602001),
            (1256.7806430753744, 1361.195495916817),
            (1261.0847133245632, 1361.195495916817),
            (1330.1305637595844, 1406.3795550431571),
            (1334.3960288420271, 1406.3795550431571),
            (1060.9423305503171, 1449.3586376395574),
            (1065.3182032594575, 1449.3586376395574),
            (1108.6465868246237, 1493.9756362677167),
            (1112.9382994207679, 1493.9756362677167),
            (662.84522896384874, 1536.9734554153649),
            (667.12956877347722, 1536.9734554153649),
            (712.5287834914659, 1581.2712766110319),
            (716.80585127180609, 1581.2712766110319),
            (956.48762939159371, 1626.1728182002655),
            (960.9581522740466, 1626.1728182002655),
            (723.23974640617337, 1670.0165354200499),
            (727.67208274341931, 1670.0165354200499),
            (1172.3594885486252, 1715.8650599984883),
            (1176.8341929555718, 1715.8650599984883),
            (1015.7329598422145, 1759.5446833817025),
            (1020.1920698607528, 1759.5446833817025),
            (935.82358262678224, 1803.5644982617907),
            (940.3126440130676, 1803.5644982617907),
            (989.98752991018682, 1847.9507718487364),
            (994.40511955530712, 1847.9507718487364),
            (1278.2218422583971, 1892.8072028048214),
            (1282.7070969966558, 1892.8072028048214),
            (1351.5377751257745, 1938.5923374638328),
            (1355.9221844080257, 1938.5923374638328),
            (1171.5812780061251, 1981.4914424153424),
            (1176.0817255338613, 1981.4914424153424),
        ])

        physical = np.array([
            (139.917, self.bar_to_slit(92)),
            (139.41, self.bar_to_slit(91)),
            (130.322, self.bar_to_slit(90)),
            (129.815, self.bar_to_slit(89)),
            (160.334, self.bar_to_slit(88)),
            (159.827, self.bar_to_slit(87)),
            (170.738, self.bar_to_slit(86)),
            (170.231, self.bar_to_slit(85)),
            (163.579, self.bar_to_slit(84)),
            (163.072, self.bar_to_slit(83)),
            (153.983, self.bar_to_slit(82)),
            (153.476, self.bar_to_slit(81)),
            (186.718, self.bar_to_slit(80)),
            (186.211, self.bar_to_slit(79)),
            (115.773, self.bar_to_slit(78)),
            (115.266, self.bar_to_slit(77)),
            (138.413, self.bar_to_slit(76)),
            (137.906, self.bar_to_slit(75)),
            (93.508, self.bar_to_slit(74)),
            (93.001, self.bar_to_slit(73)),
            (92.021, self.bar_to_slit(72)),
            (91.514, self.bar_to_slit(71)),
            (182.097, self.bar_to_slit(70)),
            (181.59, self.bar_to_slit(69)),
            (172.502, self.bar_to_slit(68)),
            (171.995, self.bar_to_slit(67)),
            (182.905, self.bar_to_slit(66)),
            (182.398, self.bar_to_slit(65)),
            (113.665, self.bar_to_slit(64)),
            (113.158, self.bar_to_slit(63)),
            (104.069, self.bar_to_slit(62)),
            (103.562, self.bar_to_slit(61)),
            (149.161, self.bar_to_slit(60)),
            (148.654, self.bar_to_slit(59)),
            (139.566, self.bar_to_slit(58)),
            (139.059, self.bar_to_slit(57)),
            (111.528, self.bar_to_slit(56)),
            (111.021, self.bar_to_slit(55)),
            (108.22, self.bar_to_slit(54)),
            (107.713, self.bar_to_slit(53)),
            (90.189, self.bar_to_slit(52)),
            (89.681, self.bar_to_slit(51)),
            (100.593, self.bar_to_slit(50)),
            (100.086, self.bar_to_slit(49)),
            (118.731, self.bar_to_slit(48)),
            (118.223, self.bar_to_slit(47)),
            (102.94, self.bar_to_slit(46)),
            (102.432, self.bar_to_slit(45)),
            (123.212, self.bar_to_slit(44)),
            (122.704, self.bar_to_slit(43)),
            (113.615, self.bar_to_slit(42)),
            (113.108, self.bar_to_slit(41)),
            (155.354, self.bar_to_slit(40)),
            (154.847, self.bar_to_slit(39)),
            (145.759, self.bar_to_slit(38)),
            (145.251, self.bar_to_slit(37)),
            (159.887, self.bar_to_slit(36)),
            (159.38, self.bar_to_slit(35)),
            (150.292, self.bar_to_slit(34)),
            (149.785, self.bar_to_slit(33)),
            (109.338, self.bar_to_slit(32)),
            (108.83, self.bar_to_slit(31)),
            (99.742, self.bar_to_slit(30)),
            (99.235, self.bar_to_slit(29)),
            (134.842, self.bar_to_slit(28)),
            (134.335, self.bar_to_slit(27)),
            (128.616, self.bar_to_slit(26)),
            (128.109, self.bar_to_slit(25)),
            (186.778, self.bar_to_slit(24)),
            (186.271, self.bar_to_slit(23)),
            (180.272, self.bar_to_slit(22)),
            (179.765, self.bar_to_slit(21)),
            (148.417, self.bar_to_slit(20)),
            (147.91, self.bar_to_slit(19)),
            (178.822, self.bar_to_slit(18)),
            (178.314, self.bar_to_slit(17)),
            (120.197, self.bar_to_slit(16)),
            (119.689, self.bar_to_slit(15)),
            (140.601, self.bar_to_slit(14)),
            (140.094, self.bar_to_slit(13)),
            (151.005, self.bar_to_slit(12)),
            (150.498, self.bar_to_slit(11)),
            (143.947, self.bar_to_slit(10)),
            (143.44, self.bar_to_slit(9)),
            (106.313, self.bar_to_slit(8)),
            (105.806, self.bar_to_slit(7)),
            (96.717, self.bar_to_slit(6)),
            (96.21, self.bar_to_slit(5)),
            (120.202, self.bar_to_slit(4)),
            (119.695, self.bar_to_slit(3)),
        ])

        tick = dt.now()
        self.fit_transforms(pixels, physical)
        tock = dt.now()
        elapsed = (tock - tick).total_seconds()
        print('  Fitted transforms in {:.3f} s'.format(elapsed))

        ## Determine slit angle and bar center to center distance in pixels
        ## from the transformation and the known longslit positions
        ##   in longslit, bar 02 is at 145.472
        ##   in longslit, bar 92 is at 129.480
        physical = [[145.472, self.bar_to_slit(2)],
                    [129.480, self.bar_to_slit(92)]]
        pixels = self.physical_to_pixel(physical)
        dx = pixels[1][0] - pixels[0][0]
        dy = pixels[0][1] - pixels[1][1]
        self.slit_angle_pix = np.arctan(dx / dy)
        print("Slit Angle on CCD = {:.3f} deg".format(self.slit_angle_pix *
                                                      180. / np.pi))
        self.slit_height_pix = dy / (self.bar_to_slit(92) -
                                     self.bar_to_slit(2))
        print("Slit Height on CCD = {:.3f} pix".format(self.slit_height_pix))
Esempio n. 7
0
    def build_gui(self, container):
        vbox, sw, self.orientation = Widgets.get_oriented_box(container)

        captions = (('Mark:', 'label', 'mark type', 'combobox'),
                    ('Color:', 'label', 'mark color', 'combobox'),
                    ('Size:', 'label', 'mark size', 'entry'),
                    ('Width:', 'label', 'mark width', 'entry'))
        w, b = Widgets.build_info(captions)
        self.w.update(b)

        combobox = b.mark_type
        for name in self._mark_options:
            combobox.append_text(name)
        b.mark_type.set_index(self._mark_options.index(self.marktype))
        b.mark_type.add_callback('activated', self.set_marktype_cb)

        combobox = b.mark_color
        for name in self._color_options:
            combobox.append_text(name)
        b.mark_color.set_index(self._color_options.index(self.markcolor))
        b.mark_color.add_callback('activated', self.set_markcolor_cb)

        b.mark_size.set_tooltip('Size/radius of the marking')
        b.mark_size.set_text(str(self.marksize))
        b.mark_size.add_callback('activated', lambda w: self.set_marksize())

        b.mark_width.set_tooltip('Line width of the marking')
        b.mark_width.set_text(str(self.markwidth))
        b.mark_width.add_callback('activated', lambda w: self.set_markwidth())

        container.add_widget(w, stretch=0)

        nb = Widgets.TabWidget()
        self.w.nb1 = nb
        container.add_widget(nb, stretch=1)

        treeview = Widgets.TreeView(auto_expand=True,
                                    sortable=True,
                                    selection='multiple',
                                    use_alt_row_color=True)
        self.treeview = treeview
        treeview.setup_table(self.columns, 2, 'MARKID')
        treeview.add_callback('selected', self.hl_table2canvas)
        nb.add_widget(treeview, title='Shown')

        treeview2 = Widgets.TreeView(auto_expand=True,
                                     sortable=True,
                                     use_alt_row_color=True)
        self.treeviewsel = treeview2
        treeview2.setup_table(self.columns, 2, 'MARKID')
        nb.add_widget(treeview2, title='Selected')

        treeview3 = Widgets.TreeView(auto_expand=True,
                                     sortable=True,
                                     use_alt_row_color=True)
        self.treeviewbad = treeview3
        treeview3.setup_table(self.columns, 2, 'MARKID')
        nb.add_widget(treeview3, title='Outliers')

        captions = (('Loaded:', 'llabel', 'ntotal', 'llabel',
                     'Shown:', 'llabel', 'nshown', 'llabel',
                     'Selected:', 'llabel', 'nselected', 'llabel'), )
        w, b = Widgets.build_info(captions)
        self.w.update(b)

        b.ntotal.set_tooltip('Number of objects read from tables')
        b.ntotal.set_text('0')

        b.nshown.set_tooltip('Number of objects shown on image')
        b.nshown.set_text('0')

        b.nselected.set_tooltip('Number of objects selected')
        b.nselected.set_text('0')

        container.add_widget(w, stretch=0)

        captions = (('Load Coords', 'button', 'Use RADEC', 'checkbutton'),
                    ('Show', 'button', 'Hide', 'button', 'Forget', 'button'))
        w, b = Widgets.build_info(captions)
        self.w.update(b)

        b.load_coords.set_tooltip('Load coordinates file')
        b.load_coords.add_callback('activated', lambda w: self.load_coords_cb())

        b.use_radec.set_tooltip('Use RA/DEC as coordinates instead of X/Y')
        b.use_radec.set_state(self.use_radec)
        b.use_radec.add_callback('activated', self.set_coordtype_cb)

        b.show.set_tooltip('Show markings')
        b.show.add_callback('activated', lambda w: self.redo())

        b.hide.set_tooltip('Hide markings')
        b.hide.add_callback('activated', lambda w: self.clear_marking())

        b.forget.set_tooltip('Forget markings')
        b.forget.add_callback('activated', lambda w: self.forget_coords())

        container.add_widget(w, stretch=0)

        btns = Widgets.HBox()
        btns.set_border_width(4)
        btns.set_spacing(3)

        btn = Widgets.Button('Close')
        btn.add_callback('activated', lambda w: self.close())
        btns.add_widget(btn, stretch=0)
        btn = Widgets.Button("Help")
        btn.add_callback('activated', lambda w: self.help())
        btns.add_widget(btn, stretch=0)
        btns.add_widget(Widgets.Label(''), stretch=1)

        container.add_widget(btns, stretch=0)

        self.gui_up = True

        # Initialize coordinates file selection dialog
        self.cfilesel = FileSelection(self.fv.w.root.get_widget())

        # Populate table
        self.redo()
Esempio n. 8
0
    def build_gui(self, container):
        vbox, sw, self.orientation = Widgets.get_oriented_box(container)

        captions = (('Color:', 'label', 'mask color', 'combobox'),
                    ('Alpha:', 'label', 'mask alpha', 'entry'))
        w, b = Widgets.build_info(captions)
        self.w.update(b)

        combobox = b.mask_color
        for name in self._color_options:
            combobox.append_text(name)
        b.mask_color.set_index(self._color_options.index(self.maskcolor))
        b.mask_color.add_callback('activated', self.set_maskcolor_cb)

        b.mask_alpha.set_tooltip('Mask alpha (transparency)')
        b.mask_alpha.set_text(str(self.maskalpha))
        b.mask_alpha.add_callback('activated', lambda w: self.set_maskalpha())

        container.add_widget(w, stretch=0)

        treeview = Widgets.TreeView(auto_expand=True,
                                    sortable=True,
                                    selection='multiple',
                                    use_alt_row_color=True)
        self.treeview = treeview
        treeview.setup_table(self.columns, 2, 'ID')
        treeview.add_callback('selected', self.hl_table2canvas)
        container.add_widget(treeview, stretch=1)

        captions = (('Load Mask', 'button'),
                    ('Show', 'button', 'Hide', 'button', 'Forget', 'button'))
        w, b = Widgets.build_info(captions)
        self.w.update(b)

        b.load_mask.set_tooltip('Load mask image')
        b.load_mask.add_callback('activated', lambda w: self.load_mask_cb())

        b.show.set_tooltip('Show masks')
        b.show.add_callback('activated', lambda w: self.redo())

        b.hide.set_tooltip('Hide masks')
        b.hide.add_callback('activated', lambda w: self.clear_mask())

        b.forget.set_tooltip('Forget masks')
        b.forget.add_callback('activated', lambda w: self.forget_masks())

        container.add_widget(w, stretch=0)

        btns = Widgets.HBox()
        btns.set_border_width(4)
        btns.set_spacing(3)

        btn = Widgets.Button('Close')
        btn.add_callback('activated', lambda w: self.close())
        btns.add_widget(btn, stretch=0)
        btn = Widgets.Button("Help")
        btn.add_callback('activated', lambda w: self.help())
        btns.add_widget(btn, stretch=0)
        btns.add_widget(Widgets.Label(''), stretch=1)

        container.add_widget(btns, stretch=0)

        self.gui_up = True

        # Initialize mask file selection dialog
        self.mfilesel = FileSelection(self.fv.w.root.get_widget())

        # Populate table
        self.redo()
Esempio n. 9
0
    def build_gui(self, container):
        top = Widgets.VBox()
        top.set_border_width(4)

        box, sw, orientation = Widgets.get_oriented_box(container)
        box.set_border_width(4)
        box.set_spacing(2)

        paned = Widgets.Splitter(orientation=orientation)

        self.fwhm_plot = plots.FWHMPlot(logger=self.logger,
                                        width=400,
                                        height=400)

        if plots.MPL_GE_2_0:
            kwargs = {'facecolor': 'white'}
        else:
            kwargs = {'axisbg': 'white'}
        ax = self.fwhm_plot.add_axis(**kwargs)
        ax.grid(True)
        w = Plot.PlotWidget(self.fwhm_plot)
        w.resize(400, 400)
        paned.add_widget(Widgets.hadjust(w, orientation))

        captions = (("Load a Nires Image", 'label', "Load", 'button'),
                    ("Load an image and sky", 'label', "Load with sky",
                     'button'), ('Object_X', 'label', 'Object_X', 'llabel'),
                    ('Object_Y', 'label', 'Object_Y',
                     'llabel'), ('Box Size (50): ', 'label', 'Box Size',
                                 'entry', "Resize", 'button'))

        w, b = Widgets.build_info(captions, orientation=orientation)
        self.w.update(b)

        self.wdetail = b

        b.load.add_callback('activated', lambda w: self.load_cb())

        b.load_with_sky.add_callback('activated',
                                     lambda w: self.load_with_sky_cb())

        b.box_size.add_callback('activated', lambda w: self.boxsize_cb())

        b.resize.add_callback('activated', lambda w: self.resize_cb())

        fr = Widgets.Frame("Pick Target Star")
        fr.set_widget(w)
        box.add_widget(fr, stretch=0)
        paned.add_widget(sw)

        paned.set_sizes([400, 500])

        top.add_widget(paned, stretch=5)

        btns = Widgets.HBox()
        btns.set_spacing(3)

        btn = Widgets.Button("Close")
        btn.add_callback('activated', lambda w: self.close())
        btns.add_widget(btn, stretch=0)
        btns.add_widget(Widgets.Label(''), stretch=1)
        top.add_widget(btns, stretch=0)

        container.add_widget(top, stretch=1)
        self.mfilesel = FileSelection(self.fv.w.root.get_widget())
    def __init__(self, fv, fitsimage):
        """
        This method is called when the plugin is loaded for the  first
        time.  ``fv`` is a reference to the Ginga (reference viewer) shell
        and ``fitsimage`` is a reference to the specific ImageViewCanvas
        object associated with the channel on which the plugin is being
        invoked.
        You need to call the superclass initializer and then do any local
        initialization.
        """
        super(CSU_initializer, self).__init__(fv, fitsimage)

        # Load plugin preferences
        prefs = self.fv.get_preferences()
        self.settings = prefs.createCategory('plugin_CSU_initializer')
        self.settings.setDefaults(
            ibar_num=1,
            mbar_num=1,
            ebar_num=1,
            move_to_open=False,
            bar_dest=0.0,
            bar_pos=137.0,
        )
        self.settings.load(onError='silent')

        self.instrument_hosts = ['vm-mosfire', 'nuu', 'vm-mosfirebld']
        self.hostname = socket.gethostname().split('.')[0].lower()

        self.bars_analysis = None
        self.state_analysis = None
        self.bars_file = None
        self.state_file = None
        self.bars_header = None
        self.state_header = None

        self.layertag = 'bars-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()
        self.canvas_img = None

        self.mfilesel = FileSelection(self.fv.w.root.get_widget())

        ## Fit relationship between bar position and pixels
        tick = dt.now()
        pixels, physical = self.get_data()
        self.fit_transforms(pixels, physical)
        tock = dt.now()
        elapsed = (tock - tick).total_seconds()
        #         print('Completed fit of transforms in {:.3f} s'.format(elapsed))

        ## Determine slit angle and bar center to center distance in pixels
        ## from the transformation and the known longslit positions
        ##   in longslit, bar 02 is at 145.472
        ##   in longslit, bar 92 is at 129.480
        physical = [[145.472, self.bar_to_slit(2)],
                    [129.480, self.bar_to_slit(92)]]
        pixels = self.physical_to_pixel(physical)
        dx = pixels[1][0] - pixels[0][0]
        dy = pixels[0][1] - pixels[1][1]
        self.slit_angle_pix = np.arctan(dx / dy)
        #         print("Slit Angle on CCD = {:.3f} deg".format(self.slit_angle_pix * 180./np.pi))
        self.slit_height_pix = dy / (self.bar_to_slit(92) -
                                     self.bar_to_slit(2))