예제 #1
0
    def __init__(self, **kwargs):
        super(MyGUI, self).__init__(**kwargs)

        #self.setGeometry(600, 480, 600, 480)
        #self.move(QtGui.QApplication.desktop().screen().rect().center() - self.rect().center())
        self.setWindowTitle('Wound Healing Assay - Online Plot')

        vertical_layout = QtGui.QVBoxLayout(self)
        self.figure_widget = mpl.MPLWidget(tight_layout=True)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
                                       QtGui.QSizePolicy.MinimumExpanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.figure_widget.sizePolicy().hasHeightForWidth())
        self.figure_widget.setSizePolicy(sizePolicy)
        vertical_layout.addWidget(self.figure_widget)

        try:
            self.ct_last = os.stat(filename).st_mtime
        except:
            self.ct_last = 0.0

        self.nodatacount = 0

        # Create a matplotlib axes
        self.ax1 = self.figure_widget.figure.add_subplot(211)
        self.ax2 = self.figure_widget.figure.add_subplot(212)
        self.ax1.set_title('Wound Healing Assay - Scratch Area [%]')
        self.ax2.set_title('Wound Healing Assay - Scratch Relative Delta [%]')

        return None
예제 #2
0
 def __init__(self, session, parent, ncap=False):
     super(SNRPlotDialog, self).__init__()
     # Center it on the parent location
     rect = parent.geometry()
     x, y = rect.center().x(), rect.center().y()
     w = 1000
     h = 640
     self.setGeometry(x - w / 2, y - h / 2, w, h)
     vbox = QtGui.QVBoxLayout(self)
     figure_widget = mpl.MPLWidget(None, tight_layout=True)
     figure_widget.enable_interactive_zoom()
     vbox.addWidget(figure_widget)
     session.make_snr_plot(figure_widget.figure)
예제 #3
0
 def __init__(self, session, parent, ncap=False):
     super(SummaryPlotDialog, self).__init__()
     # Center it on the parent location
     rect = parent.geometry()
     x, y = rect.center().x(), rect.center().y()
     w = 1000
     h = 640
     self.setGeometry(x - w / 2, y - h / 2, w, h)
     vbox = QtGui.QVBoxLayout(self)
     figure_widget = mpl.MPLWidget(None, tight_layout=True)
     vbox.addWidget(figure_widget)
     if ncap:
         session.make_ncap_summary_plot(figure_widget.figure)
     else:
         session.make_summary_plot(figure_widget.figure)
예제 #4
0
    def __init__(self, **kwargs):
        super(MyGUI, self).__init__(**kwargs)

        #self.setGeometry(600, 480, 600, 480)
        #self.move(QtGui.QApplication.desktop().screen().rect().center() - self.rect().center())
        self.setWindowTitle('Wellplate Online Heatmap')

        vertical_layout = QtGui.QVBoxLayout(self)
        self.figure_widget = mpl.MPLWidget(tight_layout=True)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
                                       QtGui.QSizePolicy.MinimumExpanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.figure_widget.sizePolicy().hasHeightForWidth())
        self.figure_widget.setSizePolicy(sizePolicy)
        vertical_layout.addWidget(self.figure_widget)

        try:
            self.ct_last = os.stat(filename).st_mtime
        except:
            self.ct_last = 0.0

        self.nodatacount = 0

        # Create a matplotlib axes.
        # self.ax = self.figure_widget.figure.add_subplot(111)
        self.ax = self.figure_widget.figure.add_axes([0.075, 0.1, 0.75, 0.85])
        self.cax = self.figure_widget.figure.add_axes([0.85, 0.1, 0.075, 0.85])
        self.ax.set_title('Online Heatmap by Experiment Feedback')

        # read in cell numbers
        self.Nr = numrows
        self.Nc = numcolumns
        # create matrix which will contain the number of counted cells
        self.well = self.create_matrix(numrows=self.Nr, numcols=self.Nc)
        self.labelx, self.labely = self.create_labels(numrows=self.Nr,
                                                      numcols=self.Nc)
        # add title & legends for plots
        self.setlabels

        return None
예제 #5
0
    def __init__(self, parent):
        """
        Create a summary tab for a SMH analysis session.

        :param parent:
            The parent widget.
        """

        super(SummaryTab, self).__init__(parent)
        self.parent = parent

        # Right pane: A MPL figure with two axes, vertically aligned.
        # Left pane:
        # - Name, RA/DEC
        # - Link to search on Vizier/Simbad
        # - Comments/notes (user info?)

        # Set a size policy.
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
                               QtGui.QSizePolicy.MinimumExpanding)
        sp.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sp)

        # Create a top-level horizontal layout to contain a MPL figure and
        # a vertical layout of settings..
        tab_layout = QtGui.QHBoxLayout(self)
        tab_layout.setContentsMargins(20, 20, 20, 0)

        # Create the left hand pane.
        summary_widget = QtGui.QWidget()
        summary_layout = QtGui.QVBoxLayout(summary_widget)

        # Star name label.
        self.star_label = QtGui.QLabel(self)
        bold_monospaced = QtGui.QFont("Courier", 14)
        bold_monospaced.setBold(True)
        self.star_label.setFont(bold_monospaced)
        summary_layout.addWidget(self.star_label)

        # Coordinates label.
        self.coordinates_label = QtGui.QLabel(self)
        self.coordinates_label.setFont(bold_monospaced)
        summary_layout.addWidget(self.coordinates_label)

        # Notes.
        self.summary_notes = QtGui.QPlainTextEdit(self)
        summary_layout.addWidget(self.summary_notes)

        # External sources of information.
        hbox = QtGui.QHBoxLayout()

        # - Simbad
        self.btn_query_simbad = QtGui.QPushButton(self)
        self.btn_query_simbad.setText("Query Simbad..")
        self.btn_query_simbad.clicked.connect(self.query_simbad)

        hbox.addWidget(self.btn_query_simbad)
        hbox.addItem(
            QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Minimum))
        summary_layout.addLayout(hbox)
        tab_layout.addWidget(summary_widget)

        # Create a matplotlib widget in the right hand pane.

        self.figure = mpl.MPLWidget(None, tight_layout=True)
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                               QtGui.QSizePolicy.Expanding)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(self.figure.sizePolicy().hasHeightForWidth())
        self.figure.setSizePolicy(sp)
        self.figure.setFixedWidth(400)
        tab_layout.addWidget(self.figure)

        self.ax_top_comparison = self.figure.figure.add_subplot(211)
        self.ax_bottom_comparison = self.figure.figure.add_subplot(212)

        # Initialize the widgets.
        self._populate_widgets()

        # Connect the widgets.
        self.summary_notes.textChanged.connect(self.update_summary_notes)

        return None
예제 #6
0
    def __init__(self, spectral_models, *args):
        """
        Initialize a widget for inspecting a list of spectral models.

        :param spectral_models:
            A list of spectral models that sub-class from 
            `smh.spectral_models.BaseSpectralModel`.
        """

        super(SpectralModelsWidget, self).__init__(*args)
        self.spectral_models = spectral_models

        self.setGeometry(300, 200, 570, 450)
        self.setWindowTitle("Spectral models")

        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
                               QtGui.QSizePolicy.MinimumExpanding)
        sp.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sp)

        self.table = QtGui.QTableView()
        self.table.setModel(SpectralModelsTableModel(self, spectral_models))
        self.table.resizeColumnsToContents()
        self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        self.table.setSortingEnabled(True)

        _ = self.table.selectionModel()
        _.selectionChanged.connect(self.row_selected)

        # Create a matplotlib widget.
        blank_widget = QtGui.QWidget(self)
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                               QtGui.QSizePolicy.Expanding)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(blank_widget.sizePolicy().hasHeightForWidth())
        blank_widget.setSizePolicy(sp)

        self.mpl_figure = mpl.MPLWidget(blank_widget,
                                        tight_layout=True,
                                        autofocus=True)

        mpl_layout = QtGui.QVBoxLayout(blank_widget)
        mpl_layout.addWidget(self.mpl_figure, 1)

        layout = QtGui.QHBoxLayout(self)
        layout.setContentsMargins(10, 10, 10, 10)
        layout.addWidget(self.table)
        layout.addWidget(blank_widget)

        self.setLayout(layout)

        # Initiate the matplotlib figure.
        self.mpl_axis = self.mpl_figure.figure.add_subplot(111)

        # Draw the spectrum first.
        normalized_spectrum = self.spectral_models[
            0].session.normalized_spectrum
        self.mpl_axis.plot(normalized_spectrum.dispersion,
                           normalized_spectrum.flux,
                           c="k",
                           drawstyle="steps-mid")
        self.mpl_axis.fill_between([], [], [],
                                   facecolor="k",
                                   alpha=0.5,
                                   edgecolor=None,
                                   zorder=1)

        self.mpl_axis.set_ylim(0, 1.2)
        self.mpl_axis.set_xlabel(r"Wavelength (${\rm \AA}$)")
        self.mpl_axis.set_ylabel(r"Normalized flux")
        self.mpl_figure.draw()

        # Plot the model spectrum.
        self.mpl_axis.plot([], [], c="r", zorder=2)
        self.mpl_axis.fill_between([], [], [],
                                   facecolor="r",
                                   alpha=0.5,
                                   edgecolor=None,
                                   zorder=1)

        self.mpl_figure.mpl_connect("button_press_event",
                                    self.figure_mouse_press)
        self.mpl_figure.mpl_connect("button_release_event",
                                    self.figure_mouse_release)

        self._mpl_masked_regions = []
        self._mpl_nearby_lines_masked_regions = []

        return None
예제 #7
0
    def __init__(self, parent):
        """
        Create a tab for the normalization of spectra.
        
        :param parent:
            The parent widget.
        """

        super(NormalizationTab, self).__init__(parent)
        self.parent = parent

        # Establish the GUI for this tab.
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, 
            QtGui.QSizePolicy.MinimumExpanding)
        sp.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sp)

        # Create a top-level horizontal layout to contain a MPL figure and
        # a vertical layout of settings..
        tab_layout = QtGui.QHBoxLayout(self)
        tab_layout.setContentsMargins(20, 20, 20, 0)
        
        settings_widget = QtGui.QWidget()
        settings_layout = QtGui.QVBoxLayout(settings_widget)
        settings_widget.setFixedWidth(300)
        
        # Start the grid layout for the normalization tab.
        settings_grid_layout = QtGui.QGridLayout()

        # Normalization function.
        self.function_label = QtGui.QLabel(self)
        self.function_label.setText("Function")
        settings_grid_layout.addWidget(self.function_label, 0, 0, 1, 1)
        
        # Put the normalization function combo box in a horizontal layout with 
        # a spacer.
        hbox = QtGui.QHBoxLayout()
        hbox.addItem(QtGui.QSpacerItem(
            40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
        self.function = QtGui.QComboBox(self)
        self.function.setObjectName("norm_function")
        hbox.addWidget(self.function)
        settings_grid_layout.addLayout(hbox, 0, 1, 1, 1)

        for each in ("polynomial", "spline"):
            self.function.addItem(each.title())

        # Normalization function order.
        self.order_label = QtGui.QLabel(self)
        self.order_label.setText("Order")
        settings_grid_layout.addWidget(self.order_label, 1, 0, 1, 1)
        
        # Put the normalization order combo box in a horizontal layout with a
        # spacer
        hbox = QtGui.QHBoxLayout()
        hbox.addItem(QtGui.QSpacerItem(
            40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
        self.order = QtGui.QComboBox(self)
        self.order.setMaximumSize(QtCore.QSize(50, 16777215))
        self.order.setObjectName("norm_order")
        hbox.addWidget(self.order)
        settings_grid_layout.addLayout(hbox, 1, 1, 1, 1)

        orders = range(1, 10)
        for order in orders:
            self.order.addItem("{0:.0f}".format(order))

        # Maximum number of iterations.
        self.max_iter_label = QtGui.QLabel(self)
        self.max_iter_label.setText("Maximum iterations")
        settings_grid_layout.addWidget(self.max_iter_label, 2, 0, 1, 1)

        # Put the maxium number of iterations in a horizontal layout with a 
        # spacer.
        hbox = QtGui.QHBoxLayout()
        hbox.addItem(QtGui.QSpacerItem(
            40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
        self.norm_max_iter = QtGui.QComboBox(self)
        self.norm_max_iter.setMaximumSize(QtCore.QSize(50, 16777215))
        self.norm_max_iter.setObjectName("norm_norm_max_iter")
        hbox.addWidget(self.norm_max_iter)
        settings_grid_layout.addLayout(hbox, 2, 1, 1, 1)

        norm_max_iters = range(1, 10)
        for iteration in norm_max_iters:
            self.norm_max_iter.addItem("{0:.0f}".format(iteration))


        # Low sigma clipping.
        self.low_sigma_clip_label = QtGui.QLabel(self)
        self.low_sigma_clip_label.setText("Low sigma clip")
        settings_grid_layout.addWidget(self.low_sigma_clip_label, 3, 0, 1, 1)

        # Put the low sigma line edit box in a horizontal layout with a spacer.
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(-1, -1, 5, -1)
        hbox.addItem(QtGui.QSpacerItem(
            40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
        self.low_sigma_clip = QtGui.QLineEdit(self)
        self.low_sigma_clip.setMaximumSize(QtCore.QSize(40, 16777215))
        self.low_sigma_clip.setAlignment(QtCore.Qt.AlignCenter)
        self.low_sigma_clip.setObjectName("norm_low_sigma_clip")
        self.low_sigma_clip.setValidator(
            QtGui.QDoubleValidator(0, 1000, 2, self.low_sigma_clip))

        hbox.addWidget(self.low_sigma_clip)
        settings_grid_layout.addLayout(hbox, 3, 1, 1, 1)


        # High sigma clipping.
        self.high_sigma_clip_label = QtGui.QLabel(self)
        self.high_sigma_clip_label.setText("High sigma clip")
        settings_grid_layout.addWidget(self.high_sigma_clip_label, 4, 0, 1, 1)

        # Put the high sigma line edit box in a horizontal layout with a spacer.
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(-1, -1, 5, -1)
        hbox.addItem(QtGui.QSpacerItem(
            40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
        self.high_sigma_clip = QtGui.QLineEdit(self)
        self.high_sigma_clip.setMaximumSize(QtCore.QSize(40, 16777215))
        self.high_sigma_clip.setAlignment(QtCore.Qt.AlignCenter)
        self.high_sigma_clip.setObjectName("norm_high_sigma_clip")
        self.high_sigma_clip.setValidator(
            QtGui.QDoubleValidator(0, 1000, 2, self.high_sigma_clip))
        hbox.addWidget(self.high_sigma_clip)
        settings_grid_layout.addLayout(hbox, 4, 1, 1, 1)
        

        # Knot spacing.
        self.knot_spacing_label = QtGui.QLabel(self)
        settings_grid_layout.addWidget(self.knot_spacing_label, 5, 0, 1, 1)
        self.knot_spacing_label.setText(u"Knot spacing (Å)")

        # Put the knot spacing lint edit box in a horizontal layout with a spacer
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(-1, -1, 5, -1)
        hbox.addItem(QtGui.QSpacerItem(
            40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
        self.knot_spacing = QtGui.QLineEdit(self)
        self.knot_spacing.setMaximumSize(QtCore.QSize(40, 16777215))
        self.knot_spacing.setAlignment(QtCore.Qt.AlignCenter)
        self.knot_spacing.setValidator(
            QtGui.QDoubleValidator(0, 10000, 0, self.knot_spacing))
        self.knot_spacing.setObjectName("norm_knot_spacing")
        hbox.addWidget(self.knot_spacing)
        settings_grid_layout.addLayout(hbox, 5, 1, 1, 1)

        # End of the grid in the normalization tab.
        settings_layout.addLayout(settings_grid_layout)

        # Add a label.
        label = QtGui.QLabel(self)
        label.setText("Global continuum mask:")
        settings_layout.addWidget(label)

        # Add options for continuum mask.
        hbox = QtGui.QHBoxLayout()
        self.continuum_mask = QtGui.QComboBox(self)
        self.continuum_mask.setObjectName("contiuum_mask")
        hbox.addWidget(self.continuum_mask)
        hbox.addItem(
            QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                QtGui.QSizePolicy.Minimum))
        self.edit_continuum_masks = QtGui.QPushButton(self)
        self.edit_continuum_masks.setObjectName("edit_continuum_masks")
        self.edit_continuum_masks.setText("Edit masks..")
        hbox.addWidget(self.edit_continuum_masks)

        settings_layout.addLayout(hbox)

        # Add a 'normalize and stitch button'
        self.stitch_btn = QtGui.QPushButton(self)
        sp = QtGui.QSizePolicy(
            QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(self.stitch_btn.sizePolicy().hasHeightForWidth())
        self.stitch_btn.setSizePolicy(sp)
        self.stitch_btn.setMinimumSize(QtCore.QSize(250, 0))
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        self.stitch_btn.setFont(font)
        self.stitch_btn.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.stitch_btn.setDefault(True)
        self.stitch_btn.setObjectName("stitch_btn")
        self.stitch_btn.setText("Normalize and stitch orders")

        settings_layout.addWidget(self.stitch_btn)

        # Add a spacer.
        settings_layout.addItem(QtGui.QSpacerItem(
            40, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding))

        tab_layout.addWidget(settings_widget)

        # Create a matplotlib widget.
        self.norm_plot = mpl.MPLWidget(None, tight_layout=True, matchbg=self)
        sp = QtGui.QSizePolicy(
            QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(self.norm_plot.sizePolicy().hasHeightForWidth())
        self.norm_plot.setSizePolicy(sp)
        self.norm_plot.setFocusPolicy(QtCore.Qt.StrongFocus)

        self.order_slide = QtGui.QSlider(self)
        self.order_slide.setGeometry(QtCore.QRect(230, 200, 160, 22))
        self.order_slide.setOrientation(QtCore.Qt.Horizontal)
        self.order_slide.setFocusPolicy(QtCore.Qt.ClickFocus)
        self.order_slide.setMaximum(15)
        self.order_slide.setOrientation(QtCore.Qt.Horizontal)
        self.order_slide.setTickInterval(1)
        self.current_order_label = QtGui.QLabel(self)
        self.current_order_label.setText("")
        self.order_slide.valueChanged.connect(self.update_order_figure)

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.norm_plot)
        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.order_slide)
        hbox.addWidget(self.current_order_label)
        vbox.addLayout(hbox)

        tab_layout.addLayout(vbox)

        # Set up the plot.
        gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1])
        self.ax_order = self.norm_plot.figure.add_subplot(gs[0])
        # Line for the data.
        self.ax_order.plot([], [], c='k', zorder=3)#, drawstyle='steps-mid')
        # Line for the continuum.
        self.ax_order.plot([], [], linestyle="--", linewidth=2, c='r', zorder=4)

        # Line for the neighbouring order(s) (joined by a NaN).
        self.ax_order.plot([], [], c='#666666', zorder=1, drawstyle='steps-mid')
        # Line for the neighbouring order(s) continuum (joined by a NaN)
        self.ax_order.plot([], [], c='b', zorder=2)

        # Additional point markers.
        self.ax_order.scatter([], [], facecolor="k", zorder=5, picker=5)

        self.ax_order.set_xticklabels([])
        self.ax_order.set_ylabel("Flux")

        self.ax_order_norm = self.norm_plot.figure.add_subplot(gs[1])
        self.ax_order_norm.axhline(1, linestyle=":", c="#666666", zorder=1)
        self.ax_order_norm.plot([], [], c='k', zorder=2)

        # TODO: Make (0, 1.2) a default view setting.
        self.ax_order_norm.set_ylim(0, 1.2)
        self.ax_order_norm.set_yticks([0, 0.5, 1.0])
        self.ax_order_norm.set_xlabel(u"Wavelength (Å)")

        self.norm_plot.draw()

        # Create signals.
        self.stitch_btn.clicked.connect(self.normalize_and_stitch)

        self.norm_plot.mpl_connect(
            "key_press_event", self.figure_key_press)
        self.norm_plot.mpl_connect(
            "button_press_event", self.figure_mouse_press)
        self.norm_plot.mpl_connect(
            "button_release_event", self.figure_mouse_release)

        # Zoom box
        #self.norm_plot.mpl_connect(
        #    "button_press_event", self.norm_plot.axis_right_mouse_press)
        #self.norm_plot.mpl_connect(
        #    "button_release_event", self.norm_plot.axis_right_mouse_release)
        #self.norm_plot.mpl_connect(
        #    "key_press_event", self.norm_plot.unzoom_on_z_press)
        self.norm_plot.enable_interactive_zoom()
        
        self.function.currentIndexChanged.connect(
            self.update_normalization_function)
        self.order.currentIndexChanged.connect(
            self.update_normalization_order)
        self.norm_max_iter.currentIndexChanged.connect(
            self.update_normalization_max_iterations)
        self.low_sigma_clip.textChanged.connect(
            self.update_low_sigma_clip)
        self.high_sigma_clip.textChanged.connect(
            self.update_high_sigma_clip)
        self.knot_spacing.textChanged.connect(self.update_knot_spacing)

        self.low_sigma_clip.textChanged.connect(self.check_state)
        self.high_sigma_clip.textChanged.connect(self.check_state)
        self.knot_spacing.textChanged.connect(self.check_state)
        return None
예제 #8
0
    def __init__(self, rv_tab, *args):
        """
        Initialise a dialog to set new RV correction regions.

        :param session:
            The session that will be inspected for transitions.
        """

        super(RVRegionDialog, self).__init__(*args)

        self.rv_tab = rv_tab

        self.setGeometry(900, 900, 900, 600)
        self.move(QtGui.QApplication.desktop().screen().rect().center() \
            - self.rect().center())

        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
                               QtGui.QSizePolicy.MinimumExpanding)
        sp.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sp)

        spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                                       QtGui.QSizePolicy.Minimum)
        spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                                        QtGui.QSizePolicy.Expanding)
        spacerItem2 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                                        QtGui.QSizePolicy.Minimum)

        self.setObjectName("RVRegionDialog")
        self.setAutoFillBackground(False)
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout_2 = QtGui.QHBoxLayout()

        ## Left column
        self.verticalLayout_2 = QtGui.QVBoxLayout()
        self.verticalLayout_2.addItem(spacerItem)
        self.listWidget = QtGui.QListWidget(self)
        self.listWidget.setObjectName("listWidget")
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,
                               QtGui.QSizePolicy.Minimum)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(self.listWidget.sizePolicy().hasHeightForWidth())
        self.listWidget.setSizePolicy(sp)
        self.verticalLayout_2.addWidget(self.listWidget)
        self.button_savedefault = QtGui.QPushButton(self)
        self.button_savedefault.setObjectName("button_savedefault")
        self.button_savesession = QtGui.QPushButton(self)
        self.button_savesession.setObjectName("button_savesession")
        self.verticalLayout_2.addWidget(self.button_savedefault)
        self.verticalLayout_2.addWidget(self.button_savesession)
        self.verticalLayout_2.addItem(spacerItem1)
        self.horizontalLayout_2.addLayout(self.verticalLayout_2)
        self.button_savedefault.clicked.connect(self.save_as_default)
        self.button_savesession.clicked.connect(self.save_to_session)

        ## Right column MPL widget
        self.verticalLayout = QtGui.QVBoxLayout()
        blank_widget = QtGui.QWidget(self)
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
                               QtGui.QSizePolicy.MinimumExpanding)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(blank_widget.sizePolicy().hasHeightForWidth())
        blank_widget.setSizePolicy(sp)
        blank_widget.setObjectName("blank_widget")
        self.mpl_plot = mpl.MPLWidget(blank_widget,
                                      tight_layout=True,
                                      autofocus=True)
        self.mpl_plot.setObjectName("mpl_plot")

        layout = QtGui.QVBoxLayout(blank_widget)
        layout.addWidget(self.mpl_plot, 1)
        self.verticalLayout.addWidget(blank_widget)

        # Copied from above; TODO refactor?
        gs = gridspec.GridSpec(2, 1, height_ratios=[1, 1])
        self.ax_order = self.mpl_plot.figure.add_subplot(gs[0])
        self.ax_order_norm = self.mpl_plot.figure.add_subplot(gs[1])
        self.ax_order.text(0.99,
                           0.9,
                           "Data",
                           color="k",
                           transform=self.ax_order.transAxes,
                           horizontalalignment="right")
        self.ax_order.text(0.99,
                           0.8,
                           "Continuum",
                           color="r",
                           transform=self.ax_order.transAxes,
                           horizontalalignment="right")
        self.ax_order.text(0.99,
                           0.7,
                           "Template",
                           color="b",
                           transform=self.ax_order.transAxes,
                           horizontalalignment="right")
        self.ax_order.set_xticklabels([])
        self.ax_order_norm.set_yticks([0, 1])
        self.ax_order_norm.set_ylim(0, 1.2)
        self.ax_order_norm.set_xlabel(u"Wavelength (Å)")
        self.ax_order.set_ylabel("Flux")
        self.ax_order.plot([], [], c='k', drawstyle='steps-mid')
        self.ax_order.plot([], [], c='r', zorder=2)
        self.ax_order.set_ylim([0, 1])
        self.ax_order_norm.axhline(1, linestyle=":", c="#666666", zorder=-1)
        self.ax_order_norm.plot([], [], c='k', drawstyle='steps-mid')
        self.ax_order_norm.plot([], [], c='b')  # Template.
        self.ax_order_norm.set_ylabel("Normalized flux")

        # Right column wavelength regions
        self.horizontalLayout_4 = QtGui.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.label = QtGui.QLabel(self)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("Lower Wavelength")
        self.horizontalLayout_4.addWidget(self.label)
        self.label_2 = QtGui.QLabel(self)
        self.label_2.setAlignment(QtCore.Qt.AlignCenter)
        self.label_2.setObjectName("Upper Wavelength")
        self.horizontalLayout_4.addWidget(self.label_2)
        self.verticalLayout.addLayout(self.horizontalLayout_4)
        self.horizontalLayout_3 = QtGui.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.text_lower_wl = QtGui.QLineEdit(self)
        self.text_lower_wl.setObjectName("Lower Wavelength Value")
        self.horizontalLayout_3.addWidget(self.text_lower_wl)
        self.text_upper_wl = QtGui.QLineEdit(self)
        self.text_upper_wl.setObjectName("Upper Wavelength Value")
        self.horizontalLayout_3.addWidget(self.text_upper_wl)
        self.verticalLayout.addLayout(self.horizontalLayout_3)
        # Signals for wavelength region
        self.text_lower_wl.textChanged.connect(self.wl_value_changed)
        self.text_upper_wl.textChanged.connect(self.wl_value_changed)

        # Right column buttons
        self.button_savetolist = QtGui.QPushButton(self)
        self.button_savetolist.setObjectName("button_savetolist")
        self.verticalLayout.addWidget(self.button_savetolist)
        self.verticalLayout.addItem(spacerItem2)
        self.button_exit = QtGui.QPushButton(self)
        self.button_exit.setObjectName("button_exit")
        self.verticalLayout.addWidget(self.button_exit)
        self.horizontalLayout_2.addLayout(self.verticalLayout)
        self.horizontalLayout.addLayout(self.horizontalLayout_2)
        self.button_savetolist.clicked.connect(self.save_to_list)
        self.button_exit.clicked.connect(self.accept)

        # Set labels for everything
        self.setWindowTitle("RVRegionDialog")
        self.label.setText("Lower Wavelength (Å)")
        self.label_2.setText("Upper Wavelength (Å)")
        self.button_savedefault.setText("Save as Default")
        self.button_savesession.setText("Save to Session")
        self.button_savetolist.setText("Save to List")
        self.button_exit.setText("Exit")
        QtCore.QMetaObject.connectSlotsByName(self)

        ## put wavelength regions into the listWidget
        wavelength_regions = self.rv_tab.parent.session.setting(
            ["rv", "wavelength_regions"])
        for each in wavelength_regions:
            self.listWidget.addItem(u"{0:.0f}-{1:.0f} Å".format(*each))
        self.listWidget.currentItemChanged.connect(self.list_selection_changed)
        self.listWidget.setSortingEnabled(False)
        self.listWidget.setCurrentRow(0)

        # allow right-click to delete menu
        self.listWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.listWidget.customContextMenuRequested.connect(
            self.list_context_menu)

        self.draw_template(refresh=True)
        self.update_wl_region()
        self.mpl_plot.draw()

        return None
예제 #9
0
    def __init__(self, parent):
        """
        Create a tab for correcting spectra for radial velocity.

        :param parent:
            The parent widget.
        """

        super(RVTab, self).__init__(parent)

        self.parent = parent

        # Create the overall RV tab.
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
                               QtGui.QSizePolicy.MinimumExpanding)
        sp.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sp)

        # Create a top-level horizontal layout to contain a matplotlib figure and
        # a vertical layout of settings..
        rv_tab_layout = QtGui.QHBoxLayout(self)
        rv_tab_layout.setContentsMargins(20, 20, 20, 0)

        # This vertical layout will be for input settings.
        rv_settings_vbox = QtGui.QVBoxLayout()
        rv_settings_vbox.setSizeConstraint(QtGui.QLayout.SetMinimumSize)

        # A two-tab setting for 'template' and 'normalization' settings in the
        # radial velocity determination.
        rv_settings_tabs = QtGui.QTabWidget(self)

        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                               QtGui.QSizePolicy.Fixed)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(rv_settings_tabs.sizePolicy().hasHeightForWidth())

        rv_settings_tabs.setSizePolicy(sp)
        rv_settings_tabs.setMinimumSize(QtCore.QSize(300, 240))
        rv_settings_tabs.setMaximumSize(QtCore.QSize(300, 240))

        rv_settings_tabs.setMovable(True)
        rv_settings_tabs.setObjectName("rv_settings_tabs")

        # A tab containing template settings.
        template_tab = QtGui.QWidget()
        template_tab.setObjectName("tv_template_tab")

        # TODO: Should template_tab and template_tab_widget actually be one entity?
        template_tab_widget = QtGui.QWidget(template_tab)
        template_tab_widget.setGeometry(QtCore.QRect(0, 0, 300, 210))

        template_tab_layout = QtGui.QVBoxLayout(template_tab_widget)
        template_tab_layout.setSizeConstraint(
            QtGui.QLayout.SetDefaultConstraint)
        template_tab_layout.setContentsMargins(10, 10, 10, 10)

        # Add a label at the top of the template settings tab.
        label = QtGui.QLabel(template_tab_widget)
        label.setMaximumSize(QtCore.QSize(240, 16777215))
        label.setText("Template spectrum filename:")
        template_tab_layout.addWidget(label)

        # Inner horizontal layout for the template path and select.
        template_path_layout = QtGui.QHBoxLayout()

        # Template path line edit (read-only).
        self.template_path = QtGui.QLineEdit(template_tab_widget)
        self.template_path.setObjectName("rv_template_path")
        self.template_path.setReadOnly(True)
        template_path_layout.addWidget(self.template_path)

        # Template path select button.
        rv_select_template_btn = QtGui.QPushButton(template_tab_widget)
        rv_select_template_btn.setObjectName("rv_select_template_btn")
        rv_select_template_btn.setText("...")
        template_path_layout.addWidget(rv_select_template_btn)

        # Add this horizontal layout to the template tab.
        template_tab_layout.addLayout(template_path_layout)

        # Add a label for the wavelength regions
        label = QtGui.QLabel(template_tab_widget)
        label.setMaximumSize(QtCore.QSize(240, 16777215))
        label.setText("Wavelength region:")
        template_tab_layout.addWidget(label)

        # Wavelength region for CCF.
        wl_region_layout = QtGui.QHBoxLayout()
        self.wl_region = QtGui.QComboBox(template_tab_widget)
        self.wl_region.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
        self.wl_region.setObjectName("rv_wl_region")
        wl_region_layout.addWidget(self.wl_region)

        # Edit button for the wavelength regions.
        rv_wl_region_edit = QtGui.QPushButton(template_tab_widget)
        rv_wl_region_edit.setMaximumSize(QtCore.QSize(80, 16777215))
        rv_wl_region_edit.setObjectName("rv_wl_region_edit")
        wl_region_layout.addWidget(rv_wl_region_edit)
        template_tab_layout.addLayout(wl_region_layout)
        rv_wl_region_edit.setText("Edit list")

        # Add a horizontal line.
        hr = QtGui.QFrame(template_tab_widget)
        hr.setFrameShape(QtGui.QFrame.HLine)
        hr.setFrameShadow(QtGui.QFrame.Sunken)
        template_tab_layout.addWidget(hr)

        # Add a flexible spacer.
        template_tab_layout.addItem(
            QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                              QtGui.QSizePolicy.Expanding))

        # Add a cross-correlate button.
        rv_cross_correlate_btn = QtGui.QPushButton(template_tab_widget)
        rv_cross_correlate_btn.setObjectName("rv_cross_correlate_btn")
        rv_cross_correlate_btn.setText("Cross-correlate")
        template_tab_layout.addWidget(rv_cross_correlate_btn)

        # End of the template tab.
        rv_settings_tabs.addTab(template_tab, "Template")

        # Start the normalization tab.
        norm_tab = QtGui.QWidget()
        norm_tab.setObjectName("rv_normalization_tab")

        norm_tab_widget = QtGui.QWidget(norm_tab)
        norm_tab_widget.setGeometry(QtCore.QRect(0, 0, 300, 210))

        norm_tab_layout = QtGui.QVBoxLayout(norm_tab_widget)
        norm_tab_layout.setContentsMargins(10, 10, 10, 10)

        # Start the grid layout for the normalization tab.
        norm_tab_grid_layout = QtGui.QGridLayout()

        # Normalization function.
        label = QtGui.QLabel(norm_tab_widget)
        label.setText("Function")
        norm_tab_grid_layout.addWidget(label, 0, 0, 1, 1)

        # Put the normalization function combo box in a horizontal layout with a
        # spacer.
        hbox = QtGui.QHBoxLayout()
        hbox.addItem(
            QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Minimum))
        self.norm_function = QtGui.QComboBox(norm_tab_widget)
        self.norm_function.setObjectName("rv_norm_function")
        hbox.addWidget(self.norm_function)
        norm_tab_grid_layout.addLayout(hbox, 0, 1, 1, 1)

        norm_functions = ("polynomial", "spline")
        for each in norm_functions:
            self.norm_function.addItem(each.title())

        # Normalization function order.
        label = QtGui.QLabel(norm_tab_widget)
        label.setText("Order")
        norm_tab_grid_layout.addWidget(label, 1, 0, 1, 1)

        # Put the normalization order combo box in a horizontal layout with a spacer
        hbox = QtGui.QHBoxLayout()
        hbox.addItem(
            QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Minimum))
        self.norm_order = QtGui.QComboBox(norm_tab_widget)
        self.norm_order.setMaximumSize(QtCore.QSize(50, 16777215))
        self.norm_order.setObjectName("rv_norm_order")
        hbox.addWidget(self.norm_order)
        norm_tab_grid_layout.addLayout(hbox, 1, 1, 1, 1)

        norm_orders = range(1, 10)
        for order in norm_orders:
            self.norm_order.addItem("{0:.0f}".format(order))

        # Maximum number of iterations.
        label = QtGui.QLabel(norm_tab_widget)
        label.setText("Maximum iterations")
        norm_tab_grid_layout.addWidget(label, 2, 0, 1, 1)

        # Put the maxium number of iterations in a horizontal layout with a spacer.
        hbox = QtGui.QHBoxLayout()
        hbox.addItem(
            QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Minimum))
        self.norm_max_iter = QtGui.QComboBox(norm_tab_widget)
        self.norm_max_iter.setMaximumSize(QtCore.QSize(50, 16777215))
        self.norm_max_iter.setObjectName("rv_norm_max_iter")
        hbox.addWidget(self.norm_max_iter)
        norm_tab_grid_layout.addLayout(hbox, 2, 1, 1, 1)

        norm_max_iters = range(1, 10)
        for iteration in norm_max_iters:
            self.norm_max_iter.addItem("{0:.0f}".format(iteration))

        # Low sigma clipping.
        label = QtGui.QLabel(norm_tab_widget)
        label.setText("Low sigma clip")
        norm_tab_grid_layout.addWidget(label, 3, 0, 1, 1)

        # Put the low sigma line edit box in a horizontal layout with a spacer.
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(-1, -1, 5, -1)
        hbox.addItem(
            QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Minimum))
        self.norm_low_sigma = QtGui.QLineEdit(norm_tab_widget)
        self.norm_low_sigma.setMaximumSize(QtCore.QSize(40, 16777215))
        self.norm_low_sigma.setAlignment(QtCore.Qt.AlignCenter)
        self.norm_low_sigma.setObjectName("rv_norm_low_sigma")
        self.norm_low_sigma.setValidator(
            QtGui.QDoubleValidator(0, 1000, 2, self.norm_low_sigma))
        hbox.addWidget(self.norm_low_sigma)
        norm_tab_grid_layout.addLayout(hbox, 3, 1, 1, 1)

        # High sigma clipping.
        label = QtGui.QLabel(norm_tab_widget)
        label.setText("High sigma clip")
        norm_tab_grid_layout.addWidget(label, 4, 0, 1, 1)

        # Put the high sigma line edit box in a horizontal layout with a spacer.
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(-1, -1, 5, -1)
        hbox.addItem(
            QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Minimum))
        self.norm_high_sigma = QtGui.QLineEdit(norm_tab_widget)
        self.norm_high_sigma.setMaximumSize(QtCore.QSize(40, 16777215))
        self.norm_high_sigma.setAlignment(QtCore.Qt.AlignCenter)
        self.norm_high_sigma.setObjectName("rv_norm_high_sigma")
        self.norm_high_sigma.setValidator(
            QtGui.QDoubleValidator(0, 1000, 2, self.norm_high_sigma))
        hbox.addWidget(self.norm_high_sigma)
        norm_tab_grid_layout.addLayout(hbox, 4, 1, 1, 1)

        # Knot spacing.
        label = QtGui.QLabel(norm_tab_widget)
        norm_tab_grid_layout.addWidget(label, 5, 0, 1, 1)
        label.setText(u"Knot spacing (Å)")

        # Put the knot spacing lint edit box in a horizontal layout with a spacer
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(-1, -1, 5, -1)
        hbox.addItem(
            QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Minimum))
        self.norm_knot_spacing = QtGui.QLineEdit(norm_tab_widget)
        self.norm_knot_spacing.setMaximumSize(QtCore.QSize(40, 16777215))
        self.norm_knot_spacing.setAlignment(QtCore.Qt.AlignCenter)
        self.norm_knot_spacing.setObjectName("rv_norm_knot_spacing")
        self.norm_knot_spacing.setValidator(
            QtGui.QIntValidator(0, 10000, self.norm_knot_spacing))
        hbox.addWidget(self.norm_knot_spacing)
        norm_tab_grid_layout.addLayout(hbox, 5, 1, 1, 1)

        # End of the grid in the normalization tab.
        norm_tab_layout.addLayout(norm_tab_grid_layout)
        norm_tab_layout.addItem(
            QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                              QtGui.QSizePolicy.Expanding))

        rv_settings_tabs.addTab(norm_tab, "Order normalization")
        rv_settings_vbox.addWidget(rv_settings_tabs)

        # Horizontal layout for the radial velocity measured/corrected.
        hbox = QtGui.QHBoxLayout()
        hbox.setSizeConstraint(QtGui.QLayout.SetMaximumSize)
        hbox.setContentsMargins(10, 0, 10, -1)

        label = QtGui.QLabel(self)
        label.setText("Radial velocity:")
        hbox.addWidget(label)

        # Radial velocity measured.
        self.rv_applied = QtGui.QLineEdit(self)
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored,
                               QtGui.QSizePolicy.Fixed)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(self.rv_applied.sizePolicy().hasHeightForWidth())
        self.rv_applied.setSizePolicy(sp)
        self.rv_applied.setMinimumSize(QtCore.QSize(50, 16777215))
        self.rv_applied.setAlignment(QtCore.Qt.AlignCenter)
        self.rv_applied.setValidator(
            QtGui.QDoubleValidator(-1e6, 1e6, 2, self.rv_applied))
        self.rv_applied.textChanged.connect(self.check_state)
        self.rv_applied.returnPressed.connect(self.correct_radial_velocity)

        hbox.addWidget(self.rv_applied)

        # Units/uncertainty label.
        label = QtGui.QLabel(self)
        label.setObjectName("rv_measured_units_label")
        label.setText("km/s")
        hbox.addWidget(label)

        # Correct for radial velocity button.
        rv_correct_btn = QtGui.QPushButton(self)
        rv_correct_btn.setObjectName("rv_correct_btn")
        rv_correct_btn.setText("Correct")
        hbox.addWidget(rv_correct_btn)
        rv_settings_vbox.addLayout(hbox)

        # The cross-correlate and correct button.
        rv_ccc_btn = QtGui.QPushButton(self)
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
                               QtGui.QSizePolicy.Fixed)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(rv_ccc_btn.sizePolicy().hasHeightForWidth())
        rv_ccc_btn.setSizePolicy(sp)
        rv_ccc_btn.setMinimumSize(QtCore.QSize(300, 0))
        rv_ccc_btn.setMaximumSize(QtCore.QSize(300, 16777215))
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        rv_ccc_btn.setFont(font)
        rv_ccc_btn.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        rv_ccc_btn.setDefault(True)
        rv_ccc_btn.setObjectName("rv_ccc_btn")
        rv_ccc_btn.setText("Cross-correlate and correct")

        rv_settings_vbox.addWidget(rv_ccc_btn)

        # Add a spacer after the big button.
        rv_settings_vbox.addItem(
            QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                              QtGui.QSizePolicy.Expanding))

        rv_tab_layout.addLayout(rv_settings_vbox)

        # Create a matplotlib widget.
        self.rv_plot = mpl.MPLWidget(None, tight_layout=True)
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                               QtGui.QSizePolicy.Expanding)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(self.rv_plot.sizePolicy().hasHeightForWidth())
        rv_tab_layout.addWidget(self.rv_plot)

        gs_top = gridspec.GridSpec(3, 1, height_ratios=[2, 1, 1])
        gs_top.update(hspace=0)
        gs_bottom = gridspec.GridSpec(3, 1)
        self.ax_order = self.rv_plot.figure.add_subplot(gs_top[0])
        self.ax_order_norm = self.rv_plot.figure.add_subplot(gs_top[1])
        self.ax_ccf = self.rv_plot.figure.add_subplot(gs_bottom[2])

        # Pseudo-legend.
        self.ax_order.text(0.99,
                           0.9,
                           "Data",
                           color="k",
                           transform=self.ax_order.transAxes,
                           horizontalalignment="right")
        self.ax_order.text(0.99,
                           0.8,
                           "Continuum",
                           color="r",
                           transform=self.ax_order.transAxes,
                           horizontalalignment="right")
        self.ax_order.text(0.99,
                           0.7,
                           "Template",
                           color="b",
                           transform=self.ax_order.transAxes,
                           horizontalalignment="right")

        # Ticks, etc
        self.ax_order.set_xticklabels([])
        self.ax_order_norm.set_yticks([0, 1])
        self.ax_order_norm.set_ylim(0, 1.2)

        self.ax_order_norm.set_xlabel(u"Wavelength (Å)")
        self.ax_order.set_ylabel("Flux")

        # Draw an initial line for data and continuum.
        self.ax_order.plot([], [], c='k', drawstyle='steps-mid')
        self.ax_order.plot([], [], c='r', zorder=2)
        self.ax_order.set_ylim([0, 1])

        self.ax_order_norm.axhline(1, linestyle=":", c="#666666", zorder=-1)
        self.ax_order_norm.plot([], [], c='k', drawstyle='steps-mid')
        self.ax_order_norm.plot([], [], c='b')  # Template.
        self.ax_order_norm.set_ylabel("Normalized flux")

        self.ax_ccf.plot([], [], c='k')
        self.ax_ccf.set_xlabel("Velocity (km/s)")
        self.ax_ccf.set_ylabel("CCF")
        self.ax_ccf.set_yticks([0, 0.5, 1.0])

        # Keep an input cache.
        self._populate_widgets()

        # Create signals for buttons.
        rv_cross_correlate_btn.clicked.connect(self.cross_correlate)
        rv_correct_btn.clicked.connect(self.correct_radial_velocity)
        rv_ccc_btn.clicked.connect(self.cross_correlate_and_correct)
        rv_wl_region_edit.clicked.connect(self.launch_rvregion_dialog)

        # Create signals for when any of these things change.
        rv_select_template_btn.clicked.connect(self.select_template)
        self.wl_region.currentIndexChanged.connect(self.update_wl_region)
        self.norm_low_sigma.textChanged.connect(
            self.update_normalization_low_sigma)
        self.norm_high_sigma.textChanged.connect(
            self.update_normalization_high_sigma)
        self.norm_knot_spacing.textChanged.connect(
            self.update_normalization_knot_spacing)
        self.norm_function.currentIndexChanged.connect(
            self.update_normalization_function)
        self.norm_order.currentIndexChanged.connect(
            self.update_normalization_order)
        self.norm_max_iter.currentIndexChanged.connect(
            self.update_normalization_max_iterations)

        # Update the background to show whether certain items are valid.
        self.norm_low_sigma.textChanged.connect(self.check_state)
        self.norm_high_sigma.textChanged.connect(self.check_state)
        self.norm_knot_spacing.textChanged.connect(self.check_state)

        # Draw the template straight up if we can.
        self.draw_template(refresh=True)

        return None
예제 #10
0
    def _add_pane_4(self):
        """
        Add pane 4 to show inference results from Balmer line models.
        """

        self.p4 = QtGui.QWidget()
        self.layout.addWidget(self.p4)

        p4_layout = QtGui.QVBoxLayout()
        self.p4.setLayout(p4_layout)

        # Two figures in two groups.
        self.p4_tabs = QtGui.QTabWidget(self)
        self.p4_tabs.setTabPosition(QtGui.QTabWidget.North)
        self.p4_tabs.setUsesScrollButtons(False)

        self.p4_figure_posterior = mpl.MPLWidget(None,
                                                 tight_layout=True,
                                                 matchbg=self)
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                               QtGui.QSizePolicy.Expanding)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(
            self.p4_figure_posterior.sizePolicy().hasHeightForWidth())
        self.p4_figure_posterior.setSizePolicy(sp)

        self.p4_tabs.addTab(self.p4_figure_posterior, "Posterior")

        self.p4_figure_projection = mpl.MPLWidget(None,
                                                  tight_layout=True,
                                                  matchbg=self)
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                               QtGui.QSizePolicy.Expanding)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(
            self.p4_figure_projection.sizePolicy().hasHeightForWidth())
        self.p4_figure_projection.setSizePolicy(sp)

        self.p4_tabs.addTab(self.p4_figure_projection, "Projection")

        p4_layout.addWidget(self.p4_tabs)

        # Hbox for lower buttons.

        hbox = QtGui.QHBoxLayout()

        # Save to session
        self.p4_btn_save_to_session = QtGui.QPushButton(self)
        self.p4_btn_save_to_session.setFocusPolicy(QtCore.Qt.NoFocus)
        self.p4_btn_save_to_session.setText("Save result to session")
        hbox.addWidget(self.p4_btn_save_to_session)

        hbox.addItem(
            QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Minimum))

        # Close.
        self.p4_btn_close = QtGui.QPushButton(self)
        self.p4_btn_close.setText("Close")
        hbox.addWidget(self.p4_btn_close)

        p4_layout.addLayout(hbox)

        # Signals.
        if self.session is None:
            self.p4_btn_save_to_session.setEnabled(False)

        self.p4_btn_save_to_session.clicked.connect(self.save_to_session)
        self.p4_btn_close.clicked.connect(self.close)

        # Axes.
        #ax = self.p4_figure_spectrum.figure.add_subplot(111)
        for i in range(1, 5):
            self.p4_figure_posterior.figure.add_subplot(2, 2, i)

        ax = self.p4_figure_projection.figure.add_subplot(111)
        ax.plot([], [], c="k", drawstyle="steps-mid", zorder=10)
        ax.xaxis.set_major_locator(MaxNLocator(5))
        ax.yaxis.set_major_locator(MaxNLocator(5))
        ax.set_xlabel(u"Wavelength [Å]")
        ax.set_ylabel(u"Flux")

        return None
예제 #11
0
    def _add_pane_1(self):
        """ Add the first pane of widgets to the dialog window. """

        self.p1 = QtGui.QWidget()
        self.layout.addWidget(self.p1)

        # Panel 1
        p1_vbox = QtGui.QVBoxLayout()
        self.p1.setLayout(p1_vbox)

        hbox = QtGui.QHBoxLayout()
        self.combo_balmer_line_selected = QtGui.QComboBox(self)

        hbox.addWidget(self.combo_balmer_line_selected)
        hbox.addItem(
            QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Maximum,
                              QtGui.QSizePolicy.Minimum))

        self.combo_spectrum_selected = QtGui.QComboBox(self)
        hbox.addWidget(self.combo_spectrum_selected)
        hbox.addItem(
            QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Minimum))
        p1_vbox.addLayout(hbox)

        line = QtGui.QFrame(self)
        line.setFrameShape(QtGui.QFrame.HLine)
        line.setFrameShadow(QtGui.QFrame.Sunken)
        p1_vbox.addWidget(line)

        # Model options table and group.
        hbox = QtGui.QHBoxLayout()
        gp = QtGui.QGroupBox(self)
        gp.setTitle("Model options")
        gp.setMinimumSize(QtCore.QSize(0, 0))
        vbox = QtGui.QVBoxLayout(gp)

        self.p1_model_options = QtGui.QTableView(gp)
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
                               QtGui.QSizePolicy.Expanding)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(
            self.p1_model_options.sizePolicy().hasHeightForWidth())
        self.p1_model_options.setSizePolicy(sp)
        self.p1_model_options.setMinimumSize(QtCore.QSize(300, 16777215))
        self.p1_model_options.setMaximumSize(QtCore.QSize(300, 16777215))
        self.p1_model_options.setEditTriggers(
            QtGui.QAbstractItemView.CurrentChanged)
        self.p1_model_options.setModel(BalmerLineOptionsTableModel(self))
        self.p1_model_options.horizontalHeader().setResizeMode(
            QtGui.QHeaderView.Stretch)

        # First column should be fixed for the checkbox.
        self.p1_model_options.horizontalHeader().setResizeMode(
            0, QtGui.QHeaderView.Fixed)
        self.p1_model_options.horizontalHeader().resizeSection(0, 30)  # MAGIC

        vbox.addWidget(self.p1_model_options)
        hbox.addWidget(gp)

        self.p1_figure = mpl.MPLWidget(None, tight_layout=True, matchbg=self)
        sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                               QtGui.QSizePolicy.Expanding)
        sp.setHorizontalStretch(0)
        sp.setVerticalStretch(0)
        sp.setHeightForWidth(self.p1_figure.sizePolicy().hasHeightForWidth())
        self.p1_figure.setSizePolicy(sp)
        hbox.addWidget(self.p1_figure)

        p1_vbox.addLayout(hbox)

        line = QtGui.QFrame(self)
        line.setFrameShape(QtGui.QFrame.HLine)
        line.setFrameShadow(QtGui.QFrame.Sunken)
        p1_vbox.addWidget(line)

        hbox = QtGui.QHBoxLayout()
        self.p1_save_settings_as_default = QtGui.QPushButton(self)
        self.p1_save_settings_as_default.setText("Save settings as default")
        self.p1_save_settings_as_default.setFocusPolicy(QtCore.Qt.NoFocus)
        if self.session is None:
            self.p1_save_settings_as_default.setEnabled(False)
        hbox.addWidget(self.p1_save_settings_as_default)

        hbox.addItem(
            QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Minimum))

        self.p1_sample_posterior = QtGui.QPushButton(self)
        self.p1_sample_posterior.setText("Sample posterior")
        self.p1_sample_posterior.setFocusPolicy(QtCore.Qt.NoFocus)
        hbox.addWidget(self.p1_sample_posterior)

        p1_vbox.addLayout(hbox)

        # Initialize widgets that do not depend on the input spectra.
        for name, wavelength \
        in zip(self.__balmer_line_wavelengths, self.__balmer_line_names):
            self.combo_balmer_line_selected.addItem(u"{} ({} Å)".format(
                name, wavelength))

        self.combo_balmer_line_selected.setFocus()

        ax = self.p1_figure.figure.add_subplot(111)
        ax.plot([], [], c="k", drawstyle="steps-mid", zorder=10)
        ax.plot([], [], c="#666666", linestyle="-", zorder=-1)
        ax.xaxis.set_major_locator(MaxNLocator(5))
        ax.yaxis.set_major_locator(MaxNLocator(5))
        ax.set_xlabel(u"Wavelength [Å]")
        ax.set_ylabel(u"Flux")

        ax.xaxis.set_visible(False)
        ax.yaxis.set_visible(False)

        self.p1_figure.enable_drag_to_mask(ax)
        self.p1_figure.enable_interactive_zoom()

        self.metadata = {}
        self.metadata.update(self._default_option_metadata)

        # Signals.
        self.combo_balmer_line_selected.currentIndexChanged.connect(
            self.updated_balmer_line_selected)
        self.combo_spectrum_selected.currentIndexChanged.connect(
            self.updated_spectrum_selected)
        self.p1_save_settings_as_default.clicked.connect(
            self.save_settings_as_default)
        self.p1_sample_posterior.clicked.connect(self.show_third_pane)

        # Create worker.
        self.worker = Worker(self)
        self.worker.updateProgress.connect(self.setProgress)

        return None