Пример #1
0
    def __init__(self,
                 inspec,
                 parent=None,
                 abssys_dir=None,
                 absid_list=None,
                 norm=True,
                 srch_id=True,
                 id_dir='ID_LINES/'):
        QtGui.QMainWindow.__init__(self, parent)
        '''
        spec = Spectrum1D
        second_file = Second spectrum file  (e.g. COS + STIS)
        '''
        # Build a widget combining several others
        self.main_widget = QtGui.QWidget()

        # Status bar
        self.create_status_bar()

        # Initialize
        if absid_list is None:
            # Automatically search for ID files
            if srch_id:
                absid_list = glob.glob(id_dir + '*id.fits')
            else:
                absid_list = []

        # Grab the pieces and tie together
        self.abssys_widg = xspw.AbsSysWidget(absid_list)
        self.pltline_widg = xspw.PlotLinesWidget(status=self.statusBar)
        self.spec_widg = xspw.ExamineSpecWidget(
            inspec,
            status=self.statusBar,
            llist=self.pltline_widg.llist,
            norm=norm,
            abs_sys=self.abssys_widg.abs_sys)
        self.pltline_widg.spec_widg = self.spec_widg

        # Connections
        self.spec_widg.canvas.mpl_connect('button_press_event', self.on_click)
        self.spec_widg.canvas.mpl_connect('key_press_event', self.on_key)
        self.abssys_widg.refine_button.clicked.connect(self.refine_abssys)

        # Layout
        anly_widg = QtGui.QWidget()
        anly_widg.setMaximumWidth(300)
        anly_widg.setMinimumWidth(150)
        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.pltline_widg)
        vbox.addWidget(self.abssys_widg)
        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, zsys=None, norm=None):
        QtGui.QMainWindow.__init__(self, parent)
        '''
        Parameters
        --------------
        spec = Spectrum1D or tuple of arrays
          Input spectrum.  If tuple then (wave,fx) or (wave,fx,sig)
        '''
        from linetools.lists.linelist import LineList
        #reload(xxgu)
        #reload(xspw)
        # INIT
        spec, _ = xxgu.read_spec(ispec)
        #xdb.set_trace()

        #
        mpl.rcParams[
            'agg.path.chunksize'] = 20000  # Needed to avoid carsh in large spectral files

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

        # Status bar
        self.create_status_bar()

        # Grab the pieces and tie together
        self.pltline_widg = xspw.PlotLinesWidget(status=self.statusBar,
                                                 init_z=zsys)
        self.pltline_widg.setMaximumWidth(300)

        # Hook the spec widget to Plot Line
        self.spec_widg = xspw.ExamineSpecWidget(spec,
                                                status=self.statusBar,
                                                llist=self.pltline_widg.llist,
                                                zsys=zsys,
                                                norm=norm)
        self.pltline_widg.spec_widg = self.spec_widg

        self.spec_widg.canvas.mpl_connect('button_press_event', self.on_click)

        extras = QtGui.QWidget()
        extras.setMaximumWidth(130)
        vbox = QtGui.QVBoxLayout()
        qbtn = QtGui.QPushButton('Quit', self)
        qbtn.clicked.connect(self.quit)
        vbox.addWidget(self.pltline_widg)
        vbox.addWidget(qbtn)
        extras.setLayout(vbox)

        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.spec_widg)
        hbox.addWidget(extras)

        self.main_widget.setLayout(hbox)

        # Point MainWindow
        self.setCentralWidget(self.main_widget)
Пример #3
0
    def __init__(self, spec, parent=None, zsys=None, norm=None):
        QtGui.QMainWindow.__init__(self, parent)
        '''
        spec = Spectrum1D
        '''
        mpl.rcParams['agg.path.chunksize'] = 20000 # Needed to avoid carsh in large spectral files
        
        # Build a widget combining several others
        self.main_widget = QtGui.QWidget()

        # Status bar
        self.create_status_bar()

        # Grab the pieces and tie together
        self.pltline_widg = xspw.PlotLinesWidget(status=self.statusBar, init_z=zsys)
        self.pltline_widg.setMaximumWidth(300)

        # Hook the spec widget to Plot Line
        self.spec_widg = xspw.ExamineSpecWidget(spec,status=self.statusBar,
                                                llist=self.pltline_widg.llist,
                                                zsys=zsys, norm=norm)
        self.pltline_widg.spec_widg = self.spec_widg

        self.spec_widg.canvas.mpl_connect('button_press_event', self.on_click)

        extras = QtGui.QWidget()
        extras.setMaximumWidth(130)
        vbox = QtGui.QVBoxLayout()
        qbtn = QtGui.QPushButton('Quit', self)
        qbtn.clicked.connect(self.quit)
        vbox.addWidget(self.pltline_widg)
        vbox.addWidget(qbtn)
        extras.setLayout(vbox)
        
        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.spec_widg)
        hbox.addWidget(extras)

        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):
        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)
Пример #5
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)
Пример #6
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)