def __init__(self, ispec, parent=None, dla_fit_file=None, zqso=None, outfil=None, smooth=3., dw=0.1, skip_wveval=False, norm=True): QtGui.QMainWindow.__init__(self, parent) """ ispec : Spectrum1D or specfil dla_fit_file: str, optional Name of the LLS fit file to input smooth : float, optional Number of pixels to smooth on (FWHM) dw : float, optional Pixel width in Angstroms for the wavelength array used to generate optical depths. Default is 0.1. skip_wveval : bool, optional Skip rebinning of wavelengths in the Voigt profile generation. This can speed up the code considerably, but use it wisely. norm : bool, optional Whether to normalize the spectrum by dividing by the continuum (default True). """ # Build a widget combining several others self.main_widget = QtGui.QWidget() # Status bar self.create_status_bar() # Initialize if outfil is None: self.outfil = 'DLA_fit.json' else: self.outfil = outfil self.count_dla = 0 self.dla_model = None self.smooth = None self.base_continuum = None self.all_forest = [] self.flag_write = False self.dw = float(dw) self.skip_wveval = skip_wveval self.zqso = zqso if skip_wveval: warnings.warn("Skipping wavelength rebinning in Voigt.") warnings.warn("Make sure you know what you are doing!") # Spectrum if isinstance(ispec, XSpectrum1D): spec = ispec spec_fil = spec.filename else: spec, spec_fil = ltgu.read_spec(ispec) self.spec = spec # LineList self.llist = ltgu.set_llist('Strong') self.llist['z'] = 0. self.plt_wv = zip(np.array([972.5367,1025.7222,1215.6700])*u.AA, ['Lyg','Lyb','Lya']) # z and N boxes self.zwidget = ltgsm.EditBox(-1., 'z_DLA=', '{:0.5f}') self.Nwidget = ltgsm.EditBox(-1., 'NHI=', '{:0.2f}') self.bwidget = ltgsm.EditBox(-1., 'b=', '{:0.1f}') self.Cwidget = ltgsm.EditBox('None', 'Comment=', '{:s}') # Grab the pieces and tie together self.abssys_widg = xspw.AbsSysWidget([],only_one=True, no_buttons=True, linelist=self.llist[self.llist['List']]) self.spec_widg = ltgsp.ExamineSpecWidget(spec,status=self.statusBar, llist=self.llist, key_events=False, abs_sys=self.abssys_widg.abs_sys, plotzero=1, norm=norm) # Initialize continuum (and LLS if from a file) if dla_fit_file is not None: self.init_DLA(dla_fit_file,spec) else: if zqso is not None: co, knots = laco.find_continuum(spec, redshift=self.zqso) else: co, knots = laco.find_continuum(spec, kind='default') self.conti_dict = dict(co=co, knots=knots) self.update_conti() #self.spec_widg.continuum = self.continuum # Full Model (LLS+continuum) self.full_model = XSpectrum1D.from_tuple(( spec.wavelength,np.ones(len(spec.wavelength)))) if self.smooth is None: self.smooth = smooth # Initialize as needed if dla_fit_file is not None: self.update_boxes() self.update_model() # Outfil wbtn = QtGui.QPushButton('Write', self) wbtn.setAutoDefault(False) wbtn.clicked.connect(self.write_out) #self.out_box = QtGui.QLineEdit() #self.out_box.setText(self.outfil) #self.connect(self.out_box, QtCore.SIGNAL('editingFinished ()'), self.set_outfil) # Quit buttons = QtGui.QWidget() wqbtn = QtGui.QPushButton('Write\n Quit', self) wqbtn.setAutoDefault(False) wqbtn.clicked.connect(self.write_quit) qbtn = QtGui.QPushButton('Quit', self) qbtn.setAutoDefault(False) qbtn.clicked.connect(self.quit) # Connections (buttons are above) self.spec_widg.canvas.mpl_connect('key_press_event', self.on_key) self.abssys_widg.abslist_widget.itemSelectionChanged.connect( self.on_list_change) self.connect(self.Nwidget.box, QtCore.SIGNAL('editingFinished ()'), self.setbzN) self.connect(self.zwidget.box, QtCore.SIGNAL('editingFinished ()'), self.setbzN) self.connect(self.bwidget.box, QtCore.SIGNAL('editingFinished ()'), self.setbzN) self.connect(self.Cwidget.box, QtCore.SIGNAL('editingFinished ()'), self.setbzN) # Layout anly_widg = QtGui.QWidget() anly_widg.setMaximumWidth(400) anly_widg.setMinimumWidth(250) # Write/Quit buttons hbox1 = QtGui.QHBoxLayout() hbox1.addWidget(wbtn) hbox1.addWidget(wqbtn) hbox1.addWidget(qbtn) buttons.setLayout(hbox1) # z,N zNwidg = QtGui.QWidget() hbox2 = QtGui.QHBoxLayout() hbox2.addWidget(self.zwidget) hbox2.addWidget(self.Nwidget) hbox2.addWidget(self.bwidget) zNwidg.setLayout(hbox2) #vbox.addWidget(self.pltline_widg) vbox = QtGui.QVBoxLayout() vbox.addWidget(zNwidg) vbox.addWidget(self.Cwidget) vbox.addWidget(self.abssys_widg) vbox.addWidget(buttons) anly_widg.setLayout(vbox) hbox = QtGui.QHBoxLayout() hbox.addWidget(self.spec_widg) hbox.addWidget(anly_widg) self.main_widget.setLayout(hbox) # Point MainWindow self.setCentralWidget(self.main_widget) #self.spec_widg.setFixedWidth(900) self.spec_widg.setMinimumWidth(900)
def __init__(self, ispec, parent=None, dla_fit_file=None, zqso=None, outfil=None, smooth=3., dw=0.1, skip_wveval=False, norm=True): QtGui.QMainWindow.__init__(self, parent) """ ispec : Spectrum1D or specfil dla_fit_file: str, optional Name of the LLS fit file to input smooth : float, optional Number of pixels to smooth on (FWHM) dw : float, optional Pixel width in Angstroms for the wavelength array used to generate optical depths. Default is 0.1. skip_wveval : bool, optional Skip rebinning of wavelengths in the Voigt profile generation. This can speed up the code considerably, but use it wisely. norm : bool, optional Whether to normalize the spectrum by dividing by the continuum (default True). """ # Build a widget combining several others self.main_widget = QtGui.QWidget() # Status bar self.create_status_bar() # Initialize if outfil is None: self.outfil = 'DLA_fit.json' else: self.outfil = outfil self.count_dla = 0 self.dla_model = None self.smooth = None self.base_continuum = None self.all_forest = [] self.flag_write = False self.dw = float(dw) self.skip_wveval = skip_wveval self.zqso = zqso if skip_wveval: warnings.warn("Skipping wavelength rebinning in Voigt.") warnings.warn("Make sure you know what you are doing!") # Spectrum if isinstance(ispec, XSpectrum1D): spec = ispec spec_fil = spec.filename else: spec, spec_fil = ltgu.read_spec(ispec) self.spec = spec # LineList self.llist = ltgu.set_llist('Strong') self.llist['z'] = 0. self.plt_wv = zip( np.array([972.5367, 1025.7222, 1215.6700]) * u.AA, ['Lyg', 'Lyb', 'Lya']) # z and N boxes self.zwidget = ltgsm.EditBox(-1., 'z_DLA=', '{:0.5f}') self.Nwidget = ltgsm.EditBox(-1., 'NHI=', '{:0.2f}') self.bwidget = ltgsm.EditBox(-1., 'b=', '{:0.1f}') self.Cwidget = ltgsm.EditBox('None', 'Comment=', '{:s}') # Grab the pieces and tie together self.abssys_widg = xspw.AbsSysWidget( [], only_one=True, no_buttons=True, linelist=self.llist[self.llist['List']]) self.spec_widg = ltgsp.ExamineSpecWidget( spec, status=self.statusBar, llist=self.llist, key_events=False, abs_sys=self.abssys_widg.abs_sys, plotzero=1, norm=norm) # Initialize continuum (and LLS if from a file) if dla_fit_file is not None: self.init_DLA(dla_fit_file, spec) else: if zqso is not None: co, knots = laco.find_continuum(spec, redshift=self.zqso) else: co, knots = laco.find_continuum(spec, kind='default') self.conti_dict = dict(co=co, knots=knots) self.update_conti() #self.spec_widg.continuum = self.continuum # Full Model (LLS+continuum) self.full_model = XSpectrum1D.from_tuple( (spec.wavelength, np.ones(len(spec.wavelength)))) if self.smooth is None: self.smooth = smooth # Initialize as needed if dla_fit_file is not None: self.update_boxes() self.update_model() # Outfil wbtn = QtGui.QPushButton('Write', self) wbtn.setAutoDefault(False) wbtn.clicked.connect(self.write_out) #self.out_box = QtGui.QLineEdit() #self.out_box.setText(self.outfil) #self.connect(self.out_box, QtCore.SIGNAL('editingFinished ()'), self.set_outfil) # Quit buttons = QtGui.QWidget() wqbtn = QtGui.QPushButton('Write\n Quit', self) wqbtn.setAutoDefault(False) wqbtn.clicked.connect(self.write_quit) qbtn = QtGui.QPushButton('Quit', self) qbtn.setAutoDefault(False) qbtn.clicked.connect(self.quit) # Connections (buttons are above) self.spec_widg.canvas.mpl_connect('key_press_event', self.on_key) self.abssys_widg.abslist_widget.itemSelectionChanged.connect( self.on_list_change) self.connect(self.Nwidget.box, QtCore.SIGNAL('editingFinished ()'), self.setbzN) self.connect(self.zwidget.box, QtCore.SIGNAL('editingFinished ()'), self.setbzN) self.connect(self.bwidget.box, QtCore.SIGNAL('editingFinished ()'), self.setbzN) self.connect(self.Cwidget.box, QtCore.SIGNAL('editingFinished ()'), self.setbzN) # Layout anly_widg = QtGui.QWidget() anly_widg.setMaximumWidth(400) anly_widg.setMinimumWidth(250) # Write/Quit buttons hbox1 = QtGui.QHBoxLayout() hbox1.addWidget(wbtn) hbox1.addWidget(wqbtn) hbox1.addWidget(qbtn) buttons.setLayout(hbox1) # z,N zNwidg = QtGui.QWidget() hbox2 = QtGui.QHBoxLayout() hbox2.addWidget(self.zwidget) hbox2.addWidget(self.Nwidget) hbox2.addWidget(self.bwidget) zNwidg.setLayout(hbox2) #vbox.addWidget(self.pltline_widg) vbox = QtGui.QVBoxLayout() vbox.addWidget(zNwidg) vbox.addWidget(self.Cwidget) vbox.addWidget(self.abssys_widg) vbox.addWidget(buttons) anly_widg.setLayout(vbox) hbox = QtGui.QHBoxLayout() hbox.addWidget(self.spec_widg) hbox.addWidget(anly_widg) self.main_widget.setLayout(hbox) # Point MainWindow self.setCentralWidget(self.main_widget) #self.spec_widg.setFixedWidth(900) self.spec_widg.setMinimumWidth(900)
def __init__(self, ispec, parent=None, dla_fit_file=None, zqso=None, outfil=None, smooth=None, dw=0.1, zdla=None, NHI=None, skip_wveval=False, norm=True, conti_file=None): QMainWindow.__init__(self, parent) """ ispec : Spectrum1D or specfil dla_fit_file: str, optional Name of the LLS fit file to input smooth : float, optional Number of pixels to smooth on (FWHM). Will not smooth if 0. dw : float, optional Pixel width in Angstroms for the wavelength array used to generate optical depths. Default is 0.1. skip_wveval : bool, optional Skip rebinning of wavelengths in the Voigt profile generation. This can speed up the code considerably, but use it wisely. norm : bool, optional Whether to normalize the spectrum by dividing by the continuum (default True). conti_file : str, optional ASCII file containing the continuum knots (wave, flux) zdla : float, optional Create a DLA at the input redshift """ self.help_message = """ Begin by left-clicking in the plot window! Then any of the following keystroke commands will work: i,o : zoom in/out x limits I,O : zoom in/out x limits (larger re-scale) Y : zoom out y limits y : guess y limits W : Show original zooom t,b : set y top/bottom limit l,r : set left/right x limit a,m,d : Add/modify/delete continuum knot A : Add a new DLA g : Move nearest Lyman line to cursor and reset z N/n : Increase/decrease NHI V/v : Increase/decrease bvalue Z/z : Increase/decrease zabs U/u : Increase/decrease sig_NHI [Default is 0.1 dex] D : Delete DLA $ : Toggle displaying metal lines 6,7,8,9 : Add forest lines ? : Print these help notes P : Save current screen in dla_plot.pdf Q : Quit the GUI """ # Build a widget combining several others self.main_widget = QWidget() # Status bar self.create_status_bar() # Initialize self.update = True self.sig_NHI = 0.1 if outfil is None: self.outfil = 'DLA_fit.json' else: self.outfil = outfil self.count_dla = 0 self.dla_model = None if smooth is None: self.smooth = 3. # Pixels to smooth model by else: self.smooth = smooth self.base_continuum = None self.all_forest = [] self.flag_write = False self.dw = float(dw) self.skip_wveval = skip_wveval self.zqso = zqso if skip_wveval: warnings.warn("Skipping wavelength rebinning in Voigt.") warnings.warn("Make sure you know what you are doing!") # Spectrum if isinstance(ispec, XSpectrum1D): spec = ispec spec_fil = spec.filename else: kwargs = {} kwargs['rsp_kwargs'] = {} kwargs['rsp_kwargs']['masking'] = 'edges' spec, spec_fil = ltgu.read_spec(ispec, norm=norm, **kwargs) self.spec = spec # LineList self.llist = ltgu.set_llist('Strong') self.llist['z'] = 0. self.plt_wv = zip(np.array([972.5367,1025.7222,1215.6700])*u.AA, ['Lyg','Lyb','Lya']) # z and N boxes self.zwidget = ltgsm.EditBox(-1., 'z_DLA=', '{:0.5f}') self.Nwidget = ltgsm.EditBox(-1., 'NHI=', '{:0.2f}') self.bwidget = ltgsm.EditBox(-1., 'b=', '{:0.1f}') self.Cwidget = ltgsm.EditBox('None', 'Comment=', '{:s}') # Grab the pieces and tie together self.abssys_widg = ltgsp.AbsSysWidget([],only_one=True, no_buttons=True, linelist=self.llist[self.llist['List']]) self.spec_widg = ltgsp.ExamineSpecWidget(spec,status=self.statusBar, llist=self.llist, key_events=False, abs_sys=self.abssys_widg.abs_sys, plotzero=1, norm=norm) # Create a DLA? if zdla is not None: self.add_DLA(zdla, NHI=NHI, model=False) # Initialize continuum (and DLA if from a file) if dla_fit_file is not None: self.init_DLA(dla_fit_file,spec) else: if conti_file is not None: # Read continuum cspec = lsi.readspec(conti_file) if not cspec.sig_is_set: cspec.sig = 0.1*np.median(cspec.flux) else: cspec = spec if zqso is not None: co, knots = laco.find_continuum(cspec, redshift=self.zqso) else: co, knots = laco.find_continuum(cspec, kind='default') self.conti_dict = dict(co=co, knots=knots) self.update_conti() #self.spec_widg.continuum = self.continuum # Full Model (LLS+continuum) self.full_model = XSpectrum1D.from_tuple(( spec.wavelength,np.ones(len(spec.wavelength)))) # Initialize as needed if (dla_fit_file is not None) or (zdla is not None): self.update_boxes() self.update_model() # Outfil wbtn = QPushButton(self) wbtn.setText('Write') wbtn.setAutoDefault(False) wbtn.clicked.connect(self.write_out) #self.out_box = QtGui.QLineEdit() #self.out_box.setText(self.outfil) #self.connect(self.out_box, QtCore.SIGNAL('editingFinished ()'), self.set_outfil) # Quit buttons = QWidget() wqbtn = QPushButton(self) wqbtn.setText('Write\n Quit') wqbtn.setAutoDefault(False) wqbtn.clicked.connect(self.write_quit) qbtn = QPushButton(self) qbtn.setText('Quit') qbtn.setAutoDefault(False) qbtn.clicked.connect(self.quit) # Connections (buttons are above) self.spec_widg.canvas.mpl_connect('key_press_event', self.on_key) self.abssys_widg.abslist_widget.itemSelectionChanged.connect( self.on_list_change) self.Nwidget.box.textChanged[str].connect(self.setbzN) self.zwidget.box.textChanged[str].connect(self.setbzN) self.bwidget.box.textChanged[str].connect(self.setbzN) self.Cwidget.box.textChanged[str].connect(self.setbzN) # Layout anly_widg = QWidget() anly_widg.setMaximumWidth(400) anly_widg.setMinimumWidth(250) # Write/Quit buttons hbox1 = QHBoxLayout() hbox1.addWidget(wbtn) hbox1.addWidget(wqbtn) hbox1.addWidget(qbtn) buttons.setLayout(hbox1) # z,N zNwidg = QWidget() hbox2 = QHBoxLayout() hbox2.addWidget(self.zwidget) hbox2.addWidget(self.Nwidget) hbox2.addWidget(self.bwidget) zNwidg.setLayout(hbox2) #vbox.addWidget(self.pltline_widg) vbox = QVBoxLayout() vbox.addWidget(zNwidg) vbox.addWidget(self.Cwidget) vbox.addWidget(self.abssys_widg) vbox.addWidget(buttons) anly_widg.setLayout(vbox) hbox = QHBoxLayout() hbox.addWidget(self.spec_widg) hbox.addWidget(anly_widg) self.main_widget.setLayout(hbox) # Point MainWindow self.setCentralWidget(self.main_widget) #self.spec_widg.setFixedWidth(900) self.spec_widg.setMinimumWidth(900) # Print help message print(self.help_message)