def test_llist(): # Init idict = ltgu.set_llist('Strong') idict = ltgu.set_llist([1215.670 * u.AA]) assert idict['List'] == 'input.lst' idict = ltgu.set_llist('None') idict = ltgu.set_llist('OVI') # wrong format with pytest.raises(IOError): idict = ltgu.set_llist((1, 2)) # input is a tuple, so it is wrong.
def test_llist(): # Init idict = ltgu.set_llist('Strong') idict = ltgu.set_llist([1215.670]*u.AA) assert idict['List'] == 'input.lst' idict = ltgu.set_llist('None') idict = ltgu.set_llist('OVI') # wrong format with pytest.raises(IOError): idict = ltgu.set_llist((1,2)) # input is a tuple, so it is wrong.
def on_list_change(self,curr,prev): llist = str(curr.text()) # Print try: self.statusBar().showMessage('You chose: {:s}'.format(llist)) except AttributeError: print('You chose: {:s}'.format(curr.text())) #QtCore.pyqtRemoveInputHook() #xdb.set_trace() #QtCore.pyqtRestoreInputHook() self.llist = ltgu.set_llist(llist,in_dict=self.llist) # Try to draw if self.llist['Plot'] is True: try: self.spec_widg.on_draw() except AttributeError: return
def __init__(self, ispec, z=None, parent=None, llist=None, norm=True, vmnx=[-300., 300.]*u.km/u.s, abs_sys=None): ''' spec = Spectrum1D Norm: Bool (False) Normalized spectrum? abs_sys: AbsSystem Absorption system class ''' super(VelPlotWidget, self).__init__(parent) # Initialize spec, spec_fil = ltgu.read_spec(ispec) self.spec = spec self.spec_fil = spec_fil self.z = z self.vmnx = vmnx self.norm = norm # Abs_System self.abs_sys = abs_sys if self.abs_sys is None: self.abs_sys = GenericAbsSystem((0.*u.deg,0.*u.deg), self.z, self.vmnx) self.abs_lines = [] else: self.z = self.abs_sys.zabs # Line list if llist is None: self.abs_lines = self.abs_sys.list_of_abslines() if len(self.abs_lines)>0: lwrest = [iline.wrest for iline in self.abs_lines] else: lwrest = None if lwrest is not None: llist = ltgu.set_llist(lwrest) # Not sure this is working.. #QtCore.pyqtRemoveInputHook() #xdb.set_trace() #QtCore.pyqtRestoreInputHook() self.psdict = {} # Dict for spectra plotting self.psdict['xmnx'] = self.vmnx.value # Too much pain to use units with this self.psdict['ymnx'] = [-0.1, 1.1] self.psdict['nav'] = ltgu.navigate(0,0,init=True) # Status Bar? #if not status is None: # self.statusBar = status # Line List if llist is None: self.llist = ltgu.set_llist('Strong') else: self.llist = llist self.llist['z'] = self.z # Indexing for line plotting self.idx_line = 0 self.init_lines() # Create the mpl Figure and FigCanvas objects. # self.dpi = 150 self.fig = Figure((8.0, 4.0), dpi=self.dpi) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self) self.canvas.setFocusPolicy( QtCore.Qt.ClickFocus ) self.canvas.setFocus() self.canvas.mpl_connect('key_press_event', self.on_key) self.canvas.mpl_connect('button_press_event', self.on_click) # Sub_plots self.sub_xy = [3,4] self.fig.subplots_adjust(hspace=0.0, wspace=0.1) vbox = QtGui.QVBoxLayout() vbox.addWidget(self.canvas) self.setLayout(vbox) # Draw on init self.on_draw()
spec = lsi.readspec(spec_fil) # Abs_sys abs_fil = '/Users/xavier/paper/LLS/Optical/Data/Analysis/MAGE/UM184_z2.930_id.fits' abs_sys = xiaa.GenericAbsSystem() abs_sys.parse_absid_file(abs_fil) # Launch app = QtGui.QApplication(sys.argv) app.setApplicationName('VelPlot') main = VelPlotWidget(spec, abs_sys=abs_sys) main.show() sys.exit(app.exec_()) # SelectedLines Widget if (flg_tst % 2**6) >= 2**5: print('Test: SelectedLines Widget') llist = ltgu.set_llist('ISM') # Launch app = QtGui.QApplication(sys.argv) app.setApplicationName('SelectedLines') main = SelectedLinesWidget(llist['ISM'])#._data) main.show() sys.exit(app.exec_()) # AODM Widget if (flg_tst % 2**7) >= 2**6: spec_fil = '/Users/xavier/PROGETTI/LLSZ3/data/normalize/UM184_nF.fits' spec = lsi.readspec(spec_fil) z=2.96916 lines = np.array([1548.195, 1550.770]) * u.AA # Launch app = QtGui.QApplication(sys.argv)
def __init__(self, ispec, guessfile=None, parent=None, zsys=None, norm=None, exten=None, rsp_kwargs={}, unit_test=False, screen_scale=1., **kwargs): QMainWindow.__init__(self, parent) """ ispec = str, XSpectrum1D or tuple of arrays Input spectrum or spectrum filename. If tuple then (wave, fx), (wave, fx, sig) or (wave, fx, sig, co) guessfile : str, optional name of the .json file generated with igmguesses GUI in Pyigm (see https://github.com/pyigm/pyigm/blob/master/docs/igmguesses.rst) if not None - overplot fitted line profiles from igmguesses parent : Widget parent, optional zsys : float, optional intial redshift exten : int, optional extension for the spectrum in multi-extension FITS file norm : bool, optional True if the spectrum is normalized screen_scale : float, optional Scale the default sizes for the gui size """ #reload(ltgl) #reload(ltgsp) # INIT #QtCore.pyqtRemoveInputHook() #xdb.set_trace() #QtCore.pyqtRestoreInputHook() self.scale = screen_scale # Needed to avoid crash in large spectral files rcParams['agg.path.chunksize'] = 20000 rcParams[ 'axes.formatter.useoffset'] = False # avoid scientific notation in axes tick labels # Build a widget combining several others self.main_widget = QWidget() # Status bar self.create_status_bar() # Grab the pieces and tie together self.pltline_widg = ltgl.PlotLinesWidget(status=self.statusBar, init_z=zsys, screen_scale=self.scale) self.pltline_widg.setMaximumWidth(300 * self.scale) ## Abs sys abs_sys = None voigtsfit = None if guessfile is not None: # Load ism = LineList('ISM') igm_guess = ltu.loadjson(guessfile) comps = [] for key in igm_guess['cmps'].keys(): comp = AbsComponent.from_dict(igm_guess['cmps'][key], chk_vel=False, linelist=ism) comps.append(comp) abs_sys = ltiu.build_systems_from_components( comps, vsys=500. * u.km / u.s) # ,chk_z=False) ### 100000.*u.km/u.s ok ### voigt fit - added # Spectrum spec, spec_fil = ltgu.read_spec(ispec, exten=exten, norm=norm, rsp_kwargs=rsp_kwargs) voigtsfit = np.asarray([0] * len(spec.wavelength)) alllines = [] for iabs_sys in abs_sys: lines = iabs_sys.list_of_abslines() alllines = alllines + lines if len(alllines) > 0: voigtsfit = lav.voigt_from_abslines(spec.wavelength, alllines, fwhm=3.).flux.value if not norm: voigtsfit = voigtsfit * spec.co # Hook the spec widget to Plot Line self.spec_widg = ltgsp.ExamineSpecWidget(ispec, guessfile=guessfile, voigtsfit=voigtsfit, status=self.statusBar, parent=self, llist=self.pltline_widg.llist, zsys=zsys, norm=norm, exten=exten, abs_sys=abs_sys, screen_scale=self.scale, rsp_kwargs=rsp_kwargs, **kwargs) # Reset redshift from spec if zsys is None: if hasattr(self.spec_widg.spec, 'z'): self.pltline_widg.setz( str(self.spec_widg.spec.z[self.spec_widg.select])) # 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) self.spec_widg.canvas.mpl_connect('button_press_event', self.on_click) # Layout # 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.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()
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, z=None, parent=None, llist=None, norm=True, vmnx=[-300., 300.] * u.km / u.s, abs_sys=None): ''' spec = Spectrum1D Norm: Bool (False) Normalized spectrum? abs_sys: AbsSystem Absorption system class ''' super(VelPlotWidget, self).__init__(parent) # Initialize spec, spec_fil = ltgu.read_spec(ispec) self.spec = spec self.spec_fil = spec_fil self.z = z self.vmnx = vmnx self.norm = norm # Abs_System self.abs_sys = abs_sys if self.abs_sys is None: self.abs_sys = GenericAbsSystem((0. * u.deg, 0. * u.deg), self.z, self.vmnx) self.abs_lines = [] else: self.z = self.abs_sys.zabs # Line list if llist is None: self.abs_lines = self.abs_sys.list_of_abslines() if len(self.abs_lines) > 0: lwrest = [iline.wrest for iline in self.abs_lines] else: lwrest = None if lwrest is not None: llist = ltgu.set_llist( lwrest) # Not sure this is working.. #QtCore.pyqtRemoveInputHook() #xdb.set_trace() #QtCore.pyqtRestoreInputHook() self.psdict = {} # Dict for spectra plotting self.psdict[ 'xmnx'] = self.vmnx.value # Too much pain to use units with this self.psdict['ymnx'] = [-0.1, 1.1] self.psdict['nav'] = ltgu.navigate(0, 0, init=True) # Status Bar? #if not status is None: # self.statusBar = status # Line List if llist is None: self.llist = ltgu.set_llist('Strong') else: self.llist = llist self.llist['z'] = self.z # Indexing for line plotting self.idx_line = 0 self.init_lines() # Create the mpl Figure and FigCanvas objects. # self.dpi = 150 self.fig = Figure((8.0, 4.0), dpi=self.dpi) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self) self.canvas.setFocusPolicy(QtCore.Qt.ClickFocus) self.canvas.setFocus() self.canvas.mpl_connect('key_press_event', self.on_key) self.canvas.mpl_connect('button_press_event', self.on_click) # Sub_plots self.sub_xy = [3, 4] self.fig.subplots_adjust(hspace=0.0, wspace=0.1) vbox = QtGui.QVBoxLayout() vbox.addWidget(self.canvas) self.setLayout(vbox) # Draw on init self.on_draw()
def __init__(self, ispec, parent=None, zsys=None, norm=None, exten=None, rsp_kwargs={}, unit_test=False, screen_scale=1., **kwargs): QMainWindow.__init__(self, parent) """ ispec = str, XSpectrum1D or tuple of arrays Input spectrum or spectrum filename. If tuple then (wave, fx), (wave, fx, sig) or (wave, fx, sig, co) parent : Widget parent, optional zsys : float, optional intial redshift exten : int, optional extension for the spectrum in multi-extension FITS file norm : bool, optional True if the spectrum is normalized screen_scale : float, optional Scale the default sizes for the gui size """ #reload(ltgl) #reload(ltgsp) # INIT #QtCore.pyqtRemoveInputHook() #xdb.set_trace() #QtCore.pyqtRestoreInputHook() self.scale = screen_scale # Needed to avoid crash in large spectral files rcParams['agg.path.chunksize'] = 20000 rcParams[ 'axes.formatter.useoffset'] = False # avoid scientific notation in axes tick labels # Build a widget combining several others self.main_widget = QWidget() # Status bar self.create_status_bar() # Grab the pieces and tie together self.pltline_widg = ltgl.PlotLinesWidget(status=self.statusBar, init_z=zsys, 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, zsys=zsys, norm=norm, exten=exten, screen_scale=self.scale, rsp_kwargs=rsp_kwargs, **kwargs) # Reset redshift from spec if zsys is None: if hasattr(self.spec_widg.spec, 'z'): self.pltline_widg.setz( str(self.spec_widg.spec.z[self.spec_widg.select])) # 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) 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) self.spec_widg.canvas.mpl_connect('button_press_event', self.on_click) # Layout # 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.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()
def __init__(self, ispec, z, abs_lines=None, parent=None, llist=None, norm=True, vmnx=[-300., 300.]*u.km/u.s): ''' spec : XSpectrum1D z : float abs_lines: list, optional List of AbsLines llist : LineList, optional Input line list. Defaults to 'Strong' norm : bool, optional Normalized spectrum? vmnx : Quantity array, optional Starting velocity range for the widget ''' super(VelPlotWidget, self).__init__(parent) self.help_message = """ Click on any white region within the velocity plots for the following keystroke commands to work: i,o : zoom in/out x limits I,O : zoom in/out x limits (larger re-scale) y : zoom out y limits t,b : set y top/bottom limit l,r : set left/right x limit [,] : pan left/right C,c : add/remove column K,k : add/remove row =,- : move to next/previous page 1,2 : Modify velocity region of the single line (left, right sides) !,@ : Modify velocity region of all lines (left, right) A,x : Add/remove select line from analysis list X : Remove all lines from analysis list ^,& : Flag line to be analyzed for low/high-ion kinematics B : Toggle as blend/no-blend (orange color = blend) N : Toggle as do/do-not include for analysis (red color = exclude) V : Indicate as a normal value L : Indicate as a lower limit U : Indicate as a upper limit ? : Print this """ # Initialize spec, spec_fil = ltgu.read_spec(ispec) self.spec = spec self.spec_fil = spec_fil self.z = z self.vmnx = vmnx self.norm = norm # Abs Lines if abs_lines is None: self.abs_lines = [] else: self.abs_lines = abs_lines #QtCore.pyqtRemoveInputHook() #xdb.set_trace() #QtCore.pyqtRestoreInputHook() self.psdict = {} # Dict for spectra plotting self.psdict['x_minmax'] = self.vmnx.value # Too much pain to use units with this self.psdict['y_minmax'] = [-0.1, 1.1] self.psdict['nav'] = ltgu.navigate(0,0,init=True) # Line List if llist is None: self.llist = ltgu.set_llist('Strong') else: self.llist = llist self.llist['z'] = self.z # Indexing for line plotting self.idx_line = 0 self.init_lines() # Create the mpl Figure and FigCanvas objects. self.dpi = 150 self.fig = Figure((8.0, 4.0), dpi=self.dpi) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self) self.canvas.setFocusPolicy( QtCore.Qt.ClickFocus ) self.canvas.setFocus() self.canvas.mpl_connect('key_press_event', self.on_key) self.canvas.mpl_connect('button_press_event', self.on_click) # Sub_plots (Initial) self.sub_xy = [3,4] self.fig.subplots_adjust(hspace=0.0, wspace=0.1) # Layout vbox = QtGui.QVBoxLayout() vbox.addWidget(self.canvas) self.setLayout(vbox) # Print help message print(self.help_message) # Draw on init self.on_draw()
def test_llist(): # Init idict = ltgu.set_llist('Strong') idict = ltgu.set_llist([1215.670*u.AA]) assert idict['List'] == 'input.lst'
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, 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, 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)
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)
spec = lsi.readspec(spec_fil) # Abs_sys abs_fil = '/Users/xavier/paper/LLS/Optical/Data/Analysis/MAGE/UM184_z2.930_id.fits' abs_sys = xiaa.GenericAbsSystem() abs_sys.parse_absid_file(abs_fil) # Launch app = QtGui.QApplication(sys.argv) app.setApplicationName('VelPlot') main = VelPlotWidget(spec, abs_sys=abs_sys) main.show() sys.exit(app.exec_()) # SelectedLines Widget if (flg_tst % 2**6) >= 2**5: print('Test: SelectedLines Widget') llist = ltgu.set_llist('ISM') # Launch app = QtGui.QApplication(sys.argv) app.setApplicationName('SelectedLines') main = SelectedLinesWidget(llist['ISM']) #._data) main.show() sys.exit(app.exec_()) # AODM Widget if (flg_tst % 2**7) >= 2**6: spec_fil = '/Users/xavier/PROGETTI/LLSZ3/data/normalize/UM184_nF.fits' spec = lsi.readspec(spec_fil) z = 2.96916 lines = np.array([1548.195, 1550.770]) * u.AA # Launch app = QtGui.QApplication(sys.argv)
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): 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. ''' # 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) # 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.dispersion.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.dispersion) # 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.dispersion,np.ones(len(spec.dispersion)))) 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.dispersion,np.ones(len(spec.dispersion)))) 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 test_llist(): # Init idict = ltgu.set_llist("Strong") idict = ltgu.set_llist([1215.670 * u.AA]) assert idict["List"] == "input.lst"