def __init__(self, ispec, zqso, parent=None, lls_fit_file=None, outfil=None, smooth=3., fN_gamma=None, template=None, dw=0.1, skip_wveval=False, coord=None, **kwargs): QMainWindow.__init__(self, parent) ''' ispec : Spectrum1D or specfil lls_fit_file: str, optional Name of the LLS fit file to input smooth : float, optional Number of pixels to smooth on (FWHM) zqso : float, optional Redshift of the quasar. If input, a Telfer continuum is used fN_gamma : float, optional Redshift evolution of f(N) or IGM fiddled continuum template : str, optional Filename of a QSO template to use instead of the Telfer continuum. Only used if zqso is also given. 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. ''' # Build a widget combining several others self.main_widget = QWidget() # Status bar self.create_status_bar() # Initialize self.update = True if outfil is None: self.outfil = 'LLS_fit.json' else: self.outfil = outfil self.zqso = zqso self.count_lls = 0 self.model_spec = -1 self.lls_model = None self.template = template self.coord = coord self.smooth = None self.base_continuum = None self.all_forest = [] self.flag_write = False self.dw = float(dw) self.skip_wveval = skip_wveval 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: # this is broken spec, spec_fil = ltgu.read_spec(ispec, **kwargs) # LineList self.llist = ltgu.set_llist('Strong') self.llist['z'] = 0. self.plt_wv = zip( np.array([911.7, 949.743, 972.5367, 1025.7222, 1215.6700]) * u.AA, ['LL', 'Lyd', 'Lyg', 'Lyb', 'Lya']) # z and N boxes self.zwidget = ltgsm.EditBox(-1., 'z_LLS=', '{: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']]) vlines = [912 * (1 + zqso)] self.spec_widg = ltgsp.ExamineSpecWidget( spec, status=self.statusBar, llist=self.llist, key_events=False, abs_sys=self.abssys_widg.abs_sys, vlines=vlines, plotzero=1, norm=False) #QtCore.pyqtRemoveInputHook() #pdb.set_trace() #QtCore.pyqtRestoreInputHook() #self.spec_widg.canvas.mpl_connect('button_press_event', self.on_click) # Multi spec self.mspec_widg = ltgsp.MultiSpecWidget(self.spec_widg) # Initialize continuum (and LLS if from a file) if lls_fit_file is not None: self.init_LLS(lls_fit_file, spec) #QtCore.pyqtRemoveInputHook() #pdb.set_trace() #QtCore.pyqtRestoreInputHook() self.update_conti() self.spec_widg.continuum = self.continuum if self.model_spec < 0: print( "NOTE: You must specify the spectrum for fitting the LLS with # before modeling will begin" ) if self.smooth is None: self.smooth = smooth self.llist['Plot'] = False # Initialize as needed if lls_fit_file is not None: if len(self.abssys_widg.all_abssys) > 0: self.update_boxes() self.update_model() # Outfil wbtn = 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 = QWidget() wqbtn = QPushButton('Write\n Quit', self) wqbtn.setAutoDefault(False) wqbtn.clicked.connect(self.write_quit) qbtn = 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.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) vbox.addWidget(self.mspec_widg) 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)
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)
def __init__(self, ispec, parent=None, lls_fit_file=None, outfil=None, smooth=3., zqso=None, fN_gamma=None, template=None, dw=0.1, skip_wveval=False, norm=True): QtGui.QMainWindow.__init__(self, parent) ''' ispec : Spectrum1D or specfil lls_fit_file: str, optional Name of the LLS fit file to input smooth : float, optional Number of pixels to smooth on (FWHM) zqso : float, optional Redshift of the quasar. If input, a Telfer continuum is used fN_gamma : float, optional Redshift evolution of f(N) or IGM fiddled continuum template : str, optional Filename of a QSO template to use instead of the Telfer continuum. Only used if zqso is also given. 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 = 'LLS_fit.json' else: self.outfil = outfil self.count_lls = 0 self.lls_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 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: # this is broken spec, spec_fil = ltgu.read_spec(ispec) # LineList self.llist = ltgu.set_llist('Strong') self.llist['z'] = 0. self.plt_wv = zip( np.array([911.7, 949.743, 972.5367, 1025.7222, 1215.6700]) * u.AA, ['LL', 'Lyd', 'Lyg', 'Lyb', 'Lya']) # z and N boxes self.zwidget = ltgsm.EditBox(-1., 'z_LLS=', '{: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']]) vlines = [(912 * (1 + zqso) if zqso is not None else None)] self.spec_widg = ltgsp.ExamineSpecWidget( spec, status=self.statusBar, llist=self.llist, key_events=False, abs_sys=self.abssys_widg.abs_sys, vlines=vlines, plotzero=1, norm=norm) # Initialize continuum (and LLS if from a file) if lls_fit_file is not None: self.init_LLS(lls_fit_file, spec) else: self.conti_dict = pycc.init_conti_dict( Norm=float(np.median(spec.flux.value)), piv_wv=1215. * (1 + zqso), #piv_wv2=915.*(1+zqso), igm='True') if self.base_continuum is None: if zqso is not None: self.zqso = zqso # Read Telfer and apply IGM if template is not None: tspec = lsi.readspec(template) # assume wavelengths tspec = XSpectrum1D.from_tuple( (tspec.wavelength.value * (1 + zqso), tspec.flux.value)) else: tspec = pycq.get_telfer_spec( zqso=zqso, igm=(self.conti_dict['igm'] == 'True')) # Rebin self.continuum = tspec.rebin(spec.wavelength) # Reset pivot wave self.conti_dict['piv_wv'] = 915. * (1 + zqso) #self.conti_dict['piv_wv'] = 1215.*(1+zqso) #self.conti_dict['piv_wv2'] = 915.*(1+zqso) else: self.zqso = None self.continuum = XSpectrum1D.from_tuple( (spec.wavelength, np.ones(len(spec.wavelength)))) self.base_continuum = self.continuum.flux 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 lls_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, redrock_file, parent=None, zdict=None, coadd_dict=None, outfile='tmp.json', unit_test=False, screen_scale=1., **kwargs): QMainWindow.__init__(self, parent) """ redrock_file = str Input RedRock output FITS file from our redrock script parent : Widget parent, optional zsys : float, optional intial redshift either from a previous vet_rr json or the original rr guesses screen_scale : float, optional Scale the default sizes for the gui size """ # Load up self.outfile = outfile self.rr_hdul = fits.open(redrock_file) if coadd_dict is not None: self.slit_info = {} for key in coadd_dict.keys(): if isinstance(coadd_dict[key], dict): if '2D_xval' in coadd_dict[key].keys(): name = coadd_dict[key]['outfile'].replace('.fits', '') self.slit_info[name] = {} self.slit_info[name]['xval'] = coadd_dict[key][ '2D_xval'] self.slit_info[name]['Gslit'] = coadd_dict[key][ 'Gemini_slit'] else: self.slit_info = None # names, spectra, zs = [], [], [] names, spectra = [], [] if zdict is None: self.zdict = OrderedDict() load_z = True else: self.zdict = OrderedDict() load_z = False for hdu in self.rr_hdul[1:]: # Grab the spectrum spec_file = hdu.name # tmp = XSpectrum1D.from_file(spec_file.replace('FITS','fits')) spectra.append( XSpectrum1D.from_file(spec_file.replace('FITS', 'fits'), masking='edges')) names.append(spec_file.replace('.FITS', '')) # RedRock data = hdu.data # Init the dict if load_z: self.zdict[names[-1]] = {} self.zdict[names[-1]]['zRR'] = data['z'] self.zdict[names[-1]]['ZQ'] = -99 self.zdict[names[-1]]['Comment'] = '' self.zdict[names[-1]]['z'] = data['z'][0] else: self.zdict[names[-1]] = zdict[names[-1]] # Collate ispec = lspu.collate(spectra, masking='edges') # Fill ispec.labels = names ispec.stypes = ['galaxy'] * ispec.nspec # ispec.z = zs # DO NOT SET THE REDSHIFT HERE self.RRi = 0 self.scale = screen_scale # Needed to avoid crash in large spectral files rcParams['agg.path.chunksize'] = 20000 # avoid scientific notation in axes tick labels rcParams['axes.formatter.useoffset'] = False # Build a widget combining several others self.main_widget = QWidget() # Status bar self.create_status_bar() # ZQ window self.ZQ_widg = ltgsm.EditBox(-99, 'ZQ', '{:d}') self.ZQ_values = [-99, -1, 0, 1, 3, 4] # Comment window self.comment_widg = ltgsm.EditBox('', 'Comment', '{:s}') # Grab the pieces and tie together self.pltline_widg = ltgl.PlotLinesWidget(status=self.statusBar, screen_scale=self.scale) self.pltline_widg.setMaximumWidth(300 * self.scale) # Hook the spec widget to Plot Line self.spec_widg = ltgsp.ExamineSpecWidget(ispec, status=self.statusBar, parent=self, llist=self.pltline_widg.llist, screen_scale=self.scale, **kwargs) # Reset redshift from spec # Auto set line list if spec has proper object type if hasattr(self.spec_widg.spec, 'stypes'): if self.spec_widg.spec.stypes[ self.spec_widg.select].lower() == 'galaxy': self.pltline_widg.llist = ltgu.set_llist( 'Galaxy', in_dict=self.pltline_widg.llist) elif self.spec_widg.spec.stypes[ self.spec_widg.select].lower() == 'absorber': self.pltline_widg.llist = ltgu.set_llist( 'Strong', in_dict=self.pltline_widg.llist) self.pltline_widg.llist['Plot'] = True idx = self.pltline_widg.lists.index( self.pltline_widg.llist['List']) self.pltline_widg.llist_widget.setCurrentRow(idx) # self.pltline_widg.spec_widg = self.spec_widg # Multi spec self.mspec_widg = ltgsp.MultiSpecWidget(self.spec_widg, extra_method=self) self.spec_widg.canvas.mpl_connect('key_press_event', self.on_key) self.spec_widg.canvas.mpl_connect('button_press_event', self.on_click) self.prev_select = 0 # Index of previous spectrum; starts at 0 # Legend -- specific to this GUI self.legend = {} self.wv_dict = {'*': 3727., '(': 3950., ')': 4940., '_': 6564.} self.legend['zoom'] = self.wv_dict self.legend['&'] = 'Toggle through ZQ' self.legend[ '#'] = 'Toggle through zRR (WARNING: will not necessary start at the first one)' self.legend['%'] = 'Set z=0 (for stars)' self.legend['9'] = 'Skip to next spectrum with ZQ=-99' self.legend['x'] = 'Next spectrum' for key, value in self.legend.items(): print(key, value) # Extras extras = QWidget() extras.setMinimumWidth(180 * self.scale) extras.setMaximumWidth(280 * self.scale) vbox = QVBoxLayout() qbtn = QPushButton(self) qbtn.setText('Quit') qbtn.clicked.connect(self.quit) vbox.addWidget(self.pltline_widg) vbox.addWidget(self.ZQ_widg) vbox.addWidget(self.comment_widg) vbox.addWidget(self.mspec_widg) vbox.addWidget(qbtn) extras.setLayout(vbox) # Main window hbox = QHBoxLayout() hbox.addWidget(self.spec_widg) hbox.addWidget(extras) self.main_widget.setLayout(hbox) # Point MainWindow self.setCentralWidget(self.main_widget) if unit_test: self.quit() # Giddy up self.run_with_select(save=False)