Пример #1
0
    def __init__(self,
                 ispec,
                 parent=None,
                 lls_fit_file=None,
                 outfil=None,
                 smooth=3.,
                 zqso=None):
        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
        '''

        # 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.all_forest = []
        self.flag_write = False

        # Spectrum
        spec, spec_fil = xxgu.read_spec(ispec)

        # Continuum
        self.conti_dict = xspc.init_conti_dict(
            Norm=float(np.median(spec.flux.value)),
            piv_wv=np.median(spec.dispersion.value),
            igm='True')
        if zqso is not None:
            self.zqso = zqso
            # Read Telfer and apply IGM
            tspec = xspc.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'] = 1025. * (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()

        # Full Model (LLS+continuum)
        self.full_model = XSpectrum1D.from_tuple(
            (spec.dispersion, np.ones(len(spec.dispersion))))
        self.smooth = smooth

        # LineList
        self.llist = xxgu.set_llist('Strong')
        self.llist['z'] = 0.
        self.plt_wv = zip(
            np.array([911.7, 972.5367, 1025.7222, 1215.6700]) * u.AA,
            ['LL', 'Lyg', 'Lyb', 'Lya'])

        # z and N boxes
        self.zwidget = xxgu.EditBox(-1., 'z_LLS=', '{:0.5f}')
        self.Nwidget = xxgu.EditBox(-1., 'NHI=', '{:0.2f}')
        self.bwidget = xxgu.EditBox(-1., 'b=', '{:0.1f}')
        self.Cwidget = xxgu.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 = xspw.ExamineSpecWidget(
            spec,
            status=self.statusBar,
            llist=self.llist,
            key_events=False,
            abs_sys=self.abssys_widg.abs_sys)
        self.spec_widg.continuum = self.continuum

        #if other_spec is not None:
        #    ospec, ospec_fil = xxgu.read_spec(other_spec)
        #    self.spec_widg.other_spec = ospec

        # Initial file
        if lls_fit_file is not None:
            self.init_LLS(lls_fit_file)

        # 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)
Пример #2
0
    def __init__(self, ispec, parent=None, lls_fit_file=None, 
        srch_id=True, outfil=None, fwhm=3., zqso=None,plot_residuals=True):
        QtGui.QMainWindow.__init__(self, parent)
        '''
        spec = Spectrum1D
        lls_fit_file: str, optional
          Name of the LLS fit file to input
        smooth: float, optional
          Number of pixels to smooth on
        zqso: float, optional
          Redshift of the quasar.  If input, a Telfer continuum is used
        plot_residuals : bool, optional
          Whether to plot residuals

        '''
        # TODO
        # 1. Fix convolve window size
            # 2. Avoid sorting of wavelengths
            # 3. Remove astropy.relativity 
            # 4. Display self.z 
            # 5. Recenter on 'z'
        # 6. Add COS LSF
            # 7. Refit component key 'F'
            # 8. Plot only selected components [DEPRECATED]
            # 9. Avoid shifting z of component outside its velocity range
            # 10. Write Component vlim to JSON
            # 11. Key to set line as some other transition (e.g. RMB in XSpec)
            # 12. Mask array with points
            # 13. Toggle line ID names
            # 14. Add error + residual arrays [NT]
        # 15. Adjust component redshift by keystroke
            # 16. Input redshift value via Widget
            # 17. Use Component list to jump between components (like 'S')

        # Build a widget combining several others
        self.main_widget = QtGui.QWidget()

        # Status bar
        self.create_status_bar()

        # Initialize
        if outfil is None:
            self.outfil = 'IGM_model.json'
        else:
            self.outfil = outfil
        self.fwhm = fwhm
        self.plot_residuals = plot_residuals

        # Spectrum
        spec, spec_fil = xxgu.read_spec(ispec)
        spec.mask = np.zeros(len(spec.dispersion),dtype=int)

        # Full Model 
        self.model = XSpectrum1D.from_tuple((
            spec.dispersion,np.ones(len(spec.dispersion))))

        # LineList (Grab ISM and HI as defaults)
        self.llist = xxgu.set_llist('ISM')
        # Load others
        self.llist['HI'] = LineList('HI')
        self.llist['Strong'] = LineList('Strong')
        self.llist['Lists'].append('HI')
        self.llist['HI']._data = self.llist['HI']._data[::-1] #invert order of Lyman series
        #self.llist['show_line'] = np.arange(10) #maximum 10 to show for Lyman series
        
        #define initial redshift
        z=0.0
        self.llist['z'] = z
        
        # Grab the pieces and tie together
        self.slines_widg = xspw.SelectedLinesWidget(
            self.llist[self.llist['List']], parent=self, 
            init_select='All')
        self.fiddle_widg = FiddleComponentWidget(parent=self)
        self.comps_widg = ComponentListWidget([], parent=self)
        self.velplot_widg = IGGVelPlotWidget(spec, z, 
            parent=self, llist=self.llist, fwhm=self.fwhm,plot_residuals=self.plot_residuals)
        self.wq_widg = xxgu.WriteQuitWidget(parent=self)
        

        # Setup strongest LineList
        self.llist['strongest'] = LineList('ISM')
        self.llist['Lists'].append('strongest')
        self.update_strongest_lines()
        self.slines_widg.selected = self.llist['show_line']
        self.slines_widg.on_list_change(
            self.llist[self.llist['List']])

        # 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)

        # Layout
        anly_widg = QtGui.QWidget()
        anly_widg.setMaximumWidth(400)
        anly_widg.setMinimumWidth(250)

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.fiddle_widg)
        vbox.addWidget(self.comps_widg)
        vbox.addWidget(self.slines_widg)
        vbox.addWidget(self.wq_widg)
        anly_widg.setLayout(vbox)
        
        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.velplot_widg)
        hbox.addWidget(anly_widg)

        self.main_widget.setLayout(hbox)

        # Point MainWindow
        self.setCentralWidget(self.main_widget)
Пример #3
0
    def __init__(self, ispec, parent=None, lls_fit_file=None, 
        outfil=None, smooth=3., zqso=None): 
        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
        '''

        # 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.all_forest = []
        self.flag_write = False

        # Spectrum
        spec, spec_fil = xxgu.read_spec(ispec)

        # Continuum
        self.conti_dict = xspc.init_conti_dict(
            Norm=float(np.median(spec.flux.value)),
            piv_wv=np.median(spec.dispersion.value),
            igm='True')
        if zqso is not None:
            self.zqso = zqso
            # Read Telfer and apply IGM
            tspec = xspc.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'] = 1025.*(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()

        # Full Model (LLS+continuum)
        self.full_model = XSpectrum1D.from_tuple((
            spec.dispersion,np.ones(len(spec.dispersion))))
        self.smooth = smooth

        # LineList
        self.llist = xxgu.set_llist('Strong') 
        self.llist['z'] = 0.
        self.plt_wv = zip(np.array([911.7,972.5367,1025.7222,1215.6700])*u.AA,
            ['LL','Lyg','Lyb','Lya'])

        # z and N boxes
        self.zwidget = xxgu.EditBox(-1., 'z_LLS=', '{:0.5f}')
        self.Nwidget = xxgu.EditBox(-1., 'NHI=', '{:0.2f}')
        self.bwidget = xxgu.EditBox(-1., 'b=', '{:0.1f}')
        self.Cwidget = xxgu.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 = xspw.ExamineSpecWidget(spec,status=self.statusBar,
                                                llist=self.llist, key_events=False,
                                                abs_sys=self.abssys_widg.abs_sys)
        self.spec_widg.continuum = self.continuum

        #if other_spec is not None:
        #    ospec, ospec_fil = xxgu.read_spec(other_spec)
        #    self.spec_widg.other_spec = ospec

        # Initial file
        if lls_fit_file is not None:
            self.init_LLS(lls_fit_file)

        # 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)
Пример #4
0
    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
        spec, spec_fil = xxgu.read_spec(ispec)

        # LineList
        self.llist = xxgu.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 = xxgu.EditBox(-1., 'z_LLS=', '{:0.5f}')
        self.Nwidget = xxgu.EditBox(-1., 'NHI=', '{:0.2f}')
        self.bwidget = xxgu.EditBox(-1., 'b=', '{:0.1f}')
        self.Cwidget = xxgu.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 = xspw.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 = xspc.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 = xspc.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)
Пример #5
0
    def __init__(self, ispec, z, parent=None, llist=None, norm=True,
                 vmnx=[-500., 500.]*u.km/u.s, fwhm=0.,plot_residuals=True):
        '''
        spec = Spectrum1D
        Norm: Bool (False)
          Normalized spectrum?
        abs_sys: AbsSystem
          Absorption system class
        '''
        super(IGGVelPlotWidget, self).__init__(parent)

        # Initialize
        self.parent = parent
        spec, spec_fil = xxgu.read_spec(ispec)
        
        self.spec = spec
        self.spec_fil = spec_fil
        self.fwhm = fwhm
        self.z = z
        self.vmnx = vmnx
        self.norm = norm
        # Init
        self.flag_add = False
        self.flag_idlbl = False
        self.flag_mask = False
        self.wrest = 0.
        self.avmnx = np.array([0.,0.])*u.km/u.s
        self.model = XSpectrum1D.from_tuple((
            spec.dispersion,np.ones(len(spec.dispersion))))

        self.plot_residuals = plot_residuals
        #Define arrays for plotting residuals
        if self.plot_residuals:
            self.residual_normalization_factor = 0.02/np.median(self.spec.sig)
            self.residual_limit = self.spec.sig * self.residual_normalization_factor
            self.residual = (self.spec.flux - self.model.flux) * self.residual_normalization_factor


        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'] = xxgu.navigate(0,0,init=True)

        

        # Status Bar?
        #if not status is None:
        #    self.statusBar = status

        # Line List
        if llist is None:
            self.llist = xxgu.set_llist(['HI 1215', 'HI 1025'])
        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 = [5,3]
        self.subxy_state = 'Out'

        self.fig.subplots_adjust(hspace=0.0, wspace=0.1,left=0.04,right=0.975)
        
        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.canvas)
        
        self.setLayout(vbox)

        # Draw on init
        self.on_draw()
Пример #6
0
    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
        spec, spec_fil = xxgu.read_spec(ispec)


        # LineList
        self.llist = xxgu.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 = xxgu.EditBox(-1., 'z_LLS=', '{:0.5f}')
        self.Nwidget = xxgu.EditBox(-1., 'NHI=', '{:0.2f}')
        self.bwidget = xxgu.EditBox(-1., 'b=', '{:0.1f}')
        self.Cwidget = xxgu.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 = xspw.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 = xspc.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 = xspc.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)
Пример #7
0
    def __init__(self, ispec, parent=None, lls_fit_file=None, 
        srch_id=True, outfil=None, fwhm=3., zqso=None):
        QtGui.QMainWindow.__init__(self, parent)
        '''
        spec = Spectrum1D
        lls_fit_file: str, optional
          Name of the LLS fit file to input
        smooth: float, optional
          Number of pixels to smooth on
        zqso: float, optional
          Redshift of the quasar.  If input, a Telfer continuum is used
        '''
        # TODO
        # 1. Fix convolve window size
            # 2. Avoid sorting of wavelengths
            # 3. Remove astropy.relativity 
            # 4. Display self.z 
            # 5. Recenter on 'z'
        # 6. Add COS LSF
            # 7. Refit component key 'F'
            # 8. Plot only selected components
            # 9. Avoid shifting z of component outside its velocity range
            # 10. Write Component vlim to JSON
            # 11. Key to set line as some other transition (e.g. RMB in XSpec)
            # 12. Mask array with points
            # 13. Toggle line ID names
        # 14. Add error + residual arrays [NT]
        # 15. Adjust component redshift by keystroke

        # Build a widget combining several others
        self.main_widget = QtGui.QWidget()

        # Status bar
        self.create_status_bar()

        # Initialize
        if outfil is None:
            self.outfil = 'IGM_model.json'
        else:
            self.outfil = outfil
        self.fwhm = fwhm

        # Spectrum
        spec, spec_fil = xxgu.read_spec(ispec)
        spec.mask = np.zeros(len(spec.dispersion),dtype=int)

        # Full Model 
        self.model = XSpectrum1D.from_tuple((
            spec.dispersion,np.ones(len(spec.dispersion))))

        # LineList
        self.llist = xxgu.set_llist(['HI 1215', 'HI 1025', 'CIV 1548'],sort=False)
        z=0.112
        self.llist['z'] = z

        # Grab the pieces and tie together
        self.fiddle_widg = FiddleComponentWidget(parent=self)
        self.comps_widg = ComponentListWidget([], parent=self,
            linelist=self.llist[self.llist['List']])
        self.velplot_widg = IGGVelPlotWidget(spec, z, 
            parent=self, llist=self.llist, fwhm=self.fwhm)
        self.wq_widg = xxgu.WriteQuitWidget(parent=self)
        self.slines_widg = xspw.SelectedLinesWidget(
            self.llist[self.llist['List']], parent=self, init_select='All')

        # 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)

        # Layout
        anly_widg = QtGui.QWidget()
        anly_widg.setMaximumWidth(400)
        anly_widg.setMinimumWidth(250)

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.fiddle_widg)
        vbox.addWidget(self.comps_widg)
        vbox.addWidget(self.slines_widg)
        vbox.addWidget(self.wq_widg)
        anly_widg.setLayout(vbox)
        
        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.velplot_widg)
        hbox.addWidget(anly_widg)

        self.main_widget.setLayout(hbox)

        # Point MainWindow
        self.setCentralWidget(self.main_widget)
Пример #8
0
    def __init__(self, ispec, parent=None, lls_fit_file=None, outfil=None, smooth=3.0, zqso=None):
        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
        zqso: float, optional
          Redshift of the quasar.  If input, a Telfer continuum is used
        """

        # 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.all_forest = []

        # Spectrum
        spec, spec_fil = xxgu.read_spec(ispec)

        # Continuum
        self.conti_dict = {
            "Norm": float(np.median(spec.flux.value)),
            "tilt": 0.0,
            "piv_wv": np.median(spec.dispersion.value),
        }
        if zqso is not None:
            # Read Telfer
            telfer = ascii.read(xa_path + "/data/quasar/telfer_hst_comp01_rq.ascii", comment="#")
            scale = telfer["flux"][(telfer["wrest"] == 1450.0)]
            tspec = XSpectrum1D.from_tuple((telfer["wrest"] * (1 + zqso), telfer["flux"] / scale[0]))  # Observer frame
            # Rebin
            self.continuum = tspec.rebin(spec.dispersion)
        else:
            self.continuum = XSpectrum1D.from_tuple((spec.dispersion, np.ones(len(spec.dispersion))))
        self.base_continuum = self.continuum.flux
        self.update_conti()

        # Full Model (LLS+continuum)
        self.full_model = XSpectrum1D.from_tuple((spec.dispersion, np.ones(len(spec.dispersion))))
        self.smooth = smooth

        # LineList
        self.llist = xxgu.set_llist("Strong")
        self.llist["z"] = 0.0

        # z and N boxes
        self.zwidget = xxgu.EditBox(-1.0, "z_LLS=", "{:0.5f}")
        self.Nwidget = xxgu.EditBox(-1.0, "NHI=", "{:0.2f}")
        self.bwidget = xxgu.EditBox(-1.0, "b=", "{:0.1f}")
        self.Cwidget = xxgu.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 = xspw.ExamineSpecWidget(
            spec, status=self.statusBar, llist=self.llist, key_events=False, abs_sys=self.abssys_widg.abs_sys
        )
        self.spec_widg.continuum = self.continuum

        # if other_spec is not None:
        #    ospec, ospec_fil = xxgu.read_spec(other_spec)
        #    self.spec_widg.other_spec = ospec

        # Initial file
        if lls_fit_file is not None:
            self.init_LLS(lls_fit_file)

        # 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)
Пример #9
0
    def __init__(self,
                 ispec,
                 parent=None,
                 lls_fit_file=None,
                 srch_id=True,
                 outfil=None,
                 fwhm=3.,
                 zqso=None):
        QtGui.QMainWindow.__init__(self, parent)
        '''
        spec = Spectrum1D
        lls_fit_file: str, optional
          Name of the LLS fit file to input
        smooth: float, optional
          Number of pixels to smooth on
        zqso: float, optional
          Redshift of the quasar.  If input, a Telfer continuum is used
        '''
        # TODO
        # 1. Fix convolve window size
        # 2. Avoid sorting of wavelengths
        # 3. Remove astropy.relativity
        # 4. Display self.z
        # 5. Recenter on 'z'
        # 6. Add COS LSF
        # 7. Refit component key 'F'
        # 8. Plot only selected components
        # 9. Avoid shifting z of component outside its velocity range
        # 10. Write Component vlim to JSON
        # 11. Key to set line as some other transition (e.g. RMB in XSpec)
        # 12. Mask array with points
        # 13. Toggle line ID names
        # 14. Add error + residual arrays [NT]
        # 15. Adjust component redshift by keystroke

        # Build a widget combining several others
        self.main_widget = QtGui.QWidget()

        # Status bar
        self.create_status_bar()

        # Initialize
        if outfil is None:
            self.outfil = 'IGM_model.json'
        else:
            self.outfil = outfil
        self.fwhm = fwhm

        # Spectrum
        spec, spec_fil = xxgu.read_spec(ispec)
        spec.mask = np.zeros(len(spec.dispersion), dtype=int)

        # Full Model
        self.model = XSpectrum1D.from_tuple(
            (spec.dispersion, np.ones(len(spec.dispersion))))

        # LineList
        self.llist = xxgu.set_llist(['HI 1215', 'HI 1025', 'CIV 1548'],
                                    sort=False)
        z = 0.112
        self.llist['z'] = z

        # Grab the pieces and tie together
        self.fiddle_widg = FiddleComponentWidget(parent=self)
        self.comps_widg = ComponentListWidget(
            [], parent=self, linelist=self.llist[self.llist['List']])
        self.velplot_widg = IGGVelPlotWidget(spec,
                                             z,
                                             parent=self,
                                             llist=self.llist,
                                             fwhm=self.fwhm)
        self.wq_widg = xxgu.WriteQuitWidget(parent=self)
        self.slines_widg = xspw.SelectedLinesWidget(
            self.llist[self.llist['List']], parent=self, init_select='All')

        # 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)

        # Layout
        anly_widg = QtGui.QWidget()
        anly_widg.setMaximumWidth(400)
        anly_widg.setMinimumWidth(250)

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.fiddle_widg)
        vbox.addWidget(self.comps_widg)
        vbox.addWidget(self.slines_widg)
        vbox.addWidget(self.wq_widg)
        anly_widg.setLayout(vbox)

        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.velplot_widg)
        hbox.addWidget(anly_widg)

        self.main_widget.setLayout(hbox)

        # Point MainWindow
        self.setCentralWidget(self.main_widget)
Пример #10
0
    def __init__(self,
                 ispec,
                 z,
                 parent=None,
                 llist=None,
                 norm=True,
                 vmnx=[-300., 300.] * u.km / u.s,
                 fwhm=0.):
        '''
        spec = Spectrum1D
        Norm: Bool (False)
          Normalized spectrum?
        abs_sys: AbsSystem
          Absorption system class
        '''
        super(IGGVelPlotWidget, self).__init__(parent)

        # Initialize
        self.parent = parent
        spec, spec_fil = xxgu.read_spec(ispec)

        self.spec = spec
        self.spec_fil = spec_fil
        self.fwhm = fwhm
        self.z = z
        self.vmnx = vmnx
        self.norm = norm
        # Init
        self.flag_add = False
        self.flag_idlbl = False
        self.flag_mask = False
        self.wrest = 0.
        self.avmnx = np.array([0., 0.]) * u.km / u.s
        self.model = XSpectrum1D.from_tuple(
            (spec.dispersion, np.ones(len(spec.dispersion))))

        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'] = xxgu.navigate(0, 0, init=True)

        # Status Bar?
        #if not status is None:
        #    self.statusBar = status

        # Line List
        if llist is None:
            self.llist = xxgu.set_llist(['HI 1215', 'HI 1025'])
        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()
Пример #11
0
    def __init__(self,
                 ispec,
                 parent=None,
                 lls_fit_file=None,
                 srch_id=True,
                 outfil=None,
                 smooth=3.):
        QtGui.QMainWindow.__init__(self, parent)
        '''
        spec = Spectrum1D
        lls_fit_file: str, optional
          Name of the LLS fit file to input
        smooth: float, optional
          Number of pixels to smooth on
        '''

        # 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.all_forest = []
        # Spectrum
        spec, spec_fil = xxgu.read_spec(ispec)
        # Continuum
        self.conti_dict = {
            'Norm': np.median(spec.flux),
            'tilt': 0.,
            'piv_wv': np.median(spec.dispersion.value)
        }
        self.continuum = XSpectrum1D.from_tuple(
            (spec.dispersion, np.ones(len(spec.dispersion))))
        self.base_continuum = self.continuum.flux
        self.update_conti()
        # Full Model (LLS+continuum)
        self.full_model = XSpectrum1D.from_tuple(
            (spec.dispersion, np.ones(len(spec.dispersion))))
        self.smooth = smooth

        # LineList
        self.llist = xxgu.set_llist('Strong')
        self.llist['z'] = 0.

        # z and N boxes
        self.zwidget = xxgu.EditBox(-1., 'z_LLS=', '{:0.5f}')
        self.Nwidget = xxgu.EditBox(-1., 'NHI=', '{:0.2f}')

        # 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 = xspw.ExamineSpecWidget(
            spec,
            status=self.statusBar,
            llist=self.llist,
            key_events=False,
            abs_sys=self.abssys_widg.abs_sys)
        self.spec_widg.continuum = self.continuum

        # Initial file
        if lls_fit_file is not None:
            self.init_LLS(lls_fit_file)

        # 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.setzN)
        self.connect(self.zwidget.box, QtCore.SIGNAL('editingFinished ()'),
                     self.setzN)

        # Layout
        anly_widg = QtGui.QWidget()
        anly_widg.setMaximumWidth(400)
        anly_widg.setMinimumWidth(200)

        # 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)
        zNwidg.setLayout(hbox2)
        #vbox.addWidget(self.pltline_widg)

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(zNwidg)
        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)
Пример #12
0
    def __init__(self, ispec, parent=None, lls_fit_file=None, 
        srch_id=True, outfil=None, smooth=3.):
        QtGui.QMainWindow.__init__(self, parent)
        '''
        spec = Spectrum1D
        lls_fit_file: str, optional
          Name of the LLS fit file to input
        smooth: float, optional
          Number of pixels to smooth on
        '''

        # 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.all_forest = []
        # Spectrum
        spec, spec_fil = xxgu.read_spec(ispec)
        # Continuum
        self.conti_dict = {'Norm': np.median(spec.flux), 'tilt': 0.,
            'piv_wv': np.median(spec.dispersion.value)}
        self.continuum = XSpectrum1D.from_tuple((
            spec.dispersion,np.ones(len(spec.dispersion))))
        self.base_continuum = self.continuum.flux
        self.update_conti()
        # Full Model (LLS+continuum)
        self.full_model = XSpectrum1D.from_tuple((
            spec.dispersion,np.ones(len(spec.dispersion))))
        self.smooth = smooth

        # LineList
        self.llist = xxgu.set_llist('Strong') 
        self.llist['z'] = 0.

        # z and N boxes
        self.zwidget = xxgu.EditBox(-1., 'z_LLS=', '{:0.5f}')
        self.Nwidget = xxgu.EditBox(-1., 'NHI=', '{:0.2f}')

        # 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 = xspw.ExamineSpecWidget(spec,status=self.statusBar,
                                                llist=self.llist, key_events=False,
                                                abs_sys=self.abssys_widg.abs_sys)
        self.spec_widg.continuum = self.continuum

        # Initial file
        if lls_fit_file is not None:
            self.init_LLS(lls_fit_file)

        # 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.setzN)
        self.connect(self.zwidget.box, 
            QtCore.SIGNAL('editingFinished ()'), self.setzN)

        # Layout
        anly_widg = QtGui.QWidget()
        anly_widg.setMaximumWidth(400)
        anly_widg.setMinimumWidth(200)

        # 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)
        zNwidg.setLayout(hbox2)
        #vbox.addWidget(self.pltline_widg)

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(zNwidg)
        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)