def init_axes(self): self.x_plot_lims = self.sp.get_conf('x_plot_lims') if self.x_plot_lims is None: self.x_plot_lims = (np.min(self.sp.w), np.max(self.sp.w)) self.y1_plot_lims = self.sp.get_conf('y1_plot_lims') if self.y1_plot_lims is None: mask = (self.sp.w_ori > self.x_plot_lims[0]) & (self.sp.w_ori < self.x_plot_lims[1]) if self.sp.sp_synth_lr is None: self.y1_plot_lims = (np.min(self.sp.f), np.max(self.sp.f)) else: self.y1_plot_lims = (np.min(self.sp.sp_synth_lr[mask]), np.max(self.sp.sp_synth_lr[mask])) self.y2_plot_lims = self.sp.get_conf('y2_plot_lims') if self.y2_plot_lims is None: self.y2_plot_lims = (-0.5, 1.5) self.y3_plot_lims = self.sp.get_conf('y3_plot_lims') if self.y3_plot_lims is None: mask = (self.sp.w_ori > self.x_plot_lims[0]) & (self.sp.w_ori < self.x_plot_lims[1]) if self.sp.cont is None: self.y3_plot_lims = (-1,1) else: self.y3_plot_lims = (np.min((self.sp.f - self.sp.cont)[mask]), np.max((self.sp.f - self.sp.cont)[mask])) log_.debug('Axes initialized. IDs {} {} {}'.format(id(self.axes), id(self.axes2), id(self.axes3)), calling=self.calling) self.print_axes()
def save_axes(self): if self.axes is not None: self.x_plot_lims = self.axes.get_xlim() self.y1_plot_lims = self.axes.get_ylim() if self.axes2 is not None: self.y2_plot_lims = self.axes2.get_ylim() if self.axes3 is not None: self.y3_plot_lims = self.axes3.get_ylim() self.sp.save_axes() log_.debug('Axes saved. IDs {} {} {}'.format(id(self.axes), id(self.axes2), id(self.axes3)), calling=self.calling) self.print_axes()
def on_draw(self): """ Redraws for w in [self.sp_min_box, self.ebv_box, self.resol_box]: hbox3.addWidget(w) hbox3.setAlignment(w, QtCore.Qt.AlignVCenter) the figure """ log_.debug('Entering on_drawn', calling=self.calling) if self.sp is None: log_.debug('Np sp in on_drawn', calling=self.calling) return if self.axes is None: log_.debug('Calling make_axes from on_draw (self.axes is None)', calling=self.calling) self.call_on_draw=False self.make_axes() self.init_axes() log_.debug('back from make_axes from on_draw', calling=self.calling) self.call_on_draw=True if self.do_save: self.save_axes() self.axes.cla() self.sp.plot_ax1(self.axes) if self.lineIDs_GroupBox.isChecked() and self.sp.get_conf('plot_ax2'): self.axes2.cla() self.sp.plot_ax2(self.axes2) # self.sp.plot_lines(self.axes3) if self.residual_GroupBox.isChecked(): self.axes3.cla() self.sp.plot_ax3(self.axes3) if self.lineIDs_GroupBox.isChecked() and not self.sp.get_conf('plot_ax2'): self.sp.plot_lines(self.axes3) if self.residual_GroupBox.isChecked(): self.axes3.set_xlabel(r'Wavelength ($\AA$)') elif self.lineIDs_GroupBox.isChecked() and self.sp.get_conf('plot_ax2'): self.axes2.set_xlabel(r'Wavelength ($\AA$)') else: self.axes.set_xlabel(r'Wavelength ($\AA$)') self.restore_axes() self.update_lim_boxes() self.canvas.draw() log_.debug('Exit on_drawn', calling=self.calling)
def make_axes(self): log_.debug('Entering make_axes', calling=self.calling) if self.call_on_draw: self.save_axes() self.fig.clf() i_ax1 = 0 i_ax2 = 1 i_ax3 = 2 rspan_ax1 = 4 rspan_ax2 = 1 rspan_ax3 = 4 n_subplots = rspan_ax1 ShowAx2 = self.lineIDs_GroupBox.isChecked() and self.sp.get_conf('plot_ax2') # if self.lineIDs_GroupBox.isChecked(): if ShowAx2: i_ax2 = n_subplots n_subplots += rspan_ax2 if self.residual_GroupBox.isChecked(): i_ax3 = n_subplots n_subplots += rspan_ax3 if self.axes is not None: del(self.axes) self.axes = plt.subplot2grid((n_subplots,1), (i_ax1,0), rowspan=rspan_ax1) self.sp.ax1 = self.axes # if self.lineIDs_GroupBox.isChecked(): if ShowAx2: if self.axes2 is not None: del(self.axes2) self.axes2 = plt.subplot2grid((n_subplots,1), (i_ax2,0), rowspan=rspan_ax2, sharex=self.axes ) self.axes2.tick_params( left='off',labelleft='off' ) self.sp.ax2 = self.axes2 self.axes.get_xaxis().set_visible(False) else: self.axes2 = None self.sp.ax2 = None if self.residual_GroupBox.isChecked(): if self.axes3 is not None: del(self.axes3) self.axes3 = plt.subplot2grid((n_subplots,1), (i_ax3,0), rowspan=rspan_ax3, sharex=self.axes ) self.sp.ax3 = self.axes3 if ShowAx2: self.axes2.get_xaxis().set_visible(False) self.axes.get_xaxis().set_visible(False) else: self.axes3 = None self.sp.ax3 = self.axes3 self.fig.subplots_adjust(hspace=0.0, bottom=0.11, right=0.98, top=0.99, left=0.1) if self.call_on_draw: log_.debug('Calling on_draw from make_axes', calling=self.calling) self.do_save = False self.on_draw() self.do_save = True log_.debug('Exit make_axes', calling=self.calling)
def restore_axes(self): if self.x_plot_lims is not None: if self.axes is not None: self.axes.set_xlim(self.x_plot_lims) log_.debug('X-axes restored to {}'.format(self.axes.get_xlim()), calling=self.calling) else: log_.debug('axes is None', calling=self.calling) else: log_.debug('x_plot_lims is None', calling=self.calling) if self.y1_plot_lims is not None: if self.axes is not None: self.axes.set_ylim(self.y1_plot_lims) if self.y2_plot_lims is not None: if self.axes2 is not None: self.axes2.set_ylim(self.y2_plot_lims) if self.y3_plot_lims is not None: if self.axes3 is not None: self.axes3.set_ylim(self.y3_plot_lims) log_.debug('Axes restored. IDs {} {} {}'.format(id(self.axes), id(self.axes2), id(self.axes3)), calling=self.calling) self.print_axes()
def make_axes_original(self): log_.debug('Entering make_axes', calling=self.calling) if self.call_on_draw: self.save_axes() self.fig.clf() n_subplots = 1 i_ax2 = 2 i_ax3 = 2 if self.lineIDs_GroupBox.isChecked(): n_subplots += 1 i_ax3 += 1 if self.residual_GroupBox.isChecked(): n_subplots += 1 if self.axes is not None: del(self.axes) self.axes = self.fig.add_subplot(n_subplots, 1, 1) self.sp.ax1 = self.axes if self.lineIDs_GroupBox.isChecked(): if self.axes2 is not None: del(self.axes2) self.axes2 = self.fig.add_subplot(n_subplots, 1, i_ax2, sharex=self.axes) self.sp.ax2 = self.axes2 self.axes.get_xaxis().set_visible(False) else: self.axes2 = None self.sp.ax2 = None if self.residual_GroupBox.isChecked(): if self.axes3 is not None: del(self.axes3) self.axes3 = self.fig.add_subplot(n_subplots, 1, i_ax3, sharex=self.axes) self.sp.ax3 = self.axes3 if self.sp.get_conf('plot_ax2'): self.axes2.get_xaxis().set_visible(False) self.axes.get_xaxis().set_visible(False) else: self.axes3 = None self.sp.ax3 = self.axes3 self.fig.subplots_adjust(hspace=0.0, bottom=0.11, right=0.97, top=0.97, left=0.1) if self.call_on_draw: log_.debug('Calling on_draw from make_axes', calling=self.calling) self.do_save = False self.on_draw() self.do_save = True log_.debug('Exit make_axes', calling=self.calling)
def verbosity(self): verbosity = self.verbosity_list.index(self.verbosity_ag.checkedAction().text()) log_.debug('Change verbosity from {} to {}'.format(log_.level, verbosity), calling=self.calling) log_.level = verbosity
def print_axes(self): log_.debug('{} {} {} {}'.format(self.x_plot_lims, self.y1_plot_lims, self.y2_plot_lims, self.y3_plot_lims), calling=self.calling) log_.debug('Axes IDs {} {} {}'.format(id(self.axes), id(self.axes2), id(self.axes3)), calling=self.calling) log_.debug(' IDs {} {} {}'.format(id(self.axes), id(self.axes2), id(self.axes3)), calling=self.calling)
def create_main_frame(self): if self.use_workspace: self.main_frame = QtGui.QWorkspace() else: self.main_frame = QtGui.QWidget() # Create the mpl Figure and FigCanvas objects. # self.dpi = 100 self.fig = plt.figure(figsize=(15,15)) # self.fig = plt.figure((figsize=(20.0, 15.0), dpi=self.dpi) log_.debug('creating figure {}'.format(id(self.fig)), calling=self.calling) self.canvas = FigureCanvas(self.fig) if self.use_workspace: self.main_frame.addWindow(self.canvas) self.fig2 = Figure((20.0, 15.0), dpi=self.dpi) self.canvas2 = FigureCanvas(self.fig2) #self.main_frame.addWindow(self.canvas2) else: self.canvas.setParent(self.main_frame) self.canvas.mpl_connect('button_press_event', self.on_click) self.canvas.mpl_connect('figure_leave_event', self.leave_fig) # Create the navigation toolbar, tied to the canvas # self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame) self.mpl_toolbar.curs.connect(self.set_cursor) # Other GUI controls # self.fix_axes_cb = QtGui.QCheckBox("fix") self.fix_axes_cb.setChecked(False) self.connect(self.fix_axes_cb, QtCore.SIGNAL('stateChanged(int)'), self.fix_axes) self.xlim_min_box = QtGui.QLineEdit() self.xlim_min_box.setMinimumWidth(50) self.connect(self.xlim_min_box, QtCore.SIGNAL('returnPressed()'), self.save_from_lim_boxes) self.xlim_max_box = QtGui.QLineEdit() self.xlim_max_box.setMinimumWidth(50) self.connect(self.xlim_max_box, QtCore.SIGNAL('returnPressed()'), self.save_from_lim_boxes) self.y1lim_min_box = QtGui.QLineEdit() self.y1lim_min_box.setMinimumWidth(50) self.connect(self.y1lim_min_box, QtCore.SIGNAL('returnPressed()'), self.save_from_lim_boxes) self.y1lim_max_box = QtGui.QLineEdit() self.y1lim_max_box.setMinimumWidth(50) self.connect(self.y1lim_max_box, QtCore.SIGNAL('returnPressed()'), self.save_from_lim_boxes) self.y3lim_min_box = QtGui.QLineEdit() self.y3lim_min_box.setMinimumWidth(50) self.connect(self.y3lim_min_box, QtCore.SIGNAL('returnPressed()'), self.save_from_lim_boxes) s = 'Minimum ordinate value of the residual plot\n\n' \ 'Set with: \n' \ ' y3_plot_lims = (<ymin>, <ymax>)' self.y3lim_min_box.setToolTip( s ) self.y3lim_max_box = QtGui.QLineEdit() self.y3lim_max_box.setMinimumWidth(50) self.connect(self.y3lim_max_box, QtCore.SIGNAL('returnPressed()'), self.save_from_lim_boxes) s = 'Maximum ordinate value of the residual plot\n\n' \ 'Set with: \n' \ ' y3_plot_lims = (<ymin>, <ymax>)' self.y3lim_max_box.setToolTip( s ) self.select_init_button = QtGui.QPushButton("Init file") self.connect(self.select_init_button, QtCore.SIGNAL('clicked()'), self.select_init) self.rerun_button = QtGui.QPushButton("&Rerun") self.connect(self.rerun_button, QtCore.SIGNAL('clicked()'), self.rerun) self.draw_button = QtGui.QPushButton("&Draw") self.connect(self.draw_button, QtCore.SIGNAL('clicked()'), self.on_draw) self.savelines_button = QtGui.QPushButton("&Save") self.savelines_button.setMinimumWidth(50) self.connect(self.savelines_button, QtCore.SIGNAL('clicked()'), self.save_lines) self.Command_GroupBox = QtGui.QGroupBox("Main commands") self.Command_GroupBox.setCheckable(False) self.ObsSpec_GroupBox = QtGui.QGroupBox("Parameters related to the observed spectrum") self.ObsSpec_GroupBox.setCheckable(False) self.SpecPlot_GroupBox = QtGui.QGroupBox("Plot of the spectra") self.SpecPlot_GroupBox.setCheckable(False) self.lineIDs_GroupBox = QtGui.QGroupBox("Show lines") self.lineIDs_GroupBox.setCheckable(True) self.lineIDs_GroupBox.setChecked(False) # self.lineIDs_GroupBox.setTristate(True) # self.lineIDs_GroupBox.setCheckState(QtCore.Qt.PartiallyChecked) self.connect(self.lineIDs_GroupBox, QtCore.SIGNAL('clicked()'), self.make_axes) self.lineIDs_GroupBox.setToolTip( 'Check to display the central positions of the spectral lines' ) self.residual_GroupBox = QtGui.QGroupBox("Plot of residuals") self.residual_GroupBox.setCheckable(True) self.residual_GroupBox.setChecked(True) self.connect(self.residual_GroupBox, QtCore.SIGNAL('clicked()'), self.make_axes) self.residual_GroupBox.setToolTip( 'Check to display the residual plot' ) self.adjust_button = QtGui.QPushButton("&Update lines") self.adjust_button.setChecked(False) self.connect(self.adjust_button, QtCore.SIGNAL('clicked()'), self.adjust) self.post_proc_button = QtGui.QPushButton("Post proc") self.post_proc_button.setChecked(False) self.connect(self.post_proc_button, QtCore.SIGNAL('clicked()'), self.apply_post_proc) self.update_profile_button = QtGui.QPushButton("Update profiles") self.update_profile_button.setChecked(False) self.connect(self.update_profile_button, QtCore.SIGNAL('clicked()'), self.update_profile) self.sp_min_box = QtGui.QLineEdit() self.sp_min_box.setMinimumWidth(50) self.connect(self.sp_min_box, QtCore.SIGNAL('returnPressed()'), self.change_sp) self.sp_max_box = QtGui.QLineEdit() self.sp_max_box.setMinimumWidth(50) self.connect(self.sp_max_box, QtCore.SIGNAL('returnPressed()'), self.change_sp) self.sp_norm_box = QtGui.QLineEdit() self.sp_norm_box.setMinimumWidth(50) self.connect(self.sp_norm_box, QtCore.SIGNAL('returnPressed()'), self.sp_norm) self.obj_velo_box = QtGui.QLineEdit() self.obj_velo_box.setMinimumWidth(50) self.connect(self.obj_velo_box, QtCore.SIGNAL('returnPressed()'), self.obj_velo) self.ebv_box = QtGui.QLineEdit() self.ebv_box.setMinimumWidth(50) self.connect(self.ebv_box, QtCore.SIGNAL('returnPressed()'), self.ebv) self.resol_box = QtGui.QLineEdit() self.resol_box.setMinimumWidth(50) self.connect(self.resol_box, QtCore.SIGNAL('returnPressed()'), self.resol) self.cut2_box = QtGui.QLineEdit() self.cut2_box.setMinimumWidth(50) self.connect(self.cut2_box, QtCore.SIGNAL('returnPressed()'), self.cut2) self.line_info_box = QtGui.QLineEdit() self.line_info_box.setMinimumWidth(50) self.connect(self.line_info_box, QtCore.SIGNAL('returnPressed()'), self.line_info) self.magenta_box = QtGui.QLineEdit() self.magenta_box.setMinimumWidth(50) self.connect(self.magenta_box, QtCore.SIGNAL('returnPressed()'), self.magenta_line) self.magenta_label_box = QtGui.QLineEdit() self.magenta_label_box.setMinimumWidth(50) self.connect(self.magenta_label_box, QtCore.SIGNAL('returnPressed()'), self.magenta_line) self.cyan_box = QtGui.QLineEdit() self.cyan_box.setMinimumWidth(50) self.connect(self.cyan_box, QtCore.SIGNAL('returnPressed()'), self.cyan_line) self.cyan_label_box = QtGui.QLineEdit() self.cyan_label_box.setMinimumWidth(50) self.connect(self.cyan_label_box, QtCore.SIGNAL('returnPressed()'), self.cyan_line) self.setStyleSheet("""QToolTip { background-color: black; color: lightgray; min-width: 20em; font-size: 14px; font-family: "sans-serif"; border: black solid 10px }""") s = 'Color excess E(B-V)\n\n' \ 'Set with: \n' \ ' e_bv = <float>\n\n' \ 'Comment: \n' \ u' E(B-V) \u2248 C(H\u03B2) / 1.5' self.ebv_box.setToolTip( s ) s = 'Radial velocity in km/s\n\n' \ 'Set with: \n' \ ' obj_velo = <float>' self.obj_velo_box.setToolTip( s ) s = 'Normalization factor, ratio between the intensity and the \n' \ u'observed flux of the reference line, 10\u2074/F(H\u03B2)\n\n' \ 'Set with: \n' \ ' sp_norm = <float>' self.sp_norm_box.setToolTip( s ) s = 'Rebinning factor, the integer factor by which the number of points \n' \ 'of the original spectrum is multiplied in the rebinning process\n\n' \ 'Set with: \n' \ ' resol = <integer>\n\n' \ 'Usage: \n' \ ' Set to \'1\' if the resolution of the observed spectrum is large enough' self.resol_box.setToolTip( s ) self.verbosity_list = ['None', 'Errors', 'Errors and warnings', 'Errors, warnings, and comments', 'Debug messages' ] self.verbosity_button = QtGui.QPushButton('Verbosity') s = 'Verbosity level:\n' for i in range(len(self.verbosity_list)): s = s + ' ' + str(i) + ' - ' + self.verbosity_list[i] + '\n' s = s + '\nSet with:\n' + ' log_level = <integer>' self.verbosity_button.setToolTip( s ) self.verbosity_ag = QtGui.QActionGroup(self, exclusive=True) self.verbosity_menu = QtGui.QMenu() for i in range(len(self.verbosity_list)): a = self.verbosity_ag.addAction(QtGui.QAction(self.verbosity_list[i], self, checkable=True)) self.verbosity_menu.addAction(a) self.verbosity_button.setMenu(self.verbosity_menu) self.verbosity_ag.triggered.connect(self.verbosity) # # Layout with box sizers # hbox5 = QtGui.QHBoxLayout() for w in [self.line_info_box, self.magenta_box, self.magenta_label_box, self.cyan_box, self.cyan_label_box]: hbox5.addWidget(w) hbox5.setAlignment(w, QtCore.Qt.AlignVCenter) CommandLayout = QtGui.QGridLayout() wList = [self.select_init_button,self.rerun_button,self.draw_button,self.adjust_button,self.post_proc_button,self.verbosity_button] Nrow = 2 for w in wList: k = wList.index( w ) i = k%Nrow j = 1+2*(k/Nrow) CommandLayout.addWidget(w,i,j) CommandLayout.setAlignment(w,QtCore.Qt.AlignCenter) self.Command_GroupBox.setLayout(CommandLayout) ObsSpecLayout = QtGui.QGridLayout() lList = ['xmin', 'xmax', u'10\u2074/F(H\u03B2)', 'radial vel.', 'E(B-V)', 'N'] wList = [self.sp_min_box, self.sp_max_box, self.sp_norm_box, self.obj_velo_box, self.ebv_box, self.resol_box ] Nrow = 2 for l in lList: w = QtGui.QLabel(l) k = lList.index( l ) i = k%Nrow j = 2*(k/Nrow) ObsSpecLayout.addWidget(w,i,j) ObsSpecLayout.setAlignment(w,QtCore.Qt.AlignRight) for w in wList: k = wList.index( w ) i = k%Nrow j = 1+2*(k/Nrow) ObsSpecLayout.addWidget(w,i,j) ObsSpecLayout.setAlignment(w,QtCore.Qt.AlignRight) self.ObsSpec_GroupBox.setLayout(ObsSpecLayout) SpecPlotLayout = QtGui.QGridLayout() SpecPlotLayout.addWidget(QtGui.QLabel('xmin'),0,0) SpecPlotLayout.addWidget(QtGui.QLabel('xmax'),1,0) SpecPlotLayout.addWidget(QtGui.QLabel('ymin'),0,2) SpecPlotLayout.addWidget(QtGui.QLabel('ymax'),1,2) SpecPlotLayout.addWidget(self.xlim_min_box,0,1) SpecPlotLayout.addWidget(self.xlim_max_box,1,1) SpecPlotLayout.addWidget(self.y1lim_min_box,0,3) SpecPlotLayout.addWidget(self.y1lim_max_box,1,3) SpecPlotLayout.addWidget(self.fix_axes_cb,0,4) self.SpecPlot_GroupBox.setLayout(SpecPlotLayout) LineIDLayout = QtGui.QGridLayout() LineIDLayout.addWidget(QtGui.QLabel('cut'),0,0) LineIDLayout.addWidget(self.cut2_box,0,1) LineIDLayout.addWidget(self.savelines_button,1,1) self.lineIDs_GroupBox.setLayout(LineIDLayout) ResidualLayout = QtGui.QGridLayout() ResidualLayout.addWidget(QtGui.QLabel('ymin'),0,0) ResidualLayout.addWidget(QtGui.QLabel('ymax'),1,0) ResidualLayout.addWidget(self.y3lim_min_box,0,1) ResidualLayout.addWidget(self.y3lim_max_box,1,1) self.residual_GroupBox.setLayout(ResidualLayout) grid = QtGui.QGridLayout() grid.addWidget(self.Command_GroupBox, 0, 1 ) grid.addWidget(self.ObsSpec_GroupBox, 0, 2 ) grid.addWidget(self.SpecPlot_GroupBox, 0, 3 ) grid.addWidget(self.residual_GroupBox, 0, 4 ) grid.addWidget(self.lineIDs_GroupBox, 0, 5 ) vbox = QtGui.QVBoxLayout() vbox.addWidget(self.canvas) vbox.addWidget(self.mpl_toolbar) vbox.addLayout(grid) # QtGui.QApplication.setStyle(QtGui.QStyleFactory.create(styleName)) # self.changePalette() QtGui.qApp.setStyle('Windows') QtGui.qApp.setStyle('Cleanlooks') QtGui.qApp.setStyle('Plastique') self.main_frame.setLayout(vbox) self.setCentralWidget(self.main_frame)